Skip to content

Commit 0ea6895

Browse files
committed
refactor: use macros for AddressInfo, TxStatus, ScriptAmount, SentAndReceived, KeychainAndIndex
1 parent d255630 commit 0ea6895

File tree

3 files changed

+24
-45
lines changed

3 files changed

+24
-45
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -272,18 +272,6 @@ interface TransactionError {
272272

273273
typedef enum KeychainKind;
274274

275-
/// A derived address and the index it was found at.
276-
dictionary AddressInfo {
277-
/// Child index of this address
278-
u32 index;
279-
280-
/// Address
281-
Address address;
282-
283-
/// Type of keychain
284-
KeychainKind keychain;
285-
};
286-
287275
/// An unspent output owned by a [`Wallet`].
288276
dictionary LocalOutput {
289277
/// Reference to a transaction output
@@ -558,27 +546,7 @@ interface Descriptor {
558546
// bdk-ffi-defined types
559547
// ------------------------------------------------------------------------
560548

561-
dictionary ScriptAmount {
562-
Script script;
563-
Amount amount;
564-
};
565-
566-
dictionary SentAndReceivedValues {
567-
Amount sent;
568-
Amount received;
569-
};
570-
571-
dictionary KeychainAndIndex {
572-
KeychainKind keychain;
573-
u32 index;
574-
};
575-
576-
dictionary TxStatus {
577-
boolean confirmed;
578-
u32? block_height;
579-
string? block_hash;
580-
u64? block_time;
581-
};
549+
typedef dictionary TxStatus;
582550

583551
dictionary Tx {
584552
string txid;
@@ -607,8 +575,6 @@ typedef interface Address;
607575

608576
typedef dictionary Header;
609577

610-
typedef interface Transaction;
611-
612578
typedef interface Psbt;
613579

614580
dictionary TxIn {
@@ -629,8 +595,6 @@ enum Network {
629595
"Testnet4",
630596
};
631597

632-
typedef interface Amount;
633-
634598
typedef interface FeeRate;
635599

636600
dictionary OutPoint {

bdk-ffi/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ mod tx_builder;
1111
mod types;
1212
mod wallet;
1313

14-
use crate::bitcoin::Address;
15-
use crate::bitcoin::Amount;
1614
use crate::bitcoin::FeeRate;
1715
use crate::bitcoin::OutPoint;
1816
use crate::bitcoin::Script;
19-
use crate::bitcoin::Transaction;
2017
use crate::bitcoin::TxIn;
2118
use crate::bitcoin::TxOut;
2219
use crate::descriptor::Descriptor;
@@ -42,21 +39,17 @@ use crate::keys::DerivationPath;
4239
use crate::keys::DescriptorPublicKey;
4340
use crate::keys::DescriptorSecretKey;
4441
use crate::keys::Mnemonic;
45-
use crate::types::AddressInfo;
4642
use crate::types::ChainPosition;
4743
use crate::types::Condition;
4844
use crate::types::FullScanRequest;
4945
use crate::types::FullScanRequestBuilder;
5046
use crate::types::FullScanScriptInspector;
51-
use crate::types::KeychainAndIndex;
5247
use crate::types::LocalOutput;
5348
use crate::types::LockTime;
5449
use crate::types::PkOrF;
5550
use crate::types::Policy;
5651
use crate::types::Satisfaction;
5752
use crate::types::SatisfiableItem;
58-
use crate::types::ScriptAmount;
59-
use crate::types::SentAndReceivedValues;
6053
use crate::types::SignOptions;
6154
use crate::types::SyncRequest;
6255
use crate::types::SyncRequestBuilder;

bdk-ffi/src/types.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,23 @@ impl From<BdkCanonicalTx<'_, Arc<BdkTransaction>, BdkConfirmationBlockTime>> for
119119
}
120120
}
121121

122+
/// A bitcoin script and associated amount.
123+
#[derive(uniffi::Record)]
122124
pub struct ScriptAmount {
125+
/// The underlying script.
123126
pub script: Arc<Script>,
127+
/// The amount owned by the script.
124128
pub amount: Arc<Amount>,
125129
}
126130

131+
/// A derived address and the index it was found at.
132+
#[derive(uniffi::Record)]
127133
pub struct AddressInfo {
134+
/// Child index of this address
128135
pub index: u32,
136+
/// The address
129137
pub address: Arc<Address>,
138+
/// Type of keychain
130139
pub keychain: KeychainKind,
131140
}
132141

@@ -289,13 +298,21 @@ impl FullScanRequestBuilder {
289298
#[derive(uniffi::Object)]
290299
pub struct Update(pub(crate) BdkUpdate);
291300

301+
/// The total value sent and received.
302+
#[derive(uniffi::Record)]
292303
pub struct SentAndReceivedValues {
304+
/// Amount sent in the transaction.
293305
pub sent: Arc<Amount>,
306+
/// The amount received in the transaction, possibly as a change output(s).
294307
pub received: Arc<Amount>,
295308
}
296309

310+
/// The keychain kind and the index in that keychain.
311+
#[derive(uniffi::Record)]
297312
pub struct KeychainAndIndex {
313+
/// Type of keychains.
298314
pub keychain: KeychainKind,
315+
/// The index in the keychain.
299316
pub index: u32,
300317
}
301318

@@ -586,11 +603,16 @@ impl From<SignOptions> for BdkSignOptions {
586603
}
587604
}
588605

589-
#[derive(Debug)]
606+
/// Transaction confirmation metadata.
607+
#[derive(uniffi::Record, Debug)]
590608
pub struct TxStatus {
609+
/// Is the transaction in a block.
591610
pub confirmed: bool,
611+
/// Height of the block this transaction was included.
592612
pub block_height: Option<u32>,
613+
/// Hash of the block.
593614
pub block_hash: Option<String>,
615+
/// The time shown in the block, not necessarily the same time as when the block was found.
594616
pub block_time: Option<u64>,
595617
}
596618

0 commit comments

Comments
 (0)