guardianset.go 1.0 KB

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