Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new types module #429

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};

dictionary 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"
};

dictionary 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
Loading