2021-06-29 04:55:44 -07:00
|
|
|
package vaa
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
2022-06-21 12:18:16 -07:00
|
|
|
|
2021-06-29 04:55:44 -07:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CoreModule is the identifier of the Core module (which is used for governance messages)
|
|
|
|
var CoreModule = []byte{00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0x43, 0x6f, 0x72, 0x65}
|
|
|
|
|
|
|
|
type (
|
|
|
|
// BodyContractUpgrade is a governance message to perform a contract upgrade of the core module
|
|
|
|
BodyContractUpgrade struct {
|
|
|
|
ChainID ChainID
|
|
|
|
NewContract Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// BodyGuardianSetUpdate is a governance message to set a new guardian set
|
|
|
|
BodyGuardianSetUpdate struct {
|
|
|
|
Keys []common.Address
|
|
|
|
NewIndex uint32
|
|
|
|
}
|
2021-09-30 07:58:54 -07:00
|
|
|
|
2021-09-30 11:57:44 -07:00
|
|
|
// BodyTokenBridgeRegisterChain is a governance message to register a chain on the token bridge
|
|
|
|
BodyTokenBridgeRegisterChain struct {
|
2021-10-01 03:26:05 -07:00
|
|
|
Module string
|
2021-09-30 07:58:54 -07:00
|
|
|
ChainID ChainID
|
|
|
|
EmitterAddress Address
|
|
|
|
}
|
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
|
|
|
|
|
|
|
// BodyTokenBridgeUpgradeContract is a governance message to upgrade the token bridge.
|
|
|
|
BodyTokenBridgeUpgradeContract struct {
|
|
|
|
Module string
|
|
|
|
TargetChainID ChainID
|
|
|
|
NewContract Address
|
|
|
|
}
|
2021-06-29 04:55:44 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b BodyContractUpgrade) Serialize() []byte {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
// Module
|
|
|
|
buf.Write(CoreModule)
|
|
|
|
// Action
|
|
|
|
MustWrite(buf, binary.BigEndian, uint8(1))
|
|
|
|
// ChainID
|
|
|
|
MustWrite(buf, binary.BigEndian, uint16(b.ChainID))
|
|
|
|
|
|
|
|
buf.Write(b.NewContract[:])
|
|
|
|
|
|
|
|
return buf.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BodyGuardianSetUpdate) Serialize() []byte {
|
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
|
|
|
|
// Module
|
|
|
|
buf.Write(CoreModule)
|
|
|
|
// Action
|
2021-06-30 13:04:32 -07:00
|
|
|
MustWrite(buf, binary.BigEndian, uint8(2))
|
2021-06-29 04:55:44 -07:00
|
|
|
// ChainID - 0 for universal
|
|
|
|
MustWrite(buf, binary.BigEndian, uint16(0))
|
|
|
|
|
|
|
|
MustWrite(buf, binary.BigEndian, b.NewIndex)
|
|
|
|
MustWrite(buf, binary.BigEndian, uint8(len(b.Keys)))
|
|
|
|
for _, k := range b.Keys {
|
|
|
|
buf.Write(k[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.Bytes()
|
|
|
|
}
|
2021-09-30 07:58:54 -07:00
|
|
|
|
2021-09-30 11:57:44 -07:00
|
|
|
func (r BodyTokenBridgeRegisterChain) Serialize() []byte {
|
2021-10-01 03:26:05 -07:00
|
|
|
if len(r.Module) > 32 {
|
|
|
|
panic("module longer than 32 byte")
|
|
|
|
}
|
|
|
|
|
2021-09-30 07:58:54 -07:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
|
|
|
|
// Write token bridge header
|
2021-10-01 03:26:05 -07:00
|
|
|
for i := 0; i < (32 - len(r.Module)); i++ {
|
|
|
|
buf.WriteByte(0x00)
|
|
|
|
}
|
|
|
|
buf.Write([]byte(r.Module))
|
2021-09-30 07:58:54 -07:00
|
|
|
// 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()
|
|
|
|
}
|
node: add BridgeUpgradeContract governance VAA
Example VAA produced by the template:
(*vaa.VAA)(0xc0004f4510)({
Version: (uint8) 1,
GuardianSetIndex: (uint32) 0,
Signatures: ([]*vaa.Signature) (len=1 cap=1) {
(*vaa.Signature)(0xc0003b0370)({
Index: (uint8) 0,
Signature: (vaa.SignatureData) (len=65 cap=65) 0f97ec9093c21ccc4ce544898ed5c21b66ab4c90be894642fbb43474ed9fb48a26d6e12f3397b9fdab160fee64e797d26599a2a9d81a4bf4bc98970b5fa5122501
})
},
Timestamp: (time.Time) 1970-01-01 00:00:00 +0000 UTC,
Nonce: (uint32) 1375049878,
Sequence: (uint64) 3557202656914991802,
ConsistencyLevel: (uint8) 32,
EmitterChain: (vaa.ChainID) solana,
EmitterAddress: (vaa.Address) (len=32 cap=32) 0000000000000000000000000000000000000000000000000000000000000004,
Payload: ([]uint8) (len=67 cap=1000) {
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 54 6f 6b 65 6e 42 72 69 64 67 65 |.....TokenBridge|
00000020 02 00 05 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 90 fb 16 72 08 af 45 5b b1 37 78 01 63 b7 b7 a9 |...r..E[.7x.c...|
00000040 a1 0c 16 |...|
}
})
Change-Id: Ibe95db01e1bc0a9c36e1be06920a389db886fdd1
2021-10-08 10:41:43 -07:00
|
|
|
|
|
|
|
func (r BodyTokenBridgeUpgradeContract) Serialize() []byte {
|
|
|
|
if len(r.Module) > 32 {
|
|
|
|
panic("module longer than 32 byte")
|
|
|
|
}
|
|
|
|
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
|
|
|
|
// Write token bridge header
|
|
|
|
for i := 0; i < (32 - len(r.Module)); i++ {
|
|
|
|
buf.WriteByte(0x00)
|
|
|
|
}
|
|
|
|
buf.Write([]byte(r.Module))
|
|
|
|
// Write action ID
|
|
|
|
MustWrite(buf, binary.BigEndian, uint8(2))
|
|
|
|
// Write target chain
|
|
|
|
MustWrite(buf, binary.BigEndian, r.TargetChainID)
|
|
|
|
// Write emitter address of chain to be registered
|
|
|
|
buf.Write(r.NewContract[:])
|
|
|
|
|
|
|
|
return buf.Bytes()
|
|
|
|
}
|