Skip to content

Commit 4ffd8bf

Browse files
authored
feat: add cloning (#2)
1 parent 36732af commit 4ffd8bf

File tree

13 files changed

+40
-8
lines changed

13 files changed

+40
-8
lines changed

src/bitcoin/wallet.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,18 @@ impl Wallet {
168168
TxBuilder::new(self.0.clone())
169169
}
170170

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

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

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

src/types/address.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ impl AddressInfo {
4848
pub fn address_type(&self) -> Option<AddressType> {
4949
self.0.address_type().map(Into::into)
5050
}
51+
52+
#[wasm_bindgen(js_name = clone)]
53+
pub fn js_clone(&self) -> AddressInfo {
54+
self.clone()
55+
}
5156
}
5257

5358
impl Deref for AddressInfo {
@@ -101,6 +106,11 @@ impl Address {
101106
pub fn script_pubkey(&self) -> ScriptBuf {
102107
self.0.script_pubkey().into()
103108
}
109+
110+
#[wasm_bindgen(js_name = clone)]
111+
pub fn js_clone(&self) -> Address {
112+
self.clone()
113+
}
104114
}
105115

106116
impl From<BdkAddress> for Address {
@@ -181,6 +191,11 @@ impl ScriptBuf {
181191
pub fn is_op_return(&self) -> bool {
182192
self.0.is_op_return()
183193
}
194+
195+
#[wasm_bindgen(js_name = clone)]
196+
pub fn js_clone(&self) -> ScriptBuf {
197+
self.clone()
198+
}
184199
}
185200

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

198213
/// The different types of addresses.
199214
#[wasm_bindgen]
215+
#[derive(Clone, Copy, PartialEq, Eq)]
200216
pub enum AddressType {
201217
/// Pay to pubkey hash.
202218
P2pkh = "p2pkh",

src/types/amount.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub struct SentAndReceived(pub Amount, pub Amount);
8585

8686
/// A set of denominations in which amounts can be expressed.
8787
#[wasm_bindgen]
88+
#[derive(Clone, Copy, PartialEq, Eq)]
8889
pub enum Denomination {
8990
/// BTC
9091
Bitcoin = "BTC",

src/types/balance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::Amount;
77

88
/// Balance, differentiated into various categories.
99
#[wasm_bindgen]
10+
#[derive(Clone)]
1011
pub struct Balance(BdkBalance);
1112

1213
#[wasm_bindgen]

src/types/block.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use wasm_bindgen::prelude::wasm_bindgen;
55

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

1011
#[wasm_bindgen]

src/types/chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl From<FullScanRequest> for BdkFullScanRequest<KeychainKind> {
7272

7373
/// An update to [`Wallet`].
7474
#[wasm_bindgen]
75+
#[derive(Clone)]
7576
pub struct Update(BdkUpdate);
7677

7778
impl Deref for Update {

src/types/checkpoint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::BlockId;
1010
/// Checkpoints are cheaply cloneable and are useful to find the agreement point between two sparse
1111
/// block chains.
1212
#[wasm_bindgen]
13+
#[derive(Clone)]
1314
pub struct CheckPoint(BdkCheckPoint);
1415

1516
#[wasm_bindgen]

src/types/fee.rs

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

4647
impl Deref for FeeRate {

src/types/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::types::{OutPoint, ScriptBuf};
1111
/// that it spends and set of scripts that satisfy its spending
1212
/// conditions.
1313
#[wasm_bindgen]
14+
#[derive(Clone)]
1415
pub struct TxIn(BdkTxIn);
1516

1617
impl Deref for TxIn {

src/types/network.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl From<BdkNetwork> for NetworkKind {
4040

4141
/// The cryptocurrency network to act on.
4242
#[wasm_bindgen]
43-
#[derive(Clone, Copy)]
43+
#[derive(Clone, Copy, PartialEq, Eq)]
4444
pub enum Network {
4545
/// Mainnet Bitcoin.
4646
Bitcoin = "bitcoin",

0 commit comments

Comments
 (0)