Skip to content

Commit 872d55c

Browse files
committed
[wallet] Default to SIGHASH_ALL if not specified
Closes #133
1 parent 12635e6 commit 872d55c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/wallet/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use std::sync::Arc;
3535
use bitcoin::consensus::encode::serialize;
3636
use bitcoin::util::bip32::ChildNumber;
3737
use bitcoin::util::psbt::PartiallySignedTransaction as PSBT;
38-
use bitcoin::{Address, Network, OutPoint, Script, SigHashType, Transaction, TxOut, Txid};
38+
use bitcoin::{Address, Network, OutPoint, Script, Transaction, TxOut, Txid};
3939

4040
use miniscript::psbt::PsbtInputSatisfier;
4141

@@ -1025,8 +1025,11 @@ where
10251025
None => continue,
10261026
};
10271027

1028-
// Add sighash, default is obviously "ALL"
1029-
psbt_input.sighash_type = builder.sighash.or(Some(SigHashType::All));
1028+
// Only set it if the builder has a custom one, otherwise leave blank which defaults to
1029+
// SIGHASH_ALL
1030+
if let Some(sighash_type) = builder.sighash {
1031+
psbt_input.sighash_type = Some(sighash_type);
1032+
}
10301033

10311034
// Try to find the prev_script in our db to figure out if this is internal or external,
10321035
// and the derivation index
@@ -1742,7 +1745,7 @@ mod test {
17421745
)]))
17431746
.unwrap();
17441747

1745-
assert_eq!(psbt.inputs[0].sighash_type, Some(bitcoin::SigHashType::All));
1748+
assert_eq!(psbt.inputs[0].sighash_type, None);
17461749
}
17471750

17481751
#[test]

src/wallet/signer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ pub enum SignerError {
136136
InvalidKey,
137137
/// The user canceled the operation
138138
UserCanceled,
139-
/// The sighash is missing in the PSBT input
140-
MissingSighash,
141139
/// Input index is out of range
142140
InputIndexOutOfRange,
143141
/// The `non_witness_utxo` field of the transaction is required to sign this input
@@ -432,7 +430,7 @@ impl ComputeSighash for Legacy {
432430
let psbt_input = &psbt.inputs[input_index];
433431
let tx_input = &psbt.global.unsigned_tx.input[input_index];
434432

435-
let sighash = psbt_input.sighash_type.ok_or(SignerError::MissingSighash)?;
433+
let sighash = psbt_input.sighash_type.unwrap_or(SigHashType::All);
436434
let script = match psbt_input.redeem_script {
437435
Some(ref redeem_script) => redeem_script.clone(),
438436
None => {
@@ -479,7 +477,7 @@ impl ComputeSighash for Segwitv0 {
479477

480478
let psbt_input = &psbt.inputs[input_index];
481479

482-
let sighash = psbt_input.sighash_type.ok_or(SignerError::MissingSighash)?;
480+
let sighash = psbt_input.sighash_type.unwrap_or(SigHashType::All);
483481

484482
let witness_utxo = psbt_input
485483
.witness_utxo

0 commit comments

Comments
 (0)