Skip to content

Commit

Permalink
SignTransactionService, WalletSigningService minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
msgilligan committed May 16, 2023
1 parent 8993f51 commit ed956ab
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The 0.7.0 release of **ConsensusJ** will require **bitcoinj** v0.17, currently i

=== bitcoinj-0.17 update

* Upgrade to bitcoinj-0.17 API
* Upgrade to bitcoinj-0.17-alpha1 API
* Migrate from `NetworkParameters` to `Network` where possible
* Remove usage of Guava `ListenableFuture`
* Remove `PatchedTransaction` class used to work around an issue in bitcoinj, see https://github.com/bitcoinj/bitcoinj/pull/2274[bitcoinj #2274]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public interface SignTransactionService extends TransactionSigner {

/**
* Create and sign a transaction to send coins to the specified address. Implements the transaction-building
* and signing portion of `sendtoaddress` RPC.
* and signing portion of {@code sendtoaddress} RPC.
* @param toAddress destination address
* @param amount amount to send
* @return a future signed transaction
Expand All @@ -37,5 +37,5 @@ public interface SignTransactionService extends TransactionSigner {
* @param changeAddress address that will receive change
* @return a completed transaction signing request
*/
SigningRequest createBitcoinSigningRequest(Network network, List<? super TransactionInputData> inputUtxos, List<TransactionOutputData> outputs, Address changeAddress) throws InsufficientMoneyException;
SigningRequest createBitcoinSigningRequest(Network network, List<TransactionInputData> inputUtxos, List<TransactionOutputData> outputs, Address changeAddress) throws InsufficientMoneyException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bitcoinj.wallet.Wallet;
import org.consensusj.bitcoin.json.rpc.BitcoinJsonRpc;
import org.consensusj.bitcoinj.service.SignTransactionService;
import org.consensusj.bitcoinj.signing.DefaultSigningRequest;
import org.consensusj.bitcoinj.signing.FeeCalculator;
import org.consensusj.bitcoinj.signing.HDKeychainSigner;
import org.consensusj.bitcoinj.signing.RawTransactionSigningRequest;
Expand Down Expand Up @@ -93,18 +92,17 @@ public CompletableFuture<Transaction> signSendToAddress(Address toAddress, Coin
}

@Override
public SigningRequest createBitcoinSigningRequest(Network network, List<? super TransactionInputData> inputUtxos, List<TransactionOutputData> outputs, Address changeAddress) throws InsufficientMoneyException {
SigningRequest request = new DefaultSigningRequest(network, (List<TransactionInputData>) inputUtxos, outputs);
public SigningRequest createBitcoinSigningRequest(Network network, List<TransactionInputData> inputUtxos, List<TransactionOutputData> outputs, Address changeAddress) throws InsufficientMoneyException {
SigningRequest request = SigningRequest.of(network, inputUtxos, outputs);
// TODO: see Wallet.calculateFee
return SigningUtils.addChange(request, changeAddress, feeCalculator);
}

List<TransactionInputData> getInputs() {
List<TransactionOutput> spendCandidates = findUnspentOutputs(1, BitcoinJsonRpc.DEFAULT_MAX_CONF, List.of());
List<? extends TransactionInputData> utxos = spendCandidates.stream()
return spendCandidates.stream()
.map(TransactionInputData::fromTxOut)
.toList();
return (List<TransactionInputData>) utxos;
}

/**
Expand Down

0 comments on commit ed956ab

Please sign in to comment.