From 107a165fc1db84f80febbe358aaab16b2764a5d5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 28 Jun 2021 13:08:09 +0200 Subject: [PATCH] support determining if tx input refers to a txo from a wallet --- .../drongo/wallet/FinalizingPSBTWallet.java | 17 +++++++++++++---- .../com/sparrowwallet/drongo/wallet/Wallet.java | 4 ++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/FinalizingPSBTWallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/FinalizingPSBTWallet.java index 360836e..5a4dff7 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/FinalizingPSBTWallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/FinalizingPSBTWallet.java @@ -5,10 +5,7 @@ import com.sparrowwallet.drongo.crypto.ECKey; import com.sparrowwallet.drongo.policy.Miniscript; import com.sparrowwallet.drongo.policy.Policy; import com.sparrowwallet.drongo.policy.PolicyType; -import com.sparrowwallet.drongo.protocol.NonStandardScriptException; -import com.sparrowwallet.drongo.protocol.Script; -import com.sparrowwallet.drongo.protocol.ScriptType; -import com.sparrowwallet.drongo.protocol.TransactionSignature; +import com.sparrowwallet.drongo.protocol.*; import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.psbt.PSBTInput; @@ -125,4 +122,16 @@ public class FinalizingPSBTWallet extends Wallet { public boolean canSign(PSBT psbt) { return !getSigningNodes(psbt).isEmpty(); } + + @Override + public boolean isWalletTxo(TransactionInput txInput) { + for(PSBTInput psbtInput : signedInputNodes.keySet()) { + TransactionInput psbtTxInput = psbtInput.getInput(); + if(psbtTxInput.getOutpoint().getHash().equals(txInput.getOutpoint().getHash()) && psbtTxInput.getOutpoint().getIndex() == txInput.getOutpoint().getIndex()) { + return true; + } + } + + return false; + } } \ No newline at end of file diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java index 2ccb848..6deee5b 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/Wallet.java @@ -351,6 +351,10 @@ public class Wallet extends Persistable { } } + public boolean isWalletTxo(TransactionInput txInput) { + return getWalletTxos().keySet().stream().anyMatch(ref -> ref.getHash().equals(txInput.getOutpoint().getHash()) && ref.getIndex() == txInput.getOutpoint().getIndex()); + } + public boolean isWalletTxo(BlockTransactionHashIndex txo) { return getWalletTxos().containsKey(txo); }