Skip to content

Commit

Permalink
Merge #91: Upgrade bitcoin
Browse files Browse the repository at this point in the history
943b6c1 Upgrade miniscript/bitcoin dependency (Tobin C. Harding)

Pull request description:

  Upgrade
  - bitcoin to v0.31.0
  - miniscript v11.0.0

ACKs for top commit:
  danielabrozzoni:
    ACK 943b6c1

Tree-SHA512: 6bd580808496218797f9ca34f539d7b1bff8dfe232843c0eee332d53d5059bd79aa7bcc3368c4983c976cd63d897f371e38e5105befedc2fbda55adf24895d50
  • Loading branch information
danielabrozzoni committed Feb 5, 2024
2 parents 98b4ea6 + 943b6c1 commit f3058b7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 2 additions & 5 deletions src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,10 +205,7 @@ impl HWIClient {
}

/// Signs a PSBT.
pub fn sign_tx(
&self,
psbt: &PartiallySignedTransaction,
) -> Result<HWIPartiallySignedTransaction, Error> {
pub fn sign_tx(&self, psbt: &Psbt) -> Result<HWIPartiallySignedTransaction, Error> {
Python::with_gil(|py| {
let output = self
.hwilib
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
}],
};
Expand All @@ -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,
}],
},
Expand Down
24 changes: 12 additions & 12 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
Expand All @@ -37,8 +36,11 @@ pub struct HWISignature {
}

fn from_b64<'de, D: Deserializer<'de>>(d: D) -> Result<Vec<u8>, 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"))
}

Expand All @@ -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<PartiallySignedTransaction, D::Error> {
fn deserialize_psbt<'de, D: Deserializer<'de>>(d: D) -> Result<Psbt, D::Error> {
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
Expand Down

0 comments on commit f3058b7

Please sign in to comment.