Skip to content

Express the wallet changeset over the FFI layer #756

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 4 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,6 @@ interface FullScanScriptInspector {
void inspect(KeychainKind keychain, u32 index, Script script);
};

/// A changeset for [`Wallet`].
[Remote]
interface ChangeSet {};

// ------------------------------------------------------------------------
// bdk_wallet crate - wallet module
// ------------------------------------------------------------------------
Expand Down
50 changes: 45 additions & 5 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,54 @@ use std::str::FromStr;
use std::sync::{Arc, Mutex};

/// A reference to an unspent output by TXID and output index.
#[derive(Debug, Clone, Eq, PartialEq, uniffi:: Record)]
#[derive(Debug, Clone, Eq, PartialEq, std::hash::Hash, uniffi:: Record)]
pub struct OutPoint {
/// The transaction.
pub txid: String,
pub txid: Arc<Txid>,
/// The index of the output in the transaction.
pub vout: u32,
}

impl From<&BdkOutPoint> for OutPoint {
fn from(outpoint: &BdkOutPoint) -> Self {
OutPoint {
txid: outpoint.txid.to_string(),
txid: Arc::new(Txid(outpoint.txid)),
vout: outpoint.vout,
}
}
}

impl From<BdkOutPoint> for OutPoint {
fn from(value: BdkOutPoint) -> Self {
Self {
txid: Arc::new(Txid(value.txid)),
vout: value.vout,
}
}
}

impl From<OutPoint> for BdkOutPoint {
fn from(outpoint: OutPoint) -> Self {
BdkOutPoint {
txid: BitcoinTxid::from_str(&outpoint.txid).unwrap(),
txid: BitcoinTxid::from_raw_hash(outpoint.txid.0.into()),
vout: outpoint.vout,
}
}
}

/// An [`OutPoint`] suitable as a key in a hash map.
#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)]
#[uniffi::export(Debug, Eq, Hash)]
pub struct HashableOutPoint(pub(crate) OutPoint);

#[uniffi::export]
impl HashableOutPoint {
/// Get the internal [`OutPoint`]
pub fn outpoint(&self) -> OutPoint {
self.0.clone()
}
}

/// Represents fee rate.
///
/// This is an integer type representing fee rate in sat/kwu. It provides protection against mixing
Expand Down Expand Up @@ -549,7 +571,7 @@ impl From<&BdkTxIn> for TxIn {
fn from(tx_in: &BdkTxIn) -> Self {
TxIn {
previous_output: OutPoint {
txid: tx_in.previous_output.txid.to_string(),
txid: Arc::new(Txid(tx_in.previous_output.txid)),
vout: tx_in.previous_output.vout,
},
script_sig: Arc::new(Script(tx_in.script_sig.clone())),
Expand Down Expand Up @@ -583,6 +605,24 @@ impl From<&BdkTxOut> for TxOut {
}
}

impl From<BdkTxOut> for TxOut {
fn from(tx_out: BdkTxOut) -> Self {
Self {
value: tx_out.value.to_sat(),
script_pubkey: Arc::new(Script(tx_out.script_pubkey)),
}
}
}

impl From<TxOut> for BdkTxOut {
fn from(tx_out: TxOut) -> Self {
Self {
value: BdkAmount::from_sat(tx_out.value),
script_pubkey: tx_out.script_pubkey.0.clone(),
}
}
}

/// A bitcoin Block hash
#[derive(Debug, Clone, Copy, PartialEq, Eq, std::hash::Hash, uniffi::Object)]
#[uniffi::export(Display, Eq, Hash)]
Expand Down
1 change: 0 additions & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ use crate::types::SyncScriptInspector;

use bdk_wallet::bitcoin::Network;
use bdk_wallet::keys::bip39::WordCount;
use bdk_wallet::ChangeSet;
use bdk_wallet::KeychainKind;

uniffi::include_scaffolding!("bdk");
Loading
Loading