Skip to content
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
12 changes: 6 additions & 6 deletions src/bitcoin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ impl Wallet {
TxBuilder::new(self.0.clone())
}

pub fn calculate_fee(&self, tx: Transaction) -> JsResult<Amount> {
let fee = self.0.borrow().calculate_fee(&tx.into())?;
pub fn calculate_fee(&self, tx: &Transaction) -> JsResult<Amount> {
let fee = self.0.borrow().calculate_fee(tx)?;
Ok(fee.into())
}

pub fn calculate_fee_rate(&self, tx: Transaction) -> JsResult<FeeRate> {
let fee_rate = self.0.borrow().calculate_fee_rate(&tx.into())?;
pub fn calculate_fee_rate(&self, tx: &Transaction) -> JsResult<FeeRate> {
let fee_rate = self.0.borrow().calculate_fee_rate(tx)?;
Ok(fee_rate.into())
}

pub fn sent_and_received(&self, tx: Transaction) -> JsResult<SentAndReceived> {
let (sent, received) = self.0.borrow().sent_and_received(&tx.into());
pub fn sent_and_received(&self, tx: &Transaction) -> JsResult<SentAndReceived> {
let (sent, received) = self.0.borrow().sent_and_received(tx);
Ok(SentAndReceived(sent.into(), received.into()))
}

Expand Down
16 changes: 16 additions & 0 deletions src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ impl AddressInfo {
pub fn address_type(&self) -> Option<AddressType> {
self.0.address_type().map(Into::into)
}

#[wasm_bindgen(js_name = clone)]
pub fn js_clone(&self) -> AddressInfo {
self.clone()
}
}

impl Deref for AddressInfo {
Expand Down Expand Up @@ -101,6 +106,11 @@ impl Address {
pub fn script_pubkey(&self) -> ScriptBuf {
self.0.script_pubkey().into()
}

#[wasm_bindgen(js_name = clone)]
pub fn js_clone(&self) -> Address {
self.clone()
}
}

impl From<BdkAddress> for Address {
Expand Down Expand Up @@ -181,6 +191,11 @@ impl ScriptBuf {
pub fn is_op_return(&self) -> bool {
self.0.is_op_return()
}

#[wasm_bindgen(js_name = clone)]
pub fn js_clone(&self) -> ScriptBuf {
self.clone()
}
}

impl From<BdkScriptBuf> for ScriptBuf {
Expand All @@ -197,6 +212,7 @@ impl From<ScriptBuf> for BdkScriptBuf {

/// The different types of addresses.
#[wasm_bindgen]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum AddressType {
/// Pay to pubkey hash.
P2pkh = "p2pkh",
Expand Down
1 change: 1 addition & 0 deletions src/types/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct SentAndReceived(pub Amount, pub Amount);

/// A set of denominations in which amounts can be expressed.
#[wasm_bindgen]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Denomination {
/// BTC
Bitcoin = "BTC",
Expand Down
1 change: 1 addition & 0 deletions src/types/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use super::Amount;

/// Balance, differentiated into various categories.
#[wasm_bindgen]
#[derive(Clone)]
pub struct Balance(BdkBalance);

#[wasm_bindgen]
Expand Down
1 change: 1 addition & 0 deletions src/types/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use wasm_bindgen::prelude::wasm_bindgen;

/// A reference to a block in the canonical chain.
#[wasm_bindgen]
#[derive(Clone)]
pub struct BlockId(BdkBlockId);

#[wasm_bindgen]
Expand Down
1 change: 1 addition & 0 deletions src/types/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl From<FullScanRequest> for BdkFullScanRequest<KeychainKind> {

/// An update to [`Wallet`].
#[wasm_bindgen]
#[derive(Clone)]
pub struct Update(BdkUpdate);

impl Deref for Update {
Expand Down
1 change: 1 addition & 0 deletions src/types/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use super::BlockId;
/// Checkpoints are cheaply cloneable and are useful to find the agreement point between two sparse
/// block chains.
#[wasm_bindgen]
#[derive(Clone)]
pub struct CheckPoint(BdkCheckPoint);

#[wasm_bindgen]
Expand Down
1 change: 1 addition & 0 deletions src/types/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl From<FeeEstimates> for HashMap<u16, f64> {
/// This is an integer newtype representing fee rate in `sat/kwu`. It provides protection against mixing
/// up the types as well as basic formatting features.
#[wasm_bindgen]
#[derive(Clone, Copy)]
pub struct FeeRate(BdkFeeRate);

impl Deref for FeeRate {
Expand Down
1 change: 1 addition & 0 deletions src/types/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::types::{OutPoint, ScriptBuf};
/// that it spends and set of scripts that satisfy its spending
/// conditions.
#[wasm_bindgen]
#[derive(Clone)]
pub struct TxIn(BdkTxIn);

impl Deref for TxIn {
Expand Down
2 changes: 1 addition & 1 deletion src/types/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl From<BdkNetwork> for NetworkKind {

/// The cryptocurrency network to act on.
#[wasm_bindgen]
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub enum Network {
/// Mainnet Bitcoin.
Bitcoin = "bitcoin",
Expand Down
4 changes: 3 additions & 1 deletion src/types/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::Txid;

/// A reference to a transaction output.
#[wasm_bindgen]
#[derive(Clone, PartialEq, Eq)]
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct OutPoint(BdkOutPoint);

impl Deref for OutPoint {
Expand Down Expand Up @@ -76,6 +76,7 @@ impl From<OutPoint> for BdkOutPoint {
///
/// An output that is not yet spent by an input is called Unspent Transaction Output ("UTXO").
#[wasm_bindgen]
#[derive(Clone)]
pub struct TxOut(BdkTxOut);

impl Deref for TxOut {
Expand Down Expand Up @@ -129,6 +130,7 @@ impl From<TxOut> for BdkTxOut {

/// A reference to a transaction output.
#[wasm_bindgen]
#[derive(Clone)]
pub struct LocalOutput(BdkLocalOutput);

impl Deref for LocalOutput {
Expand Down
6 changes: 6 additions & 0 deletions src/types/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use super::{Address, Amount, FeeRate, Transaction};

/// A Partially Signed Transaction.
#[wasm_bindgen]
#[derive(Clone)]
pub struct Psbt(BdkPsbt);

impl Deref for Psbt {
Expand Down Expand Up @@ -114,6 +115,11 @@ impl Psbt {
pub fn to_json(&self) -> String {
to_string(&self.0).expect("Serialization should not fail")
}

#[wasm_bindgen(js_name = clone)]
pub fn js_clone(&self) -> Psbt {
self.clone()
}
}

impl From<BdkPsbt> for Psbt {
Expand Down
1 change: 1 addition & 0 deletions src/types/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ impl From<Transaction> for BdkTransaction {

/// A bitcoin transaction hash/transaction ID.
#[wasm_bindgen]
#[derive(Clone, Copy)]
pub struct Txid(BdkTxid);

impl Deref for Txid {
Expand Down