From 24d1725cc82b01bcaede188068365a8b0078fba7 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Tue, 6 Jul 2021 14:27:07 +0300 Subject: [PATCH] [#666] innerring: Make GlagoliticLetter enum public for re-use Signed-off-by: Alex Vanin --- pkg/innerring/alphabet.go | 16 ++++++++-------- pkg/innerring/innerring.go | 6 +++--- pkg/innerring/state.go | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/innerring/alphabet.go b/pkg/innerring/alphabet.go index c649090ee..b5f2c2a1c 100644 --- a/pkg/innerring/alphabet.go +++ b/pkg/innerring/alphabet.go @@ -2,10 +2,10 @@ package innerring import "github.com/nspcc-dev/neo-go/pkg/util" -type glagoliticLetter int8 +type GlagoliticLetter int8 const ( - _ glagoliticLetter = iota - 1 + _ GlagoliticLetter = iota - 1 az buky @@ -53,7 +53,7 @@ const ( ) // returns string in config-compatible format -func (l glagoliticLetter) configString() string { +func (l GlagoliticLetter) String() string { switch l { default: return "unknown" @@ -142,10 +142,10 @@ func (l glagoliticLetter) configString() string { } } -type alphabetContracts map[glagoliticLetter]util.Uint160 +type alphabetContracts map[GlagoliticLetter]util.Uint160 func newAlphabetContracts() alphabetContracts { - return make(map[glagoliticLetter]util.Uint160, lastLetterNum) + return make(map[GlagoliticLetter]util.Uint160, lastLetterNum) } func (a alphabetContracts) GetByIndex(ind int) (util.Uint160, bool) { @@ -153,7 +153,7 @@ func (a alphabetContracts) GetByIndex(ind int) (util.Uint160, bool) { return util.Uint160{}, false } - contract, ok := a[glagoliticLetter(ind)] + contract, ok := a[GlagoliticLetter(ind)] return contract, ok } @@ -162,12 +162,12 @@ func (a alphabetContracts) indexOutOfRange(ind int) bool { return ind < 0 && ind >= len(a) } -func (a alphabetContracts) iterate(f func(glagoliticLetter, util.Uint160)) { +func (a alphabetContracts) iterate(f func(GlagoliticLetter, util.Uint160)) { for letter, contract := range a { f(letter, contract) } } -func (a *alphabetContracts) set(l glagoliticLetter, h util.Uint160) { +func (a *alphabetContracts) set(l GlagoliticLetter, h util.Uint160) { (*a)[l] = h } diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index 9c92c4417..5a945a910 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -921,7 +921,7 @@ func ParsePublicKeysFromStrings(pubKeys []string) (keys.PublicKeys, error) { } func parseAlphabetContracts(cfg *viper.Viper) (alphabetContracts, error) { - num := glagoliticLetter(cfg.GetUint("contracts.alphabet.amount")) + num := GlagoliticLetter(cfg.GetUint("contracts.alphabet.amount")) alpha := newAlphabetContracts() if num > lastLetterNum { @@ -929,11 +929,11 @@ func parseAlphabetContracts(cfg *viper.Viper) (alphabetContracts, error) { } for letter := az; letter < num; letter++ { - contractStr := cfg.GetString("contracts.alphabet." + letter.configString()) + contractStr := cfg.GetString("contracts.alphabet." + letter.String()) contractHash, err := util.Uint160DecodeStringLE(contractStr) if err != nil { - return nil, fmt.Errorf("invalid alphabet %s contract: %s: %w", letter.configString(), contractStr, err) + return nil, fmt.Errorf("invalid alphabet %s contract: %s: %w", letter.String(), contractStr, err) } alpha.set(letter, contractHash) diff --git a/pkg/innerring/state.go b/pkg/innerring/state.go index abe90cb5b..e74ccd327 100644 --- a/pkg/innerring/state.go +++ b/pkg/innerring/state.go @@ -85,7 +85,7 @@ func (s *Server) voteForSidechainValidator(validators keys.PublicKeys) error { epoch := s.EpochCounter() - s.contracts.alphabet.iterate(func(letter glagoliticLetter, contract util.Uint160) { + s.contracts.alphabet.iterate(func(letter GlagoliticLetter, contract util.Uint160) { err := s.morphClient.NotaryInvoke(contract, s.feeConfig.SideChainFee(), voteMethod, int64(epoch), validators) if err != nil { s.log.Warn("can't invoke vote method in alphabet contract",