guardianset.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package common
  2. import (
  3. "github.com/ethereum/go-ethereum/common"
  4. )
  5. // TODO: this should be 20, https://github.com/certusone/wormhole/issues/86
  6. //
  7. // Matching constants:
  8. // - MAX_LEN_GUARDIAN_KEYS in Solana contract
  9. //
  10. // The Eth and Terra contracts do not specify a maximum number and support more than 20,
  11. // but presumably, chain-specific transaction size limits will apply at some point (untested).
  12. const MaxGuardianCount = 19
  13. type GuardianSet struct {
  14. // Guardian's public keys truncated by the ETH standard hashing mechanism (20 bytes).
  15. Keys []common.Address
  16. // On-chain set index
  17. Index uint32
  18. }
  19. func (g *GuardianSet) KeysAsHexStrings() []string {
  20. r := make([]string, len(g.Keys))
  21. for n, k := range g.Keys {
  22. r[n] = k.Hex()
  23. }
  24. return r
  25. }
  26. // Get a given address index from the guardian set. Returns (-1, false)
  27. // if the address wasn't found and (addr, true) otherwise.
  28. func (g *GuardianSet) KeyIndex(addr common.Address) (int, bool) {
  29. for n, k := range g.Keys {
  30. if k == addr {
  31. return n, true
  32. }
  33. }
  34. return -1, false
  35. }