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

Delete all API docs to prepare for the new 1.0 API docs #435

Merged
merged 2 commits into from
Dec 15, 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
34 changes: 17 additions & 17 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface Wallet {

Balance get_balance();

boolean is_mine(Script script);
boolean is_mine([ByRef] Script script);

[Throws=BdkError]
void apply_update(Update update);
Expand All @@ -118,7 +118,7 @@ interface Update {};
interface TxBuilder {
constructor();

TxBuilder add_recipient(Script script, u64 amount);
TxBuilder add_recipient([ByRef] Script script, u64 amount);

TxBuilder set_recipients(sequence<ScriptAmount> recipients);

Expand All @@ -142,7 +142,7 @@ interface TxBuilder {

TxBuilder drain_wallet();

TxBuilder drain_to(Script script);
TxBuilder drain_to([ByRef] Script script);

TxBuilder enable_rbf();

Expand Down Expand Up @@ -187,16 +187,16 @@ interface DerivationPath {
};

interface DescriptorSecretKey {
constructor(Network network, Mnemonic mnemonic, string? password);
constructor(Network network, [ByRef] Mnemonic mnemonic, string? password);

[Name=from_string, Throws=BdkError]
constructor(string secret_key);

[Throws=BdkError]
DescriptorSecretKey derive(DerivationPath path);
DescriptorSecretKey derive([ByRef] DerivationPath path);

[Throws=BdkError]
DescriptorSecretKey extend(DerivationPath path);
DescriptorSecretKey extend([ByRef] DerivationPath path);

DescriptorPublicKey as_public();

Expand All @@ -210,10 +210,10 @@ interface DescriptorPublicKey {
constructor(string public_key);

[Throws=BdkError]
DescriptorPublicKey derive(DerivationPath path);
DescriptorPublicKey derive([ByRef] DerivationPath path);

[Throws=BdkError]
DescriptorPublicKey extend(DerivationPath path);
DescriptorPublicKey extend([ByRef] DerivationPath path);

string as_string();
};
Expand All @@ -223,28 +223,28 @@ interface Descriptor {
constructor(string descriptor, Network network);

[Name=new_bip44]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);

[Name=new_bip44_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

[Name=new_bip49]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);

[Name=new_bip49_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

[Name=new_bip84]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);

[Name=new_bip84_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

[Name=new_bip86]
constructor(DescriptorSecretKey secret_key, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorSecretKey secret_key, KeychainKind keychain, Network network);

[Name=new_bip86_public]
constructor(DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);
constructor([ByRef] DescriptorPublicKey public_key, string fingerprint, KeychainKind keychain, Network network);

string as_string();

Expand All @@ -262,7 +262,7 @@ interface EsploraClient {
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);

[Throws=BdkError]
void broadcast(Transaction transaction);
void broadcast([ByRef] Transaction transaction);
};

// ------------------------------------------------------------------------
Expand Down
14 changes: 0 additions & 14 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::io::Cursor;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

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

Expand All @@ -36,13 +35,9 @@ impl From<BdkScriptBuf> for Script {
}

pub enum Network {
/// Mainnet Bitcoin.
Bitcoin,
/// Bitcoin's testnet network.
Testnet,
/// Bitcoin's signet network.
Signet,
/// Bitcoin's regtest network.
Regtest,
}

Expand All @@ -69,7 +64,6 @@ impl From<BdkNetwork> for Network {
}
}

/// A Bitcoin address.
#[derive(Debug, PartialEq, Eq)]
pub struct Address {
inner: BdkAddress<NetworkChecked>,
Expand Down Expand Up @@ -141,7 +135,6 @@ impl From<BdkAddress> for Address {
}
}

/// A Bitcoin transaction.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transaction {
inner: BdkTransaction,
Expand Down Expand Up @@ -242,7 +235,6 @@ impl PartiallySignedTransaction {
// txid.to_hex()
// }

/// Return the transaction.
pub(crate) fn extract_tx(&self) -> Arc<Transaction> {
let tx = self.inner.lock().unwrap().clone().extract_tx();
Arc::new(tx.into())
Expand Down Expand Up @@ -293,12 +285,9 @@ impl From<BdkPartiallySignedTransaction> for PartiallySignedTransaction {
}
}

/// A reference to a transaction output.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct OutPoint {
/// The referenced transaction's txid.
pub txid: String,
/// The index of the referenced output in its transaction's vout.
pub vout: u32,
}

Expand All @@ -311,12 +300,9 @@ 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>,
}

Expand Down
58 changes: 22 additions & 36 deletions bdk-ffi/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use bdk::Error as BdkError;
use bdk::KeychainKind;

use std::str::FromStr;
use std::sync::Arc;

#[derive(Debug)]
pub struct Descriptor {
Expand All @@ -35,7 +34,7 @@ impl Descriptor {
}

pub(crate) fn new_bip44(
secret_key: Arc<DescriptorSecretKey>,
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
) -> Self {
Expand All @@ -62,7 +61,7 @@ impl Descriptor {
}

pub(crate) fn new_bip44_public(
public_key: Arc<DescriptorPublicKey>,
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
network: Network,
Expand Down Expand Up @@ -93,7 +92,7 @@ impl Descriptor {
}

pub(crate) fn new_bip49(
secret_key: Arc<DescriptorSecretKey>,
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
) -> Self {
Expand All @@ -120,7 +119,7 @@ impl Descriptor {
}

pub(crate) fn new_bip49_public(
public_key: Arc<DescriptorPublicKey>,
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
network: Network,
Expand Down Expand Up @@ -151,7 +150,7 @@ impl Descriptor {
}

pub(crate) fn new_bip84(
secret_key: Arc<DescriptorSecretKey>,
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
) -> Self {
Expand All @@ -178,7 +177,7 @@ impl Descriptor {
}

pub(crate) fn new_bip84_public(
public_key: Arc<DescriptorPublicKey>,
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
network: Network,
Expand Down Expand Up @@ -209,7 +208,7 @@ impl Descriptor {
}

pub(crate) fn new_bip86(
secret_key: Arc<DescriptorSecretKey>,
secret_key: &DescriptorSecretKey,
keychain_kind: KeychainKind,
network: Network,
) -> Self {
Expand All @@ -236,7 +235,7 @@ impl Descriptor {
}

pub(crate) fn new_bip86_public(
public_key: Arc<DescriptorPublicKey>,
public_key: &DescriptorPublicKey,
fingerprint: String,
keychain_kind: KeychainKind,
network: Network,
Expand Down Expand Up @@ -277,9 +276,6 @@ impl Descriptor {
}
}

// // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs.
// // These tests should not be used to verify `bdk` behavior that is already tested in the `bdk`
// // crate.
#[cfg(test)]
mod test {
use crate::*;
Expand All @@ -288,83 +284,73 @@ mod test {
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)
DescriptorSecretKey::new(Network::Testnet, &mnemonic, None)
}

#[test]
fn test_descriptor_templates() {
let master: Arc<DescriptorSecretKey> = Arc::new(get_descriptor_secret_key());
let master: DescriptorSecretKey = get_descriptor_secret_key();
println!("Master: {:?}", master.as_string());
// tprv8ZgxMBicQKsPdWuqM1t1CDRvQtQuBPyfL6GbhQwtxDKgUAVPbxmj71pRA8raTqLrec5LyTs5TqCxdABcZr77bt2KyWA5bizJHnC4g4ysm4h
let handmade_public_44 = master
.derive(Arc::new(
DerivationPath::new("m/44h/1h/0h".to_string()).unwrap(),
))
.derive(&DerivationPath::new("m/44h/1h/0h".to_string()).unwrap())
.unwrap()
.as_public();
println!("Public 44: {}", handmade_public_44.as_string());
// Public 44: [d1d04177/44'/1'/0']tpubDCoPjomfTqh1e7o1WgGpQtARWtkueXQAepTeNpWiitS3Sdv8RKJ1yvTrGHcwjDXp2SKyMrTEca4LoN7gEUiGCWboyWe2rz99Kf4jK4m2Zmx/*
let handmade_public_49 = master
.derive(Arc::new(
DerivationPath::new("m/49h/1h/0h".to_string()).unwrap(),
))
.derive(&DerivationPath::new("m/49h/1h/0h".to_string()).unwrap())
.unwrap()
.as_public();
println!("Public 49: {}", handmade_public_49.as_string());
// Public 49: [d1d04177/49'/1'/0']tpubDC65ZRvk1NDddHrVAUAZrUPJ772QXzooNYmPywYF9tMyNLYKf5wpKE7ZJvK9kvfG3FV7rCsHBNXy1LVKW95jrmC7c7z4hq7a27aD2sRrAhR/*
let handmade_public_84 = master
.derive(Arc::new(
DerivationPath::new("m/84h/1h/0h".to_string()).unwrap(),
))
.derive(&DerivationPath::new("m/84h/1h/0h".to_string()).unwrap())
.unwrap()
.as_public();
println!("Public 84: {}", handmade_public_84.as_string());
// Public 84: [d1d04177/84'/1'/0']tpubDDNxbq17egjFk2edjv8oLnzxk52zny9aAYNv9CMqTzA4mQDiQq818sEkNe9Gzmd4QU8558zftqbfoVBDQorG3E4Wq26tB2JeE4KUoahLkx6/*
let handmade_public_86 = master
.derive(Arc::new(
DerivationPath::new("m/86h/1h/0h".to_string()).unwrap(),
))
.derive(&DerivationPath::new("m/86h/1h/0h".to_string()).unwrap())
.unwrap()
.as_public();
println!("Public 86: {}", handmade_public_86.as_string());
// Public 86: [d1d04177/86'/1'/0']tpubDCJzjbcGbdEfXMWaL6QmgVmuSfXkrue7m2YNoacWwyc7a2XjXaKojRqNEbo41CFL3PyYmKdhwg2fkGpLX4SQCbQjCGxAkWHJTw9WEeenrJb/*
let template_private_44 =
Descriptor::new_bip44(master.clone(), KeychainKind::External, Network::Testnet);
Descriptor::new_bip44(&master, KeychainKind::External, Network::Testnet);
let template_private_49 =
Descriptor::new_bip49(master.clone(), KeychainKind::External, Network::Testnet);
Descriptor::new_bip49(&master, KeychainKind::External, Network::Testnet);
let template_private_84 =
Descriptor::new_bip84(master.clone(), KeychainKind::External, Network::Testnet);
Descriptor::new_bip84(&master, KeychainKind::External, Network::Testnet);
let template_private_86 =
Descriptor::new_bip86(master, KeychainKind::External, Network::Testnet);
Descriptor::new_bip86(&master, KeychainKind::External, Network::Testnet);
// the extended public keys are the same when creating them manually as they are with the templates
println!("Template 49: {}", template_private_49.as_string());
println!("Template 44: {}", template_private_44.as_string());
println!("Template 84: {}", template_private_84.as_string());
println!("Template 86: {}", template_private_86.as_string());
let template_public_44 = Descriptor::new_bip44_public(
handmade_public_44,
&handmade_public_44,
"d1d04177".to_string(),
KeychainKind::External,
Network::Testnet,
);
let template_public_49 = Descriptor::new_bip49_public(
handmade_public_49,
&handmade_public_49,
"d1d04177".to_string(),
KeychainKind::External,
Network::Testnet,
);
let template_public_84 = Descriptor::new_bip84_public(
handmade_public_84,
&handmade_public_84,
"d1d04177".to_string(),
KeychainKind::External,
Network::Testnet,
);
let template_public_86 = Descriptor::new_bip86_public(
handmade_public_86,
&handmade_public_86,
"d1d04177".to_string(),
KeychainKind::External,
Network::Testnet,
Expand Down
7 changes: 4 additions & 3 deletions bdk-ffi/src/esplora.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::wallet::{Update, Wallet};
use std::ops::Deref;

use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::wallet::Update as BdkUpdate;
use bdk::Error as BdkError;
use bdk_esplora::esplora_client::{BlockingClient, Builder};
use bdk_esplora::EsploraExt;

use crate::bitcoin::Transaction;
use std::sync::Arc;

pub struct EsploraClient(BlockingClient);
Expand Down Expand Up @@ -57,8 +58,8 @@ impl EsploraClient {

// pub fn sync();

pub fn broadcast(&self, transaction: Arc<crate::bitcoin::Transaction>) -> Result<(), BdkError> {
let bdk_transaction: bdk::bitcoin::Transaction = transaction.deref().clone().into();
pub fn broadcast(&self, transaction: &Transaction) -> Result<(), BdkError> {
let bdk_transaction: BdkTransaction = transaction.clone().into();
self.0
.broadcast(&bdk_transaction)
.map_err(|e| BdkError::Generic(e.to_string()))
Expand Down
Loading
Loading