-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_stake_info.go
79 lines (66 loc) · 1.78 KB
/
get_stake_info.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
package main
import (
"fmt"
"main/base"
"main/node_manager"
"math/big"
"strings"
)
type GetStakeInfoParser struct {
rawAction *RawAction
}
func (g *GetStakeInfoParser) ParseInput(input string) error {
param := &node_manager.GetStakeInfoParam{}
g.rawAction.Input = param
parts := strings.Split(input, ";")
if len(parts) != 2 {
err := fmt.Errorf("invalid format input[%s]", input)
return err
}
consensusHdAddress, err := parseAddress(parts[0])
if err != nil {
err = fmt.Errorf("parse consensusAddress failed, input: %s", input)
return err
}
param.ConsensusAddress = consensusHdAddress.ToAddress()
stakeHdAddress, err := parseAddress(parts[1])
if err != nil {
err = fmt.Errorf("parse stakeAddress failed, input: %s", input)
return err
}
param.StakeAddress = stakeHdAddress.ToAddress()
return nil
}
func (g *GetStakeInfoParser) ParseAssertion(input string) error {
if input == "nil" {
return nil
}
parts := strings.Split(input, ";")
field := parts[1]
assertType, err := formatAssertType(parts[0])
if err != nil {
return err
}
switch field {
case "Amount":
assertion := Assertion{}
assertion.AssertType = assertType
assertion.MethodName = base.MethodGetStakeInfo
fieldValues := make([]FieldValue, 0)
amount, ok := new(big.Int).SetString(parts[2], 10)
if !ok {
return fmt.Errorf("invalid assertion format: %s", parts[2])
}
amount = amount.Mul(amount, base.ZionPrecision)
amountDec := node_manager.NewDecFromBigInt(amount)
fieldValue := FieldValue{}
fieldValue.Field = field
fieldValue.Value = amountDec
fieldValues = append(fieldValues, fieldValue)
assertion.FieldValues = fieldValues
g.rawAction.Assertions = append(g.rawAction.Assertions, assertion)
default:
return fmt.Errorf("undefined assertion field: %s", field)
}
return nil
}