From 5123b88c36cb4aa686d8d6b949b8e40ac03e67f7 Mon Sep 17 00:00:00 2001
From: Anna Shaleva <shaleva.ann@nspcc.ru>
Date: Thu, 5 May 2022 15:38:41 +0300
Subject: [PATCH] core: extend native Neo interop API

Add GetAllCandidates and GetCandidateVote methods.
---
 pkg/compiler/native_test.go   |  2 ++
 pkg/interop/native/neo/neo.go | 19 ++++++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletion(-)

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)