Skip to content

Commit 58a156a

Browse files
committed
upgrade bitcoin 0.31 -> 0.32
1 parent ea70b14 commit 58a156a

File tree

9 files changed

+44
-47
lines changed

9 files changed

+44
-47
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ json-contract = ["serde_json"]
2222
base64 = ["bitcoin/base64"]
2323

2424
[dependencies]
25-
bitcoin = "0.31.0"
26-
secp256k1-zkp = { version = "0.10.0", features = ["global-context", "hashes"] }
25+
bech32 = "0.11.0"
26+
bitcoin = "0.32.2"
27+
secp256k1-zkp = { version = "0.11.0", features = ["global-context", "hashes"] }
2728

2829
# Used for ContractHash::from_json_contract.
2930
serde_json = { version = "1.0", optional = true }

src/address.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::fmt;
2121
use std::fmt::Write as _;
2222
use std::str::FromStr;
2323

24-
use crate::bech32::{Bech32, Bech32m, ByteIterExt, Fe32, Fe32IterExt, Hrp};
24+
use bech32::{Bech32, Bech32m, ByteIterExt, Fe32, Fe32IterExt, Hrp};
2525
use crate::blech32::{Blech32, Blech32m};
2626
use crate::hashes::Hash;
2727
use bitcoin::base58;
@@ -44,7 +44,7 @@ pub enum AddressError {
4444
/// Base58 encoding error
4545
Base58(base58::Error),
4646
/// Bech32 encoding error
47-
Bech32(crate::bech32::primitives::decode::SegwitHrpstringError),
47+
Bech32(bech32::primitives::decode::SegwitHrpstringError),
4848
/// Blech32 encoding error
4949
Blech32(crate::blech32::decode::SegwitHrpstringError),
5050
/// Was unable to parse the address.
@@ -70,8 +70,8 @@ pub enum AddressError {
7070
InvalidAddressVersion(u8),
7171
}
7272

73-
impl From<crate::bech32::primitives::decode::SegwitHrpstringError> for AddressError {
74-
fn from(e: crate::bech32::primitives::decode::SegwitHrpstringError) -> Self {
73+
impl From<bech32::primitives::decode::SegwitHrpstringError> for AddressError {
74+
fn from(e: bech32::primitives::decode::SegwitHrpstringError) -> Self {
7575
AddressError::Bech32(e)
7676
}
7777
}
@@ -458,7 +458,7 @@ impl Address {
458458
let hs = crate::blech32::decode::SegwitHrpstring::new(s)?;
459459
(hs.witness_version(), hs.byte_iter().collect())
460460
} else {
461-
let hs = crate::bech32::primitives::decode::SegwitHrpstring::new(s)?;
461+
let hs = bech32::primitives::decode::SegwitHrpstring::new(s)?;
462462
(hs.witness_version(), hs.byte_iter().collect())
463463
};
464464

@@ -908,7 +908,7 @@ mod test {
908908
"ert130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqqu2tys".parse();
909909
assert_eq!(
910910
address.err().unwrap().to_string(),
911-
"bech32 error: invalid segwit witness version: 3", // FIXME https://github.com/rust-bitcoin/rust-bech32/issues/162 should be 17
911+
"bech32 error: invalid segwit witness version: 17 (bech32 character: '3')",
912912
);
913913

914914
let address: Result<Address, _> = "el1pq0umk3pez693jrrlxz9ndlkuwne93gdu9g83mhhzuyf46e3mdzfpva0w48gqgzgrklncnm0k5zeyw8my2ypfsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpe9jfn0gypaj".parse();
@@ -920,10 +920,7 @@ mod test {
920920
// "invalid prefix" gives a weird error message because we do
921921
// a dumb prefix check before even attempting bech32 decoding
922922
let address: Result<Address, _> = "rrr1qq0umk3pez693jrrlxz9ndlkuwne93gdu9g83mhhzuyf46e3mdzfpva0w48gqgzgrklncnm0k5zeyw8my2ypfs2d9rp7meq4kg".parse();
923-
assert_eq!(
924-
address.err().unwrap().to_string(),
925-
"base58 error: invalid base58 character 0x30",
926-
);
923+
assert_eq!(address.err().unwrap().to_string(), "base58 error: decode",);
927924
}
928925

929926
#[test]

src/blech32/decode.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@
6666
use core::{fmt, iter, slice, str};
6767

6868
use crate::error::write_err;
69-
use crate::bech32::primitives::checksum::{self, Checksum};
70-
use crate::bech32::primitives::gf32::Fe32;
71-
use crate::bech32::primitives::hrp::{self, Hrp};
72-
use crate::bech32::primitives::iter::{Fe32IterExt, FesToBytes};
73-
use crate::bech32::primitives::segwit::{WitnessLengthError, VERSION_0};
69+
use bech32::primitives::checksum::{self, Checksum};
70+
use bech32::primitives::gf32::Fe32;
71+
use bech32::primitives::hrp::{self, Hrp};
72+
use bech32::primitives::iter::{Fe32IterExt, FesToBytes};
73+
use bech32::primitives::segwit::{WitnessLengthError, VERSION_0};
7474
use super::{Blech32, Blech32m};
7575

7676
/// Separator between the hrp and payload (as defined by BIP-173).
@@ -150,7 +150,7 @@ impl<'s> UncheckedHrpstring<'s> {
150150
}
151151

152152
let mut checksum_eng = checksum::Engine::<Ck>::new();
153-
checksum_eng.input_hrp(&self.hrp());
153+
checksum_eng.input_hrp(self.hrp());
154154

155155
// Unwrap ok since we checked all characters in our constructor.
156156
for fe in self.data.iter().map(|&b| Fe32::from_char(b.into()).unwrap()) {
@@ -881,7 +881,7 @@ mod tests {
881881
"an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio";
882882

883883
let hrp = Hrp::parse_unchecked(hrps);
884-
let s = crate::bech32::encode::<Blech32>(hrp, &[]).expect("failed to encode empty buffer");
884+
let s = bech32::encode::<Blech32>(hrp, &[]).expect("failed to encode empty buffer");
885885

886886
let unchecked = UncheckedHrpstring::new(&s).expect("failed to parse address");
887887
assert_eq!(unchecked.hrp(), hrp);

src/blech32/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub mod decode;
2626
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2727
pub enum Blech32 {}
2828

29-
impl crate::bech32::Checksum for Blech32 {
29+
impl bech32::Checksum for Blech32 {
3030
type MidstateRepr = u64;
3131
const CHECKSUM_LENGTH: usize = 12;
3232
const GENERATOR_SH: [u64; 5] = [
@@ -37,13 +37,15 @@ impl crate::bech32::Checksum for Blech32 {
3737
0x7093e5a608865b,
3838
];
3939
const TARGET_RESIDUE: u64 = 1;
40+
41+
const CODE_LENGTH: usize = 1024;
4042
}
4143

4244
/// The blech32m checksum algorithm.
4345
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
4446
pub enum Blech32m {}
4547

46-
impl crate::bech32::Checksum for Blech32m {
48+
impl bech32::Checksum for Blech32m {
4749
type MidstateRepr = u64;
4850
const CHECKSUM_LENGTH: usize = 12;
4951
const GENERATOR_SH: [u64; 5] = [
@@ -54,5 +56,6 @@ impl crate::bech32::Checksum for Blech32m {
5456
0x7093e5a608865b,
5557
];
5658
const TARGET_RESIDUE: u64 = 0x455972a3350f7a1;
57-
}
5859

60+
const CODE_LENGTH: usize = 1024;
61+
}

src/blind.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@ mod tests {
13751375
use crate::encode::deserialize;
13761376
use crate::hex::FromHex;
13771377
use crate::Script;
1378-
use bitcoin::{Network, PrivateKey, PublicKey};
1378+
use bitcoin::{PrivateKey, PublicKey};
13791379
use rand::thread_rng;
13801380
use secp256k1_zkp::SECP256K1;
13811381
use std::str::FromStr;
@@ -1466,7 +1466,7 @@ mod tests {
14661466
SECP256K1,
14671467
&PrivateKey {
14681468
compressed: true,
1469-
network: Network::Regtest,
1469+
network: bitcoin::NetworkKind::Test,
14701470
inner: sk,
14711471
},
14721472
);
@@ -1475,7 +1475,7 @@ mod tests {
14751475
SECP256K1,
14761476
&PrivateKey {
14771477
compressed: true,
1478-
network: Network::Regtest,
1478+
network: bitcoin::NetworkKind::Test,
14791479
inner: blinding_sk,
14801480
},
14811481
);

src/hash_types.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,39 @@
1616
//! to avoid mixing data of the same hash format (like SHA256d) but of different meaning
1717
//! (transaction id, block hash etc).
1818
19-
use crate:: hashes::{hash_newtype, hash160, sha256, sha256d, Hash};
20-
use bitcoin::secp256k1::ThirtyTwoByteHash;
19+
use crate::hashes::{hash160, hash_newtype, sha256, sha256d, Hash};
2120

2221
macro_rules! impl_hashencode {
2322
($hashtype:ident) => {
2423
impl $crate::encode::Encodable for $hashtype {
25-
fn consensus_encode<W: std::io::Write>(&self, w: W) -> Result<usize, crate::encode::Error> {
24+
fn consensus_encode<W: std::io::Write>(
25+
&self,
26+
w: W,
27+
) -> Result<usize, crate::encode::Error> {
2628
self.0.consensus_encode(w)
2729
}
2830
}
2931

3032
impl $crate::encode::Decodable for $hashtype {
3133
fn consensus_decode<R: std::io::Read>(r: R) -> Result<Self, $crate::encode::Error> {
32-
Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?))
34+
Ok(Self::from_byte_array(
35+
<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?,
36+
))
3337
}
3438
}
3539
};
3640
}
3741

3842
hash_newtype! {
3943
/// An elements transaction ID
40-
pub struct Txid(sha256d::Hash);
44+
pub struct Txid(sha256d::Hash);
4145
/// An elements witness transaction ID
42-
pub struct Wtxid(sha256d::Hash);
46+
pub struct Wtxid(sha256d::Hash);
4347
/// An elements blockhash
44-
pub struct BlockHash(sha256d::Hash);
48+
pub struct BlockHash(sha256d::Hash);
4549

4650
/// "Hash of the transaction according to the signature algorithm"
47-
pub struct Sighash(sha256d::Hash);
51+
pub struct Sighash(sha256d::Hash);
4852

4953
/// A hash of a public key.
5054
pub struct PubkeyHash(hash160::Hash);
@@ -59,15 +63,8 @@ hash_newtype! {
5963
pub struct TxMerkleNode(sha256d::Hash);
6064
}
6165

62-
6366
impl_hashencode!(Txid);
6467
impl_hashencode!(Wtxid);
6568
impl_hashencode!(Sighash);
6669
impl_hashencode!(BlockHash);
6770
impl_hashencode!(TxMerkleNode);
68-
69-
impl ThirtyTwoByteHash for Sighash {
70-
fn into_32(self) -> [u8; 32] {
71-
self.0.to_byte_array()
72-
}
73-
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ mod transaction;
7373
// consider making upstream public
7474
mod endian;
7575
// re-export bitcoin deps which we re-use
76-
pub use bitcoin::bech32;
7776
pub use bitcoin::hashes;
7877
// export everything at the top level so it can be used as `elements::Transaction` etc.
7978
pub use crate::address::{Address, AddressError, AddressParams};

src/pset/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub enum Error {
117117

118118
impl fmt::Display for Error {
119119
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120-
match *self {
120+
match self {
121121
Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
122122
Error::InvalidProprietaryKey => write!(
123123
f,

src/script.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,29 @@ impl Script {
261261

262262
/// Generates P2WPKH-type of scriptPubkey
263263
pub fn new_v0_wpkh(pubkey_hash: &WPubkeyHash) -> Script {
264-
Script::new_witness_program(crate::bech32::Fe32::Q, &pubkey_hash.to_raw_hash().to_byte_array())
264+
Script::new_witness_program(bech32::Fe32::Q, &pubkey_hash.to_raw_hash().to_byte_array())
265265
}
266266

267267
/// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script
268268
pub fn new_v0_wsh(script_hash: &WScriptHash) -> Script {
269-
Script::new_witness_program(crate::bech32::Fe32::Q, &script_hash.to_raw_hash().to_byte_array())
269+
Script::new_witness_program(bech32::Fe32::Q, &script_hash.to_raw_hash().to_byte_array())
270270
}
271271

272272
/// Generates P2TR for script spending path using an internal public key and some optional
273273
/// script tree merkle root.
274274
pub fn new_v1_p2tr<C: Verification>(secp: &Secp256k1<C>, internal_key: UntweakedPublicKey, merkle_root: Option<TapNodeHash>) -> Script {
275275
let (output_key, _) = internal_key.tap_tweak(secp, merkle_root);
276-
Script::new_witness_program(crate::bech32::Fe32::P, &output_key.as_inner().serialize())
276+
Script::new_witness_program(bech32::Fe32::P, &output_key.as_inner().serialize())
277277
}
278278

279279
/// Generates P2TR for key spending path for a known [`TweakedPublicKey`].
280280
pub fn new_v1_p2tr_tweaked(output_key: TweakedPublicKey) -> Script {
281-
Script::new_witness_program(crate::bech32::Fe32::P, &output_key.as_inner().serialize())
281+
Script::new_witness_program(bech32::Fe32::P, &output_key.as_inner().serialize())
282282
}
283283

284284

285285
/// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script
286-
pub fn new_witness_program(ver: crate::bech32::Fe32, program: &[u8]) -> Script {
286+
pub fn new_witness_program(ver: bech32::Fe32, program: &[u8]) -> Script {
287287
let mut verop = ver.to_u8();
288288
assert!(verop <= 16, "incorrect witness version provided: {}", verop);
289289
if verop > 0 {

0 commit comments

Comments
 (0)