Code review rework
This commit is contained in:
parent
5a0296f34e
commit
22eec880ec
|
@ -118,12 +118,16 @@ func adminGuardianSetUpdateToVAA(req *nodev1.GuardianSetUpdate, timestamp time.T
|
|||
addrs[i] = ethAddr
|
||||
}
|
||||
|
||||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex,
|
||||
vaa.BodyGuardianSetUpdate{
|
||||
Keys: addrs,
|
||||
NewIndex: guardianSetIndex + 1,
|
||||
}.Serialize())
|
||||
body, err := vaa.BodyGuardianSetUpdate{
|
||||
Keys: addrs,
|
||||
NewIndex: guardianSetIndex + 1,
|
||||
}.Serialize()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to serialize governance body: %w", err)
|
||||
}
|
||||
|
||||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, body)
|
||||
return v, nil
|
||||
}
|
||||
|
||||
|
@ -146,12 +150,16 @@ func adminContractUpgradeToVAA(req *nodev1.ContractUpgrade, timestamp time.Time,
|
|||
newContractAddress := vaa.Address{}
|
||||
copy(newContractAddress[:], b)
|
||||
|
||||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex,
|
||||
vaa.BodyContractUpgrade{
|
||||
ChainID: vaa.ChainID(req.ChainId),
|
||||
NewContract: newContractAddress,
|
||||
}.Serialize())
|
||||
body, err := vaa.BodyContractUpgrade{
|
||||
ChainID: vaa.ChainID(req.ChainId),
|
||||
NewContract: newContractAddress,
|
||||
}.Serialize()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to serialize governance body: %w", err)
|
||||
}
|
||||
|
||||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, body)
|
||||
return v, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
func (b BodyContractUpgrade) Serialize() []byte {
|
||||
func (b BodyContractUpgrade) Serialize() ([]byte, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
// Module
|
||||
|
@ -261,10 +261,10 @@ func (b BodyContractUpgrade) Serialize() []byte {
|
|||
|
||||
buf.Write(b.NewContract[:])
|
||||
|
||||
return buf.Bytes()
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (b BodyGuardianSetUpdate) Serialize() []byte {
|
||||
func (b BodyGuardianSetUpdate) Serialize() ([]byte, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
// Module
|
||||
|
@ -280,7 +280,7 @@ func (b BodyGuardianSetUpdate) Serialize() []byte {
|
|||
buf.Write(k[:])
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (r BodyTokenBridgeRegisterChain) Serialize() ([]byte, error) {
|
||||
|
@ -398,9 +398,10 @@ func (r BodyGatewayScheduleUpgrade) Serialize() ([]byte, error) {
|
|||
return serializeBridgeGovernanceVaa(GatewayModuleStr, ActionScheduleUpgrade, ChainIDWormchain, payload.Bytes())
|
||||
}
|
||||
|
||||
func (r *BodyGatewayScheduleUpgrade) Deserialize(bz []byte) {
|
||||
func (r *BodyGatewayScheduleUpgrade) Deserialize(bz []byte) error {
|
||||
r.Name = string(bz[0 : len(bz)-8])
|
||||
r.Height = binary.BigEndian.Uint64(bz[len(bz)-8:])
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r BodyCircleIntegrationUpdateWormholeFinality) Serialize() ([]byte, error) {
|
||||
|
|
|
@ -56,7 +56,8 @@ func TestBodyTokenBridgeUpgradeContract(t *testing.T) {
|
|||
func TestBodyContractUpgradeSerialize(t *testing.T) {
|
||||
bodyContractUpgrade := BodyContractUpgrade{ChainID: 1, NewContract: addr}
|
||||
expected := "00000000000000000000000000000000000000000000000000000000436f72650100010000000000000000000000000000000000000000000000000000000000000004"
|
||||
serializedBodyContractUpgrade := bodyContractUpgrade.Serialize()
|
||||
serializedBodyContractUpgrade, err := bodyContractUpgrade.Serialize()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, hex.EncodeToString(serializedBodyContractUpgrade))
|
||||
}
|
||||
|
||||
|
@ -67,7 +68,8 @@ func TestBodyGuardianSetUpdateSerialize(t *testing.T) {
|
|||
}
|
||||
bodyGuardianSetUpdate := BodyGuardianSetUpdate{Keys: keys, NewIndex: uint32(1)}
|
||||
expected := "00000000000000000000000000000000000000000000000000000000436f726502000000000001025aaeb6053f3e94c9b9a09f33669435e7ef1beaed5aaeb6053f3e94c9b9a09f33669435e7ef1beaee"
|
||||
serializedBodyGuardianSetUpdate := bodyGuardianSetUpdate.Serialize()
|
||||
serializedBodyGuardianSetUpdate, err := bodyGuardianSetUpdate.Serialize()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, expected, hex.EncodeToString(serializedBodyGuardianSetUpdate))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue