diff --git a/node/pkg/vaa/payloads.go b/node/pkg/vaa/payloads.go index 495b7aed..3b85cefd 100644 --- a/node/pkg/vaa/payloads.go +++ b/node/pkg/vaa/payloads.go @@ -21,6 +21,13 @@ type ( Keys []common.Address NewIndex uint32 } + + // BodyRegisterChain is a governance message to register a chain on the token bridge + BodyRegisterChain struct { + Header [32]byte + ChainID ChainID + EmitterAddress Address + } ) func (b BodyContractUpgrade) Serialize() []byte { @@ -56,3 +63,20 @@ func (b BodyGuardianSetUpdate) Serialize() []byte { return buf.Bytes() } + +func (r BodyRegisterChain) Serialize() []byte { + buf := &bytes.Buffer{} + + // Write token bridge header + buf.Write(r.Header[:]) + // Write action ID + MustWrite(buf, binary.BigEndian, uint8(1)) + // Write target chain (0 = universal) + MustWrite(buf, binary.BigEndian, uint16(0)) + // Write chain to be registered + MustWrite(buf, binary.BigEndian, r.ChainID) + // Write emitter address of chain to be registered + buf.Write(r.EmitterAddress[:]) + + return buf.Bytes() +} diff --git a/node/pkg/vaa/types_test.go b/node/pkg/vaa/types_test.go index 4b91b942..7d70ddc6 100644 --- a/node/pkg/vaa/types_test.go +++ b/node/pkg/vaa/types_test.go @@ -85,3 +85,19 @@ func TestVerifySignature(t *testing.T) { addr, })) } + +func TestBodyRegisterChain_Serialize(t *testing.T) { + header, _ := hex.DecodeString("000000000000000000000000000000000000000000546f6b656e427269646765") + require.Len(t, header, 32) + + var headerB [32]byte + copy(headerB[:], header) + msg := &BodyRegisterChain{ + Header: headerB, + ChainID: 8, + EmitterAddress: Address{1, 2, 3, 4}, + } + + data := msg.Serialize() + require.Equal(t, "000000000000000000000000000000000000000000546f6b656e42726964676501000000080102030400000000000000000000000000000000000000000000000000000000", hex.EncodeToString(data)) +}