-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
61 lines (51 loc) · 1.49 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"log"
"os"
"time"
eos "github.com/eoscanada/eos-go"
"github.com/eoscanada/eos-go/system"
)
// Define EOS_CLAIMER_KEY (with the private key that is allowed to
// call `eosio::claimrewards`)
//
// Define EOS_CLAIMER_PERMISSION if the permission of the
// EOS_CLAIMER_OWNER account is not `active` (because you linkauth'd
// the action to another permission.
//
// Define EOS_CLAIMER_OWNER which is your BP account.
//
// Define EOS_CLAIMER_URL to a reachable endpoint where to send
// transactions.
func main() {
if os.Getenv("EOS_CLAIMER_URL") == "" {
log.Fatalln("EOS_CLAIMER_URL not set: make sure you set all of the required env vars. See main.go for details.")
}
api := eos.New(os.Getenv("EOS_CLAIMER_URL"))
keyBag := eos.NewKeyBag()
for _, key := range []string{
os.Getenv("EOS_CLAIMER_KEY"),
} {
if err := keyBag.Add(key); err != nil {
log.Fatalln("Couldn't load private key specified by env var EOS_CLAIMER_KEY:", err)
}
}
api.SetSigner(keyBag)
act := system.NewClaimRewards(eos.AccountName(os.Getenv("EOS_CLAIMER_OWNER")))
if perm := os.Getenv("EOS_CLAIMER_PERMISSION"); perm != "" {
act.Authorization[0].Permission = eos.PermissionName(perm)
}
var sleep time.Duration
for {
time.Sleep(sleep)
sleep = 10 * time.Second
log.Println("Submitting claimrewards")
actionResp, err := api.SignPushActions(act)
if err != nil {
fmt.Println("ERROR sending claimrewards:", err)
} else {
fmt.Println("SUCCESSFUL RESP:", actionResp)
}
}
}