Add PSBT deserialize and serialize functions, remove details
This commit is contained in:
parent
1f0b053872
commit
c039281ffc
@ -131,6 +131,9 @@ interface Wallet {
|
||||
interface PartiallySignedBitcoinTransaction {
|
||||
[Throws=BdkError]
|
||||
constructor([ByRef] Wallet wallet, string recipient, u64 amount, float? fee_rate);
|
||||
[Name=deserialize,Throws=BdkError]
|
||||
constructor(string psbt_base64);
|
||||
string serialize();
|
||||
};
|
||||
|
||||
dictionary ExtendedKeyInfo {
|
||||
|
@ -45,7 +45,13 @@ fn generate_python() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
let out_path = env::var("GENERATE_PYTHON_BINDINGS_OUT")
|
||||
.map_err(|_| String::from("`GENERATE_PYTHON_BINDINGS_OUT` env variable missing"))?;
|
||||
uniffi_bindgen::generate_bindings(&format!("{}/{}", env!("CARGO_MANIFEST_DIR"), BDK_UDL), None, vec!["python"], Some(&out_path), false)?;
|
||||
uniffi_bindgen::generate_bindings(
|
||||
&format!("{}/{}", env!("CARGO_MANIFEST_DIR"), BDK_UDL),
|
||||
None,
|
||||
vec!["python"],
|
||||
Some(&out_path),
|
||||
false,
|
||||
)?;
|
||||
|
||||
if let Some(name) = env::var("GENERATE_PYTHON_BINDINGS_FIXUP_LIB_PATH").ok() {
|
||||
fixup_python_lib_path(&out_path, &name)?;
|
||||
|
26
src/lib.rs
26
src/lib.rs
@ -12,7 +12,7 @@ use bdk::keys::bip39::{Language, Mnemonic, WordCount};
|
||||
use bdk::keys::{DerivableKey, ExtendedKey, GeneratableKey, GeneratedKey};
|
||||
use bdk::miniscript::BareCtx;
|
||||
use bdk::wallet::AddressIndex;
|
||||
use bdk::{BlockTime, Error, FeeRate, SignOptions, Wallet as BdkWallet };
|
||||
use bdk::{BlockTime, Error, FeeRate, SignOptions, Wallet as BdkWallet};
|
||||
use std::convert::TryFrom;
|
||||
use std::str::FromStr;
|
||||
use std::sync::{Mutex, MutexGuard};
|
||||
@ -155,7 +155,6 @@ impl Progress for BdkProgressHolder {
|
||||
|
||||
struct PartiallySignedBitcoinTransaction {
|
||||
internal: Mutex<PartiallySignedTransaction>,
|
||||
details: bdk::TransactionDetails,
|
||||
}
|
||||
|
||||
impl PartiallySignedBitcoinTransaction {
|
||||
@ -168,7 +167,7 @@ impl PartiallySignedBitcoinTransaction {
|
||||
let wallet = wallet.get_wallet();
|
||||
match Address::from_str(&recipient) {
|
||||
Ok(address) => {
|
||||
let (psbt, details) = {
|
||||
let (psbt, _details) = {
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(address.script_pubkey(), amount);
|
||||
if let Some(sat_per_vb) = fee_rate {
|
||||
@ -178,7 +177,6 @@ impl PartiallySignedBitcoinTransaction {
|
||||
};
|
||||
Ok(PartiallySignedBitcoinTransaction {
|
||||
internal: Mutex::new(psbt),
|
||||
details,
|
||||
})
|
||||
}
|
||||
Err(..) => Err(BdkError::Generic(
|
||||
@ -186,6 +184,18 @@ impl PartiallySignedBitcoinTransaction {
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize(psbt_base64: String) -> Result<Self, Error> {
|
||||
let psbt: PartiallySignedTransaction = PartiallySignedTransaction::from_str(&psbt_base64)?;
|
||||
Ok(PartiallySignedBitcoinTransaction {
|
||||
internal: Mutex::new(psbt),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> String {
|
||||
let psbt = self.internal.lock().unwrap().clone();
|
||||
psbt.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl WalletHolder<AnyBlockchain> for Wallet {
|
||||
@ -254,13 +264,11 @@ impl Wallet {
|
||||
.sync(BdkProgressHolder { progress_update }, max_address_param)
|
||||
}
|
||||
|
||||
fn broadcast(
|
||||
&self,
|
||||
psbt: &PartiallySignedBitcoinTransaction,
|
||||
) -> Result<Transaction, Error> {
|
||||
fn broadcast(&self, psbt: &PartiallySignedBitcoinTransaction) -> Result<Transaction, Error> {
|
||||
let tx = psbt.internal.lock().unwrap().clone().extract_tx();
|
||||
self.get_wallet().broadcast(&tx)?;
|
||||
Ok(Transaction::from(&psbt.details))
|
||||
let tx_details = self.get_wallet().get_tx(&tx.txid(), true)?;
|
||||
Ok(Transaction::from(&tx_details.unwrap()))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user