diff --git a/api/service/restclientsupport/service.go b/api/service/restclientsupport/service.go index a30b4bb55..275884b9f 100644 --- a/api/service/restclientsupport/service.go +++ b/api/service/restclientsupport/service.go @@ -36,7 +36,7 @@ type Service struct { CallFaucetContract func(common.Address) common.Hash GetAccountBalance func(common.Address) (*big.Int, error) CreateTransactionForPlayMethod func(string) error - CreateTransactionForPayoutMethod func(string, int) error + CreateTransactionForPayoutMethod func(string, int, int, string) error } // New returns new client support service. @@ -46,7 +46,7 @@ func New( CreateTransactionForPickWinner func() error, CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error), CreateTransactionForPlayMethod func(string) error, - CreateTransactionForPayoutMethod func(string, int) error) *Service { + CreateTransactionForPayoutMethod func(string, int, int, string) error) *Service { return &Service{ CreateTransactionForEnterMethod: CreateTransactionForEnterMethod, GetResult: GetResult, @@ -104,7 +104,7 @@ func (s *Service) Run() *http.Server { s.router.Path("/play").HandlerFunc(s.Play) // Set up router for payout. - s.router.Path("/payout").Queries("key", "{[0-9A-Fa-fx]*?}", "new_level", "{[0-9]*?}").HandlerFunc(s.Payout).Methods("GET") + s.router.Path("/payout").Queries("key", "{[0-9A-Fa-fx]*?}", "new_level", "{[0-9]*?}", "txid", "{[0-9]*?}", "sequence", "{[A-Za-z]*?}").HandlerFunc(s.Payout).Methods("GET") s.router.Path("/payout").HandlerFunc(s.Payout) // Do serving now. utils.GetLogInstance().Info("Listening on ", "port: ", Port) @@ -268,8 +268,10 @@ func (s *Service) Play(w http.ResponseWriter, r *http.Request) { func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") key := r.FormValue("key") - newLevel := r.FormValue("new_level") - fmt.Println("payout: key", key, "new_level", newLevel) + newLevel := r.FormValue("level") + sessionID = r.FormValue("txid") + solutionSequence = r.FormValue("sequence") + fmt.Println("payout: key", key, "level", newLevel, "session", sessionID, "solution sequence", solutionSequence) newLevelInt, err := strconv.Atoi(newLevel) fmt.Println("play") @@ -282,7 +284,7 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { return } - if err = s.CreateTransactionForPayoutMethod(key, newLevelInt); err != nil { + if err = s.CreateTransactionForPayoutMethod(key, newLevelInt, sessionID, solutionSequence); err != nil { utils.GetLogInstance().Error("error", err) json.NewEncoder(w).Encode(res) return diff --git a/node/puzzle_contract.go b/node/puzzle_contract.go index 839019ae1..ee162defd 100644 --- a/node/puzzle_contract.go +++ b/node/puzzle_contract.go @@ -22,8 +22,8 @@ const ( Payout = "payout" ) -// OneEther represents one ether. -var OneEther = big.NewInt(params.Ether) +// GameStake represents one ether. +var GameStake = 2 * big.NewInt(params.Ether) // AddPuzzleContract adds the demo puzzle contract the genesis block. func (node *Node) AddPuzzleContract() { @@ -72,7 +72,7 @@ func (node *Node) CreateTransactionForPlayMethod(priKey string) error { if err != nil { utils.GetLogInstance().Error("puzzle-play: can not get address", "error", err) return err - } else if balance.Cmp(OneEther) == -1 { + } else if balance.Cmp(GameStake) == -1 { utils.GetLogInstance().Error("puzzle-play: insufficient fund", "error", err) return ErrPuzzleInsufficientFund } @@ -81,7 +81,7 @@ func (node *Node) CreateTransactionForPlayMethod(priKey string) error { nonce, toAddress, 0, - OneEther, + GameStake, params.TxGas*10, nil, bytesData, @@ -100,7 +100,7 @@ func (node *Node) CreateTransactionForPlayMethod(priKey string) error { } // CreateTransactionForPayoutMethod generates transaction for payout method and add it into pending tx list. -func (node *Node) CreateTransactionForPayoutMethod(address string, newLevel int) error { +func (node *Node) CreateTransactionForPayoutMethod(address string, newLevel int, session int, sequence string) error { var err error toAddress := node.PuzzleContractAddress @@ -109,9 +109,7 @@ func (node *Node) CreateTransactionForPayoutMethod(address string, newLevel int) utils.GetLogInstance().Error("Failed to generate staking contract's ABI", "error", err) return err } - // add params for address payable player, uint8 new_level - // TODO(minh, rj) - bytesData, err := abi.Pack(Payout) + bytesData, err := abi.Pack("payout", address, newLevel, session, sequence) if err != nil { utils.GetLogInstance().Error("Failed to generate ABI function bytes data", "error", err) return err