@@ -199,26 +199,26 @@ where
199
199
Ok ( res)
200
200
}
201
201
202
- enum KVStoreUpdatingPersisterError {
202
+ enum KVStoreUpdatingPersisterError < ' a > {
203
203
/// The monitor name was improperly formatted.
204
- BadMonitorName { reason : String , context : String } ,
204
+ BadMonitorName { reason : & ' a str , context : & ' a str } ,
205
205
/// The monitor could not be decoded.
206
206
MonitorDecodeFailed {
207
207
reason : DecodeError ,
208
- context : String ,
208
+ context : & ' a str ,
209
209
} ,
210
210
/// The update could not be decoded.
211
211
UpdateDecodeFailed {
212
212
reason : DecodeError ,
213
- context : String ,
213
+ context : & ' a str ,
214
214
} ,
215
215
/// Storage could not be read.
216
- StorageReadFailed { reason : io:: Error , context : String } ,
216
+ StorageReadFailed { reason : io:: Error , context : & ' a str } ,
217
217
/// An update could not be applied to a monitor.
218
- UpdateFailed { reason : String , context : String } ,
218
+ UpdateFailed { reason : & ' a str , context : & ' a str } ,
219
219
}
220
220
221
- impl From < KVStoreUpdatingPersisterError > for io:: Error {
221
+ impl < ' a > From < KVStoreUpdatingPersisterError < ' a > > for io:: Error {
222
222
fn from ( value : KVStoreUpdatingPersisterError ) -> Self {
223
223
match value {
224
224
KVStoreUpdatingPersisterError :: BadMonitorName { reason, context } => io:: Error :: new (
@@ -255,8 +255,8 @@ pub struct MonitorName(String);
255
255
256
256
impl MonitorName {
257
257
/// The key to store this monitor with.
258
- fn storage_key ( & self ) -> String {
259
- self . 0 . clone ( )
258
+ fn storage_key ( & self ) -> & str {
259
+ & self . 0
260
260
}
261
261
}
262
262
@@ -269,25 +269,25 @@ impl TryFrom<MonitorName> for OutPoint {
269
269
parts
270
270
. next ( )
271
271
. ok_or_else ( || KVStoreUpdatingPersisterError :: BadMonitorName {
272
- reason : "no txid found, maybe there is no underscore" . to_string ( ) ,
273
- context : value. 0 . clone ( ) ,
272
+ reason : "no txid found, maybe there is no underscore" ,
273
+ context : & value. 0 ,
274
274
} ) ?;
275
275
let index = parts
276
276
. next ( )
277
277
. ok_or_else ( || KVStoreUpdatingPersisterError :: BadMonitorName {
278
- reason : "no index value found after underscore" . to_string ( ) ,
279
- context : value. 0 . clone ( ) ,
278
+ reason : "no index value found after underscore" ,
279
+ context : & value. 0 ,
280
280
} ) ?;
281
281
let index = index
282
282
. parse ( )
283
- . map_err ( |e | KVStoreUpdatingPersisterError :: BadMonitorName {
284
- reason : format ! ( "bad index value, caused by {}" , e ) ,
285
- context : value. 0 . clone ( ) ,
283
+ . map_err ( |_ | KVStoreUpdatingPersisterError :: BadMonitorName {
284
+ reason : "could not parse index value in monitor name" ,
285
+ context : & value. 0 ,
286
286
} ) ?;
287
- let txid = Txid :: from_hex ( txid_hex) . map_err ( |e | {
287
+ let txid = Txid :: from_hex ( txid_hex) . map_err ( |_ | {
288
288
KVStoreUpdatingPersisterError :: BadMonitorName {
289
- reason : format ! ( "bad txid, caused by: {}" , e ) ,
290
- context : value. 0 . clone ( ) ,
289
+ reason : "bad txid in monitor name" ,
290
+ context : & value. 0 ,
291
291
}
292
292
} ) ?;
293
293
Ok ( OutPoint { txid, index } )
@@ -306,8 +306,8 @@ pub struct UpdateName(String);
306
306
307
307
impl UpdateName {
308
308
/// The key to store this update with.
309
- fn storage_key ( & self ) -> String {
310
- self . 0 . clone ( )
309
+ fn storage_key ( & self ) -> & str {
310
+ & self . 0
311
311
}
312
312
}
313
313
@@ -356,7 +356,7 @@ where
356
356
let ( bh, monitor) = self . deserialize_monitor (
357
357
entropy_source. clone ( ) ,
358
358
signer_provider. clone ( ) ,
359
- monitor_name. clone ( ) ,
359
+ & monitor_name,
360
360
) ?;
361
361
// ...parse and apply the updates with an id higher than the monitor.
362
362
for update_name in self . list_update_names ( & monitor_name) ? {
@@ -367,8 +367,8 @@ where
367
367
monitor
368
368
. update_monitor ( & update, broadcaster, fee_estimator. clone ( ) , & self . logger )
369
369
. map_err ( |_| KVStoreUpdatingPersisterError :: UpdateFailed {
370
- reason : "update_monitor returned Err(())" . to_string ( ) ,
371
- context : format ! ( "monitor: {:?}" , monitor_name) ,
370
+ reason : "update_monitor returned Err(())" ,
371
+ context : & monitor_name. 0 ,
372
372
} ) ?;
373
373
}
374
374
}
@@ -382,7 +382,7 @@ where
382
382
fn monitor_update_namespace ( & self , monitor_name : & MonitorName ) -> String {
383
383
// Append the monitor name to the namespace with an underscore.
384
384
[
385
- CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE . to_owned ( ) ,
385
+ CHANNEL_MONITOR_UPDATE_PERSISTENCE_NAMESPACE ,
386
386
monitor_name. storage_key ( ) ,
387
387
]
388
388
. join ( "_" )
@@ -407,7 +407,7 @@ where
407
407
& self ,
408
408
entropy_source : ES ,
409
409
signer_provider : SP ,
410
- monitor_name : MonitorName ,
410
+ monitor_name : & MonitorName ,
411
411
) -> io:: Result < (
412
412
BlockHash ,
413
413
ChannelMonitor < <SP :: Target as SignerProvider >:: Signer > ,
@@ -417,17 +417,17 @@ where
417
417
SP :: Target : SignerProvider + Sized ,
418
418
{
419
419
let key = monitor_name. storage_key ( ) ;
420
- let outpoint: OutPoint = monitor_name. try_into ( ) ?;
420
+ let outpoint: OutPoint = monitor_name. to_owned ( ) . try_into ( ) ?;
421
421
match <(
422
422
BlockHash ,
423
423
ChannelMonitor < <SP :: Target as SignerProvider >:: Signer > ,
424
424
) >:: read (
425
425
& mut self
426
426
. kv
427
- . read ( CHANNEL_MONITOR_PERSISTENCE_NAMESPACE , & key)
427
+ . read ( CHANNEL_MONITOR_PERSISTENCE_NAMESPACE , key)
428
428
. map_err ( |e| KVStoreUpdatingPersisterError :: StorageReadFailed {
429
429
reason : e,
430
- context : key. clone ( ) ,
430
+ context : key,
431
431
} ) ?,
432
432
( & * entropy_source, & * signer_provider) ,
433
433
) {
@@ -465,7 +465,7 @@ where
465
465
ChannelMonitorUpdate :: read ( & mut self . kv . read ( & ns, & key) . map_err ( |e| {
466
466
KVStoreUpdatingPersisterError :: StorageReadFailed {
467
467
reason : e,
468
- context : key. clone ( ) ,
468
+ context : key,
469
469
}
470
470
} ) ?)
471
471
. map_err ( |e| KVStoreUpdatingPersisterError :: UpdateDecodeFailed {
@@ -490,7 +490,7 @@ where
490
490
{
491
491
let ns = self . monitor_update_namespace ( & monitor_name) ;
492
492
let key = update_name. storage_key ( ) ;
493
- self . kv . remove ( & ns, & key) ?;
493
+ self . kv . remove ( & ns, key) ?;
494
494
}
495
495
}
496
496
Ok ( ( ) )
0 commit comments