public UnsignedTransaction createUnsignedTransaction(List<UnspentTransactionOutput> unspent, Address changeAddress,
         long fee, PublicKeyRing keyRing, NetworkParameters network) throws InsufficientFundsException {
      // Make a copy so we can mutate the list
      unspent = new LinkedList<UnspentTransactionOutput>(unspent);
      List<UnspentTransactionOutput> funding = new LinkedList<UnspentTransactionOutput>();
      long outputSum = outputSum();
      long toSend = fee + outputSum;
      long found = 0;
      while (found < toSend) {
         UnspentTransactionOutput output = extractOldest(unspent);
         if (output == null) {
            // We do not have enough funds
            throw new InsufficientFundsException(outputSum, fee);
         }
         found += output.value;
         funding.add(output);
      }
      // We have our funding, calculate change
      long change = found - toSend;

      // Get a copy of all outputs
      List<TransactionOutput> outputs = new LinkedList<TransactionOutput>(_outputs);

      if (change > 0) {
         // We have more funds than needed, add an output to our change address
         outputs.add(createOutput(changeAddress, change));
      }

      return new UnsignedTransaction(outputs, funding, keyRing, network);
   }
public UnsignedTransaction createUnsignedTransaction ( List < UnspentTransactionOutput > unspent , Address changeAddress , long fee , PublicKeyRing keyRing , NetworkParameters network ) throws InsufficientFundsException { unspent = new LinkedList < UnspentTransactionOutput > ( unspent ) ; List < UnspentTransactionOutput > funding = new LinkedList < UnspentTransactionOutput > ( ) ; long outputSum = outputSum ( ) ; long toSend = fee + outputSum ; long found = 0 ; while ( found < toSend ) { UnspentTransactionOutput output = extractOldest ( unspent ) ; if ( output == null ) { throw new InsufficientFundsException ( outputSum , fee ) ; } found += output . value ; funding . add ( output ) ; } long change = found - toSend ; List < TransactionOutput > outputs = new LinkedList < TransactionOutput > ( _outputs ) ; if ( change > 0 ) { outputs . add ( createOutput ( changeAddress , change ) ) ; } return new UnsignedTransaction ( outputs , funding , keyRing , network ) ; }
Create an unsigned transaction with a specific miner fee. Note that
specifying a miner fee that is too low may result in hanging transactions
that never confirm.

@param unspent
The list of unspent transaction outputs that can be used as
funding
@param changeAddress
The address to send any change to
@param fee
The miner fee to pay. Specifying zero may result in hanging
transactions.
@param keyRing
The public key ring matching the unspent outputs
@param network
The network we are working on
@return An unsigned transaction or null if not enough funds were available
@throws InsufficientFundsException