Skip to content

Commit 6b177f0

Browse files
feat: add new types module
1 parent 05ce7da commit 6b177f0

File tree

6 files changed

+228
-289
lines changed

6 files changed

+228
-289
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,53 @@
11
namespace bdk {};
22

33
// ------------------------------------------------------------------------
4-
// bdk crate - root module
4+
// bdk crate - types module
55
// ------------------------------------------------------------------------
66

77
enum KeychainKind {
88
"External",
99
"Internal",
1010
};
1111

12+
dictionary AddressInfo {
13+
u32 index;
14+
Address address;
15+
KeychainKind keychain;
16+
};
17+
18+
[Enum]
19+
interface AddressIndex {
20+
New();
21+
LastUnused();
22+
Peek(u32 index);
23+
};
24+
25+
dictionary Balance {
26+
u64 immature;
27+
28+
u64 trusted_pending;
29+
30+
u64 untrusted_pending;
31+
32+
u64 confirmed;
33+
34+
u64 trusted_spendable;
35+
36+
u64 total;
37+
};
38+
39+
dictionary LocalUtxo {
40+
OutPoint outpoint;
41+
TxOut txout;
42+
KeychainKind keychain;
43+
boolean is_spent;
44+
};
45+
46+
dictionary TxOut {
47+
u64 value;
48+
Script script_pubkey;
49+
};
50+
1251
// ------------------------------------------------------------------------
1352
// bdk crate - wallet module
1453
// ------------------------------------------------------------------------
@@ -49,33 +88,6 @@ enum ChangeSpendPolicy {
4988
"ChangeForbidden"
5089
};
5190

52-
dictionary Balance {
53-
u64 immature;
54-
55-
u64 trusted_pending;
56-
57-
u64 untrusted_pending;
58-
59-
u64 confirmed;
60-
61-
u64 trusted_spendable;
62-
63-
u64 total;
64-
};
65-
66-
dictionary AddressInfo {
67-
u32 index;
68-
Address address;
69-
KeychainKind keychain;
70-
};
71-
72-
[Enum]
73-
interface AddressIndex {
74-
New();
75-
LastUnused();
76-
Peek(u32 index);
77-
};
78-
7991
interface Wallet {
8092
[Name=new_no_persist, Throws=BdkError]
8193
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network);

bdk-ffi/src/bitcoin.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
22
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
3+
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
34
use bdk::bitcoin::consensus::Decodable;
45
use bdk::bitcoin::network::constants::Network as BdkNetwork;
56
use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction;
@@ -309,3 +310,21 @@ impl From<&OutPoint> for BdkOutPoint {
309310
}
310311
}
311312
}
313+
314+
/// A transaction output, which defines new coins to be created from old ones.
315+
#[derive(Debug, Clone)]
316+
pub struct TxOut {
317+
/// The value of the output, in satoshis.
318+
pub value: u64,
319+
/// The address of the output.
320+
pub script_pubkey: Arc<Script>,
321+
}
322+
323+
impl From<&BdkTxOut> for TxOut {
324+
fn from(tx_out: &BdkTxOut) -> Self {
325+
TxOut {
326+
value: tx_out.value,
327+
script_pubkey: Arc::new(Script(tx_out.script_pubkey.clone())),
328+
}
329+
}
330+
}

bdk-ffi/src/descriptor.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,12 @@ impl Descriptor {
284284
mod test {
285285
use crate::*;
286286
use assert_matches::assert_matches;
287+
287288
use bdk::descriptor::DescriptorError::Key;
288289
use bdk::keys::KeyError::InvalidNetwork;
289290

291+
use std::sync::Arc;
292+
290293
fn get_descriptor_secret_key() -> DescriptorSecretKey {
291294
let mnemonic = Mnemonic::from_string("chaos fabric time speed sponsor all flat solution wisdom trophy crack object robot pave observe combine where aware bench orient secret primary cable detect".to_string()).unwrap();
292295
DescriptorSecretKey::new(Network::Testnet, Arc::new(mnemonic), None)

0 commit comments

Comments
 (0)