Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade bitcoin #91

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading