File tree Expand file tree Collapse file tree 4 files changed +42
-12
lines changed Expand file tree Collapse file tree 4 files changed +42
-12
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ use crate::{
13
13
} ,
14
14
} ;
15
15
16
- use super :: TxBuilder ;
16
+ use super :: { TxBuilder , UnconfirmedTx } ;
17
17
18
18
// We wrap a `BdkWallet` in `Rc<RefCell<...>>` because `wasm_bindgen` do not
19
19
// support Rust's lifetimes. This allows us to forward a reference to the
@@ -183,6 +183,12 @@ impl Wallet {
183
183
. derivation_of_spk ( spk. into ( ) )
184
184
. map ( |( keychain, index) | SpkIndexed ( keychain. into ( ) , index) )
185
185
}
186
+
187
+ pub fn apply_unconfirmed_txs ( & self , unconfirmed_txs : Vec < UnconfirmedTx > ) {
188
+ self . 0
189
+ . borrow_mut ( )
190
+ . apply_unconfirmed_txs ( unconfirmed_txs. into_iter ( ) . map ( Into :: into) )
191
+ }
186
192
}
187
193
188
194
#[ wasm_bindgen]
Original file line number Diff line number Diff line change 1
- use std:: collections:: BTreeSet ;
1
+ use std:: { collections:: BTreeSet , sync :: Arc } ;
2
2
3
3
use bdk_wallet:: {
4
4
bitcoin:: { Transaction as BdkTransaction , Txid as BdkTxid } ,
@@ -63,3 +63,32 @@ impl From<BdkWalletTx<'_>> for WalletTx {
63
63
}
64
64
}
65
65
}
66
+
67
+ #[ wasm_bindgen]
68
+ pub struct UnconfirmedTx ( Transaction , pub u64 ) ;
69
+
70
+ #[ wasm_bindgen]
71
+ impl UnconfirmedTx {
72
+ /// `tx` – your wrapped `Transaction`
73
+ /// `last_seen` – unix epoch seconds (same convention as the rest of the API)
74
+ #[ wasm_bindgen( constructor) ]
75
+ pub fn new ( tx : Transaction , last_seen : u64 ) -> UnconfirmedTx {
76
+ UnconfirmedTx ( tx, last_seen)
77
+ }
78
+
79
+ #[ wasm_bindgen( getter) ]
80
+ pub fn tx ( & self ) -> Transaction {
81
+ self . 0 . clone ( )
82
+ }
83
+
84
+ #[ wasm_bindgen( getter) ]
85
+ pub fn last_seen ( & self ) -> u64 {
86
+ self . 1
87
+ }
88
+ }
89
+
90
+ impl From < UnconfirmedTx > for ( Arc < BdkTransaction > , u64 ) {
91
+ fn from ( uctx : UnconfirmedTx ) -> Self {
92
+ ( Arc :: new ( uctx. 0 . into ( ) ) , uctx. 1 )
93
+ }
94
+ }
Original file line number Diff line number Diff line change @@ -59,19 +59,16 @@ impl FeeRate {
59
59
}
60
60
61
61
/// Returns raw fee rate.
62
- #[ wasm_bindgen( getter) ]
63
62
pub fn to_sat_per_kwu ( & self ) -> u64 {
64
63
self . 0 . to_sat_per_kwu ( )
65
64
}
66
65
67
66
/// Converts to sat/vB rounding up.
68
- #[ wasm_bindgen( getter) ]
69
67
pub fn to_sat_per_vb_ceil ( & self ) -> u64 {
70
68
self . 0 . to_sat_per_vb_ceil ( )
71
69
}
72
70
73
71
/// Converts to sat/vB rounding down.
74
- #[ wasm_bindgen( getter) ]
75
72
pub fn to_sat_per_vb_floor ( & self ) -> u64 {
76
73
self . 0 . to_sat_per_vb_floor ( )
77
74
}
Original file line number Diff line number Diff line change 5
5
FeeRate ,
6
6
Network ,
7
7
Recipient ,
8
+ UnconfirmedTx ,
8
9
Wallet ,
9
10
SignOptions ,
10
11
} from "../../../pkg/bitcoindevkit" ;
@@ -23,6 +24,7 @@ describe("Esplora client", () => {
23
24
"tb1qd28npep0s8frcm3y7dxqajkcy2m40eysplyr9v" ,
24
25
network
25
26
) ;
27
+ const unixTimestamp = BigInt ( Math . floor ( Date . now ( ) / 1000 ) ) ;
26
28
27
29
let feeRate : FeeRate ;
28
30
let wallet : Wallet ;
@@ -83,14 +85,10 @@ describe("Esplora client", () => {
83
85
const currentDerivationIndex = wallet . derivation_index ( "internal" ) ;
84
86
expect ( initialDerivationIndex ) . toBeLessThan ( currentDerivationIndex ) ;
85
87
86
- // Synchronizes the wallet to get the new state
87
- const request = wallet . start_sync_with_revealed_spks ( ) ;
88
- const update = await esploraClient . sync ( request , parallelRequests ) ;
89
- wallet . apply_update ( update ) ;
90
-
91
- // Verify the sent transaction is part of the wallet in an unconfirmed state
88
+ // Assert that the transaction is in the wallet
89
+ wallet . apply_unconfirmed_txs ( [ new UnconfirmedTx ( tx , unixTimestamp ) ] ) ;
92
90
const walletTx = wallet . get_tx ( txid ) ;
93
- expect ( walletTx . last_seen_unconfirmed ) . toBeDefined ( ) ;
91
+ expect ( walletTx . last_seen_unconfirmed ) . toEqual ( unixTimestamp ) ;
94
92
expect ( walletTx . chain_position . is_confirmed ) . toBe ( false ) ;
95
93
} , 30000 ) ;
96
94
You can’t perform that action at this time.
0 commit comments