-
Notifications
You must be signed in to change notification settings - Fork 17
/
validators.go
111 lines (100 loc) · 2.7 KB
/
validators.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package tlb
import (
"encoding/json"
"fmt"
)
// validator_info$_
//
// validator_list_hash_short:uint32
// catchain_seqno:uint32
// nx_cc_updated:Bool
//
// = ValidatorInfo;
type ValidatorInfo struct {
ValidatorListHashShort uint32
CatchainSeqno uint32
NxCcUpdated bool
}
// validator_base_info$_
//
// validator_list_hash_short:uint32
// catchain_seqno:uint32
//
// = ValidatorBaseInfo;
type ValidatorBaseInfo struct {
ValidatorListHashShort uint32
CatchainSeqno uint32
}
type ValidatorsSet struct {
SumType
// validators#11 utime_since:uint32 utime_until:uint32
// total:(## 16) main:(## 16) { main <= total } { main >= 1 }
// list:(Hashmap 16 ValidatorDescr) = ValidatorSet;
Validators *struct {
ValidatorSetsCommon
List Hashmap[Uint16, ValidatorDescr]
} `tlbSumType:"validators#11"`
// validators_ext#12 utime_since:uint32 utime_until:uint32
// total:(## 16) main:(## 16) { main <= total } { main >= 1 }
// total_weight:uint64 list:(HashmapE 16 ValidatorDescr) = ValidatorSet;
ValidatorsExt *struct {
ValidatorSetsCommon
TotalWeight uint64
List HashmapE[Uint16, ValidatorDescr]
} `tlbSumType:"validatorsext#12"`
}
type ValidatorSetsCommon struct {
UtimeSince uint32
UtimeUntil uint32
Total uint16
Main uint16
}
func (vs ValidatorsSet) Common() ValidatorSetsCommon {
if vs.SumType == "Validators" {
return vs.Validators.ValidatorSetsCommon
}
return vs.ValidatorsExt.ValidatorSetsCommon
}
type ValidatorDescr struct {
SumType
// validator#53 public_key:SigPubKey weight:uint64 = ValidatorDescr;
Validator *struct {
PublicKey SigPubKey
Weight uint64
} `tlbSumType:"validator#53"`
// validator_addr#73 public_key:SigPubKey weight:uint64 adnl_addr:bits256 = ValidatorDescr;
ValidatorAddr *struct {
PublicKey SigPubKey
Weight uint64
AdnlAddr Bits256
} `tlbSumType:"validatoraddr#73"`
}
func (vd ValidatorDescr) MarshalJSON() ([]byte, error) {
switch vd.SumType {
case "Validator":
bytes, err := json.Marshal(vd.Validator)
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"SumType": "Validator","Validator":%v}`, string(bytes))), nil
case "ValidatorAddr":
bytes, err := json.Marshal(vd.ValidatorAddr)
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf(`{"SumType": "ValidatorAddr","ValidatorAddr":%v}`, string(bytes))), nil
default:
return nil, fmt.Errorf("unknown sum type %v", vd.SumType)
}
}
func (vd ValidatorDescr) PubKey() Bits256 {
if vd.SumType == "Validator" {
return vd.Validator.PublicKey.PubKey
}
return vd.ValidatorAddr.PublicKey.PubKey
}
type SigPubKey struct {
Magic Magic `tlb:"pubkey#8e81278a"`
PubKey Bits256
}
//ed25519_pubkey#8e81278a pubkey:bits256 = SigPubKey;