Skip to content

Commit 7114542

Browse files
committed
refactor: HashableOutPoint to Record
1 parent 9fa0fa0 commit 7114542

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

bdk-ffi/src/bitcoin.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,23 @@ pub enum Network {
9898
///
9999
/// Due to limitations in generating the foreign language bindings, we cannot use [`OutPoint`] as a
100100
/// key for hash maps.
101-
#[derive(Debug, PartialEq, Eq, std::hash::Hash, uniffi::Object)]
102-
#[uniffi::export(Debug, Eq, Hash)]
103-
pub struct HashableOutPoint(pub(crate) OutPoint);
101+
#[derive(Debug, Clone, PartialEq, Eq, std::hash::Hash, uniffi::Record)]
102+
pub struct HashableOutPoint {
103+
/// The wrapped [`OutPoint`] that acts as a hashmap key.
104+
pub outpoint: OutPoint,
105+
}
104106

105107
#[uniffi::export]
106108
impl HashableOutPoint {
107109
/// Create a key for a key-value store from an [`OutPoint`]
108110
#[uniffi::constructor]
109111
pub fn new(outpoint: OutPoint) -> Self {
110-
Self(outpoint)
112+
Self { outpoint }
111113
}
112114

113115
/// Get the internal [`OutPoint`]
114116
pub fn outpoint(&self) -> OutPoint {
115-
self.0.clone()
117+
self.outpoint.clone()
116118
}
117119
}
118120

bdk-ffi/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ pub struct Anchor {
881881
#[derive(Debug, Clone, uniffi::Record)]
882882
pub struct TxGraphChangeSet {
883883
pub txs: Vec<Arc<Transaction>>,
884-
pub txouts: HashMap<Arc<HashableOutPoint>, TxOut>,
884+
pub txouts: HashMap<HashableOutPoint, TxOut>,
885885
pub anchors: Vec<Anchor>,
886886
pub last_seen: HashMap<Arc<Txid>, u64>,
887887
pub first_seen: HashMap<Arc<Txid>, u64>,
@@ -897,7 +897,7 @@ impl From<bdk_wallet::chain::tx_graph::ChangeSet<BdkConfirmationBlockTime>> for
897897
.collect::<Vec<Arc<Transaction>>>();
898898
let mut txouts = HashMap::new();
899899
for (outpoint, txout) in core::mem::take(&mut value.txouts) {
900-
txouts.insert(Arc::new(HashableOutPoint(outpoint.into())), txout.into());
900+
txouts.insert(HashableOutPoint::new(outpoint.into()), txout.into());
901901
}
902902
let mut anchors = Vec::new();
903903
for anchor in core::mem::take(&mut value.anchors) {
@@ -949,8 +949,8 @@ impl From<TxGraphChangeSet> for bdk_wallet::chain::tx_graph::ChangeSet<BdkConfir
949949
txs.insert(tx);
950950
}
951951
let mut txouts = BTreeMap::new();
952-
for txout in core::mem::take(&mut value.txouts) {
953-
txouts.insert(txout.0.outpoint().into(), txout.1.into());
952+
for (outpoint, txout) in core::mem::take(&mut value.txouts) {
953+
txouts.insert(outpoint.outpoint().into(), txout.into());
954954
}
955955
let mut anchors = BTreeSet::new();
956956
for anchor in core::mem::take(&mut value.anchors) {

0 commit comments

Comments
 (0)