@Test public void transferFromDefaultAccountShouldAddAccountAsSigner() throws Throwable { setUpWireMockForCall("invokescript", "invokescript_transfer.json"); setUpWireMockForInvokeFunction("decimals", "invokefunction_decimals_gas.json"); setUpWireMockForGetBlockCount(1000); setUpWireMockForBalanceOf(account1.getScriptHash(), "invokefunction_balanceOf_300000000.json"); Transaction tx = gasToken.transferFromDefaultAccount(Wallet.withAccounts(account1), RECIPIENT_SCRIPT_HASH, BigDecimal.ONE) .buildTransaction(); assertThat(tx.getSigners().get(0).getScriptHash(), is(account1.getScriptHash())); assertThat(tx.getSigners().get(0).getScopes().get(0), is(WitnessScope.CALLED_BY_ENTRY)); assertThat(tx.getSender(), is(account1.getScriptHash())); }
public TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to, BigDecimal amount) throws IOException { if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } Account acc = wallet.getDefaultAccount(); BigInteger fractions = getAmountAsBigInteger(amount); BigInteger accBalance = getBalanceOf(acc.getScriptHash()); if (accBalance.compareTo(fractions) < 0) { throw new InsufficientFundsException("The wallet's default account does not hold enough" + " tokens. Transfer amount is " + fractions.toString() + " but account" + " only holds " + accBalance.toString() + " (in token fractions)."); } return invokeFunction(NEP5_TRANSFER, ContractParameter.hash160(acc.getScriptHash()), ContractParameter.hash160(to), ContractParameter.integer(fractions)) .wallet(wallet) .signers(Signer.calledByEntry(acc.getScriptHash())); }
Nep5Token extends SmartContract { public TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to, BigDecimal amount) throws IOException { if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } Account acc = wallet.getDefaultAccount(); BigInteger fractions = getAmountAsBigInteger(amount); BigInteger accBalance = getBalanceOf(acc.getScriptHash()); if (accBalance.compareTo(fractions) < 0) { throw new InsufficientFundsException("The wallet's default account does not hold enough" + " tokens. Transfer amount is " + fractions.toString() + " but account" + " only holds " + accBalance.toString() + " (in token fractions)."); } return invokeFunction(NEP5_TRANSFER, ContractParameter.hash160(acc.getScriptHash()), ContractParameter.hash160(to), ContractParameter.integer(fractions)) .wallet(wallet) .signers(Signer.calledByEntry(acc.getScriptHash())); } }
Nep5Token extends SmartContract { public TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to, BigDecimal amount) throws IOException { if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } Account acc = wallet.getDefaultAccount(); BigInteger fractions = getAmountAsBigInteger(amount); BigInteger accBalance = getBalanceOf(acc.getScriptHash()); if (accBalance.compareTo(fractions) < 0) { throw new InsufficientFundsException("The wallet's default account does not hold enough" + " tokens. Transfer amount is " + fractions.toString() + " but account" + " only holds " + accBalance.toString() + " (in token fractions)."); } return invokeFunction(NEP5_TRANSFER, ContractParameter.hash160(acc.getScriptHash()), ContractParameter.hash160(to), ContractParameter.integer(fractions)) .wallet(wallet) .signers(Signer.calledByEntry(acc.getScriptHash())); } Nep5Token(ScriptHash scriptHash, Neow3j neow); }
Nep5Token extends SmartContract { public TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to, BigDecimal amount) throws IOException { if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } Account acc = wallet.getDefaultAccount(); BigInteger fractions = getAmountAsBigInteger(amount); BigInteger accBalance = getBalanceOf(acc.getScriptHash()); if (accBalance.compareTo(fractions) < 0) { throw new InsufficientFundsException("The wallet's default account does not hold enough" + " tokens. Transfer amount is " + fractions.toString() + " but account" + " only holds " + accBalance.toString() + " (in token fractions)."); } return invokeFunction(NEP5_TRANSFER, ContractParameter.hash160(acc.getScriptHash()), ContractParameter.hash160(to), ContractParameter.integer(fractions)) .wallet(wallet) .signers(Signer.calledByEntry(acc.getScriptHash())); } 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); }
Nep5Token extends SmartContract { public TransactionBuilder transferFromDefaultAccount(Wallet wallet, ScriptHash to, BigDecimal amount) throws IOException { if (amount.signum() < 0) { throw new IllegalArgumentException( "The parameter amount must be greater than or equal to 0"); } Account acc = wallet.getDefaultAccount(); BigInteger fractions = getAmountAsBigInteger(amount); BigInteger accBalance = getBalanceOf(acc.getScriptHash()); if (accBalance.compareTo(fractions) < 0) { throw new InsufficientFundsException("The wallet's default account does not hold enough" + " tokens. Transfer amount is " + fractions.toString() + " but account" + " only holds " + accBalance.toString() + " (in token fractions)."); } return invokeFunction(NEP5_TRANSFER, ContractParameter.hash160(acc.getScriptHash()), ContractParameter.hash160(to), ContractParameter.integer(fractions)) .wallet(wallet) .signers(Signer.calledByEntry(acc.getScriptHash())); } 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);  }