@@ -2,7 +2,6 @@ use crate::error::MutinyError;
2
2
use crate :: nodemanager:: NodeManager ;
3
3
use crate :: storage:: MutinyStorage ;
4
4
use bitcoin:: { Address , XOnlyPublicKey } ;
5
- use lightning_invoice:: Bolt11Invoice ;
6
5
use lnurl:: lightning_address:: LightningAddress ;
7
6
use lnurl:: lnurl:: LnUrl ;
8
7
use nostr:: Metadata ;
@@ -21,7 +20,7 @@ pub struct LabelItem {
21
20
/// List of addresses that have this label
22
21
pub addresses : Vec < Address > ,
23
22
/// List of invoices that have this label
24
- pub invoices : Vec < Bolt11Invoice > ,
23
+ pub invoices : Vec < String > ,
25
24
/// Epoch time in seconds when this label was last used
26
25
pub last_used_time : u64 ,
27
26
}
@@ -96,7 +95,7 @@ pub trait LabelStorage {
96
95
/// Get a map of addresses to labels. This can be used to get all the labels for an address
97
96
fn get_address_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > ;
98
97
/// Get a map of invoices to labels. This can be used to get all the labels for an invoice
99
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > ;
98
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > ;
100
99
/// Get all the existing labels
101
100
fn get_labels ( & self ) -> Result < HashMap < String , LabelItem > , MutinyError > ;
102
101
/// Get information about a label
@@ -108,11 +107,7 @@ pub trait LabelStorage {
108
107
/// Set the labels for an invoice, replacing any existing labels
109
108
/// If you do not want to replace any existing labels, use `get_invoice_labels` to get the existing labels,
110
109
/// add the new labels, and then use `set_invoice_labels` to set the new labels
111
- fn set_invoice_labels (
112
- & self ,
113
- invoice : Bolt11Invoice ,
114
- labels : Vec < String > ,
115
- ) -> Result < ( ) , MutinyError > ;
110
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > ;
116
111
/// Get all the existing contacts
117
112
fn get_contacts ( & self ) -> Result < HashMap < String , Contact > , MutinyError > ;
118
113
/// Get a contact by label, the label should be a uuid
@@ -139,9 +134,8 @@ impl<S: MutinyStorage> LabelStorage for S {
139
134
Ok ( res. unwrap_or_default ( ) ) // if no labels exist, return an empty map
140
135
}
141
136
142
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > {
143
- let res: Option < HashMap < Bolt11Invoice , Vec < String > > > =
144
- self . get_data ( INVOICE_LABELS_MAP_KEY ) ?;
137
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > {
138
+ let res: Option < HashMap < String , Vec < String > > > = self . get_data ( INVOICE_LABELS_MAP_KEY ) ?;
145
139
Ok ( res. unwrap_or_default ( ) ) // if no labels exist, return an empty map
146
140
}
147
141
@@ -207,11 +201,7 @@ impl<S: MutinyStorage> LabelStorage for S {
207
201
Ok ( ( ) )
208
202
}
209
203
210
- fn set_invoice_labels (
211
- & self ,
212
- invoice : Bolt11Invoice ,
213
- labels : Vec < String > ,
214
- ) -> Result < ( ) , MutinyError > {
204
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > {
215
205
// update the labels map
216
206
let mut invoice_labels = self . get_invoice_labels ( ) ?;
217
207
invoice_labels. insert ( invoice. clone ( ) , labels. clone ( ) ) ;
@@ -397,7 +387,7 @@ impl<S: MutinyStorage> LabelStorage for NodeManager<S> {
397
387
self . storage . get_address_labels ( )
398
388
}
399
389
400
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > {
390
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > {
401
391
self . storage . get_invoice_labels ( )
402
392
}
403
393
@@ -413,11 +403,7 @@ impl<S: MutinyStorage> LabelStorage for NodeManager<S> {
413
403
self . storage . set_address_labels ( address, labels)
414
404
}
415
405
416
- fn set_invoice_labels (
417
- & self ,
418
- invoice : Bolt11Invoice ,
419
- labels : Vec < String > ,
420
- ) -> Result < ( ) , MutinyError > {
406
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > {
421
407
self . storage . set_invoice_labels ( invoice, labels)
422
408
}
423
409
@@ -459,7 +445,6 @@ mod tests {
459
445
use super :: * ;
460
446
use crate :: test_utils:: * ;
461
447
use bitcoin:: Address ;
462
- use lightning_invoice:: Bolt11Invoice ;
463
448
use std:: collections:: HashMap ;
464
449
use std:: str:: FromStr ;
465
450
@@ -487,18 +472,18 @@ mod tests {
487
472
labels
488
473
}
489
474
490
- fn create_test_invoice_labels_map ( ) -> HashMap < Bolt11Invoice , Vec < String > > {
475
+ fn create_test_invoice_labels_map ( ) -> HashMap < String , Vec < String > > {
491
476
let mut labels = HashMap :: new ( ) ;
492
477
labels. insert (
493
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nrefpp5pczykgk37af5388n8dzynljpkzs7sje4melqgazlwv9y3apay8jqhp5rd8saxz3juve3eejq7z5fjttxmpaq88d7l92xv34n4h3mq6kwq2qcqzzsxqzfvsp5z0jwpehkuz9f2kv96h62p8x30nku76aj8yddpcust7g8ad0tr52q9qyyssqfy622q25helv8cj8hyxqltws4rdwz0xx2hw0uh575mn7a76cp3q4jcptmtjkjs4a34dqqxn8uy70d0qlxqleezv4zp84uk30pp5q3nqq4c9gkz" ) . unwrap ( ) ,
478
+ String :: from ( "lnbc923720n1pj9nrefpp5pczykgk37af5388n8dzynljpkzs7sje4melqgazlwv9y3apay8jqhp5rd8saxz3juve3eejq7z5fjttxmpaq88d7l92xv34n4h3mq6kwq2qcqzzsxqzfvsp5z0jwpehkuz9f2kv96h62p8x30nku76aj8yddpcust7g8ad0tr52q9qyyssqfy622q25helv8cj8hyxqltws4rdwz0xx2hw0uh575mn7a76cp3q4jcptmtjkjs4a34dqqxn8uy70d0qlxqleezv4zp84uk30pp5q3nqq4c9gkz" ) ,
494
479
vec ! [ "test1" . to_string( ) ] ,
495
480
) ;
496
481
labels. insert (
497
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nre4pp58zjsgd3xkyj33wv6rfmsshg9hqdpqrh8dyaulzwg62x6h3qs39tqhp5vqcr4c3tnxyxr08rk28n8mkphe6c5gfusmyncpmdh604trq3cafqcqzzsxqzfvsp5un4ey9rh0pl23648xtng2k6gtw7w2p6ldaexl6ylwcuhnsnxnsfs9qyyssqxnhr6jvdqfwr97qk7dtsnqaps78r7fjlpyz5z57r2k70az5tvvss4tpucycqpph8gx0vxxr7xse442zf8wxlskln8n77qkd4kad4t5qp92lvrm" ) . unwrap ( ) ,
482
+ String :: from ( "lnbc923720n1pj9nre4pp58zjsgd3xkyj33wv6rfmsshg9hqdpqrh8dyaulzwg62x6h3qs39tqhp5vqcr4c3tnxyxr08rk28n8mkphe6c5gfusmyncpmdh604trq3cafqcqzzsxqzfvsp5un4ey9rh0pl23648xtng2k6gtw7w2p6ldaexl6ylwcuhnsnxnsfs9qyyssqxnhr6jvdqfwr97qk7dtsnqaps78r7fjlpyz5z57r2k70az5tvvss4tpucycqpph8gx0vxxr7xse442zf8wxlskln8n77qkd4kad4t5qp92lvrm" ) ,
498
483
vec ! [ "test2" . to_string( ) ] ,
499
484
) ;
500
485
labels. insert (
501
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) . unwrap ( ) ,
486
+ String :: from ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) ,
502
487
vec ! [ "test3" . to_string( ) ] ,
503
488
) ;
504
489
labels
@@ -517,7 +502,7 @@ mod tests {
517
502
"test2" . to_string ( ) ,
518
503
LabelItem {
519
504
addresses : vec ! [ Address :: from_str( "1BitcoinEaterAddressDontSendf59kuE" ) . unwrap( ) ] ,
520
- invoices : vec ! [ Bolt11Invoice :: from_str ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) . unwrap ( ) ] ,
505
+ invoices : vec ! [ String :: from ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) ] ,
521
506
..Default :: default ( )
522
507
} ,
523
508
) ;
@@ -672,7 +657,7 @@ mod tests {
672
657
673
658
let storage = MemoryStorage :: default ( ) ;
674
659
675
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
660
+ let invoice = INVOICE . to_string ( ) ;
676
661
let labels = vec ! [ "label1" . to_string( ) , "label2" . to_string( ) ] ;
677
662
678
663
let result = storage. set_invoice_labels ( invoice. clone ( ) , labels. clone ( ) ) ;
@@ -792,7 +777,7 @@ mod tests {
792
777
let storage = MemoryStorage :: default ( ) ;
793
778
794
779
let address = Address :: from_str ( ADDRESS ) . unwrap ( ) ;
795
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
780
+ let invoice = INVOICE . to_string ( ) ;
796
781
let label = "test_label" . to_string ( ) ;
797
782
let other_label = "other_label" . to_string ( ) ;
798
783
let contact = create_test_contacts ( ) . iter ( ) . next ( ) . unwrap ( ) . 1 . to_owned ( ) ;
@@ -920,7 +905,7 @@ mod tests {
920
905
assert_eq ! ( contact. last_used, 0 ) ;
921
906
let id = storage. create_new_contact ( contact. clone ( ) ) . unwrap ( ) ;
922
907
923
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
908
+ let invoice = INVOICE . to_string ( ) ;
924
909
925
910
storage
926
911
. set_invoice_labels ( invoice, vec ! [ id. clone( ) ] )
0 commit comments