2020-08-19 05:23:00 -07:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
)
|
|
|
|
|
2020-11-19 03:53:19 -08:00
|
|
|
// Matching constants:
|
2021-01-11 06:07:24 -08:00
|
|
|
// - MAX_LEN_GUARDIAN_KEYS in Solana contract (limited by transaction size - 19 is the maximum amount possible)
|
2020-11-19 03:53:19 -08:00
|
|
|
//
|
2021-01-11 06:07:24 -08:00
|
|
|
// The Eth and Terra contracts do not specify a maximum number and support more than that,
|
2020-11-19 03:53:19 -08:00
|
|
|
// but presumably, chain-specific transaction size limits will apply at some point (untested).
|
|
|
|
const MaxGuardianCount = 19
|
|
|
|
|
2020-08-19 05:23:00 -07:00
|
|
|
type GuardianSet struct {
|
2021-01-20 15:59:50 -08:00
|
|
|
// Guardian's public key hashes truncated by the ETH standard hashing mechanism (20 bytes).
|
2020-08-19 05:23:00 -07:00
|
|
|
Keys []common.Address
|
|
|
|
// On-chain set index
|
|
|
|
Index uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (g *GuardianSet) KeysAsHexStrings() []string {
|
|
|
|
r := make([]string, len(g.Keys))
|
|
|
|
|
|
|
|
for n, k := range g.Keys {
|
|
|
|
r[n] = k.Hex()
|
|
|
|
}
|
|
|
|
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a given address index from the guardian set. Returns (-1, false)
|
|
|
|
// if the address wasn't found and (addr, true) otherwise.
|
|
|
|
func (g *GuardianSet) KeyIndex(addr common.Address) (int, bool) {
|
|
|
|
for n, k := range g.Keys {
|
|
|
|
if k == addr {
|
|
|
|
return n, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1, false
|
|
|
|
}
|