From 943b6c103bc44a8ac4134f1ad0f6e4a493796beb Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 16 Oct 2023 17:22:18 +1100 Subject: [PATCH] Upgrade miniscript/bitcoin dependency Upgrade: - bitcoin to v0.31.0 - miniscript to v11.0.0 --- Cargo.toml | 4 ++-- src/interface.rs | 7 ++----- src/lib.rs | 12 ++++++------ src/types.rs | 24 ++++++++++++------------ 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16d1056..69af067 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,12 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bitcoin = { version = "0.30.0", features = ["serde", "base64"] } +bitcoin = { version = "0.31.0", features = ["serde", "base64"] } serde = { version = "^1.0", features = ["derive"] } serde_json = { version = "^1.0" } pyo3 = { version = "0.15.1", features = ["auto-initialize"] } -miniscript = { version = "10.0", features = ["serde"], optional = true } +miniscript = { version = "11.0", features = ["serde"], optional = true } [dev-dependencies] serial_test = "0.6.0" diff --git a/src/interface.rs b/src/interface.rs index b4c57e1..f5745cb 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -3,7 +3,7 @@ use std::ops::Deref; use std::process::Command; use bitcoin::bip32::DerivationPath; -use bitcoin::psbt::PartiallySignedTransaction; +use bitcoin::Psbt; use serde::de::DeserializeOwned; use serde_json::value::Value; @@ -205,10 +205,7 @@ impl HWIClient { } /// Signs a PSBT. - pub fn sign_tx( - &self, - psbt: &PartiallySignedTransaction, - ) -> Result { + pub fn sign_tx(&self, psbt: &Psbt) -> Result { Python::with_gil(|py| { let output = self .hwilib diff --git a/src/lib.rs b/src/lib.rs index 033b71b..d986b1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,7 +49,7 @@ mod tests { use bitcoin::locktime::absolute; use bitcoin::psbt::{Input, Output}; use bitcoin::{secp256k1, Transaction}; - use bitcoin::{Network, TxIn, TxOut}; + use bitcoin::{transaction, Amount, Network, TxIn, TxOut}; #[cfg(feature = "miniscript")] use miniscript::{Descriptor, DescriptorPublicKey}; @@ -213,11 +213,11 @@ mod tests { let script_pubkey = address.address.assume_checked().script_pubkey(); let previous_tx = Transaction { - version: 1, + version: transaction::Version::ONE, lock_time: absolute::LockTime::from_consensus(0), input: vec![TxIn::default()], output: vec![TxOut { - value: 100, + value: Amount::from_sat(100), script_pubkey: script_pubkey.clone(), }], }; @@ -229,13 +229,13 @@ mod tests { }, ..Default::default() }; - let psbt = bitcoin::psbt::PartiallySignedTransaction { + let psbt = bitcoin::Psbt { unsigned_tx: Transaction { - version: 1, + version: transaction::Version::ONE, lock_time: absolute::LockTime::from_consensus(0), input: vec![previous_txin], output: vec![TxOut { - value: 50, + value: Amount::from_sat(50), script_pubkey: script_pubkey, }], }, diff --git a/src/types.rs b/src/types.rs index 2eb0591..4f368ef 100644 --- a/src/types.rs +++ b/src/types.rs @@ -3,10 +3,9 @@ use std::ops::Deref; use std::str::FromStr; use bitcoin::address::{Address, NetworkUnchecked}; -use bitcoin::base64; -use bitcoin::bip32::{ExtendedPubKey, Fingerprint}; -use bitcoin::psbt::PartiallySignedTransaction; +use bitcoin::bip32::{Fingerprint, Xpub}; use bitcoin::Network; +use bitcoin::Psbt; use pyo3::types::PyModule; use pyo3::{IntoPy, PyObject}; @@ -19,11 +18,11 @@ use crate::error::{Error, ErrorCode}; #[derive(Clone, Eq, PartialEq, Debug, Deserialize)] pub struct HWIExtendedPubKey { - pub xpub: ExtendedPubKey, + pub xpub: Xpub, } impl Deref for HWIExtendedPubKey { - type Target = ExtendedPubKey; + type Target = Xpub; fn deref(&self) -> &Self::Target { &self.xpub @@ -37,8 +36,11 @@ pub struct HWISignature { } fn from_b64<'de, D: Deserializer<'de>>(d: D) -> Result, D::Error> { + use bitcoin::base64::{engine::general_purpose, Engine as _}; + let b64_string = String::deserialize(d)?; - base64::decode(b64_string) + general_purpose::STANDARD + .decode(b64_string) .map_err(|_| serde::de::Error::custom("error while deserializing signature")) } @@ -58,18 +60,16 @@ pub struct HWIAddress { #[derive(Clone, Eq, PartialEq, Debug, Deserialize)] pub struct HWIPartiallySignedTransaction { #[serde(deserialize_with = "deserialize_psbt")] - pub psbt: PartiallySignedTransaction, + pub psbt: Psbt, } -fn deserialize_psbt<'de, D: Deserializer<'de>>( - d: D, -) -> Result { +fn deserialize_psbt<'de, D: Deserializer<'de>>(d: D) -> Result { let s = String::deserialize(d)?; - PartiallySignedTransaction::from_str(&s).map_err(serde::de::Error::custom) + Psbt::from_str(&s).map_err(serde::de::Error::custom) } impl Deref for HWIPartiallySignedTransaction { - type Target = PartiallySignedTransaction; + type Target = Psbt; fn deref(&self) -> &Self::Target { &self.psbt