Skip to content

Commit 0d392dc

Browse files
committed
update rust-bitcoin to 0.31; fix hard errors
Will fix warnings and deprecations in following commits.
1 parent e839f6f commit 0d392dc

14 files changed

Lines changed: 91 additions & 118 deletions

File tree

Cargo.toml

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

2424
[dependencies]
25-
bech32 = { version = "0.10.0-beta" }
26-
bitcoin = "0.30.0"
27-
secp256k1-zkp = { version = "0.9.2", features = [ "global-context", "bitcoin_hashes" ] }
25+
bitcoin = "0.31.0"
26+
secp256k1-zkp = { version = "0.10.0", features = [ "global-context", "hashes" ] }
2827

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

elementsd-tests/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2018"
77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
bitcoin = "0.30.0"
10+
bitcoin = "0.31.0"
1111
elements = {path = "../", features = ["base64"]}
12-
elementsd = "0.8.0"
12+
elementsd = "0.9.0"
1313
rand = "0.8"
1414

elementsd-tests/src/taproot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate rand;
55

66
use crate::{Call, setup};
77

8-
use bitcoin::key::{XOnlyPublicKey, KeyPair};
8+
use bitcoin::key::{XOnlyPublicKey, Keypair};
99
use bitcoin::Amount;
1010
use elements::hex::FromHex;
1111
use elements::confidential::{AssetBlindingFactor, ValueBlindingFactor};
@@ -31,8 +31,8 @@ static PARAMS: AddressParams = AddressParams::ELEMENTS;
3131
fn gen_keypair(
3232
secp: &secp256k1_zkp::Secp256k1<secp256k1_zkp::All>,
3333
rng: &mut rngs::ThreadRng,
34-
) -> (XOnlyPublicKey, KeyPair) {
35-
let keypair = KeyPair::new(secp, rng);
34+
) -> (XOnlyPublicKey, Keypair) {
35+
let keypair = Keypair::new(secp, rng);
3636
let (pk, _) = XOnlyPublicKey::from_keypair(&keypair);
3737
(pk, keypair)
3838
}
@@ -42,10 +42,10 @@ fn gen_keypair(
4242
struct TapTxOutData {
4343
_blind_sk: Option<secp256k1_zkp::SecretKey>,
4444
_blind_pk: Option<secp256k1_zkp::PublicKey>,
45-
leaf1_keypair: KeyPair,
45+
leaf1_keypair: Keypair,
4646
_leaf1_pk: XOnlyPublicKey,
4747
leaf1_script: Script,
48-
internal_keypair: KeyPair,
48+
internal_keypair: Keypair,
4949
internal_pk: XOnlyPublicKey,
5050
spend_info: TaprootSpendInfo,
5151
utxo: TxOut,

src/address.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use secp256k1_zkp::Verification;
3333
use serde;
3434

3535
use crate::schnorr::{TapTweak, TweakedPublicKey, UntweakedPublicKey};
36-
use crate::taproot::TapBranchHash;
36+
use crate::taproot::TapNodeHash;
3737

3838
use crate::{PubkeyHash, ScriptHash, WPubkeyHash, WScriptHash};
3939
use crate::{opcodes, script};
@@ -316,7 +316,7 @@ impl Address {
316316
pub fn p2tr<C: Verification>(
317317
secp: &Secp256k1<C>,
318318
internal_key: UntweakedPublicKey,
319-
merkle_root: Option<TapBranchHash>,
319+
merkle_root: Option<TapNodeHash>,
320320
blinder: Option<secp256k1_zkp::PublicKey>,
321321
params: &'static AddressParams,
322322
) -> Address {

src/blind.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ pub enum UnblindError {
794794
/// Transaction output does not have a rangeproof.
795795
MissingRangeproof,
796796
/// Malformed asset ID.
797-
MalformedAssetId(hashes::Error),
797+
MalformedAssetId(hashes::FromSliceError),
798798
/// Error originated in `secp256k1_zkp`.
799799
Upstream(secp256k1_zkp::Error),
800800
}
@@ -829,8 +829,8 @@ impl From<secp256k1_zkp::Error> for UnblindError {
829829
}
830830
}
831831

832-
impl From<hashes::Error> for UnblindError {
833-
fn from(from: hashes::Error) -> Self {
832+
impl From<hashes::FromSliceError> for UnblindError {
833+
fn from(from: hashes::FromSliceError) -> Self {
834834
UnblindError::MalformedAssetId(from)
835835
}
836836
}

src/issuance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl AssetId {
8686
}
8787

8888
/// Copies a byte slice into an AssetId object
89-
pub fn from_slice(sl: &[u8]) -> Result<AssetId, hashes::Error> {
89+
pub fn from_slice(sl: &[u8]) -> Result<AssetId, hashes::FromSliceError> {
9090
sha256::Midstate::from_slice(sl).map(AssetId)
9191
}
9292

@@ -167,7 +167,7 @@ impl ::std::fmt::LowerHex for AssetId {
167167
}
168168

169169
impl FromStr for AssetId {
170-
type Err = crate::hashes::hex::Error;
170+
type Err = crate::hashes::hex::HexToArrayError;
171171
fn from_str(s: &str) -> Result<Self, Self::Err> {
172172
sha256::Midstate::from_str(s).map(AssetId)
173173
}

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ mod serde_utils;
6565
// consider making upstream public
6666
mod endian;
6767
// re-export bitcoin deps which we re-use
68-
//pub use bitcoin::bech32;
69-
pub extern crate bech32; // FIXME remove this in later commit
68+
pub use bitcoin::bech32;
7069
pub use bitcoin::hashes;
7170
// export everything at the top level so it can be used as `elements::Transaction` etc.
7271
pub use crate::address::{Address, AddressParams, AddressError};

src/pset/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub enum Error {
6767
/// Unable to parse as a standard Sighash type.
6868
NonStandardSighashType(u32),
6969
/// Parsing errors from bitcoin_hashes
70-
HashParseError(hashes::Error),
70+
HashParseError(hashes::FromSliceError),
7171
/// The pre-image must hash to the correponding pset hash
7272
InvalidPreimageHashPair {
7373
/// Hash-type
@@ -214,8 +214,8 @@ impl fmt::Display for Error {
214214
impl error::Error for Error {}
215215

216216
#[doc(hidden)]
217-
impl From<hashes::Error> for Error {
218-
fn from(e: hashes::Error) -> Error {
217+
impl From<hashes::FromSliceError> for Error {
218+
fn from(e: hashes::FromSliceError) -> Error {
219219
Error::HashParseError(e)
220220
}
221221
}

src/pset/map/global.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::encode::Decodable;
2525
use crate::endian::u32_to_array_le;
2626
use crate::pset::{self, map::Map, raw, Error};
2727
use crate::{LockTime, VarInt};
28-
use bitcoin::bip32::{ChildNumber, DerivationPath, ExtendedPubKey, Fingerprint, KeySource};
28+
use bitcoin::bip32::{ChildNumber, DerivationPath, Xpub, Fingerprint, KeySource};
2929
use secp256k1_zkp::Tweak;
3030

3131
// (Not used in pset) Type: Unsigned Transaction PSET_GLOBAL_UNSIGNED_TX = 0x00
@@ -102,7 +102,7 @@ pub struct Global {
102102
pub version: u32,
103103
/// A global map from extended public keys to the used key fingerprint and
104104
/// derivation path as defined by BIP 32
105-
pub xpub: BTreeMap<ExtendedPubKey, KeySource>,
105+
pub xpub: BTreeMap<Xpub, KeySource>,
106106
// Global proprietary key-value pairs.
107107
/// Scalars used for blinding
108108
pub scalars: Vec<Tweak>,
@@ -369,7 +369,7 @@ impl Decodable for Global {
369369
fn consensus_decode<D: io::Read>(mut d: D) -> Result<Self, encode::Error> {
370370
let mut version: Option<u32> = None;
371371
let mut unknowns: BTreeMap<raw::Key, Vec<u8>> = Default::default();
372-
let mut xpub_map: BTreeMap<ExtendedPubKey, (Fingerprint, DerivationPath)> =
372+
let mut xpub_map: BTreeMap<Xpub, (Fingerprint, DerivationPath)> =
373373
Default::default();
374374
let mut proprietary = BTreeMap::new();
375375
let mut scalars = Vec::new();
@@ -416,9 +416,9 @@ impl Decodable for Global {
416416
}
417417
PSET_GLOBAL_XPUB => {
418418
if !raw_key.key.is_empty() {
419-
let xpub = ExtendedPubKey::decode(&raw_key.key)
419+
let xpub = Xpub::decode(&raw_key.key)
420420
.map_err(|_| encode::Error::ParseFailed(
421-
"Can't deserialize ExtendedPublicKey from global XPUB key data"
421+
"Can't deserialize Xpub from global XPUB key data"
422422
))?;
423423

424424
if raw_value.is_empty() || raw_value.len() % 4 != 0 {

src/pset/map/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{
2020
str::FromStr,
2121
};
2222

23-
use crate::taproot::{ControlBlock, LeafVersion, TapBranchHash, TapLeafHash};
23+
use crate::taproot::{ControlBlock, LeafVersion, TapNodeHash, TapLeafHash};
2424
use crate::{schnorr, AssetId, ContractHash};
2525

2626
use crate::{confidential, locktime};
@@ -234,7 +234,7 @@ pub struct Input {
234234
/// Taproot Internal key
235235
pub tap_internal_key: Option<XOnlyPublicKey>,
236236
/// Taproot Merkle root
237-
pub tap_merkle_root: Option<TapBranchHash>,
237+
pub tap_merkle_root: Option<TapNodeHash>,
238238
// Proprietary key-value pairs for this input.
239239
/// The issuance value
240240
pub issuance_value_amount: Option<u64>,
@@ -646,7 +646,7 @@ impl Map for Input {
646646
}
647647
PSBT_IN_TAP_MERKLE_ROOT => {
648648
impl_pset_insert_pair! {
649-
self.tap_merkle_root <= <raw_key: _>|< raw_value: TapBranchHash>
649+
self.tap_merkle_root <= <raw_key: _>|< raw_value: TapNodeHash>
650650
}
651651
}
652652
PSET_IN_PROPRIETARY => {

0 commit comments

Comments
 (0)