public List<TransactionOutPoint> listUnspentOutPoints(Address fromAddress) throws JsonRpcStatusException, IOException { List<Address> addresses = Collections.singletonList(fromAddress); List<UnspentOutput> unspentOutputsRPC = listUnspent(0, defaultMaxConf, addresses); // RPC UnspentOutput objects List<TransactionOutPoint> unspentOutPoints = new ArrayList<TransactionOutPoint>(); for (UnspentOutput it : unspentOutputsRPC) { unspentOutPoints.add(new TransactionOutPoint(getNetParams(), it.getVout(), it.getTxid())); } return unspentOutPoints; } }
/** * Returns the Bitcoin balance of an address where spendable outputs have at least {@code minConf} and not more * than {@code maxConf} confirmations. * * @param address The address (must be in wallet) * @param minConf Minimum amount of confirmations * @param maxConf Maximum amount of confirmations * @return The balance */ public Coin getBitcoinBalance(Address address, Integer minConf, Integer maxConf) throws JsonRpcStatusException, IOException { long btcBalance = 0; List<UnspentOutput> unspentOutputs = listUnspent(minConf, maxConf, Collections.singletonList(address)); for (UnspentOutput unspentOutput : unspentOutputs) { btcBalance += unspentOutput.getAmount().value; } return Coin.valueOf(btcBalance); }
/** * Build a list of bitcoinj <code>TransactionOutput</code>s using <code>listUnspent</code> * and <code>getRawTransaction</code> RPCs * * @param fromAddress Address to get UTXOs for * @return All unspent TransactionOutputs for fromAddress */ public List<TransactionOutput> listUnspentJ(Address fromAddress) throws JsonRpcStatusException, IOException { List<Address> addresses = Collections.singletonList(fromAddress); List<UnspentOutput> unspentOutputsRPC = listUnspent(0, defaultMaxConf, addresses); // RPC UnspentOutput objects List<TransactionOutput> unspentOutputsJ = new ArrayList<TransactionOutput>(); for (UnspentOutput it : unspentOutputsRPC) { unspentOutputsJ.add(getRawTransaction(it.getTxid()).getOutput(it.getVout())); } return unspentOutputsJ; }