-
Notifications
You must be signed in to change notification settings - Fork 23
/
collect_reward.go
59 lines (49 loc) · 1.4 KB
/
collect_reward.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
package cmd
import (
"log"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var collectRewards = &cobra.Command{
Use: "collect-reward",
Short: "Collect accrued rewards for a stake pool.",
Long: "Collect accrued rewards for a stake pool.",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
flags := cmd.Flags()
var providerId string
var err error
if flags.Changed("provider_id") {
providerId, err = flags.GetString("provider_id")
if err != nil {
log.Fatal(err)
}
}
if !flags.Changed("provider_type") {
log.Fatal("missing tokens flag")
}
providerName, err := flags.GetString("provider_type")
if err != nil {
log.Fatal(err)
}
switch providerName {
case "blobber":
_, _, err = sdk.CollectRewards(providerId, sdk.ProviderBlobber)
case "validator":
_, _, err = sdk.CollectRewards(providerId, sdk.ProviderValidator)
default:
log.Fatal("provider type must be blobber or validator")
}
if err != nil {
log.Fatal("Error paying reward:", err)
}
log.Println("transferred reward tokens")
},
}
func init() {
rootCmd.AddCommand(collectRewards)
collectRewards.PersistentFlags().String("provider_type", "blobber", "provider type")
collectRewards.PersistentFlags().String("provider_id", "", "blobber or validator id")
collectRewards.MarkFlagRequired("provider_id")
collectRewards.MarkFlagRequired("provider_type")
}