node: Add chain registration payload
Change-Id: I0c7d7a5c3d776c924e8ab54314b8b99ab2483a4f
This commit is contained in:
parent
75880ec74a
commit
6bbc1f7ad4
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue