node/admin: better error handling and fix comments
This commit is contained in:
parent
e1c8bc8299
commit
2bc1d0ab3f
|
@ -578,23 +578,26 @@ func wormholeRelayerSetDefaultDeliveryProvider(req *nodev1.WormholeRelayerSetDef
|
|||
}
|
||||
|
||||
func evmCallToVaa(evmCall *nodev1.EvmCall, timestamp time.Time, guardianSetIndex, nonce uint32, sequence uint64) (*vaa.VAA, error) {
|
||||
var governanceContract [32]byte
|
||||
copy(governanceContract[:], ethcommon.HexToAddress(evmCall.GovernanceContract).Bytes())
|
||||
var targetContract [32]byte
|
||||
copy(targetContract[:], ethcommon.HexToAddress(evmCall.TargetContract).Bytes())
|
||||
governanceContract := ethcommon.HexToAddress(evmCall.GovernanceContract)
|
||||
targetContract := ethcommon.HexToAddress(evmCall.TargetContract)
|
||||
|
||||
payload, err := hex.DecodeString(evmCall.AbiEncodedCall)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode ABI encoded call: %w", err)
|
||||
}
|
||||
|
||||
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex,
|
||||
vaa.BodyGeneralPurposeGovernanceEvm{
|
||||
ChainID: vaa.ChainID(evmCall.ChainId),
|
||||
GovernanceContract: governanceContract,
|
||||
TargetContract: targetContract,
|
||||
Payload: payload,
|
||||
}.Serialize())
|
||||
body, err := vaa.BodyGeneralPurposeGovernanceEvm{
|
||||
ChainID: vaa.ChainID(evmCall.ChainId),
|
||||
GovernanceContract: governanceContract,
|
||||
TargetContract: targetContract,
|
||||
Payload: payload,
|
||||
}.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
|
||||
}
|
||||
|
|
|
@ -2922,6 +2922,7 @@ type EvmCall struct {
|
|||
GovernanceContract string `protobuf:"bytes,2,opt,name=governance_contract,json=governanceContract,proto3" json:"governance_contract,omitempty"`
|
||||
// Address of the governed contract (eth address starting with 0x)
|
||||
TargetContract string `protobuf:"bytes,3,opt,name=target_contract,json=targetContract,proto3" json:"target_contract,omitempty"`
|
||||
// ABI-encoded calldata to be passed on to the governed contract (hex encoded)
|
||||
AbiEncodedCall string `protobuf:"bytes,4,opt,name=abi_encoded_call,json=abiEncodedCall,proto3" json:"abi_encoded_call,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -2995,7 +2996,7 @@ type SolanaCall struct {
|
|||
ChainId uint32 `protobuf:"varint,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"`
|
||||
// Address of the governance contract (solana address)
|
||||
GovernanceContract string `protobuf:"bytes,2,opt,name=governance_contract,json=governanceContract,proto3" json:"governance_contract,omitempty"`
|
||||
// Address of the governed contract (eth address starting with 0x)
|
||||
// Encoded instruction data to be passed on to the governed contract (hex encoded)
|
||||
EncodedInstruction string `protobuf:"bytes,3,opt,name=encoded_instruction,json=encodedInstruction,proto3" json:"encoded_instruction,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -433,6 +433,7 @@ message EvmCall {
|
|||
// Address of the governed contract (eth address starting with 0x)
|
||||
string target_contract = 3;
|
||||
|
||||
// ABI-encoded calldata to be passed on to the governed contract (hex encoded)
|
||||
string abi_encoded_call = 4;
|
||||
}
|
||||
|
||||
|
@ -444,6 +445,6 @@ message SolanaCall {
|
|||
// Address of the governance contract (solana address)
|
||||
string governance_contract = 2;
|
||||
|
||||
// Address of the governed contract (eth address starting with 0x)
|
||||
// Encoded instruction data to be passed on to the governed contract (hex encoded)
|
||||
string encoded_instruction = 3;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
ethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/holiman/uint256"
|
||||
)
|
||||
|
||||
|
@ -118,7 +118,7 @@ type (
|
|||
|
||||
// BodyGuardianSetUpdate is a governance message to set a new guardian set
|
||||
BodyGuardianSetUpdate struct {
|
||||
Keys []common.Address
|
||||
Keys []ethcommon.Address
|
||||
NewIndex uint32
|
||||
}
|
||||
|
||||
|
@ -228,8 +228,8 @@ type (
|
|||
// BodyGeneralPurposeGovernanceEvm is a general purpose governance message for EVM chains
|
||||
BodyGeneralPurposeGovernanceEvm struct {
|
||||
ChainID ChainID
|
||||
GovernanceContract Address
|
||||
TargetContract Address
|
||||
GovernanceContract ethcommon.Address
|
||||
TargetContract ethcommon.Address
|
||||
Payload []byte
|
||||
}
|
||||
|
||||
|
@ -428,34 +428,18 @@ func (r BodyWormholeRelayerSetDefaultDeliveryProvider) Serialize() []byte {
|
|||
return serializeBridgeGovernanceVaa(WormholeRelayerModuleStr, WormholeRelayerSetDefaultDeliveryProvider, r.ChainID, payload.Bytes())
|
||||
}
|
||||
|
||||
func allZero(b []byte) bool {
|
||||
for _, v := range b {
|
||||
if v != 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r BodyGeneralPurposeGovernanceEvm) Serialize() []byte {
|
||||
func (r BodyGeneralPurposeGovernanceEvm) Serialize() ([]byte, error) {
|
||||
payload := &bytes.Buffer{}
|
||||
if !allZero(r.GovernanceContract[0:12]) {
|
||||
panic("governance contract address must be 0-padded")
|
||||
}
|
||||
payload.Write(r.GovernanceContract[:])
|
||||
payload.Write(r.TargetContract[:])
|
||||
|
||||
if !allZero(r.TargetContract[0:12]) {
|
||||
panic("target contract address must be 0-padded")
|
||||
}
|
||||
|
||||
payload.Write(r.GovernanceContract[12:])
|
||||
payload.Write(r.TargetContract[12:])
|
||||
// write payload len as uint16
|
||||
if len(r.Payload) > math.MaxUint16 {
|
||||
panic("payload too long")
|
||||
return nil, fmt.Errorf("payload too long; expected at most %d bytes", math.MaxUint16)
|
||||
}
|
||||
MustWrite(payload, binary.BigEndian, uint16(len(r.Payload)))
|
||||
payload.Write(r.Payload)
|
||||
return serializeBridgeGovernanceVaa(GeneralPurposeGovernanceModuleStr, GovernanceAction(1), r.ChainID, payload.Bytes())
|
||||
return serializeBridgeGovernanceVaa(GeneralPurposeGovernanceModuleStr, GovernanceAction(1), r.ChainID, payload.Bytes()), nil
|
||||
}
|
||||
|
||||
func (r BodyGeneralPurposeGovernanceSolana) Serialize() []byte {
|
||||
|
|
Loading…
Reference in New Issue