support determining if tx input refers to a txo from a wallet

This commit is contained in:
Craig Raw 2021-06-28 13:08:09 +02:00
parent 9d3c02d184
commit 107a165fc1
2 changed files with 17 additions and 4 deletions

View file

@ -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;
}
}

View file

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