|
|
@ -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) error |
|
|
|
CreateTransactionForPlayMethod func(string) error |
|
|
|
CreateTransactionForPayoutMethod func(string, int) error |
|
|
|
CreateTransactionForPayoutMethod func(string, int, 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) error, |
|
|
|
CreateTransactionForPlayMethod func(string) error, |
|
|
|
CreateTransactionForPayoutMethod func(string, int) error) *Service { |
|
|
|
CreateTransactionForPayoutMethod func(string, int, 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("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) |
|
|
|
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) |
|
|
@ -268,8 +268,10 @@ func (s *Service) Play(w http.ResponseWriter, r *http.Request) { |
|
|
|
func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { |
|
|
|
func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { |
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
w.Header().Set("Content-Type", "application/json") |
|
|
|
key := r.FormValue("key") |
|
|
|
key := r.FormValue("key") |
|
|
|
newLevel := r.FormValue("new_level") |
|
|
|
newLevel := r.FormValue("level") |
|
|
|
fmt.Println("payout: key", key, "new_level", newLevel) |
|
|
|
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) |
|
|
|
newLevelInt, err := strconv.Atoi(newLevel) |
|
|
|
|
|
|
|
|
|
|
|
fmt.Println("play") |
|
|
|
fmt.Println("play") |
|
|
@ -282,7 +284,7 @@ func (s *Service) Payout(w http.ResponseWriter, r *http.Request) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err = s.CreateTransactionForPayoutMethod(key, newLevelInt); err != nil { |
|
|
|
if err = s.CreateTransactionForPayoutMethod(key, newLevelInt, sessionID, solutionSequence); err != nil { |
|
|
|
utils.GetLogInstance().Error("error", err) |
|
|
|
utils.GetLogInstance().Error("error", err) |
|
|
|
json.NewEncoder(w).Encode(res) |
|
|
|
json.NewEncoder(w).Encode(res) |
|
|
|
return |
|
|
|
return |
|
|
|