mirror of
https://github.com/sparrowwallet/drongo.git
synced 2024-12-27 02:26:44 +00:00
add non witness utxo to witness types for trezor and ledger
This commit is contained in:
parent
1f7be6c7d5
commit
d2582c0414
2 changed files with 10 additions and 9 deletions
|
@ -54,10 +54,11 @@ public class PSBTInput {
|
||||||
|
|
||||||
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
|
||||||
|
this.nonWitnessUtxo = utxo;
|
||||||
|
|
||||||
this.redeemScript = redeemScript;
|
this.redeemScript = redeemScript;
|
||||||
this.witnessScript = witnessScript;
|
this.witnessScript = witnessScript;
|
||||||
|
|
||||||
|
@ -70,9 +71,6 @@ public class PSBTInput {
|
||||||
switch(entry.getKeyType()) {
|
switch(entry.getKeyType()) {
|
||||||
case PSBT_IN_NON_WITNESS_UTXO:
|
case PSBT_IN_NON_WITNESS_UTXO:
|
||||||
entry.checkOneByteKey();
|
entry.checkOneByteKey();
|
||||||
if(witnessUtxo != null) {
|
|
||||||
throw new PSBTParseException("Cannot have both witness and non-witness utxos in PSBT input");
|
|
||||||
}
|
|
||||||
Transaction nonWitnessTx = new Transaction(entry.getData());
|
Transaction nonWitnessTx = new Transaction(entry.getData());
|
||||||
nonWitnessTx.verify();
|
nonWitnessTx.verify();
|
||||||
Sha256Hash inputHash = nonWitnessTx.calculateTxId(false);
|
Sha256Hash inputHash = nonWitnessTx.calculateTxId(false);
|
||||||
|
@ -96,9 +94,6 @@ public class PSBTInput {
|
||||||
break;
|
break;
|
||||||
case PSBT_IN_WITNESS_UTXO:
|
case PSBT_IN_WITNESS_UTXO:
|
||||||
entry.checkOneByteKey();
|
entry.checkOneByteKey();
|
||||||
if(nonWitnessUtxo != null) {
|
|
||||||
throw new PSBTParseException("Cannot have both witness and non-witness utxos in PSBT input");
|
|
||||||
}
|
|
||||||
TransactionOutput witnessTxOutput = new TransactionOutput(null, entry.getData(), 0);
|
TransactionOutput witnessTxOutput = new TransactionOutput(null, entry.getData(), 0);
|
||||||
if(!P2SH.isScriptType(witnessTxOutput.getScript()) && !P2WPKH.isScriptType(witnessTxOutput.getScript()) && !P2WSH.isScriptType(witnessTxOutput.getScript())) {
|
if(!P2SH.isScriptType(witnessTxOutput.getScript()) && !P2WPKH.isScriptType(witnessTxOutput.getScript()) && !P2WSH.isScriptType(witnessTxOutput.getScript())) {
|
||||||
throw new PSBTParseException("Witness UTXO provided for non-witness or unknown input");
|
throw new PSBTParseException("Witness UTXO provided for non-witness or unknown input");
|
||||||
|
@ -527,6 +522,12 @@ public class PSBTInput {
|
||||||
|
|
||||||
private Sha256Hash getHashForSignature(Script connectedScript, SigHash localSigHash) {
|
private Sha256Hash getHashForSignature(Script connectedScript, SigHash localSigHash) {
|
||||||
Sha256Hash hash;
|
Sha256Hash hash;
|
||||||
|
|
||||||
|
ScriptType scriptType = getScriptType();
|
||||||
|
if(getWitnessUtxo() == null && Arrays.asList(WITNESS_TYPES).contains(scriptType)) {
|
||||||
|
throw new IllegalStateException("Trying to get signature hash for " + scriptType + " script without a PSBT witness UTXO");
|
||||||
|
}
|
||||||
|
|
||||||
if(getWitnessUtxo() != null) {
|
if(getWitnessUtxo() != null) {
|
||||||
long prevValue = getWitnessUtxo().getValue();
|
long prevValue = getWitnessUtxo().getValue();
|
||||||
hash = transaction.hashForWitnessSignature(index, connectedScript, prevValue, localSigHash);
|
hash = transaction.hashForWitnessSignature(index, connectedScript, prevValue, localSigHash);
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class FinalizingPSBTWallet extends Wallet {
|
||||||
|
|
||||||
ScriptType scriptType = psbtInput.getScriptType();
|
ScriptType scriptType = psbtInput.getScriptType();
|
||||||
if(scriptType == null || (getScriptType() != null && scriptType.equals(getScriptType()))) {
|
if(scriptType == null || (getScriptType() != null && scriptType.equals(getScriptType()))) {
|
||||||
throw new IllegalArgumentException("Cannot determine a single script type from the PSBT");
|
throw new IllegalArgumentException("Cannot determine the script type from the PSBT, or there are multiple script types");
|
||||||
} else {
|
} else {
|
||||||
setScriptType(scriptType);
|
setScriptType(scriptType);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue