[#447] innerring: Use alias type for slice of public keys

Alias type provide sort function so it is better to use it
everywhere where list of public keys is presented.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-03-25 10:34:27 +03:00 committed by Alex Vanin
parent 34f25adc8c
commit 3965cc2296
4 changed files with 10 additions and 15 deletions

View file

@ -100,7 +100,7 @@ func main() {
log.Info("application stopped") log.Info("application stopped")
} }
func parsePublicKeysFromString(argument string) ([]keys.PublicKey, error) { func parsePublicKeysFromString(argument string) (keys.PublicKeys, error) {
publicKeysString := strings.Split(argument, ",") publicKeysString := strings.Split(argument, ",")
return innerring.ParsePublicKeysFromStrings(publicKeysString) return innerring.ParsePublicKeysFromStrings(publicKeysString)

View file

@ -62,7 +62,7 @@ type (
key *ecdsa.PrivateKey key *ecdsa.PrivateKey
pubKey []byte pubKey []byte
contracts *contracts contracts *contracts
predefinedValidators []keys.PublicKey predefinedValidators keys.PublicKeys
workers []func(context.Context) workers []func(context.Context)
@ -664,7 +664,7 @@ func parseContracts(cfg *viper.Viper) (*contracts, error) {
return result, nil return result, nil
} }
func parsePredefinedValidators(cfg *viper.Viper) ([]keys.PublicKey, error) { func parsePredefinedValidators(cfg *viper.Viper) (keys.PublicKeys, error) {
publicKeyStrings := cfg.GetStringSlice("morph.validators") publicKeyStrings := cfg.GetStringSlice("morph.validators")
return ParsePublicKeysFromStrings(publicKeyStrings) return ParsePublicKeysFromStrings(publicKeyStrings)
@ -672,8 +672,8 @@ func parsePredefinedValidators(cfg *viper.Viper) ([]keys.PublicKey, error) {
// ParsePublicKeysFromStrings returns slice of neo public keys from slice // ParsePublicKeysFromStrings returns slice of neo public keys from slice
// of hex encoded strings. // of hex encoded strings.
func ParsePublicKeysFromStrings(pubKeys []string) ([]keys.PublicKey, error) { func ParsePublicKeysFromStrings(pubKeys []string) (keys.PublicKeys, error) {
publicKeys := make([]keys.PublicKey, 0, len(pubKeys)) publicKeys := make(keys.PublicKeys, 0, len(pubKeys))
for i := range pubKeys { for i := range pubKeys {
key, err := keys.NewPublicKeyFromString(pubKeys[i]) key, err := keys.NewPublicKeyFromString(pubKeys[i])
@ -681,7 +681,7 @@ func ParsePublicKeysFromStrings(pubKeys []string) ([]keys.PublicKey, error) {
return nil, errors.Wrap(err, "can't decode public key") return nil, errors.Wrap(err, "can't decode public key")
} }
publicKeys = append(publicKeys, *key) publicKeys = append(publicKeys, key)
} }
return publicKeys, nil return publicKeys, nil

View file

@ -22,15 +22,10 @@ func AlphabetEmit(cli *client.Client, con util.Uint160) error {
} }
// AlphabetVote invokes vote method on alphabet contract. // AlphabetVote invokes vote method on alphabet contract.
func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys []keys.PublicKey) error { func AlphabetVote(cli *client.Client, con util.Uint160, epoch uint64, keys keys.PublicKeys) error {
if cli == nil { if cli == nil {
return client.ErrNilClient return client.ErrNilClient
} }
binaryKeys := make([][]byte, 0, len(keys)) return cli.NotaryInvoke(con, voteMethod, int64(epoch), keys)
for i := range keys {
binaryKeys = append(binaryKeys, keys[i].Bytes())
}
return cli.NotaryInvoke(con, voteMethod, int64(epoch), binaryKeys)
} }

View file

@ -65,7 +65,7 @@ func (s *Server) AlphabetIndex() int {
return int(index) return int(index)
} }
func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error { func (s *Server) voteForSidechainValidator(validators keys.PublicKeys) error {
index := s.InnerRingIndex() index := s.InnerRingIndex()
if s.contracts.alphabet.indexOutOfRange(index) { if s.contracts.alphabet.indexOutOfRange(index) {
s.log.Info("ignore validator vote: node not in alphabet range") s.log.Info("ignore validator vote: node not in alphabet range")
@ -96,7 +96,7 @@ func (s *Server) voteForSidechainValidator(validators []keys.PublicKey) error {
// InitAndVoteForSidechainValidator is a public function to use outside of // InitAndVoteForSidechainValidator is a public function to use outside of
// inner ring daemon execution. It initialize inner ring structure with data // inner ring daemon execution. It initialize inner ring structure with data
// from blockchain and then calls vote method on corresponding alphabet contract. // from blockchain and then calls vote method on corresponding alphabet contract.
func (s *Server) InitAndVoteForSidechainValidator(validators []keys.PublicKey) error { func (s *Server) InitAndVoteForSidechainValidator(validators keys.PublicKeys) error {
err := s.initConfigFromBlockchain() err := s.initConfigFromBlockchain()
if err != nil { if err != nil {
return err return err