Skip to content

Commit

Permalink
feat(wallet): add IndexedScript and SpkIterator types, and wallet::sp…
Browse files Browse the repository at this point in the history
…ks_of_all_keychains()"
  • Loading branch information
thunderbiscuit authored and notmandatory committed Oct 24, 2023
1 parent 7463fa7 commit a2fa233
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 64 deletions.
56 changes: 28 additions & 28 deletions bdk-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 45 additions & 27 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,22 @@ interface Wallet {

[Throws=BdkError]
void apply_update(Update update);
};

interface Update {};

// ------------------------------------------------------------------------
// bdk crate - bitcoin reexports
// ------------------------------------------------------------------------

enum Network {
"Bitcoin",
"Testnet",
"Signet",
"Regtest",
record<KeychainKind, SpkIterator> spks_of_all_keychains();
};

enum WordCount {
"Words12",
"Words15",
"Words18",
"Words21",
"Words24",
dictionary IndexedScript {
u32 index;
Script script;
};

interface Address {
[Throws=BdkError]
constructor(string address, Network network);

Network network();

string to_qr_uri();

string as_string();
interface SpkIterator {
constructor(Descriptor descriptor);
IndexedScript? next();
};

interface Update {};

// ------------------------------------------------------------------------
// bdk crate - descriptor module
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -209,3 +191,39 @@ interface Descriptor {
interface EsploraClient {
constructor(string url);
};

// ------------------------------------------------------------------------
// bdk crate - bitcoin reexports
// ------------------------------------------------------------------------

interface Script {
constructor(sequence<u8> raw_output_script);

sequence<u8> to_bytes();
};

enum Network {
"Bitcoin",
"Testnet",
"Signet",
"Regtest",
};

enum WordCount {
"Words12",
"Words15",
"Words18",
"Words21",
"Words24",
};

interface Address {
[Throws=BdkError]
constructor(string address, Network network);

Network network();

string to_qr_uri();

string as_string();
};
22 changes: 22 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;

/// A Bitcoin script.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Script(pub(crate) BdkScriptBuf);

impl Script {
pub fn new(raw_output_script: Vec<u8>) -> Self {
let script: BdkScriptBuf = BdkScriptBuf::from(raw_output_script);
Script(script)
}

pub fn to_bytes(&self) -> Vec<u8> {
self.0.to_bytes()
}
}

impl From<BdkScriptBuf> for Script {
fn from(script: BdkScriptBuf) -> Self {
Script(script)
}
}
5 changes: 4 additions & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod bitcoin;
mod descriptor;
mod esplora;
mod keys;
Expand All @@ -15,16 +16,18 @@ use bdk::KeychainKind;
use std::sync::Arc;

// TODO 6: Why are these imports required?
use crate::bitcoin::Script;
use crate::descriptor::Descriptor;
use crate::esplora::EsploraClient;
use crate::keys::DerivationPath;
use crate::keys::DescriptorPublicKey;
use crate::keys::DescriptorSecretKey;
use crate::keys::Mnemonic;
use crate::wallet::IndexedScript;
use crate::wallet::SpkIterator;
use crate::wallet::Update;
use crate::wallet::Wallet;
use bdk::keys::bip39::WordCount;
// use bdk_esplora::EsploraExt;

uniffi::include_scaffolding!("bdk");

Expand Down
Loading

0 comments on commit a2fa233

Please sign in to comment.