Skip to content

Commit 2c359be

Browse files
committed
feat: convert between FFI/Rust changesets
1 parent 81b2399 commit 2c359be

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
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
@@ -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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::bitcoin::{
33
TxOut, Txid,
44
};
55
use crate::error::{CreateTxError, RequestBuilderError};
6+
use crate::keys::DescriptorPublicKey;
67

78
use bdk_core::bitcoin::absolute::LockTime as BdkLockTime;
89
use bdk_core::spk_client::SyncItem;
@@ -902,3 +903,61 @@ 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<DescriptorPublicKey>>,
910+
pub change_descriptor: Option<Arc<DescriptorPublicKey>>,
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| {
920+
let str_repr = d.to_string();
921+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
922+
});
923+
let change_descriptor = value.change_descriptor.map(|d| {
924+
let str_repr = d.to_string();
925+
str_repr.parse::<bdk_wallet::miniscript::Descriptor<bdk_wallet::miniscript::DescriptorPublicKey>>().unwrap()
926+
});
927+
let network = value.network;
928+
let local_chain = value.local_chain.into();
929+
let tx_graph = value.tx_graph.into();
930+
let indexer = value.indexer.into();
931+
Self {
932+
descriptor,
933+
change_descriptor,
934+
network,
935+
local_chain,
936+
tx_graph,
937+
indexer,
938+
}
939+
}
940+
}
941+
942+
impl From<bdk_wallet::ChangeSet> for ChangeSet {
943+
fn from(value: bdk_wallet::ChangeSet) -> Self {
944+
let descriptor = value
945+
.descriptor
946+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
947+
let change_descriptor = value
948+
.change_descriptor
949+
.map(|d| Arc::new(DescriptorPublicKey::from_string(d.to_string()).unwrap()));
950+
let network = value.network;
951+
let local_chain = value.local_chain.into();
952+
let tx_graph = value.tx_graph.into();
953+
let indexer = value.indexer.into();
954+
Self {
955+
descriptor,
956+
change_descriptor,
957+
network,
958+
local_chain,
959+
tx_graph,
960+
indexer,
961+
}
962+
}
963+
}

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)