@@ -8,13 +8,11 @@ use std::time::Duration;
8
8
use bitcoin:: address:: NetworkUnchecked ;
9
9
use bitcoin:: consensus:: encode:: Error as EncodeError ;
10
10
use bitcoin:: hashes:: serde;
11
- use bitcoin:: psbt:: PartiallySignedTransaction ;
11
+ use bitcoin:: psbt:: Psbt ;
12
12
use bitcoin:: secp256k1:: rand:: thread_rng;
13
- use bitcoin:: secp256k1:: { PublicKey , SecretKey } ;
14
- use bitcoin:: {
15
- consensus:: Decodable , network:: constants:: Network , Amount , PrivateKey , Transaction , Txid ,
16
- } ;
17
- use bitcoin:: { Address , OutPoint , ScriptBuf , TxOut } ;
13
+ use bitcoin:: secp256k1:: SecretKey ;
14
+ use bitcoin:: { consensus:: Decodable , Network , PrivateKey , Transaction , Txid } ;
15
+ use bitcoin:: { secp256k1:: PublicKey , Address , OutPoint , ScriptBuf , TxOut } ;
18
16
use bitcoincore_rpc:: jsonrpc:: serde_json;
19
17
use bitcoincore_rpc:: jsonrpc:: serde_json:: Value ;
20
18
use bitcoincore_rpc:: { json, Auth , Client , RpcApi } ;
@@ -106,7 +104,7 @@ impl BitcoinCoreProvider {
106
104
pub fn new_from_rpc_client ( rpc_client : Client ) -> Self {
107
105
let client = Arc :: new ( Mutex :: new ( rpc_client) ) ;
108
106
let mut fees: HashMap < ConfirmationTarget , AtomicU32 > = HashMap :: with_capacity ( 7 ) ;
109
- fees. insert ( ConfirmationTarget :: OnChainSweep , AtomicU32 :: new ( 5000 ) ) ;
107
+ fees. insert ( ConfirmationTarget :: UrgentOnChainSweep , AtomicU32 :: new ( 5000 ) ) ;
110
108
fees. insert (
111
109
ConfirmationTarget :: MinAllowedAnchorChannelRemoteFee ,
112
110
AtomicU32 :: new ( MIN_FEERATE ) ,
@@ -155,7 +153,7 @@ struct UtxoWrap(Utxo);
155
153
156
154
impl rust_bitcoin_coin_selection:: Utxo for UtxoWrap {
157
155
fn get_value ( & self ) -> u64 {
158
- self . 0 . tx_out . value
156
+ self . 0 . tx_out . value . to_sat ( )
159
157
}
160
158
}
161
159
@@ -206,7 +204,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
206
204
. import_private_key (
207
205
& PrivateKey {
208
206
compressed : true ,
209
- network,
207
+ network : network . into ( ) ,
210
208
inner : sk,
211
209
} ,
212
210
Some ( & keys_id. to_lower_hex_string ( ) ) ,
@@ -219,12 +217,8 @@ impl ContractSignerProvider for BitcoinCoreProvider {
219
217
}
220
218
221
219
fn get_secret_key_for_pubkey ( & self , pubkey : & PublicKey ) -> Result < SecretKey , ManagerError > {
222
- let b_pubkey = bitcoin:: PublicKey {
223
- compressed : true ,
224
- inner : * pubkey,
225
- } ;
226
- let address =
227
- Address :: p2wpkh ( & b_pubkey, self . get_network ( ) ?) . or ( Err ( Error :: BitcoinError ) ) ?;
220
+ let b_pubkey = bitcoin:: CompressedPublicKey ( * pubkey) ;
221
+ let address = Address :: p2wpkh ( & b_pubkey, self . get_network ( ) ?) ;
228
222
229
223
let pk = self
230
224
. client
@@ -244,7 +238,7 @@ impl ContractSignerProvider for BitcoinCoreProvider {
244
238
. import_private_key (
245
239
& PrivateKey {
246
240
compressed : true ,
247
- network,
241
+ network : network . into ( ) ,
248
242
inner : sk,
249
243
} ,
250
244
None ,
@@ -296,7 +290,7 @@ impl Wallet for BitcoinCoreProvider {
296
290
. map ( |x| {
297
291
Ok ( UtxoWrap ( Utxo {
298
292
tx_out : TxOut {
299
- value : x. amount . to_sat ( ) ,
293
+ value : x. amount ,
300
294
script_pubkey : x. script_pub_key . clone ( ) ,
301
295
} ,
302
296
outpoint : OutPoint {
@@ -338,11 +332,7 @@ impl Wallet for BitcoinCoreProvider {
338
332
. map_err ( rpc_err_to_manager_err)
339
333
}
340
334
341
- fn sign_psbt_input (
342
- & self ,
343
- psbt : & mut PartiallySignedTransaction ,
344
- input_index : usize ,
345
- ) -> Result < ( ) , ManagerError > {
335
+ fn sign_psbt_input ( & self , psbt : & mut Psbt , input_index : usize ) -> Result < ( ) , ManagerError > {
346
336
let outpoint = & psbt. unsigned_tx . input [ input_index] . previous_output ;
347
337
let tx_out = if let Some ( input) = psbt. inputs . get ( input_index) {
348
338
if let Some ( wit_utxo) = & input. witness_utxo {
@@ -370,7 +360,7 @@ impl Wallet for BitcoinCoreProvider {
370
360
vout : outpoint. vout ,
371
361
script_pub_key : tx_out. script_pubkey . clone ( ) ,
372
362
redeem_script,
373
- amount : Some ( Amount :: from_sat ( tx_out. value ) ) ,
363
+ amount : Some ( tx_out. value ) ,
374
364
} ;
375
365
376
366
let sign_result = self
@@ -417,25 +407,13 @@ impl Blockchain for BitcoinCoreProvider {
417
407
}
418
408
419
409
fn get_network ( & self ) -> Result < Network , ManagerError > {
420
- let network = match self
410
+ let network = self
421
411
. client
422
412
. lock ( )
423
413
. unwrap ( )
424
414
. get_blockchain_info ( )
425
415
. map_err ( rpc_err_to_manager_err) ?
426
- . chain
427
- . as_ref ( )
428
- {
429
- "main" => Network :: Bitcoin ,
430
- "test" => Network :: Testnet ,
431
- "regtest" => Network :: Regtest ,
432
- "signet" => Network :: Signet ,
433
- _ => {
434
- return Err ( ManagerError :: BlockchainError (
435
- "Unknown Bitcoin network" . to_string ( ) ,
436
- ) )
437
- }
438
- } ;
416
+ . chain ;
439
417
440
418
Ok ( network)
441
419
}
@@ -547,7 +525,7 @@ fn poll_for_fee_estimates(
547
525
} ;
548
526
match query_fee_estimate ( & client, 6 , EstimateMode :: Conservative ) {
549
527
Ok ( fee_rate) => {
550
- fees. get ( & ConfirmationTarget :: OnChainSweep )
528
+ fees. get ( & ConfirmationTarget :: UrgentOnChainSweep )
551
529
. unwrap ( )
552
530
. store ( fee_rate, Ordering :: Release ) ;
553
531
}
0 commit comments