@@ -63,28 +63,29 @@ type CandidateRegister struct {
6363 duration uint32
6464 autoStake bool
6565 payload []byte
66- pubKey []byte // BLS public key
66+ blsPubKey []byte
6767}
6868
6969func init () {
7070 var ok bool
71- _candidateRegisterMethod , ok = NativeStakingContractABI ().Methods ["candidateRegister" ]
71+ abi := NativeStakingContractABI ()
72+ _candidateRegisterMethod , ok = abi .Methods ["candidateRegister" ]
7273 if ! ok {
7374 panic ("fail to load the method" )
7475 }
75- _candidateRegisterWithBLSMethod , ok = NativeStakingContractABI () .Methods ["candidateRegisterWithBLS" ]
76+ _candidateRegisterWithBLSMethod , ok = abi .Methods ["candidateRegisterWithBLS" ]
7677 if ! ok {
7778 panic ("fail to load the method" )
7879 }
79- _candidateRegisteredEvent , ok = NativeStakingContractABI () .Events ["CandidateRegistered" ]
80+ _candidateRegisteredEvent , ok = abi .Events ["CandidateRegistered" ]
8081 if ! ok {
8182 panic ("fail to load the event" )
8283 }
83- _stakedEvent , ok = NativeStakingContractABI () .Events ["Staked" ]
84+ _stakedEvent , ok = abi .Events ["Staked" ]
8485 if ! ok {
8586 panic ("fail to load the event" )
8687 }
87- _candidateActivatedEvent , ok = NativeStakingContractABI () .Events ["CandidateActivated" ]
88+ _candidateActivatedEvent , ok = abi .Events ["CandidateActivated" ]
8889 if ! ok {
8990 panic ("fail to load the event" )
9091 }
@@ -137,19 +138,21 @@ func NewCandidateRegisterWithBLS(
137138 name , operatorAddrStr , rewardAddrStr , ownerAddrStr , amountStr string ,
138139 duration uint32 ,
139140 autoStake bool ,
141+ blsPubKey []byte ,
140142 payload []byte ,
141- pubKey []byte ,
142143) (* CandidateRegister , error ) {
143144 cr , err := NewCandidateRegister (name , operatorAddrStr , rewardAddrStr , ownerAddrStr , amountStr , duration , autoStake , payload )
144145 if err != nil {
145146 return nil , err
146147 }
147- _ , err = crypto .BLS12381PublicKeyFromBytes (pubKey )
148+ _ , err = crypto .BLS12381PublicKeyFromBytes (blsPubKey )
148149 if err != nil {
149150 return nil , errors .Wrap (err , "failed to parse BLS public key" )
150151 }
151- cr .pubKey = make ([]byte , len (pubKey ))
152- copy (cr .pubKey , pubKey )
152+ cr .value = cr .amount
153+ cr .amount = nil
154+ cr .blsPubKey = make ([]byte , len (blsPubKey ))
155+ copy (cr .blsPubKey , blsPubKey )
153156 return cr , nil
154157}
155158
@@ -189,12 +192,12 @@ func (cr *CandidateRegister) OwnerAddress() address.Address { return cr.ownerAdd
189192
190193// WithBLS returns true if the candidate register action is with BLS public key
191194func (cr * CandidateRegister ) WithBLS () bool {
192- return len (cr .pubKey ) > 0
195+ return len (cr .blsPubKey ) > 0
193196}
194197
195- // PubKey returns the BLS public key if the candidate register action is with BLS public key
196- func (cr * CandidateRegister ) PubKey () []byte {
197- return cr .pubKey
198+ // BLSPubKey returns the BLS public key if the candidate register action is with BLS public key
199+ func (cr * CandidateRegister ) BLSPubKey () []byte {
200+ return cr .blsPubKey
198201}
199202
200203// Serialize returns a raw byte stream of the CandidateRegister struct
@@ -229,8 +232,8 @@ func (cr *CandidateRegister) Proto() *iotextypes.CandidateRegister {
229232
230233 switch {
231234 case cr .WithBLS ():
232- act .Candidate .PubKey = make ([]byte , len (cr .pubKey ))
233- copy (act .Candidate .PubKey , cr .pubKey )
235+ act .Candidate .BlsPubKey = make ([]byte , len (cr .blsPubKey ))
236+ copy (act .Candidate .BlsPubKey , cr .blsPubKey )
234237 if cr .value != nil {
235238 act .StakedAmount = cr .value .String ()
236239 }
@@ -266,10 +269,10 @@ func (cr *CandidateRegister) LoadProto(pbAct *iotextypes.CandidateRegister) erro
266269 cr .duration = pbAct .GetStakedDuration ()
267270 cr .autoStake = pbAct .GetAutoStake ()
268271
269- withBLS := len (pbAct .Candidate .GetPubKey ()) > 0
272+ withBLS := len (pbAct .Candidate .GetBlsPubKey ()) > 0
270273 if withBLS {
271- cr .pubKey = make ([]byte , len (pbAct .Candidate .GetPubKey ()))
272- copy (cr .pubKey , pbAct .Candidate .GetPubKey ())
274+ cr .blsPubKey = make ([]byte , len (pbAct .Candidate .GetBlsPubKey ()))
275+ copy (cr .blsPubKey , pbAct .Candidate .GetBlsPubKey ())
273276 }
274277 if len (pbAct .GetStakedAmount ()) > 0 {
275278 amount , ok := new (big.Int ).SetString (pbAct .GetStakedAmount (), 10 )
@@ -335,15 +338,14 @@ func (cr *CandidateRegister) EthData() ([]byte, error) {
335338 common .BytesToAddress (cr .operatorAddress .Bytes ()),
336339 common .BytesToAddress (cr .rewardAddress .Bytes ()),
337340 common .BytesToAddress (cr .ownerAddress .Bytes ()),
338- cr .amount ,
339341 cr .duration ,
340342 cr .autoStake ,
341- cr .pubKey ,
343+ cr .blsPubKey ,
342344 cr .payload )
343345 if err != nil {
344346 return nil , err
345347 }
346- return append (_candidateRegisterMethod .ID , data ... ), nil
348+ return append (_candidateRegisterWithBLSMethod .ID , data ... ), nil
347349 default :
348350 data , err := _candidateRegisterMethod .Inputs .Pack (
349351 cr .name ,
@@ -368,13 +370,13 @@ func PackCandidateRegisteredEvent(
368370 ownerAddress address.Address ,
369371 name string ,
370372 rewardAddress address.Address ,
371- blsPublicKey []byte ,
373+ blsPubKey []byte ,
372374) (Topics , []byte , error ) {
373375 data , err := _candidateRegisteredEvent .Inputs .NonIndexed ().Pack (
374376 operatorAddress .Bytes (),
375377 name ,
376378 rewardAddress .Bytes (),
377- blsPublicKey ,
379+ blsPubKey ,
378380 )
379381 if err != nil {
380382 return nil , nil , errors .Wrap (err , "failed to pack CandidateRegisterWithBLS event" )
@@ -475,15 +477,15 @@ func NewCandidateRegisterFromABIBinary(data []byte, value *big.Int) (*CandidateR
475477 // specific fields parsing for methods
476478 if withBLS {
477479 if value != nil {
478- cr .value .Set (value )
480+ cr .value = new (big. Int ) .Set (value )
479481 }
480- if cr .pubKey , ok = paramsMap ["pubKey " ].([]byte ); ! ok {
481- return nil , errors .Wrapf (errDecodeFailure , "invalid pubKey %+v" , paramsMap ["pubKey " ])
482+ if cr .blsPubKey , ok = paramsMap ["blsPubKey " ].([]byte ); ! ok {
483+ return nil , errors .Wrapf (errDecodeFailure , "invalid pubKey %+v" , paramsMap ["blsPubKey " ])
482484 }
483- if len (cr .pubKey ) == 0 {
485+ if len (cr .blsPubKey ) == 0 {
484486 return nil , errors .Wrap (errDecodeFailure , "pubKey is empty" )
485487 }
486- _ , err := crypto .BLS12381PublicKeyFromBytes (cr .pubKey )
488+ _ , err := crypto .BLS12381PublicKeyFromBytes (cr .blsPubKey )
487489 if err != nil {
488490 return nil , errors .Wrap (err , "failed to parse BLS public key" )
489491 }
0 commit comments