@@ -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
}
@@ -89,7 +88,7 @@ pub trait LabelStorage {
89
88
/// Get a map of addresses to labels. This can be used to get all the labels for an address
90
89
fn get_address_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > ;
91
90
/// Get a map of invoices to labels. This can be used to get all the labels for an invoice
92
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > ;
91
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > ;
93
92
/// Get all the existing labels
94
93
fn get_labels ( & self ) -> Result < HashMap < String , LabelItem > , MutinyError > ;
95
94
/// Get information about a label
@@ -101,11 +100,7 @@ pub trait LabelStorage {
101
100
/// Set the labels for an invoice, replacing any existing labels
102
101
/// If you do not want to replace any existing labels, use `get_invoice_labels` to get the existing labels,
103
102
/// add the new labels, and then use `set_invoice_labels` to set the new labels
104
- fn set_invoice_labels (
105
- & self ,
106
- invoice : Bolt11Invoice ,
107
- labels : Vec < String > ,
108
- ) -> Result < ( ) , MutinyError > ;
103
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > ;
109
104
/// Get all the existing contacts
110
105
fn get_contacts ( & self ) -> Result < HashMap < String , Contact > , MutinyError > ;
111
106
/// Get a contact by label, the label should be a uuid
@@ -132,9 +127,8 @@ impl<S: MutinyStorage> LabelStorage for S {
132
127
Ok ( res. unwrap_or_default ( ) ) // if no labels exist, return an empty map
133
128
}
134
129
135
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > {
136
- let res: Option < HashMap < Bolt11Invoice , Vec < String > > > =
137
- self . get_data ( INVOICE_LABELS_MAP_KEY ) ?;
130
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > {
131
+ let res: Option < HashMap < String , Vec < String > > > = self . get_data ( INVOICE_LABELS_MAP_KEY ) ?;
138
132
Ok ( res. unwrap_or_default ( ) ) // if no labels exist, return an empty map
139
133
}
140
134
@@ -200,11 +194,7 @@ impl<S: MutinyStorage> LabelStorage for S {
200
194
Ok ( ( ) )
201
195
}
202
196
203
- fn set_invoice_labels (
204
- & self ,
205
- invoice : Bolt11Invoice ,
206
- labels : Vec < String > ,
207
- ) -> Result < ( ) , MutinyError > {
197
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > {
208
198
// update the labels map
209
199
let mut invoice_labels = self . get_invoice_labels ( ) ?;
210
200
invoice_labels. insert ( invoice. clone ( ) , labels. clone ( ) ) ;
@@ -390,7 +380,7 @@ impl<S: MutinyStorage> LabelStorage for NodeManager<S> {
390
380
self . storage . get_address_labels ( )
391
381
}
392
382
393
- fn get_invoice_labels ( & self ) -> Result < HashMap < Bolt11Invoice , Vec < String > > , MutinyError > {
383
+ fn get_invoice_labels ( & self ) -> Result < HashMap < String , Vec < String > > , MutinyError > {
394
384
self . storage . get_invoice_labels ( )
395
385
}
396
386
@@ -406,11 +396,7 @@ impl<S: MutinyStorage> LabelStorage for NodeManager<S> {
406
396
self . storage . set_address_labels ( address, labels)
407
397
}
408
398
409
- fn set_invoice_labels (
410
- & self ,
411
- invoice : Bolt11Invoice ,
412
- labels : Vec < String > ,
413
- ) -> Result < ( ) , MutinyError > {
399
+ fn set_invoice_labels ( & self , invoice : String , labels : Vec < String > ) -> Result < ( ) , MutinyError > {
414
400
self . storage . set_invoice_labels ( invoice, labels)
415
401
}
416
402
@@ -452,7 +438,6 @@ mod tests {
452
438
use super :: * ;
453
439
use crate :: test_utils:: * ;
454
440
use bitcoin:: Address ;
455
- use lightning_invoice:: Bolt11Invoice ;
456
441
use std:: collections:: HashMap ;
457
442
use std:: str:: FromStr ;
458
443
@@ -480,18 +465,18 @@ mod tests {
480
465
labels
481
466
}
482
467
483
- fn create_test_invoice_labels_map ( ) -> HashMap < Bolt11Invoice , Vec < String > > {
468
+ fn create_test_invoice_labels_map ( ) -> HashMap < String , Vec < String > > {
484
469
let mut labels = HashMap :: new ( ) ;
485
470
labels. insert (
486
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nrefpp5pczykgk37af5388n8dzynljpkzs7sje4melqgazlwv9y3apay8jqhp5rd8saxz3juve3eejq7z5fjttxmpaq88d7l92xv34n4h3mq6kwq2qcqzzsxqzfvsp5z0jwpehkuz9f2kv96h62p8x30nku76aj8yddpcust7g8ad0tr52q9qyyssqfy622q25helv8cj8hyxqltws4rdwz0xx2hw0uh575mn7a76cp3q4jcptmtjkjs4a34dqqxn8uy70d0qlxqleezv4zp84uk30pp5q3nqq4c9gkz" ) . unwrap ( ) ,
471
+ String :: from ( "lnbc923720n1pj9nrefpp5pczykgk37af5388n8dzynljpkzs7sje4melqgazlwv9y3apay8jqhp5rd8saxz3juve3eejq7z5fjttxmpaq88d7l92xv34n4h3mq6kwq2qcqzzsxqzfvsp5z0jwpehkuz9f2kv96h62p8x30nku76aj8yddpcust7g8ad0tr52q9qyyssqfy622q25helv8cj8hyxqltws4rdwz0xx2hw0uh575mn7a76cp3q4jcptmtjkjs4a34dqqxn8uy70d0qlxqleezv4zp84uk30pp5q3nqq4c9gkz" ) ,
487
472
vec ! [ "test1" . to_string( ) ] ,
488
473
) ;
489
474
labels. insert (
490
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nre4pp58zjsgd3xkyj33wv6rfmsshg9hqdpqrh8dyaulzwg62x6h3qs39tqhp5vqcr4c3tnxyxr08rk28n8mkphe6c5gfusmyncpmdh604trq3cafqcqzzsxqzfvsp5un4ey9rh0pl23648xtng2k6gtw7w2p6ldaexl6ylwcuhnsnxnsfs9qyyssqxnhr6jvdqfwr97qk7dtsnqaps78r7fjlpyz5z57r2k70az5tvvss4tpucycqpph8gx0vxxr7xse442zf8wxlskln8n77qkd4kad4t5qp92lvrm" ) . unwrap ( ) ,
475
+ String :: from ( "lnbc923720n1pj9nre4pp58zjsgd3xkyj33wv6rfmsshg9hqdpqrh8dyaulzwg62x6h3qs39tqhp5vqcr4c3tnxyxr08rk28n8mkphe6c5gfusmyncpmdh604trq3cafqcqzzsxqzfvsp5un4ey9rh0pl23648xtng2k6gtw7w2p6ldaexl6ylwcuhnsnxnsfs9qyyssqxnhr6jvdqfwr97qk7dtsnqaps78r7fjlpyz5z57r2k70az5tvvss4tpucycqpph8gx0vxxr7xse442zf8wxlskln8n77qkd4kad4t5qp92lvrm" ) ,
491
476
vec ! [ "test2" . to_string( ) ] ,
492
477
) ;
493
478
labels. insert (
494
- Bolt11Invoice :: from_str ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) . unwrap ( ) ,
479
+ String :: from ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) ,
495
480
vec ! [ "test3" . to_string( ) ] ,
496
481
) ;
497
482
labels
@@ -510,7 +495,7 @@ mod tests {
510
495
"test2" . to_string ( ) ,
511
496
LabelItem {
512
497
addresses : vec ! [ Address :: from_str( "1BitcoinEaterAddressDontSendf59kuE" ) . unwrap( ) ] ,
513
- invoices : vec ! [ Bolt11Invoice :: from_str ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) . unwrap ( ) ] ,
498
+ invoices : vec ! [ String :: from ( "lnbc923720n1pj9nr6zpp5xmvlq2u5253htn52mflh2e6gn7pk5ht0d4qyhc62fadytccxw7hqhp5l4s6qwh57a7cwr7zrcz706qx0qy4eykcpr8m8dwz08hqf362egfscqzzsxqzfvsp5pr7yjvcn4ggrf6fq090zey0yvf8nqvdh2kq7fue0s0gnm69evy6s9qyyssqjyq0fwjr22eeg08xvmz88307yqu8tqqdjpycmermks822fpqyxgshj8hvnl9mkh6srclnxx0uf4ugfq43d66ak3rrz4dqcqd23vxwpsqf7dmhm" ) ] ,
514
499
..Default :: default ( )
515
500
} ,
516
501
) ;
@@ -665,7 +650,7 @@ mod tests {
665
650
666
651
let storage = MemoryStorage :: default ( ) ;
667
652
668
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
653
+ let invoice = INVOICE . to_string ( ) ;
669
654
let labels = vec ! [ "label1" . to_string( ) , "label2" . to_string( ) ] ;
670
655
671
656
let result = storage. set_invoice_labels ( invoice. clone ( ) , labels. clone ( ) ) ;
@@ -785,7 +770,7 @@ mod tests {
785
770
let storage = MemoryStorage :: default ( ) ;
786
771
787
772
let address = Address :: from_str ( ADDRESS ) . unwrap ( ) ;
788
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
773
+ let invoice = INVOICE . to_string ( ) ;
789
774
let label = "test_label" . to_string ( ) ;
790
775
let other_label = "other_label" . to_string ( ) ;
791
776
let contact = create_test_contacts ( ) . iter ( ) . next ( ) . unwrap ( ) . 1 . to_owned ( ) ;
@@ -913,7 +898,7 @@ mod tests {
913
898
assert_eq ! ( contact. last_used, 0 ) ;
914
899
let id = storage. create_new_contact ( contact. clone ( ) ) . unwrap ( ) ;
915
900
916
- let invoice = Bolt11Invoice :: from_str ( INVOICE ) . unwrap ( ) ;
901
+ let invoice = INVOICE . to_string ( ) ;
917
902
918
903
storage
919
904
. set_invoice_labels ( invoice, vec ! [ id. clone( ) ] )
0 commit comments