/
claim.go
76 lines (64 loc) · 1.43 KB
/
claim.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Copyright (C) CESS. All rights reserved.
Copyright (C) Cumulus Encrypted Storage System. All rights reserved.
SPDX-License-Identifier: Apache-2.0
*/
package console
import (
"context"
"os"
"github.com/CESSProject/cess-bucket/configs"
"github.com/CESSProject/cess-bucket/node"
cess "github.com/CESSProject/cess-go-sdk"
"github.com/CESSProject/cess-go-sdk/config"
"github.com/CESSProject/p2p-go/out"
"github.com/spf13/cobra"
)
const (
claim_cmd = "claim"
claim_cmd_use = "claim"
claim_cmd_short = "claim reward"
)
var claimCmd = &cobra.Command{
Use: claim_cmd_use,
Short: claim_cmd_short,
Run: Command_Claim_Runfunc,
DisableFlagsInUseLine: true,
}
func init() {
rootCmd.AddCommand(claimCmd)
}
// Exit
func Command_Claim_Runfunc(cmd *cobra.Command, args []string) {
var (
err error
n = node.NewEmptyNode()
)
n.Confile, err = buildAuthenticationConfig(cmd)
if err != nil {
out.Err(err.Error())
os.Exit(1)
}
n.SDK, err = cess.New(
context.Background(),
cess.Name(config.CharacterName_Bucket),
cess.ConnectRpcAddrs(n.GetRpcAddr()),
cess.Mnemonic(n.GetMnemonic()),
cess.TransactionTimeout(configs.TimeToWaitEvent),
)
if err != nil {
out.Err(err.Error())
os.Exit(1)
}
txhash, err := n.ClaimRewards()
if err != nil {
if txhash == "" {
out.Err(err.Error())
os.Exit(1)
}
out.Warn(txhash)
os.Exit(0)
}
out.Ok(txhash)
os.Exit(0)
}