payloads.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package vaa
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. "github.com/ethereum/go-ethereum/common"
  6. )
  7. // CoreModule is the identifier of the Core module (which is used for governance messages)
  8. 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}
  9. type (
  10. // BodyContractUpgrade is a governance message to perform a contract upgrade of the core module
  11. BodyContractUpgrade struct {
  12. ChainID ChainID
  13. NewContract Address
  14. }
  15. // BodyGuardianSetUpdate is a governance message to set a new guardian set
  16. BodyGuardianSetUpdate struct {
  17. Keys []common.Address
  18. NewIndex uint32
  19. }
  20. )
  21. func (b BodyContractUpgrade) Serialize() []byte {
  22. buf := new(bytes.Buffer)
  23. // Module
  24. buf.Write(CoreModule)
  25. // Action
  26. MustWrite(buf, binary.BigEndian, uint8(1))
  27. // ChainID
  28. MustWrite(buf, binary.BigEndian, uint16(b.ChainID))
  29. buf.Write(b.NewContract[:])
  30. return buf.Bytes()
  31. }
  32. func (b BodyGuardianSetUpdate) Serialize() []byte {
  33. buf := new(bytes.Buffer)
  34. // Module
  35. buf.Write(CoreModule)
  36. // Action
  37. MustWrite(buf, binary.BigEndian, uint8(2))
  38. // ChainID - 0 for universal
  39. MustWrite(buf, binary.BigEndian, uint16(0))
  40. MustWrite(buf, binary.BigEndian, b.NewIndex)
  41. MustWrite(buf, binary.BigEndian, uint8(len(b.Keys)))
  42. for _, k := range b.Keys {
  43. buf.Write(k[:])
  44. }
  45. return buf.Bytes()
  46. }