Skip to content

Commit 30675df

Browse files
committed
feat: convert between FFI/Rust changesets
1 parent 8a4e372 commit 30675df

File tree

6 files changed

+71
-8
lines changed

6 files changed

+71
-8
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,6 @@ interface FullScanScriptInspector {
304304
void inspect(KeychainKind keychain, u32 index, Script script);
305305
};
306306

307-
/// A changeset for [`Wallet`].
308-
[Remote]
309-
interface ChangeSet {};
310-
311307
// ------------------------------------------------------------------------
312308
// bdk_wallet crate - wallet module
313309
// ------------------------------------------------------------------------

bdk-ffi/src/bitcoin.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,22 @@ impl From<OutPoint> for BdkOutPoint {
7272
}
7373
}
7474

75-
/// An [`OutPoint`] suitable as a key in a hash map.
75+
/// An [`OutPoint`] used as a key in a hash map.
76+
///
77+
/// Due to limitations in generating the foreign language bindings, we cannot use [`OutPoint`] as a
78+
/// key for hash maps.
7679
#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)]
7780
#[uniffi::export(Debug, Eq, Hash)]
7881
pub struct HashableOutPoint(pub(crate) OutPoint);
7982

8083
#[uniffi::export]
8184
impl HashableOutPoint {
85+
/// Create a key for a key-value store from an [`OutPoint`]
86+
#[uniffi::constructor]
87+
pub fn new(outpoint: OutPoint) -> Self {
88+
Self(outpoint)
89+
}
90+
8291
/// Get the internal [`OutPoint`]
8392
pub fn outpoint(&self) -> OutPoint {
8493
self.0.clone()

bdk-ffi/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use crate::types::SyncScriptInspector;
4343

4444
use bdk_wallet::bitcoin::Network;
4545
use bdk_wallet::keys::bip39::WordCount;
46-
use bdk_wallet::ChangeSet;
4746
use bdk_wallet::KeychainKind;
4847

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

bdk-ffi/src/types.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::bitcoin::{
22
Address, Amount, BlockHash, DescriptorId, HashableOutPoint, OutPoint, Script, Transaction,
33
TxOut, Txid,
44
};
5+
use crate::descriptor::Descriptor;
56
use crate::error::{CreateTxError, RequestBuilderError};
67

78
use bdk_core::bitcoin::absolute::LockTime as BdkLockTime;
@@ -902,3 +903,63 @@ impl From<TxGraphChangeSet> for bdk_wallet::chain::tx_graph::ChangeSet<BdkConfir
902903
}
903904
}
904905
}
906+
907+
#[derive(Debug, Clone, uniffi::Record)]
908+
pub struct ChangeSet {
909+
pub descriptor: Option<Arc<Descriptor>>,
910+
pub change_descriptor: Option<Arc<Descriptor>>,
911+
pub network: Option<bdk_wallet::bitcoin::Network>,
912+
pub local_chain: LocalChainChangeSet,
913+
pub tx_graph: TxGraphChangeSet,
914+
pub indexer: IndexerChangeSet,
915+
}
916+
917+
impl From<ChangeSet> for bdk_wallet::ChangeSet {
918+
fn from(value: ChangeSet) -> Self {
919+
let descriptor = value.descriptor.map(|d| d.extended_descriptor.clone());
920+
let change_descriptor = value
921+
.change_descriptor
922+
.map(|d| d.extended_descriptor.clone());
923+
let network = value.network;
924+
let local_chain = value.local_chain.into();
925+
let tx_graph = value.tx_graph.into();
926+
let indexer = value.indexer.into();
927+
Self {
928+
descriptor,
929+
change_descriptor,
930+
network,
931+
local_chain,
932+
tx_graph,
933+
indexer,
934+
}
935+
}
936+
}
937+
938+
impl From<bdk_wallet::ChangeSet> for ChangeSet {
939+
fn from(value: bdk_wallet::ChangeSet) -> Self {
940+
let descriptor = value.descriptor.map(|d| {
941+
Arc::new(Descriptor {
942+
extended_descriptor: d,
943+
key_map: BTreeMap::new(),
944+
})
945+
});
946+
let change_descriptor = value.change_descriptor.map(|d| {
947+
Arc::new(Descriptor {
948+
extended_descriptor: d,
949+
key_map: BTreeMap::new(),
950+
})
951+
});
952+
let network = value.network;
953+
let local_chain = value.local_chain.into();
954+
let tx_graph = value.tx_graph.into();
955+
let indexer = value.indexer.into();
956+
Self {
957+
descriptor,
958+
change_descriptor,
959+
network,
960+
local_chain,
961+
tx_graph,
962+
indexer,
963+
}
964+
}
965+
}

bdk-ffi/tests/bindings/test.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
import org.bitcoindevkit.bitcoin.Network
7-
import org.bitcoindevkit.Condition
87

98
// A type from bitcoin-ffi
109
val network = Network.TESTNET

bdk-ffi/tests/bindings/test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from bdkpython import Condition
21
from bdkpython.bitcoin import Network
32

43
import unittest

0 commit comments

Comments
 (0)