Skip to content

Commit

Permalink
feat: add MVP transaction builder type
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Oct 19, 2023
1 parent 2541a92 commit 3691c6e
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 292 deletions.
69 changes: 44 additions & 25 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace bdk {};

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

enum KeychainKind {
Expand Down Expand Up @@ -86,34 +86,15 @@ interface Wallet {

interface Update {};

// ------------------------------------------------------------------------
// bdk crate - bitcoin reexports
// ------------------------------------------------------------------------
interface TxBuilder {
constructor();

enum Network {
"Bitcoin",
"Testnet",
"Signet",
"Regtest",
};
TxBuilder add_recipient(Script script, u64 amount);

enum WordCount {
"Words12",
"Words15",
"Words18",
"Words21",
"Words24",
};
TxBuilder fee_rate(float sat_per_vbyte);

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

Network network();

string to_qr_uri();

string as_string();
string finish([ByRef] Wallet wallet);
};

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -212,3 +193,41 @@ interface EsploraClient {
[Throws=BdkError]
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
};

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

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

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

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

Network network();

Script script_pubkey();

string to_qr_uri();

string as_string();
};

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

sequence<u8> to_bytes();
};
48 changes: 25 additions & 23 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod psbt;
mod wallet;

use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked};
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::Address as BdkAddress;
use bdk::bitcoin::Network as BdkNetwork;
use bdk::wallet::AddressIndex as BdkAddressIndex;
Expand All @@ -21,6 +22,7 @@ use crate::keys::DerivationPath;
use crate::keys::DescriptorPublicKey;
use crate::keys::DescriptorSecretKey;
use crate::keys::Mnemonic;
use crate::wallet::TxBuilder;
use crate::wallet::Update;
use crate::wallet::Wallet;
use bdk::keys::bip39::WordCount;
Expand Down Expand Up @@ -452,11 +454,11 @@ impl Address {
self.inner.network.into()
}

// fn script_pubkey(&self) -> Arc<Script> {
// Arc::new(Script {
// inner: self.inner.script_pubkey(),
// })
// }
fn script_pubkey(&self) -> Arc<Script> {
Arc::new(Script {
inner: self.inner.script_pubkey(),
})
}

fn to_qr_uri(&self) -> String {
self.inner.to_qr_uri()
Expand Down Expand Up @@ -494,24 +496,24 @@ impl From<Address> for BdkAddress {
// program: Vec<u8>,
// },
// }
//
// /// A Bitcoin script.
// #[derive(Clone, Debug, PartialEq, Eq)]
// pub struct Script {
// inner: BdkScript,
// }
//
// impl Script {
// fn new(raw_output_script: Vec<u8>) -> Self {
// let script: BdkScript = BdkScript::from(raw_output_script);
// Script { inner: script }
// }
//
// fn to_bytes(&self) -> Vec<u8> {
// self.inner.to_bytes()
// }
// }
//

/// A Bitcoin script.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Script {
inner: BdkScriptBuf,
}

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

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

// impl From<BdkScript> for Script {
// fn from(bdk_script: BdkScript) -> Self {
// Script { inner: bdk_script }
Expand Down
Loading

0 comments on commit 3691c6e

Please sign in to comment.