add FundMe skeleton

pull/788/head
Minh Doan 6 years ago committed by Rongjian Lan
parent 44355edebe
commit 5eac1d2b06
  1. 36
      api/service/restclientsupport/service.go
  2. 2
      node/service_setup.go

@ -9,11 +9,16 @@ import (
"net/http" "net/http"
"strconv" "strconv"
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux" "github.com/gorilla/mux"
msg_pb "github.com/harmony-one/harmony/api/proto/message" msg_pb "github.com/harmony-one/harmony/api/proto/message"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
) )
/*
* This service is specific to support the lottery app.
*/
// Constants for rest client support service. // Constants for rest client support service.
const ( const (
Port = "30000" Port = "30000"
@ -34,11 +39,12 @@ func New(
CreateTransactionForEnterMethod func(int64, string) error, CreateTransactionForEnterMethod func(int64, string) error,
GetResult func(string) ([]string, []*big.Int), GetResult func(string) ([]string, []*big.Int),
CreateTransactionForPickWinner func() error, CreateTransactionForPickWinner func() error,
) *Service { CallFaucetContract func(common.Address) common.Hash) *Service {
return &Service{ return &Service{
CreateTransactionForEnterMethod: CreateTransactionForEnterMethod, CreateTransactionForEnterMethod: CreateTransactionForEnterMethod,
GetResult: GetResult, GetResult: GetResult,
CreateTransactionForPickWinner: CreateTransactionForPickWinner, CreateTransactionForPickWinner: CreateTransactionForPickWinner,
CallFaucetContract: CallFaucetContract,
} }
} }
@ -72,6 +78,10 @@ func (s *Service) Run() *http.Server {
s.router.Path("/result").Queries("key", "{[0-9A-Fa-fx]*?}").HandlerFunc(s.Result).Methods("GET") s.router.Path("/result").Queries("key", "{[0-9A-Fa-fx]*?}").HandlerFunc(s.Result).Methods("GET")
s.router.Path("/result").HandlerFunc(s.Result) s.router.Path("/result").HandlerFunc(s.Result)
// Set up router for tx.
s.router.Path("/fundme").Queries("key", "{[0-9A-Fa-fx]*?}").HandlerFunc(s.FundMe).Methods("GET")
s.router.Path("/fundme").HandlerFunc(s.FundMe)
// Set up router for tx. // Set up router for tx.
s.router.Path("/winner").HandlerFunc(s.Winner) s.router.Path("/winner").HandlerFunc(s.Winner)
@ -89,6 +99,30 @@ type Response struct {
Success bool `json:"success"` Success bool `json:"success"`
} }
// FundMe implements the GetFreeToken interface to request free token.
func (s *Service) FundMe(w http.ResponseWriter, r *http.Request) {
// (ctx context.Context, request *proto.GetFreeTokenRequest) (*proto.GetFreeTokenResponse, error) {
// var address common.Address
// address.SetBytes(request.Address)
// // log.Println("Returning GetFreeTokenResponse for address: ", address.Hex())
// return &proto.GetFreeTokenResponse{TxId: s.callFaucetContract(address).Bytes()}, nil
w.Header().Set("Content-Type", "application/json")
key := r.FormValue("key")
// TODO(RJ): implement the logic similar to get FreeToken with key.
// GetFreeToken implements the GetFreeToken interface to request free token.
// func (s *Server) GetFreeToken(ctx context.Context, request *proto.GetFreeTokenRequest) (*proto.GetFreeTokenResponse, error) {
// var address common.Address
// address.SetBytes(request.Address)
// // log.Println("Returning GetFreeTokenResponse for address: ", address.Hex())
// return &proto.GetFreeTokenResponse{TxId: s.callFaucetContract(address).Bytes()}, nil
// }
res := &Response{Success: false}
json.NewEncoder(w).Encode(res)
}
// Enter triggers enter method of smart contract. // Enter triggers enter method of smart contract.
func (s *Service) Enter(w http.ResponseWriter, r *http.Request) { func (s *Service) Enter(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")

@ -64,7 +64,7 @@ func (node *Node) setupForBeaconLeader() {
// Register client new support service. // Register client new support service.
// TODO(minhdoan): Also consider provide clientsupport/restclientsupport for other shards in the future. // TODO(minhdoan): Also consider provide clientsupport/restclientsupport for other shards in the future.
node.serviceManager.RegisterService(service.RestClientSupport, restclientsupport.New( node.serviceManager.RegisterService(service.RestClientSupport, restclientsupport.New(
node.CreateTransactionForEnterMethod, node.GetResult, node.CreateTransactionForPickWinner)) node.CreateTransactionForEnterMethod, node.GetResult, node.CreateTransactionForPickWinner, node.CallFaucetContract))
// Register randomness service // Register randomness service
node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand)) node.serviceManager.RegisterService(service.Randomness, randomness.New(node.DRand))
// Register explorer service. // Register explorer service.

Loading…
Cancel
Save