Skip to content

Commit 4940e39

Browse files
committed
feat: convert between FFI/Rust changesets
1 parent d676afa commit 4940e39

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
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/lib.rs

Lines changed: 0 additions & 1 deletion
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

Lines changed: 61 additions & 1 deletion
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;
@@ -899,3 +901,61 @@ impl From<TxGraphChangeSet> for bdk_wallet::chain::tx_graph::ChangeSet<BdkConfir
899901
}
900902
}
901903
}
904+
905+
#[derive(Debug, Clone, uniffi::Record)]
906+
pub struct ChangeSet {
907+
pub descriptor: Option<Arc<DescriptorPublicKey>>,
908+
pub change_descriptor: Option<Arc<DescriptorPublicKey>>,
909+
pub network: Option<bdk_wallet::bitcoin::Network>,
910+
pub local_chain: LocalChainChangeSet,
911+
pub tx_graph: TxGraphChangeSet,
912+
pub indexer: IndexerChangeSet,
913+
}
914+
915+
impl From<ChangeSet> for bdk_wallet::ChangeSet {
916+
fn from(value: ChangeSet) -> Self {
917+
let descriptor = value.descriptor.map(|d| {
918+
let str_repr = d.to_string();
919+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
920+
});
921+
let change_descriptor = value.change_descriptor.map(|d| {
922+
let str_repr = d.to_string();
923+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
924+
});
925+
let network = value.network;
926+
let local_chain = value.local_chain.into();
927+
let tx_graph = value.tx_graph.into();
928+
let indexer = value.indexer.into();
929+
Self {
930+
descriptor,
931+
change_descriptor,
932+
network,
933+
local_chain,
934+
tx_graph,
935+
indexer,
936+
}
937+
}
938+
}
939+
940+
impl From<bdk_wallet::ChangeSet> for ChangeSet {
941+
fn from(value: bdk_wallet::ChangeSet) -> Self {
942+
let descriptor = value
943+
.descriptor
944+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
945+
let change_descriptor = value
946+
.change_descriptor
947+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
948+
let network = value.network;
949+
let local_chain = value.local_chain.into();
950+
let tx_graph = value.tx_graph.into();
951+
let indexer = value.indexer.into();
952+
Self {
953+
descriptor,
954+
change_descriptor,
955+
network,
956+
local_chain,
957+
tx_graph,
958+
indexer,
959+
}
960+
}
961+
}

0 commit comments

Comments
 (0)