Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Nov 17, 2023
1 parent f2cd561 commit 53bbff9
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class LiveWalletTest {
val update = esploraClient.scan(wallet, 10uL, 1uL)
wallet.applyUpdate(update)
println("Balance: ${wallet.getBalance().total()}")
val balance: Balance = wallet.getBalance()
println("Balance: $balance")

assert(wallet.getBalance().total() > 0uL)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.bitcoindevkit

import kotlin.test.Test
import kotlin.test.assertEquals
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.runner.RunWith
import kotlin.test.assertEquals
Expand Down
34 changes: 34 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ enum BdkError {
"Psbt",
};

enum ChangeSpendPolicy {
"ChangeAllowed",
"OnlyChange",
"ChangeForbidden"
};

interface Balance {
u64 immature();

Expand Down Expand Up @@ -95,6 +101,20 @@ interface TxBuilder {

TxBuilder add_recipient(Script script, u64 amount);

TxBuilder set_recipients(sequence<ScriptAmount> script_amount);

TxBuilder add_unspendable(OutPoint unspendable);

TxBuilder add_utxo(OutPoint outpoint);

TxBuilder change_policy(ChangeSpendPolicy change_policy);

TxBuilder do_not_spend_change();

TxBuilder only_spend_change();

TxBuilder manually_selected_only();

TxBuilder fee_rate(float sat_per_vbyte);

[Throws=BdkError]
Expand Down Expand Up @@ -198,6 +218,15 @@ interface EsploraClient {
Update scan(Wallet wallet, u64 stop_gap, u64 parallel_requests);
};

// ------------------------------------------------------------------------
// bdk-ffi-defined types
// ------------------------------------------------------------------------

dictionary ScriptAmount {
Script script;
u64 amount;
};

// ------------------------------------------------------------------------
// bdk crate - bitcoin re-exports
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -263,3 +292,8 @@ interface PartiallySignedTransaction {

Transaction extract_tx();
};

dictionary OutPoint {
string txid;
u32 vout;
};
20 changes: 20 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use bdk::bitcoin::consensus::Decodable;
use bdk::bitcoin::network::constants::Network as BdkNetwork;
use bdk::bitcoin::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction;
use bdk::bitcoin::Address as BdkAddress;
use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::bitcoin::Txid;
use bdk::Error as BdkError;

use std::io::Cursor;
Expand Down Expand Up @@ -279,3 +281,21 @@ 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,
}

impl From<&OutPoint> for BdkOutPoint {
fn from(outpoint: &OutPoint) -> Self {
BdkOutPoint {
txid: Txid::from_str(&outpoint.txid).unwrap(),
vout: outpoint.vout,
}
}
}
10 changes: 6 additions & 4 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod wallet;
// TODO 6: Why are these imports required?
use crate::bitcoin::Address;
use crate::bitcoin::Network;
use crate::bitcoin::OutPoint;
use crate::bitcoin::PartiallySignedTransaction;
use crate::bitcoin::Script;
use crate::bitcoin::Transaction;
Expand All @@ -21,6 +22,7 @@ use crate::wallet::Update;
use crate::wallet::Wallet;

use bdk::keys::bip39::WordCount;
use bdk::wallet::tx_builder::ChangeSpendPolicy;
use bdk::wallet::AddressIndex as BdkAddressIndex;
use bdk::wallet::AddressInfo as BdkAddressInfo;
use bdk::wallet::Balance as BdkBalance;
Expand All @@ -32,10 +34,10 @@ use std::sync::Arc;
uniffi::include_scaffolding!("bdk");

/// A output script and an amount of satoshis.
// pub struct ScriptAmount {
// pub script: Arc<Script>,
// pub amount: u64,
// }
pub struct ScriptAmount {
pub script: Arc<Script>,
pub amount: u64,
}

/// A derived address and the index it was found at.
pub struct AddressInfo {
Expand Down
Loading

0 comments on commit 53bbff9

Please sign in to comment.