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 d45a1bb
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 305 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
Expand Up @@ -7,6 +7,7 @@ use bdk::bitcoin::Address as BdkAddress;
use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::bitcoin::Txid;
use bdk::bitcoin::blockdata::transaction::TxOut as BdkTxOut;
use bdk::Error as BdkError;

use std::io::Cursor;
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()))
}
}
}
Loading

0 comments on commit d45a1bb

Please sign in to comment.