rpc: allow to getcontractstate by address, id or name

close #1423
This commit is contained in:
Anna Shaleva 2020-09-25 12:40:57 +03:00
parent 7121686571
commit 15a939b1da
7 changed files with 112 additions and 5 deletions

View file

@ -2,6 +2,7 @@ package native
import (
"errors"
"strings"
"github.com/nspcc-dev/neo-go/pkg/core/interop"
"github.com/nspcc-dev/neo-go/pkg/io"
@ -35,6 +36,17 @@ func (cs *Contracts) ByHash(h util.Uint160) interop.Contract {
return nil
}
// ByName returns native contract with the specified name.
func (cs *Contracts) ByName(name string) interop.Contract {
name = strings.ToLower(name)
for _, ctr := range cs.Contracts {
if strings.ToLower(ctr.Metadata().Name) == name {
return ctr
}
}
return nil
}
// NewContracts returns new set of native contracts with new GAS, NEO and Policy
// contracts.
func NewContracts() *Contracts {