diff --git a/pkg/compiler/native_test.go b/pkg/compiler/native_test.go index e3862b0d5..49460401b 100644 --- a/pkg/compiler/native_test.go +++ b/pkg/compiler/native_test.go @@ -144,6 +144,8 @@ func TestNativeHelpersCompile(t *testing.T) { } runNativeTestCases(t, cs.NEO.ContractMD, "neo", append([]nativeTestCase{ {"getCandidates", nil}, + {"getAllCandidates", nil}, + {"getCandidateVote", []string{pub}}, {"getCommittee", nil}, {"getGasPerBlock", nil}, {"getNextBlockValidators", nil}, diff --git a/pkg/interop/native/neo/neo.go b/pkg/interop/native/neo/neo.go index f14a17799..4c5e4c9b0 100644 --- a/pkg/interop/native/neo/neo.go +++ b/pkg/interop/native/neo/neo.go @@ -9,6 +9,7 @@ package neo 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" ) @@ -54,11 +55,27 @@ func GetCommittee() []interop.PublicKey { } // GetCandidates represents `getCandidates` method of NEO native contract. It -// returns up to 256 candidates. +// returns up to 256 candidates. Use GetAllCandidates in case if you need the +// whole set of candidates. func GetCandidates() []Candidate { return neogointernal.CallWithToken(Hash, "getCandidates", int(contract.ReadStates)).([]Candidate) } +// GetAllCandidates represents `getAllCandidates` method of NEO native contract. +// It returns Iterator over the whole set of Neo candidates sorted by public key +// bytes. Each iterator value can be cast to Candidate. Use iterator interop +// package to work with the returned Iterator. +func GetAllCandidates() iterator.Iterator { + return neogointernal.CallWithToken(Hash, "getAllCandidates", int(contract.ReadStates)).(iterator.Iterator) +} + +// GetCandidateVote represents `getCandidateVote` method of NEO native contract. +// It returns -1 if the candidate hasn't been registered or voted for and the +// overall candidate votes otherwise. +func GetCandidateVote(pub interop.PublicKey) int { + return neogointernal.CallWithToken(Hash, "getCandidateVote", int(contract.ReadStates), pub).(int) +} + // GetNextBlockValidators represents `getNextBlockValidators` method of NEO native contract. func GetNextBlockValidators() []interop.PublicKey { return neogointernal.CallWithToken(Hash, "getNextBlockValidators", int(contract.ReadStates)).([]interop.PublicKey)