merge conflict

pull/806/head
Rongjian Lan 6 years ago
commit a386ad3fe3
  1. 3
      api/service/restclientsupport/puzzle_service.go
  2. 6
      api/service/restclientsupport/service.go
  3. 8
      node/puzzle_contract.go

@ -47,6 +47,7 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
address := r.FormValue("address") address := r.FormValue("address")
newLevel := r.FormValue("new_level") newLevel := r.FormValue("new_level")
sequence := r.FormValue("sequence")
newLevelInt, err := strconv.Atoi(newLevel) newLevelInt, err := strconv.Atoi(newLevel)
fmt.Println("Payout: address", address, "new_level", newLevelInt) fmt.Println("Payout: address", address, "new_level", newLevelInt)
@ -59,7 +60,7 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) {
return return
} }
if err = s.CreateTransactionForPayoutMethod(common.HexToAddress(address), uint8(newLevelInt), "" /* place holder for steps*/); err != nil { if err = s.CreateTransactionForPayoutMethod(common.HexToAddress(address), newLevelInt, sequence); err != nil {
utils.GetLogInstance().Error("Payout error", err) utils.GetLogInstance().Error("Payout error", err)
json.NewEncoder(w).Encode(res) json.NewEncoder(w).Encode(res)
return return

@ -36,7 +36,7 @@ type Service struct {
CallFaucetContract func(common.Address) common.Hash CallFaucetContract func(common.Address) common.Hash
GetAccountBalance func(common.Address) (*big.Int, error) GetAccountBalance func(common.Address) (*big.Int, error)
CreateTransactionForPlayMethod func(string, int64) error CreateTransactionForPlayMethod func(string, int64) error
CreateTransactionForPayoutMethod func(common.Address, uint8, string) error CreateTransactionForPayoutMethod func(common.Address, int, string) error
} }
// New returns new client support service. // New returns new client support service.
@ -46,7 +46,7 @@ func New(
CreateTransactionForPickWinner func() error, CreateTransactionForPickWinner func() error,
CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error), CallFaucetContract func(common.Address) common.Hash, GetAccountBalance func(common.Address) (*big.Int, error),
CreateTransactionForPlayMethod func(string, int64) error, CreateTransactionForPlayMethod func(string, int64) error,
CreateTransactionForPayoutMethod func(common.Address, uint8, string) error) *Service { CreateTransactionForPayoutMethod func(common.Address, int, string) error) *Service {
return &Service{ return &Service{
CreateTransactionForEnterMethod: CreateTransactionForEnterMethod, CreateTransactionForEnterMethod: CreateTransactionForEnterMethod,
GetResult: GetResult, GetResult: GetResult,
@ -104,7 +104,7 @@ func (s *Service) Run() *http.Server {
s.router.Path("/play").HandlerFunc(s.Play) s.router.Path("/play").HandlerFunc(s.Play)
// Set up router for payout. // Set up router for payout.
s.router.Path("/payout").Queries("address", "{[0-9A-Fa-fx]*?}", "new_level", "{[0-9]*?}").HandlerFunc(s.Payout).Methods("GET") s.router.Path("/payout").Queries("address", "{[0-9A-Fa-fx]*?}", "level", "{[0-9]*?}", "sequence", "{[A-Za-z]*?}").HandlerFunc(s.Payout).Methods("GET")
s.router.Path("/payout").HandlerFunc(s.Payout) s.router.Path("/payout").HandlerFunc(s.Payout)
// Do serving now. // Do serving now.
utils.GetLogInstance().Info("Listening on ", "port: ", Port) utils.GetLogInstance().Info("Listening on ", "port: ", Port)

@ -22,7 +22,6 @@ const (
Payout = "payout" Payout = "payout"
) )
// OneEther represents one ether.
var OneEther = big.NewInt(params.Ether) var OneEther = big.NewInt(params.Ether)
// AddPuzzleContract adds the demo puzzle contract the genesis block. // AddPuzzleContract adds the demo puzzle contract the genesis block.
@ -54,7 +53,6 @@ func (node *Node) AddPuzzleContract() {
func (node *Node) CreateTransactionForPlayMethod(priKey string, amount int64) error { func (node *Node) CreateTransactionForPlayMethod(priKey string, amount int64) error {
var err error var err error
toAddress := node.PuzzleContractAddress toAddress := node.PuzzleContractAddress
abi, err := abi.JSON(strings.NewReader(contracts.PuzzleABI)) abi, err := abi.JSON(strings.NewReader(contracts.PuzzleABI))
if err != nil { if err != nil {
utils.GetLogInstance().Error("puzzle-play: Failed to generate staking contract's ABI", "error", err) utils.GetLogInstance().Error("puzzle-play: Failed to generate staking contract's ABI", "error", err)
@ -85,7 +83,7 @@ func (node *Node) CreateTransactionForPlayMethod(priKey string, amount int64) er
toAddress, toAddress,
node.NodeConfig.ShardID, node.NodeConfig.ShardID,
Stake, Stake,
params.TxGas*10, params.TxGas*100,
nil, nil,
bytesData, bytesData,
) )
@ -103,7 +101,7 @@ func (node *Node) CreateTransactionForPlayMethod(priKey string, amount int64) er
} }
// CreateTransactionForPayoutMethod generates transaction for payout method and add it into pending tx list. // CreateTransactionForPayoutMethod generates transaction for payout method and add it into pending tx list.
func (node *Node) CreateTransactionForPayoutMethod(address common.Address, newLevel uint8, steps string) error { func (node *Node) CreateTransactionForPayoutMethod(address common.Address, level int, sequence string) error {
var err error var err error
toAddress := node.PuzzleContractAddress toAddress := node.PuzzleContractAddress
@ -114,7 +112,7 @@ func (node *Node) CreateTransactionForPayoutMethod(address common.Address, newLe
} }
// add params for address payable player, uint8 new_level, steps string // add params for address payable player, uint8 new_level, steps string
fmt.Println("Payout: address", address) fmt.Println("Payout: address", address)
bytesData, err := abi.Pack(Payout, address, big.NewInt(int64(newLevel)), steps) bytesData, err := abi.Pack(Payout, address, big.NewInt(int64(level)), sequence)
if err != nil { if err != nil {
utils.GetLogInstance().Error("Failed to generate ABI function bytes data", "error", err) utils.GetLogInstance().Error("Failed to generate ABI function bytes data", "error", err)
return err return err

Loading…
Cancel
Save