[#666] innerring: Make GlagoliticLetter enum public for re-use

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-07-06 14:27:07 +03:00 committed by Alex Vanin
parent 48c3573e0c
commit 24d1725cc8
3 changed files with 12 additions and 12 deletions

View file

@ -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
}

View file

@ -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)

View file

@ -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",