/
params.go
59 lines (45 loc) · 1.38 KB
/
params.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 withdraw
import (
"bytes"
"fmt"
"math/big"
"github.com/0xPolygon/polygon-edge/command/helper"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/sidechain"
)
var (
addressToFlag = "to"
)
type withdrawParams struct {
accountDir string
accountConfig string
jsonRPC string
stakeManagerAddr string
addressTo string
amount string
amountValue *big.Int
}
func (v *withdrawParams) validateFlags() (err error) {
if v.amountValue, err = helper.ParseAmount(v.amount); err != nil {
return err
}
if _, err = helper.ParseJSONRPCAddress(v.jsonRPC); err != nil {
return fmt.Errorf("failed to parse json rpc address. Error: %w", err)
}
return sidechainHelper.ValidateSecretFlags(v.accountDir, v.accountConfig)
}
type withdrawResult struct {
ValidatorAddress string `json:"validatorAddress"`
Amount uint64 `json:"amount"`
WithdrawnTo string `json:"withdrawnTo"`
}
func (wr withdrawResult) GetOutput() string {
var buffer bytes.Buffer
buffer.WriteString("\n[WITHDRAWN AMOUNT]\n")
vals := make([]string, 0, 3)
vals = append(vals, fmt.Sprintf("Validator Address|%s", wr.ValidatorAddress))
vals = append(vals, fmt.Sprintf("Amount Withdrawn|%v", wr.Amount))
vals = append(vals, fmt.Sprintf("Withdrawn To|%s", wr.WithdrawnTo))
buffer.WriteString(helper.FormatKV(vals))
buffer.WriteString("\n")
return buffer.String()
}