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 ) ; }
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 .