Skip to content

Commit

Permalink
upgrade bitcoin 0.31 -> 0.32
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Aug 19, 2024
1 parent c08382c commit 2d52f75
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 29 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ json-contract = ["serde_json"]
base64 = ["bitcoin/base64"]

[dependencies]
bitcoin = "0.31.0"
secp256k1-zkp = { version = "0.10.0", features = ["global-context", "hashes"] }
bech32 = "0.11.0"
bitcoin = "0.32.2"
secp256k1-zkp = { version = "0.11.0", features = ["global-context", "hashes"] }

# Used for ContractHash::from_json_contract.
serde_json = { version = "1.0", optional = true }
Expand Down
7 changes: 2 additions & 5 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ mod test {
"ert130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqqu2tys".parse();
assert_eq!(
address.err().unwrap().to_string(),
"bech32 error: invalid segwit witness version: 3", // FIXME https://github.com/rust-bitcoin/rust-bech32/issues/162 should be 17
"bech32 error: invalid segwit witness version: 17 (bech32 character: '3')",
);

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

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/blech32/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'s> UncheckedHrpstring<'s> {
}

let mut checksum_eng = checksum::Engine::<Ck>::new();
checksum_eng.input_hrp(&self.hrp());
checksum_eng.input_hrp(self.hrp());

// Unwrap ok since we checked all characters in our constructor.
for fe in self.data.iter().map(|&b| Fe32::from_char(b.into()).unwrap()) {
Expand Down
5 changes: 4 additions & 1 deletion src/blech32/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ impl crate::bech32::Checksum for Blech32 {
0x7093e5a608865b,
];
const TARGET_RESIDUE: u64 = 1;

const CODE_LENGTH: usize = 1024;
}

/// The blech32m checksum algorithm.
Expand All @@ -54,5 +56,6 @@ impl crate::bech32::Checksum for Blech32m {
0x7093e5a608865b,
];
const TARGET_RESIDUE: u64 = 0x455972a3350f7a1;
}

const CODE_LENGTH: usize = 1024;
}
6 changes: 3 additions & 3 deletions src/blind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ mod tests {
use crate::encode::deserialize;
use crate::hex::FromHex;
use crate::Script;
use bitcoin::{Network, PrivateKey, PublicKey};
use bitcoin::{PrivateKey, PublicKey};
use rand::thread_rng;
use secp256k1_zkp::SECP256K1;
use std::str::FromStr;
Expand Down Expand Up @@ -1466,7 +1466,7 @@ mod tests {
SECP256K1,
&PrivateKey {
compressed: true,
network: Network::Regtest,
network: bitcoin::NetworkKind::Test,
inner: sk,
},
);
Expand All @@ -1475,7 +1475,7 @@ mod tests {
SECP256K1,
&PrivateKey {
compressed: true,
network: Network::Regtest,
network: bitcoin::NetworkKind::Test,
inner: blinding_sk,
},
);
Expand Down
27 changes: 12 additions & 15 deletions src/hash_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,39 @@
//! to avoid mixing data of the same hash format (like SHA256d) but of different meaning
//! (transaction id, block hash etc).

use crate:: hashes::{hash_newtype, hash160, sha256, sha256d, Hash};
use bitcoin::secp256k1::ThirtyTwoByteHash;
use crate::hashes::{hash160, hash_newtype, sha256, sha256d, Hash};

macro_rules! impl_hashencode {
($hashtype:ident) => {
impl $crate::encode::Encodable for $hashtype {
fn consensus_encode<W: std::io::Write>(&self, w: W) -> Result<usize, crate::encode::Error> {
fn consensus_encode<W: std::io::Write>(
&self,
w: W,
) -> Result<usize, crate::encode::Error> {
self.0.consensus_encode(w)
}
}

impl $crate::encode::Decodable for $hashtype {
fn consensus_decode<R: std::io::Read>(r: R) -> Result<Self, $crate::encode::Error> {
Ok(Self::from_byte_array(<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?))
Ok(Self::from_byte_array(
<<$hashtype as $crate::hashes::Hash>::Bytes>::consensus_decode(r)?,
))
}
}
};
}

hash_newtype! {
/// An elements transaction ID
pub struct Txid(sha256d::Hash);
pub struct Txid(sha256d::Hash);
/// An elements witness transaction ID
pub struct Wtxid(sha256d::Hash);
pub struct Wtxid(sha256d::Hash);
/// An elements blockhash
pub struct BlockHash(sha256d::Hash);
pub struct BlockHash(sha256d::Hash);

/// "Hash of the transaction according to the signature algorithm"
pub struct Sighash(sha256d::Hash);
pub struct Sighash(sha256d::Hash);

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


impl_hashencode!(Txid);
impl_hashencode!(Wtxid);
impl_hashencode!(Sighash);
impl_hashencode!(BlockHash);
impl_hashencode!(TxMerkleNode);

impl ThirtyTwoByteHash for Sighash {
fn into_32(self) -> [u8; 32] {
self.0.to_byte_array()
}
}
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ mod transaction;
// consider making upstream public
mod endian;
// re-export bitcoin deps which we re-use
pub use bitcoin::bech32;
pub use bitcoin::hashes;
// export everything at the top level so it can be used as `elements::Transaction` etc.
pub use crate::address::{Address, AddressError, AddressParams};
Expand Down
2 changes: 1 addition & 1 deletion src/pset/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub enum Error {

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
match self {
Error::InvalidKey(ref rkey) => write!(f, "invalid key: {}", rkey),
Error::InvalidProprietaryKey => write!(
f,
Expand Down

0 comments on commit 2d52f75

Please sign in to comment.