dont add non-witness utxo when keystores are exclusively coldcard or cobovault

This commit is contained in:
Craig Raw 2021-01-26 12:18:27 +02:00
parent 93d494fcde
commit 4b682fb3e7
3 changed files with 18 additions and 4 deletions

View file

@ -87,6 +87,8 @@ public class PSBT {
this.version = version; this.version = version;
} }
boolean alwaysIncludeWitnessUtxo = wallet.getKeystores().stream().anyMatch(keystore -> keystore.getWalletModel().alwaysIncludeNonWitnessUtxo());
int inputIndex = 0; int inputIndex = 0;
for(Iterator<Map.Entry<BlockTransactionHashIndex, WalletNode>> iter = walletTransaction.getSelectedUtxos().entrySet().iterator(); iter.hasNext(); inputIndex++) { for(Iterator<Map.Entry<BlockTransactionHashIndex, WalletNode>> iter = walletTransaction.getSelectedUtxos().entrySet().iterator(); iter.hasNext(); inputIndex++) {
Map.Entry<BlockTransactionHashIndex, WalletNode> utxoEntry = iter.next(); Map.Entry<BlockTransactionHashIndex, WalletNode> utxoEntry = iter.next();
@ -112,7 +114,7 @@ public class PSBT {
derivedPublicKeys.put(keystore.getPubKey(walletNode), keystore.getKeyDerivation().extend(walletNode.getDerivation())); derivedPublicKeys.put(keystore.getPubKey(walletNode), keystore.getKeyDerivation().extend(walletNode.getDerivation()));
} }
PSBTInput psbtInput = new PSBTInput(wallet.getScriptType(), transaction, inputIndex, utxo, utxoIndex, redeemScript, witnessScript, derivedPublicKeys, Collections.emptyMap()); PSBTInput psbtInput = new PSBTInput(wallet.getScriptType(), transaction, inputIndex, utxo, utxoIndex, redeemScript, witnessScript, derivedPublicKeys, Collections.emptyMap(), alwaysIncludeWitnessUtxo);
psbtInputs.add(psbtInput); psbtInputs.add(psbtInput);
} }

View file

@ -48,16 +48,20 @@ public class PSBTInput {
this.index = index; this.index = index;
} }
PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map<ECKey, KeyDerivation> derivedPublicKeys, Map<String, String> proprietary) { PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map<ECKey, KeyDerivation> derivedPublicKeys, Map<String, String> proprietary, boolean alwaysAddNonWitnessTx) {
this(transaction, index); this(transaction, index);
sigHash = SigHash.ALL; sigHash = SigHash.ALL;
if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(scriptType)) { if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(scriptType)) {
this.witnessUtxo = utxo.getOutputs().get(utxoIndex); this.witnessUtxo = utxo.getOutputs().get(utxoIndex);
} else {
this.nonWitnessUtxo = utxo;
} }
//Add non-witness UTXO to segwit types to handle Trezor and Ledger requirements if(alwaysAddNonWitnessTx) {
this.nonWitnessUtxo = utxo; //Add non-witness UTXO to segwit types to handle Trezor, Bitbox and Ledger requirements
this.nonWitnessUtxo = utxo;
}
this.redeemScript = redeemScript; this.redeemScript = redeemScript;
this.witnessScript = witnessScript; this.witnessScript = witnessScript;

View file

@ -35,6 +35,14 @@ public enum WalletModel {
return this.toString().toLowerCase(); return this.toString().toLowerCase();
} }
public boolean alwaysIncludeNonWitnessUtxo() {
if(this == COLDCARD || this == COBO_VAULT) {
return false;
}
return true;
}
public boolean requiresPinPrompt() { public boolean requiresPinPrompt() {
return (this == TREZOR_1 || this == KEEPKEY); return (this == TREZOR_1 || this == KEEPKEY);
} }