Skip to content

Commit a2fa233

Browse files
thunderbiscuitnotmandatory
authored andcommitted
feat(wallet): add IndexedScript and SpkIterator types, and wallet::spks_of_all_keychains()"
1 parent 7463fa7 commit a2fa233

File tree

6 files changed

+204
-64
lines changed

6 files changed

+204
-64
lines changed

bdk-ffi/Cargo.lock

+28-28
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bdk-ffi/src/bdk.udl

+45-27
Original file line numberDiff line numberDiff line change
@@ -82,40 +82,22 @@ interface Wallet {
8282

8383
[Throws=BdkError]
8484
void apply_update(Update update);
85-
};
86-
87-
interface Update {};
88-
89-
// ------------------------------------------------------------------------
90-
// bdk crate - bitcoin reexports
91-
// ------------------------------------------------------------------------
9285

93-
enum Network {
94-
"Bitcoin",
95-
"Testnet",
96-
"Signet",
97-
"Regtest",
86+
record<KeychainKind, SpkIterator> spks_of_all_keychains();
9887
};
9988

100-
enum WordCount {
101-
"Words12",
102-
"Words15",
103-
"Words18",
104-
"Words21",
105-
"Words24",
89+
dictionary IndexedScript {
90+
u32 index;
91+
Script script;
10692
};
10793

108-
interface Address {
109-
[Throws=BdkError]
110-
constructor(string address, Network network);
111-
112-
Network network();
113-
114-
string to_qr_uri();
115-
116-
string as_string();
94+
interface SpkIterator {
95+
constructor(Descriptor descriptor);
96+
IndexedScript? next();
11797
};
11898

99+
interface Update {};
100+
119101
// ------------------------------------------------------------------------
120102
// bdk crate - descriptor module
121103
// ------------------------------------------------------------------------
@@ -209,3 +191,39 @@ interface Descriptor {
209191
interface EsploraClient {
210192
constructor(string url);
211193
};
194+
195+
// ------------------------------------------------------------------------
196+
// bdk crate - bitcoin reexports
197+
// ------------------------------------------------------------------------
198+
199+
interface Script {
200+
constructor(sequence<u8> raw_output_script);
201+
202+
sequence<u8> to_bytes();
203+
};
204+
205+
enum Network {
206+
"Bitcoin",
207+
"Testnet",
208+
"Signet",
209+
"Regtest",
210+
};
211+
212+
enum WordCount {
213+
"Words12",
214+
"Words15",
215+
"Words18",
216+
"Words21",
217+
"Words24",
218+
};
219+
220+
interface Address {
221+
[Throws=BdkError]
222+
constructor(string address, Network network);
223+
224+
Network network();
225+
226+
string to_qr_uri();
227+
228+
string as_string();
229+
};

bdk-ffi/src/bitcoin.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
2+
3+
/// A Bitcoin script.
4+
#[derive(Clone, Debug, PartialEq, Eq)]
5+
pub struct Script(pub(crate) BdkScriptBuf);
6+
7+
impl Script {
8+
pub fn new(raw_output_script: Vec<u8>) -> Self {
9+
let script: BdkScriptBuf = BdkScriptBuf::from(raw_output_script);
10+
Script(script)
11+
}
12+
13+
pub fn to_bytes(&self) -> Vec<u8> {
14+
self.0.to_bytes()
15+
}
16+
}
17+
18+
impl From<BdkScriptBuf> for Script {
19+
fn from(script: BdkScriptBuf) -> Self {
20+
Script(script)
21+
}
22+
}

bdk-ffi/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod bitcoin;
12
mod descriptor;
23
mod esplora;
34
mod keys;
@@ -15,16 +16,18 @@ use bdk::KeychainKind;
1516
use std::sync::Arc;
1617

1718
// TODO 6: Why are these imports required?
19+
use crate::bitcoin::Script;
1820
use crate::descriptor::Descriptor;
1921
use crate::esplora::EsploraClient;
2022
use crate::keys::DerivationPath;
2123
use crate::keys::DescriptorPublicKey;
2224
use crate::keys::DescriptorSecretKey;
2325
use crate::keys::Mnemonic;
26+
use crate::wallet::IndexedScript;
27+
use crate::wallet::SpkIterator;
2428
use crate::wallet::Update;
2529
use crate::wallet::Wallet;
2630
use bdk::keys::bip39::WordCount;
27-
// use bdk_esplora::EsploraExt;
2831

2932
uniffi::include_scaffolding!("bdk");
3033

0 commit comments

Comments
 (0)