Nep5Token extends SmartContract { public TransactionBuilder transferFromSpecificAccounts(Wallet wallet, ScriptHash to, BigDecimal amount, ScriptHash... from) throws IOException { if (from.length == 0) { throw new IllegalArgumentException( "An account address must be provided to build an invocation."); } if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } List<Account> accounts = new ArrayList<>(); for (ScriptHash fromScriptHash : from) { Account a = wallet.getAccount(fromScriptHash); if (a.isMultiSig() && !privateKeysArePresentForMultiSig(wallet, fromScriptHash)) { throw new IllegalArgumentException("The multi-sig account with script hash " + fromScriptHash.toString() + " does not have the corresponding private " + "keys in the wallet that are required for signing the transfer " + "transaction."); } accounts.add(a); } return buildMultiTransferInvocation(wallet, to, amount, accounts); } Nep5Token(ScriptHash scriptHash, Neow3j neow); String getName(); String getSymbol(); BigInteger getTotalSupply(); int getDecimals(); BigInteger getBalanceOf(ScriptHash scriptHash); BigInteger getBalanceOf(Wallet wallet); TransactionBuilder transfer(Wallet wallet, ScriptHash to, BigDecimal amount); TransactionBuilder transferFromSpecificAccounts(Wallet wallet, ScriptHash to,
            BigDecimal amount, ScriptHash... from); TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to,
            BigDecimal amount);  }
@Test public void testTransferFromSpecificAccounts() throws IOException { setUpWireMockForCall("invokescript", "invokescript_transfer.json"); setUpWireMockForGetBlockCount(1000); setUpWireMockForInvokeFunction("decimals", "invokefunction_decimals.json"); setUpWireMockForBalanceOf(account2.getScriptHash(), "invokefunction_balanceOf_4.json"); setUpWireMockForBalanceOf(account3.getScriptHash(), "invokefunction_balanceOf_3.json"); byte[] expectedScript = new ScriptBuilder() .contractCall(NEO_TOKEN_SCRIPT_HASH, NEP5_TRANSFER, Arrays.asList( ContractParameter.hash160(account3.getScriptHash()), ContractParameter.hash160(RECIPIENT_SCRIPT_HASH), ContractParameter.integer(3))) .contractCall(NEO_TOKEN_SCRIPT_HASH, NEP5_TRANSFER, Arrays.asList( ContractParameter.hash160(account2.getScriptHash()), ContractParameter.hash160(RECIPIENT_SCRIPT_HASH), ContractParameter.integer(2))).toArray(); Wallet w = Wallet.withAccounts(account1, account2, account3); TransactionBuilder b = neoToken.buildMultiTransferInvocation(w, RECIPIENT_SCRIPT_HASH, new BigDecimal("5"), Arrays.asList(account3, account2)); assertThat(b.getScript(), is(expectedScript)); }
@Test(expected = IllegalArgumentException.class) public void testTransferFromSpecificAccounts_MultiSigNotEnoughSignersPresent_NoOtherAccountPresent() throws IOException { setUpWireMockForInvokeFunction("decimals", "invokefunction_decimals.json"); setUpWireMockForBalanceOf(multiSigAccount.getScriptHash(), "invokefunction_balanceOf_3.json"); Wallet wallet = Wallet.withAccounts(multiSigAccount); neoToken.transferFromSpecificAccounts(wallet, RECIPIENT_SCRIPT_HASH, new BigDecimal("2"), multiSigAccount.getScriptHash()); }
@Test(expected = IllegalArgumentException.class) public void testTransferFromSpecificAccounts_noAccountProvided() throws IOException { neoToken.transferFromSpecificAccounts(Wallet.createWallet(), RECIPIENT_SCRIPT_HASH, new BigDecimal("1")); }
@Test(expected = IllegalArgumentException.class) public void testTransferFromSpecificAccounts_illegalAmountProvided() throws IOException { neoToken.transferFromSpecificAccounts(Wallet.createWallet(), RECIPIENT_SCRIPT_HASH, new BigDecimal("-2"), account1.getScriptHash()); }