NeoToken extends Nep5Token { public Map<ECPublicKey, Integer> getCandidates() throws IOException { StackItem arrayItem = callInvokeFunction(GET_CANDIDATES).getInvocationResult().getStack().get(0); if (!arrayItem.getType().equals(StackItemType.ARRAY)) { throw new UnexpectedReturnTypeException(arrayItem.getType(), StackItemType.ARRAY); } Map<ECPublicKey, Integer> validators = new HashMap<>(); for (StackItem valItem : arrayItem.asArray().getValue()) { if (!valItem.getType().equals(StackItemType.ARRAY)) { throw new UnexpectedReturnTypeException(valItem.getType(), StackItemType.ARRAY); } ECPublicKey key = extractPublicKey(valItem.asArray().getValue().get(0)); StackItem nrItem = valItem.asArray().getValue().get(1); if (!nrItem.getType().equals(StackItemType.INTEGER)) { throw new UnexpectedReturnTypeException(nrItem.getType(), StackItemType.INTEGER); } validators.put(key, nrItem.asInteger().getValue().intValue()); } return validators; } NeoToken(Neow3j neow); @Override String getName(); @Override String getSymbol(); @Override BigInteger getTotalSupply(); @Override int getDecimals(); BigInteger unclaimedGas(ScriptHash scriptHash, long blockHeight); TransactionBuilder registerCandidate(ECPublicKey candidateKey); TransactionBuilder unregisterCandidate(ECPublicKey candidateKey); List<ECPublicKey> getValidators(); List<ECPublicKey> getCommittee(); Map<ECPublicKey, Integer> getCandidates(); List<ECPublicKey> getNextBlockValidators(); TransactionBuilder vote(ScriptHash voter, ECPublicKey... validators); final static int DECIMALS; final static String NAME; final static String SYMBOL; final static BigInteger TOTAL_SUPPLY; static final ScriptHash SCRIPT_HASH; static final String UNCLAIMED_GAS; static final String REGISTER_CANDIDATE; static final String UNREGISTER_CANDIDATE; static final String VOTE; static final String GET_CANDIDATES; static final String GET_VALIDATORS; static final String GET_COMMITTEE; static final String GET_NEXT_BLOCK_VALIDATORS; }
@Test public void getCandidates() throws IOException { String responseBody = ContractTestHelper.loadFile( "/responses/invokefunction_getcandidates.json"); WireMock.stubFor(post(urlEqualTo("/")) .withRequestBody(new RegexPattern("" + ".*\"method\":\"invokefunction\"" + ".*\"params\":" + ".*\"de5f57d430d3dece511cf975a8d37848cb9e0525\"" + ".*\"getCandidates\".*" )) .willReturn(aResponse() .withStatus(200) .withBody(responseBody))); Map<ECPublicKey, Integer> result = new NeoToken(neow).getCandidates(); assertThat(result.keySet(), contains( new ECPublicKey(Numeric.hexStringToByteArray( "02200284598c6c1117f163dd938a4c8014cf2cf1164c4b7197f347109db50eae7c")), new ECPublicKey(Numeric.hexStringToByteArray( "02c0b60c995bc092e866f15a37c176bb59b7ebacf069ba94c0ebf561cb8f956238")) )); assertThat(result.values(), contains(100, 49999900)); }