Skip to content

Commit 3fb311e

Browse files
committed
Bump bitcoin version to v0.25.0
1 parent abf3681 commit 3fb311e

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ readme = "README.md"
1414
use-serde = ["serde", "bitcoin/use-serde"]
1515

1616
[dependencies]
17-
bitcoin = "0.23"
17+
bitcoin = "0.25"
1818
rand = "0.7"
1919
rust-crypto = "0.2"
2020

2121
serde = { version = "1", optional = true, features = ["derive"] }
2222

2323
[dev-dependencies]
24-
bitcoin = { version = "0.23", features = ["use-serde", "bitcoinconsensus"] }
24+
bitcoin = { version = "0.25", features = ["use-serde", "bitcoinconsensus"] }
2525
serde = { version = "1", features = ["derive"] }
2626
serde_json = "1"

src/account.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -641,8 +641,9 @@ impl Account {
641641
R: Fn(&OutPoint) -> Option<TxOut>,
642642
{
643643
let mut signed = 0;
644+
//TODO(stevenroose) try to prevent this clone here
644645
let txclone = transaction.clone();
645-
let mut bip143hasher: Option<bip143::SighashComponents> = None;
646+
let mut bip143hasher = bip143::SigHashCache::new(&txclone);
646647
for (ix, input) in transaction.input.iter_mut().enumerate() {
647648
if let Some(spend) = resolver(&input.previous_output) {
648649
if let Some((kix, instantiated)) = self
@@ -680,14 +681,12 @@ impl Account {
680681
return Err(Error::Unsupported("can only sign all inputs for now"));
681682
}
682683
input.script_sig = Script::new();
683-
let hasher =
684-
bip143hasher.unwrap_or(bip143::SighashComponents::new(&txclone));
685-
let sighash = hasher.sighash_all(
686-
&txclone.input[ix],
684+
let sighash = bip143hasher.signature_hash(
685+
ix,
687686
&instantiated.script_code,
688687
spend.value,
688+
hash_type,
689689
);
690-
bip143hasher = Some(hasher);
691690
let signature = self.context.sign(&sighash[..], &pk)?.serialize_der();
692691
let mut with_hashtype = signature.to_vec();
693692
with_hashtype.push(hash_type.as_u32() as u8);
@@ -712,14 +711,12 @@ impl Account {
712711
.into_script()[..],
713712
)
714713
.into_script();
715-
let hasher =
716-
bip143hasher.unwrap_or(bip143::SighashComponents::new(&txclone));
717-
let sighash = hasher.sighash_all(
718-
&txclone.input[ix],
714+
let sighash = bip143hasher.signature_hash(
715+
ix,
719716
&instantiated.script_code,
720717
spend.value,
718+
hash_type,
721719
);
722-
bip143hasher = Some(hasher);
723720
let signature = self.context.sign(&sighash[..], &pk)?.serialize_der();
724721
let mut with_hashtype = signature.to_vec();
725722
with_hashtype.push(hash_type.as_u32() as u8);
@@ -733,14 +730,12 @@ impl Account {
733730
return Err(Error::Unsupported("can only sign all inputs for now"));
734731
}
735732
input.script_sig = Script::new();
736-
let hasher =
737-
bip143hasher.unwrap_or(bip143::SighashComponents::new(&txclone));
738-
let sighash = hasher.sighash_all(
739-
&txclone.input[ix],
733+
let sighash = bip143hasher.signature_hash(
734+
ix,
740735
&instantiated.script_code,
741736
spend.value,
737+
hash_type,
742738
);
743-
bip143hasher = Some(hasher);
744739
let signature = self.context.sign(&sighash[..], &pk)?.serialize_der();
745740
let mut with_hashtype = signature.to_vec();
746741
with_hashtype.push(hash_type.as_u32() as u8);
@@ -789,10 +784,15 @@ impl InstantiatedKey {
789784
context.tweak_exp_add(&mut public, tweak)?;
790785
}
791786
let script_code = scripter(&public, csv);
787+
assert!(public.compressed);
792788
let address = match address_type {
793789
AccountAddressType::P2PKH => Address::p2pkh(&public, network),
794-
AccountAddressType::P2SHWPKH => Address::p2shwpkh(&public, network),
795-
AccountAddressType::P2WPKH => Address::p2wpkh(&public, network),
790+
AccountAddressType::P2SHWPKH => {
791+
Address::p2shwpkh(&public, network).expect("compressed pubkey")
792+
}
793+
AccountAddressType::P2WPKH => {
794+
Address::p2wpkh(&public, network).expect("compressed pubkey")
795+
}
796796
AccountAddressType::P2WSH(_) => Address::p2wsh(&script_code, network),
797797
};
798798
Ok(InstantiatedKey {

src/coins.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ use bitcoin::hashes::hex::FromHex;
325325
use bitcoin::blockdata::script::Builder;
326326
use bitcoin::util::bip32::ExtendedPubKey;
327327
use bitcoin::{
328-
network::constants::Network, Address, BitcoinHash, Block, BlockHeader, OutPoint,
328+
network::constants::Network, Address, Block, BlockHeader, OutPoint,
329329
Transaction, TxIn, TxOut,
330330
};
331331

@@ -406,10 +406,10 @@ use bitcoin::hashes::hex::FromHex;
406406
.address
407407
.clone();
408408
let genesis = genesis_block(Network::Testnet);
409-
let next = mine(&genesis.bitcoin_hash(), 1, miner);
409+
let next = mine(&genesis.block_hash(), 1, miner);
410410
coins.process(&mut master, &next);
411411
assert_eq!(coins.confirmed_balance(), NEW_COINS);
412-
coins.unwind_tip(&next.bitcoin_hash());
412+
coins.unwind_tip(&next.block_hash());
413413
assert_eq!(coins.confirmed_balance(), 0);
414414
}
415415
}

src/proved.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//!
2020
2121
use bitcoin::hashes::{sha256d, Hash, HashEngine};
22-
use bitcoin::{BitcoinHash, Block, Transaction};
22+
use bitcoin::{Block, Transaction};
2323

2424
/// A confirmed transaction with its SPV proof
2525
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -34,7 +34,7 @@ impl ProvedTransaction {
3434
pub fn new(block: &Block, txnr: usize) -> ProvedTransaction {
3535
let transaction = block.txdata[txnr].clone();
3636
ProvedTransaction {
37-
block_hash: block.header.bitcoin_hash(),
37+
block_hash: block.header.block_hash(),
3838
merkle_path: Self::compute_proof(txnr, block),
3939
transaction,
4040
}
@@ -136,7 +136,7 @@ mod test {
136136
let pt = ProvedTransaction {
137137
transaction: tx.clone(),
138138
merkle_path: proof,
139-
block_hash: block.header.bitcoin_hash(),
139+
block_hash: block.header.block_hash(),
140140
};
141141
assert_eq!(pt.merkle_root(), block.header.merkle_root);
142142
}

0 commit comments

Comments
 (0)