Skip to content

Commit 1af0175

Browse files
committed
feat: convert between FFI/Rust changesets
1 parent d612397 commit 1af0175

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

bdk-ffi/src/bdk.udl

-4
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/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ use crate::types::SyncScriptInspector;
4747

4848
use bdk_wallet::bitcoin::Network;
4949
use bdk_wallet::keys::bip39::WordCount;
50-
use bdk_wallet::ChangeSet;
5150
use bdk_wallet::KeychainKind;
5251

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

bdk-ffi/src/types.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::bitcoin::{
2-
Address, Amount, BlockHash, DescriptorId, HashableOutPoint, OutPoint, Script, Transaction, TxOut, Txid
2+
Address, Amount, BlockHash, DescriptorId, HashableOutPoint, OutPoint, Script, Transaction,
3+
TxOut, Txid,
34
};
45
use crate::error::{CreateTxError, RequestBuilderError};
6+
use crate::keys::DescriptorPublicKey;
57

68
use bdk_core::bitcoin::absolute::LockTime as BdkLockTime;
79
use bdk_core::spk_client::SyncItem;
@@ -896,3 +898,61 @@ impl From<TxGraphChangeSet> for bdk_wallet::chain::tx_graph::ChangeSet<BdkConfir
896898
}
897899
}
898900
}
901+
902+
#[derive(Debug, uniffi::Record)]
903+
pub struct ChangeSet {
904+
pub descriptor: Option<Arc<DescriptorPublicKey>>,
905+
pub change_descriptor: Option<Arc<DescriptorPublicKey>>,
906+
pub network: Option<bdk_wallet::bitcoin::Network>,
907+
pub local_chain: LocalChainChangeSet,
908+
pub tx_graph: TxGraphChangeSet,
909+
pub indexer: IndexerChangeSet,
910+
}
911+
912+
impl From<ChangeSet> for bdk_wallet::ChangeSet {
913+
fn from(value: ChangeSet) -> Self {
914+
let descriptor = value.descriptor.map(|d| {
915+
let str_repr = d.to_string();
916+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
917+
});
918+
let change_descriptor = value.change_descriptor.map(|d| {
919+
let str_repr = d.to_string();
920+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
921+
});
922+
let network = value.network;
923+
let local_chain = value.local_chain.into();
924+
let tx_graph = value.tx_graph.into();
925+
let indexer = value.indexer.into();
926+
Self {
927+
descriptor,
928+
change_descriptor,
929+
network,
930+
local_chain,
931+
tx_graph,
932+
indexer,
933+
}
934+
}
935+
}
936+
937+
impl From<bdk_wallet::ChangeSet> for ChangeSet {
938+
fn from(value: bdk_wallet::ChangeSet) -> Self {
939+
let descriptor = value
940+
.descriptor
941+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
942+
let change_descriptor = value
943+
.change_descriptor
944+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
945+
let network = value.network;
946+
let local_chain = value.local_chain.into();
947+
let tx_graph = value.tx_graph.into();
948+
let indexer = value.indexer.into();
949+
Self {
950+
descriptor,
951+
change_descriptor,
952+
network,
953+
local_chain,
954+
tx_graph,
955+
indexer,
956+
}
957+
}
958+
}

0 commit comments

Comments
 (0)