@@ -7,12 +7,15 @@ import (
7
7
"log"
8
8
"os"
9
9
"os/exec"
10
+ "regexp"
10
11
"os/signal"
11
12
"strconv"
12
13
"sync"
13
14
"syscall"
14
15
)
15
16
17
+ var blanceRegex = regexp .MustCompile (`balance: (\d+\.\d+)` )
18
+
16
19
type Cfg struct {
17
20
PactusWalletExecPath string `json:"pactus_wallet_exec_path"`
18
21
WalletPath string `json:"wallet_path"`
@@ -30,6 +33,8 @@ func main() {
30
33
cfgPath := flag .String ("config" , "./cfg.json" , "config file path" )
31
34
password := flag .String ("password" , "" , "pactus wallet password" )
32
35
rpc := flag .String ("server" , "" , "custom node rpc" )
36
+ total := flag .Bool ("total" , false , "determine that all balance of account will be staked" )
37
+
33
38
flag .Parse ()
34
39
35
40
b , err := os .ReadFile (* cfgPath )
@@ -45,6 +50,22 @@ func main() {
45
50
46
51
amount := strconv .FormatFloat (cfg .Amount , 'g' , - 1 , 64 )
47
52
53
+ if * total {
54
+ args := make ([]string , 0 )
55
+ args = append (args , "address" , "balance" , cfg .WalletAddress )
56
+ out , err := exec .Command (cfg .PactusWalletExecPath , args ... ).Output ()
57
+ if err != nil {
58
+ log .Fatalf ("err: %s, msg: %s" , err .Error (), string (out ))
59
+ }
60
+
61
+ match := blanceRegex .FindStringSubmatch (string (out ))
62
+ if len (match ) > 1 {
63
+ amount = match [1 ]
64
+ } else {
65
+ log .Fatalf ("err: can't find the address balance, msg: %s" , string (out ))
66
+ }
67
+ }
68
+
48
69
var wg sync.WaitGroup
49
70
ctx , cancel := context .WithCancel (context .Background ())
50
71
@@ -53,6 +74,7 @@ func main() {
53
74
os .Exit (0 )
54
75
}()
55
76
77
+
56
78
for _ , val := range cfg .Validators {
57
79
args := make ([]string , 0 )
58
80
args = append (args , "--path" , cfg .WalletPath , "tx" , "bond" )
0 commit comments