From 1016ba3a5d24d70ae57b4c9cb19872ea19a77eff Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Sun, 21 Feb 2021 09:37:48 +0300 Subject: [PATCH] [#392] ir: Implement type for group of alphabet contracts Define `alphabetContracts` type that map glagolic letters to smart contract addresses. Implement constructor and all methods which are going to be used in IR processing. Signed-off-by: Leonard Lyubich --- pkg/innerring/alphabet.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/innerring/alphabet.go b/pkg/innerring/alphabet.go index 20341303c4..9d12136fb6 100644 --- a/pkg/innerring/alphabet.go +++ b/pkg/innerring/alphabet.go @@ -1,5 +1,7 @@ package innerring +import "github.com/nspcc-dev/neo-go/pkg/util" + type glagoliticLetter int8 const ( @@ -139,3 +141,33 @@ func (l glagoliticLetter) configString() string { return "izhitsa" } } + +type alphabetContracts map[glagoliticLetter]util.Uint160 + +func newAlphabetContracts() alphabetContracts { + return make(map[glagoliticLetter]util.Uint160, lastLetterNum) +} + +func (a alphabetContracts) GetByIndex(ind int) (util.Uint160, bool) { + if ind < 0 || ind >= int(lastLetterNum) { + return util.Uint160{}, false + } + + contract, ok := a[glagoliticLetter(ind)] + + return contract, ok +} + +func (a alphabetContracts) indexOutOfRange(ind int) bool { + return ind < 0 && ind >= len(a) +} + +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) { + (*a)[l] = h +}