[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-02-21 09:37:48 +03:00 committed by Alex Vanin
parent 3430a6d101
commit 1016ba3a5d

View file

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