6
6
//! ```no run
7
7
//! ```
8
8
9
- use crate :: bitcoin:: { Address , Network } ;
9
+ use crate :: bitcoin:: { Address , Network , Transaction , Txid } ;
10
10
use crate :: blockchain:: * ;
11
+ use crate :: database:: BatchDatabase ;
12
+ use crate :: { Error , FeeRate } ;
11
13
use bitcoincore_rpc:: Auth as RpcAuth ;
12
- use bitcoincore_rpc:: Client ;
14
+ use bitcoincore_rpc:: { Client , RpcApi } ;
13
15
use serde:: { Deserialize , Serialize } ;
14
16
use std:: collections:: HashSet ;
15
17
use std:: path:: PathBuf ;
@@ -18,11 +20,11 @@ use std::path::PathBuf;
18
20
#[ derive( Debug ) ]
19
21
pub struct PrunedRpcBlockchain {
20
22
/// Rpc client to the node, includes the wallet name
21
- _client : Client ,
23
+ client : Client ,
22
24
/// Whether the wallet is a "descriptor" or "legacy" wallet in Core
23
25
_is_descriptors : bool ,
24
26
/// Blockchain capabilities, cached here at startup
25
- _capabilities : HashSet < Capability > ,
27
+ capabilities : HashSet < Capability > ,
26
28
/// This is a fixed Address used as a hack key to store information on the node
27
29
_storage_address : Address ,
28
30
}
@@ -78,27 +80,34 @@ impl PrunedRpcBlockchain {}
78
80
79
81
impl Blockchain for PrunedRpcBlockchain {
80
82
fn get_capabilities ( & self ) -> HashSet < Capability > {
81
- todo ! ( )
83
+ self . capabilities . clone ( )
82
84
}
83
85
84
- fn broadcast ( & self , _tx : & Transaction ) -> Result < ( ) , Error > {
85
- todo ! ( )
86
+ fn broadcast ( & self , tx : & Transaction ) -> Result < ( ) , Error > {
87
+ Ok ( self . client . send_raw_transaction ( tx ) . map ( |_| ( ) ) ? )
86
88
}
87
89
88
- fn estimate_fee ( & self , _target : usize ) -> Result < FeeRate , Error > {
89
- todo ! ( )
90
+ fn estimate_fee ( & self , target : usize ) -> Result < FeeRate , Error > {
91
+ let sat_per_kb = self
92
+ . client
93
+ . estimate_smart_fee ( target as u16 , None ) ?
94
+ . fee_rate
95
+ . ok_or ( Error :: FeeRateUnavailable ) ?
96
+ . as_sat ( ) as f64 ;
97
+
98
+ Ok ( FeeRate :: from_sat_per_vb ( ( sat_per_kb / 1000f64 ) as f32 ) )
90
99
}
91
100
}
92
101
93
102
impl GetTx for PrunedRpcBlockchain {
94
- fn get_tx ( & self , _txid : & Txid ) -> Result < Option < Transaction > , Error > {
95
- todo ! ( )
103
+ fn get_tx ( & self , txid : & Txid ) -> Result < Option < Transaction > , Error > {
104
+ Ok ( Some ( self . client . get_raw_transaction ( txid , None ) ? ) )
96
105
}
97
106
}
98
107
99
108
impl GetHeight for PrunedRpcBlockchain {
100
109
fn get_height ( & self ) -> Result < u32 , Error > {
101
- todo ! ( )
110
+ Ok ( self . client . get_blockchain_info ( ) . map ( |i| i . blocks as u32 ) ? )
102
111
}
103
112
}
104
113
0 commit comments