55
66 "github.com/XinFinOrg/XDPoSChain/common"
77 "github.com/XinFinOrg/XDPoSChain/core/types"
8-
98 "github.com/XinFinOrg/XDPoSChain/crypto"
109)
1110
@@ -16,19 +15,19 @@ var (
1615 }
1716)
1817
19- func GetSigners ( statedb * StateDB , block * types.Block ) []common.Address {
18+ func ( s * StateDB ) GetSigners ( block * types.Block ) []common.Address {
2019 slot := slotBlockSignerMapping ["blockSigners" ]
2120 keys := []common.Hash {}
2221 keyArrSlot := GetLocMappingAtKey (block .Hash (), slot )
23- arrSlot := statedb .GetState (common .BlockSignersBinary , common .BigToHash (keyArrSlot ))
22+ arrSlot := s .GetState (common .BlockSignersBinary , common .BigToHash (keyArrSlot ))
2423 arrLength := arrSlot .Big ().Uint64 ()
25- for i := uint64 ( 0 ); i < arrLength ; i ++ {
24+ for i := range arrLength {
2625 key := GetLocDynamicArrAtElement (common .BigToHash (keyArrSlot ), i , 1 )
2726 keys = append (keys , key )
2827 }
2928 rets := []common.Address {}
3029 for _ , key := range keys {
31- ret := statedb .GetState (common .BlockSignersBinary , key )
30+ ret := s .GetState (common .BlockSignersBinary , key )
3231 rets = append (rets , common .HexToAddress (ret .Hex ()))
3332 }
3433
@@ -42,27 +41,27 @@ var (
4241 }
4342)
4443
45- func GetSecret ( statedb * StateDB , address common.Address ) [][32 ]byte {
44+ func ( s * StateDB ) GetSecret ( address common.Address ) [][32 ]byte {
4645 slot := slotRandomizeMapping ["randomSecret" ]
4746 locSecret := GetLocMappingAtKey (address .Hash (), slot )
48- arrLength := statedb .GetState (common .RandomizeSMCBinary , common .BigToHash (locSecret ))
47+ arrLength := s .GetState (common .RandomizeSMCBinary , common .BigToHash (locSecret ))
4948 keys := []common.Hash {}
5049 for i := uint64 (0 ); i < arrLength .Big ().Uint64 (); i ++ {
5150 key := GetLocDynamicArrAtElement (common .BigToHash (locSecret ), i , 1 )
5251 keys = append (keys , key )
5352 }
5453 rets := [][32 ]byte {}
5554 for _ , key := range keys {
56- ret := statedb .GetState (common .RandomizeSMCBinary , key )
55+ ret := s .GetState (common .RandomizeSMCBinary , key )
5756 rets = append (rets , ret )
5857 }
5958 return rets
6059}
6160
62- func GetOpening ( statedb * StateDB , address common.Address ) [32 ]byte {
61+ func ( s * StateDB ) GetOpening ( address common.Address ) [32 ]byte {
6362 slot := slotRandomizeMapping ["randomOpening" ]
6463 locOpening := GetLocMappingAtKey (address .Hash (), slot )
65- ret := statedb .GetState (common .RandomizeSMCBinary , common .BigToHash (locOpening ))
64+ ret := s .GetState (common .RandomizeSMCBinary , common .BigToHash (locOpening ))
6665 return ret
6766}
6867
@@ -89,16 +88,16 @@ var (
8988 }
9089)
9190
92- func GetCandidates ( statedb * StateDB ) []common.Address {
91+ func ( s * StateDB ) GetCandidates ( ) []common.Address {
9392 slot := slotValidatorMapping ["candidates" ]
9493 slotHash := common .BigToHash (new (big.Int ).SetUint64 (slot ))
95- arrLength := statedb .GetState (common .MasternodeVotingSMCBinary , slotHash )
94+ arrLength := s .GetState (common .MasternodeVotingSMCBinary , slotHash )
9695 count := arrLength .Big ().Uint64 ()
9796 rets := make ([]common.Address , 0 , count )
9897
99- for i := uint64 ( 0 ); i < count ; i ++ {
98+ for i := range count {
10099 key := GetLocDynamicArrAtElement (slotHash , i , 1 )
101- ret := statedb .GetState (common .MasternodeVotingSMCBinary , key )
100+ ret := s .GetState (common .MasternodeVotingSMCBinary , key )
102101 if ! ret .IsZero () {
103102 rets = append (rets , common .HexToAddress (ret .Hex ()))
104103 }
@@ -107,49 +106,49 @@ func GetCandidates(statedb *StateDB) []common.Address {
107106 return rets
108107}
109108
110- func GetCandidateOwner ( statedb * StateDB , candidate common.Address ) common.Address {
109+ func ( s * StateDB ) GetCandidateOwner ( candidate common.Address ) common.Address {
111110 slot := slotValidatorMapping ["validatorsState" ]
112111 // validatorsState[_candidate].owner;
113112 locValidatorsState := GetLocMappingAtKey (candidate .Hash (), slot )
114113 locCandidateOwner := locValidatorsState .Add (locValidatorsState , new (big.Int ).SetUint64 (uint64 (0 )))
115- ret := statedb .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locCandidateOwner ))
114+ ret := s .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locCandidateOwner ))
116115 return common .HexToAddress (ret .Hex ())
117116}
118117
119- func GetCandidateCap ( statedb * StateDB , candidate common.Address ) * big.Int {
118+ func ( s * StateDB ) GetCandidateCap ( candidate common.Address ) * big.Int {
120119 slot := slotValidatorMapping ["validatorsState" ]
121120 // validatorsState[_candidate].cap;
122121 locValidatorsState := GetLocMappingAtKey (candidate .Hash (), slot )
123122 locCandidateCap := locValidatorsState .Add (locValidatorsState , new (big.Int ).SetUint64 (uint64 (1 )))
124- ret := statedb .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locCandidateCap ))
123+ ret := s .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locCandidateCap ))
125124 return ret .Big ()
126125}
127126
128- func GetVoters ( statedb * StateDB , candidate common.Address ) []common.Address {
127+ func ( s * StateDB ) GetVoters ( candidate common.Address ) []common.Address {
129128 //mapping(address => address[]) voters;
130129 slot := slotValidatorMapping ["voters" ]
131130 locVoters := GetLocMappingAtKey (candidate .Hash (), slot )
132- arrLength := statedb .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locVoters ))
131+ arrLength := s .GetState (common .MasternodeVotingSMCBinary , common .BigToHash (locVoters ))
133132 keys := []common.Hash {}
134133 for i := uint64 (0 ); i < arrLength .Big ().Uint64 (); i ++ {
135134 key := GetLocDynamicArrAtElement (common .BigToHash (locVoters ), i , 1 )
136135 keys = append (keys , key )
137136 }
138137 rets := []common.Address {}
139138 for _ , key := range keys {
140- ret := statedb .GetState (common .MasternodeVotingSMCBinary , key )
139+ ret := s .GetState (common .MasternodeVotingSMCBinary , key )
141140 rets = append (rets , common .HexToAddress (ret .Hex ()))
142141 }
143142
144143 return rets
145144}
146145
147- func GetVoterCap ( statedb * StateDB , candidate , voter common.Address ) * big.Int {
146+ func ( s * StateDB ) GetVoterCap ( candidate , voter common.Address ) * big.Int {
148147 slot := slotValidatorMapping ["validatorsState" ]
149148 locValidatorsState := GetLocMappingAtKey (candidate .Hash (), slot )
150149 locCandidateVoters := locValidatorsState .Add (locValidatorsState , new (big.Int ).SetUint64 (uint64 (2 )))
151150 retByte := crypto .Keccak256 (voter .Hash ().Bytes (), common .BigToHash (locCandidateVoters ).Bytes ())
152- ret := statedb .GetState (common .MasternodeVotingSMCBinary , common .BytesToHash (retByte ))
151+ ret := s .GetState (common .MasternodeVotingSMCBinary , common .BytesToHash (retByte ))
153152 return ret .Big ()
154153}
155154
@@ -158,29 +157,29 @@ var (
158157 slotMintedRecordLastEpochNum uint64 = 1
159158)
160159
161- func GetTotalMinted ( statedb * StateDB ) common.Hash {
160+ func ( s * StateDB ) GetTotalMinted ( ) common.Hash {
162161 hash := GetLocSimpleVariable (slotMintedRecordTotalMinted )
163- totalMinted := statedb .GetState (common .MintedRecordAddressBinary , hash )
162+ totalMinted := s .GetState (common .MintedRecordAddressBinary , hash )
164163 return totalMinted
165164}
166165
167- func PutTotalMinted ( statedb * StateDB , value common.Hash ) {
166+ func ( s * StateDB ) PutTotalMinted ( value common.Hash ) {
168167 hash := GetLocSimpleVariable (slotMintedRecordTotalMinted )
169- statedb .SetState (common .MintedRecordAddressBinary , hash , value )
168+ s .SetState (common .MintedRecordAddressBinary , hash , value )
170169}
171170
172- func GetLastEpochNum ( statedb * StateDB ) common.Hash {
171+ func ( s * StateDB ) GetLastEpochNum ( ) common.Hash {
173172 hash := GetLocSimpleVariable (slotMintedRecordLastEpochNum )
174- totalMinted := statedb .GetState (common .MintedRecordAddressBinary , hash )
173+ totalMinted := s .GetState (common .MintedRecordAddressBinary , hash )
175174 return totalMinted
176175}
177176
178- func PutLastEpochNum ( statedb * StateDB , value common.Hash ) {
177+ func ( s * StateDB ) PutLastEpochNum ( value common.Hash ) {
179178 hash := GetLocSimpleVariable (slotMintedRecordLastEpochNum )
180- statedb .SetState (common .MintedRecordAddressBinary , hash , value )
179+ s .SetState (common .MintedRecordAddressBinary , hash , value )
181180}
182181
183- func IncrementMintedRecordNonce ( statedb * StateDB ) {
184- nonce := statedb .GetNonce (common .MintedRecordAddressBinary )
185- statedb .SetNonce (common .MintedRecordAddressBinary , nonce + 1 )
182+ func ( s * StateDB ) IncrementMintedRecordNonce ( ) {
183+ nonce := s .GetNonce (common .MintedRecordAddressBinary )
184+ s .SetNonce (common .MintedRecordAddressBinary , nonce + 1 )
186185}
0 commit comments