From cb5c18dc73eba34794ddc95265ac7ff7e00bd4b6 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 20 Sep 2022 16:09:34 +0300 Subject: [PATCH] interop: add getContractByID and getContractHashes to management --- pkg/interop/native/management/management.go | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/interop/native/management/management.go b/pkg/interop/native/management/management.go index 8e392a2c7..8f6517242 100644 --- a/pkg/interop/native/management/management.go +++ b/pkg/interop/native/management/management.go @@ -7,12 +7,21 @@ package management import ( "github.com/nspcc-dev/neo-go/pkg/interop" "github.com/nspcc-dev/neo-go/pkg/interop/contract" + "github.com/nspcc-dev/neo-go/pkg/interop/iterator" "github.com/nspcc-dev/neo-go/pkg/interop/neogointernal" ) // Hash represents Management contract hash. const Hash = "\xfd\xa3\xfa\x43\x46\xea\x53\x2a\x25\x8f\xc4\x97\xdd\xad\xdb\x64\x37\xc9\xfd\xff" +// IDHash is an ID/Hash pair returned by the iterator from the GetContractHashes method. +type IDHash struct { + // ID is a 32-bit number, but it's represented in big endian form + // natively, because that's the key scheme used by ContractManagement. + ID []byte + Hash interop.Hash160 +} + // Deploy represents `deploy` method of Management native contract. func Deploy(script, manifest []byte) *Contract { return neogointernal.CallWithToken(Hash, "deploy", @@ -35,6 +44,19 @@ func GetContract(addr interop.Hash160) *Contract { return neogointernal.CallWithToken(Hash, "getContract", int(contract.ReadStates), addr).(*Contract) } +// GetContractByID represents `getContractById` method of the Management native contract. +func GetContractByID(id int) *Contract { + return neogointernal.CallWithToken(Hash, "getContractById", int(contract.ReadStates), id).(*Contract) +} + +// GetContractHashes represents `getContractHashes` method of the Management +// native contract. It returns an Iterator over the list of non-native contract +// hashes. Each iterator value can be cast to IDHash. Use [iterator] interop +// package to work with the returned Iterator. +func GetContractHashes() iterator.Iterator { + return neogointernal.CallWithToken(Hash, "getContractHashes", int(contract.ReadStates)).(iterator.Iterator) +} + // GetMinimumDeploymentFee represents `getMinimumDeploymentFee` method of Management native contract. func GetMinimumDeploymentFee() int { return neogointernal.CallWithToken(Hash, "getMinimumDeploymentFee", int(contract.ReadStates)).(int)