Skip to content

Commit

Permalink
feat: add new types module
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Dec 6, 2023
1 parent e5ded1a commit 97dec1d
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 303 deletions.
68 changes: 40 additions & 28 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
@@ -1,14 +1,53 @@
namespace bdk {};

// ------------------------------------------------------------------------
// bdk crate - root module
// bdk crate - types module
// ------------------------------------------------------------------------

enum KeychainKind {
"External",
"Internal",
};

dictionary AddressInfo {
u32 index;
Address address;
KeychainKind keychain;
};

[Enum]
interface AddressIndex {
New();
LastUnused();
Peek(u32 index);
};

interface Balance {
u64 immature();

u64 trusted_pending();

u64 untrusted_pending();

u64 confirmed();

u64 trusted_spendable();

u64 total();
};

dictionary LocalUtxo {
OutPoint outpoint;
TxOut txout;
KeychainKind keychain;
boolean is_spent;
};

dictionary TxOut {
u64 value;
Script script_pubkey;
};

// ------------------------------------------------------------------------
// bdk crate - wallet module
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -49,33 +88,6 @@ enum ChangeSpendPolicy {
"ChangeForbidden"
};

interface Balance {
u64 immature();

u64 trusted_pending();

u64 untrusted_pending();

u64 confirmed();

u64 trusted_spendable();

u64 total();
};

dictionary AddressInfo {
u32 index;
Address address;
KeychainKind keychain;
};

[Enum]
interface AddressIndex {
New();
LastUnused();
Peek(u32 index);
};

interface Wallet {
[Name=new_no_persist, Throws=BdkError]
constructor(Descriptor descriptor, Descriptor? change_descriptor, Network network);
Expand Down
19 changes: 19 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
use bdk::bitcoin::consensus::Decodable;
use bdk::bitcoin::network::constants::Network as BdkNetwork;
use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction;
Expand Down Expand Up @@ -309,3 +310,21 @@ impl From<&OutPoint> for BdkOutPoint {
}
}
}

/// A transaction output, which defines new coins to be created from old ones.
#[derive(Debug, Clone)]
pub struct TxOut {
/// The value of the output, in satoshis.
pub value: u64,
/// The address of the output.
pub script_pubkey: Arc<Script>,
}

impl From<&BdkTxOut> for TxOut {
fn from(tx_out: &BdkTxOut) -> Self {
TxOut {
value: tx_out.value,
script_pubkey: Arc::new(Script(tx_out.script_pubkey.clone())),
}
}
}
3 changes: 3 additions & 0 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,12 @@ impl Descriptor {
mod test {
use crate::*;
use assert_matches::assert_matches;

use bdk::descriptor::DescriptorError::Key;
use bdk::keys::KeyError::InvalidNetwork;

use std::sync::Arc;

fn get_descriptor_secret_key() -> DescriptorSecretKey {
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();
DescriptorSecretKey::new(Network::Testnet, Arc::new(mnemonic), None)
Expand Down
Loading

0 comments on commit 97dec1d

Please sign in to comment.