Skip to content

Commit

Permalink
WalletAppKit, BaseTransactionSigner: add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
msgilligan committed May 17, 2023
1 parent ed956ab commit 9c217ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.consensusj.bitcoinj.signing;

import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.TransactionInput;
import org.bitcoinj.crypto.ECKey;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.params.BitcoinNetworkParams;
import org.bitcoinj.script.ScriptException;
import org.bitcoinj.wallet.DeterministicKeyChain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Optional;
Expand All @@ -19,6 +22,7 @@
* Keys and PubKeys can be searched for, but not UTXOs or amounts
*/
public interface BaseTransactionSigner extends TransactionSigner {
Logger log = LoggerFactory.getLogger(BaseTransactionSigner.class);
/**
* Create a signed bitcoinj transaction from the signing request
* <p>
Expand All @@ -41,6 +45,8 @@ default CompletableFuture<Transaction> signTransaction(SigningRequest request) {
input -> addSignedInput(transaction, input, () -> new RuntimeException("Unsupported transaction input"))
);

log.info("signed tx: {}", transaction);

// TODO: Additional Transaction validation?
return verify(transaction, request.inputs())
.map(CompletableFuture::<Transaction>failedFuture)
Expand All @@ -55,9 +61,11 @@ default Optional<Exception> verify(Transaction tx, List<TransactionInputData> re

default Optional<Exception> verifyInput(Transaction tx, int index, TransactionInputData inputData) {
try {
log.info("Verifying input {}", tx.getInputs().get(index));
TransactionVerification.correctlySpendsInput(tx, index, inputData.script());
return Optional.empty();
} catch (ScriptException se) {
log.error("Invalid input", se);
return Optional.of(se);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ public CompletableFuture<SignedRawTransaction> signrawtransactionwithwallet(Stri
RawTransactionSigningRequest signingRequest;
try {
Transaction unsignedTx = new Transaction(NetworkParameters.of(network), raw);
log.info("received tx: {}", unsignedTx);
signingRequest = RawTransactionSigningRequest.ofTransaction(network, unsignedTx);
} catch (ProtocolException e) {
return CompletableFuture.failedFuture(new RuntimeException("Invalid raw (hex) transaction", e));
Expand Down

0 comments on commit 9c217ab

Please sign in to comment.