Allow creating partially signed bitcoin transactions
This commit is contained in:
parent
a528a76c5d
commit
69a676ba36
@ -105,3 +105,8 @@ interface OnlineWallet {
|
|||||||
[Throws=BdkError]
|
[Throws=BdkError]
|
||||||
u64 get_balance();
|
u64 get_balance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface PartiallySignedBitcoinTransaction {
|
||||||
|
[Throws=BdkError]
|
||||||
|
constructor([ByRef] OnlineWallet wallet, string recipient, u64 amount);
|
||||||
|
};
|
||||||
|
31
src/lib.rs
31
src/lib.rs
@ -1,4 +1,6 @@
|
|||||||
use bdk::bitcoin::Network;
|
use bdk::address_validator::AddressValidatorError;
|
||||||
|
use bdk::bitcoin::util::psbt::PartiallySignedTransaction;
|
||||||
|
use bdk::bitcoin::{Address, Network};
|
||||||
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
use bdk::blockchain::any::{AnyBlockchain, AnyBlockchainConfig};
|
||||||
use bdk::blockchain::Progress;
|
use bdk::blockchain::Progress;
|
||||||
use bdk::blockchain::{
|
use bdk::blockchain::{
|
||||||
@ -7,9 +9,9 @@ use bdk::blockchain::{
|
|||||||
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
use bdk::database::any::{AnyDatabase, SledDbConfiguration};
|
||||||
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
use bdk::database::{AnyDatabaseConfig, ConfigurableDatabase};
|
||||||
use bdk::wallet::AddressIndex;
|
use bdk::wallet::AddressIndex;
|
||||||
use bdk::Error;
|
use bdk::{Error, Wallet};
|
||||||
use bdk::Wallet;
|
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::{Mutex, MutexGuard};
|
use std::sync::{Mutex, MutexGuard};
|
||||||
|
|
||||||
uniffi_macros::include_scaffolding!("bdk");
|
uniffi_macros::include_scaffolding!("bdk");
|
||||||
@ -103,6 +105,29 @@ impl Progress for BdkProgressHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct PartiallySignedBitcoinTransaction {
|
||||||
|
internal: Mutex<PartiallySignedTransaction>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartiallySignedBitcoinTransaction {
|
||||||
|
fn new(online_wallet: &OnlineWallet, recipient: String, amount: u64) -> Result<Self, Error> {
|
||||||
|
let wallet = online_wallet.get_wallet();
|
||||||
|
match Address::from_str(&recipient) {
|
||||||
|
Ok(address) => {
|
||||||
|
let mut builder = wallet.build_tx();
|
||||||
|
builder.add_recipient(address.script_pubkey(), amount);
|
||||||
|
let (pst, ..) = builder.finish()?;
|
||||||
|
Ok(PartiallySignedBitcoinTransaction {
|
||||||
|
internal: Mutex::new(pst),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Err(..) => Err(BdkError::AddressValidator(
|
||||||
|
AddressValidatorError::InvalidScript,
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl OnlineWallet {
|
impl OnlineWallet {
|
||||||
fn new(
|
fn new(
|
||||||
descriptor: String,
|
descriptor: String,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user