package main import ( "fmt" "github.com/pkg/errors" "github.com/sirupsen/logrus" "math/rand" "strings" "time" ) 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 { Player string `json:"player"` StarId int `json:"star_id"` }