core: extend native Neo interop API
Add GetAllCandidates and GetCandidateVote methods.
This commit is contained in:
parent
5e2a81ad03
commit
5123b88c36
2 changed files with 20 additions and 1 deletions
|
@ -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},
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue