|
@@ -1,13 +1,39 @@
|
|
|
package main
|
|
|
|
|
|
-var NET_HOST string
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "github.com/pkg/errors"
|
|
|
+ "github.com/sirupsen/logrus"
|
|
|
+ "math/rand"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
|
|
|
-func init() {
|
|
|
- if ENV == "dev" {
|
|
|
- NET_HOST = "https://localnet.eosget.io:443/"
|
|
|
- } else {
|
|
|
- NET_HOST = "https://proxy.eosnode.tools:443/"
|
|
|
+func Transfer(player string, starId int) error {
|
|
|
+
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
+ single := (rand.Intn(2) + 1) * 1000
|
|
|
+ total := toEOS(single * 10)
|
|
|
+ num := rand.Intn(23) + 75 // [75, 97]
|
|
|
+
|
|
|
+ cmd := fmt.Sprintf("cleos -u %s transfer %s supstargames \"%s\" \"dice|%d|10|%d|%d\" -p %s", NET_HOST, player, total, starId, num, single, player)
|
|
|
+
|
|
|
+ logrus.WithField("command", cmd).Infof("execute command")
|
|
|
+
|
|
|
+ _, errStr, err := ShellCmdTimeout(5, "/bin/sh", "-c", cmd)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
}
|
|
|
+
|
|
|
+ if len(errStr) > 0 && strings.Contains(errStr, "Error ") {
|
|
|
+ return errors.New(errStr)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func toEOS(num int) string {
|
|
|
+ return fmt.Sprintf("%.4f EOS", float64(num)/10000)
|
|
|
}
|
|
|
|
|
|
type Account struct {
|