-
Notifications
You must be signed in to change notification settings - Fork 26
/
increase.go
87 lines (73 loc) · 1.77 KB
/
increase.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
77
78
79
80
81
82
83
84
85
86
87
/*
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"
"math/big"
"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/cess-go-sdk/core/pattern"
"github.com/CESSProject/p2p-go/out"
"github.com/spf13/cobra"
)
const increase_cmd = "increase"
var increaseCmd = &cobra.Command{
Use: increase_cmd + " <stakes amount>",
Short: "Increase the stakes of storage miner",
Run: Command_Increase_Runfunc,
DisableFlagsInUseLine: true,
}
func init() {
rootCmd.AddCommand(increaseCmd)
}
// Increase stakes
func Command_Increase_Runfunc(cmd *cobra.Command, args []string) {
var (
err error
n = node.New()
)
if len(os.Args) < 3 {
out.Err("Please enter the stakes amount")
os.Exit(1)
}
stakes, ok := new(big.Int).SetString(os.Args[2]+pattern.TokenPrecision_CESS, 10)
if !ok {
out.Err("Please enter the correct stakes amount")
os.Exit(1)
}
// Build profile instances
n.Confile, err = buildAuthenticationConfig(cmd)
if err != nil {
out.Err(err.Error())
os.Exit(1)
}
//Build client
n.SDK, err = cess.New(
context.Background(),
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.IncreaseStakingAmount(stakes)
if err != nil {
if txhash == "" {
out.Err(err.Error())
os.Exit(1)
}
out.Warn(txhash)
os.Exit(0)
}
out.Ok(txhash)
os.Exit(0)
}