@@ -47,9 +47,10 @@ pub use crate::gossip::{GOSSIP_SYNC_TIME_KEY, NETWORK_GRAPH_KEY, PROB_SCORER_KEY
47
47
pub use crate :: keymanager:: generate_seed;
48
48
pub use crate :: ldkstorage:: { CHANNEL_CLOSURE_PREFIX , CHANNEL_MANAGER_KEY , MONITORS_PREFIX_KEY } ;
49
49
use crate :: storage:: {
50
- list_payment_info, persist_payment_info, update_nostr_contact_list, IndexItem , MutinyStorage ,
51
- DEVICE_ID_KEY , EXPECTED_NETWORK_KEY , NEED_FULL_SYNC_KEY , ONCHAIN_PREFIX ,
52
- PAYMENT_INBOUND_PREFIX_KEY , PAYMENT_OUTBOUND_PREFIX_KEY , SUBSCRIPTION_TIMESTAMP ,
50
+ get_payment_hash_from_key, list_payment_info, persist_payment_info, update_nostr_contact_list,
51
+ IndexItem , MutinyStorage , DEVICE_ID_KEY , EXPECTED_NETWORK_KEY , NEED_FULL_SYNC_KEY ,
52
+ ONCHAIN_PREFIX , PAYMENT_INBOUND_PREFIX_KEY , PAYMENT_OUTBOUND_PREFIX_KEY ,
53
+ SUBSCRIPTION_TIMESTAMP ,
53
54
} ;
54
55
use crate :: { auth:: MutinyAuthClient , hermes:: HermesClient , logging:: MutinyLogger } ;
55
56
use crate :: { blindauth:: BlindAuthClient , cashu:: CashuHttpClient } ;
@@ -114,6 +115,7 @@ use nostr_sdk::{NostrSigner, RelayPoolNotification};
114
115
use reqwest:: multipart:: { Form , Part } ;
115
116
use serde:: { Deserialize , Serialize } ;
116
117
use serde_json:: Value ;
118
+ use std:: collections:: HashSet ;
117
119
use std:: sync:: Arc ;
118
120
#[ cfg( not( target_arch = "wasm32" ) ) ]
119
121
use std:: time:: Instant ;
@@ -1720,10 +1722,7 @@ impl<S: MutinyStorage> MutinyWallet<S> {
1720
1722
true => PAYMENT_INBOUND_PREFIX_KEY ,
1721
1723
false => PAYMENT_OUTBOUND_PREFIX_KEY ,
1722
1724
} ;
1723
- let payment_hash_str = key
1724
- . trim_start_matches ( prefix)
1725
- . splitn ( 2 , '_' ) // To support the old format that had `_{node_id}` at the end
1726
- . collect :: < Vec < & str > > ( ) [ 0 ] ;
1725
+ let payment_hash_str = get_payment_hash_from_key ( key, prefix) ;
1727
1726
let hash: [ u8 ; 32 ] = FromHex :: from_hex ( payment_hash_str) ?;
1728
1727
1729
1728
return MutinyInvoice :: from ( info, PaymentHash ( hash) , inbound, labels) . map ( Some ) ;
@@ -1810,6 +1809,59 @@ impl<S: MutinyStorage> MutinyWallet<S> {
1810
1809
Ok ( activities)
1811
1810
}
1812
1811
1812
+ /// Returns all the lightning activity for a given label
1813
+ pub async fn get_label_activity (
1814
+ & self ,
1815
+ label : & String ,
1816
+ ) -> Result < Vec < ActivityItem > , MutinyError > {
1817
+ let Some ( label_item) = self . node_manager . get_label ( label) ? else {
1818
+ return Ok ( Vec :: new ( ) ) ;
1819
+ } ;
1820
+
1821
+ // get all the payment hashes for this label
1822
+ let payment_hashes: HashSet < sha256:: Hash > = label_item
1823
+ . invoices
1824
+ . into_iter ( )
1825
+ . map ( |i| * i. payment_hash ( ) )
1826
+ . collect ( ) ;
1827
+
1828
+ let index = self . storage . activity_index ( ) ;
1829
+ let index = index. try_read ( ) ?. clone ( ) . into_iter ( ) . collect_vec ( ) ;
1830
+
1831
+ let labels_map = self . storage . get_invoice_labels ( ) ?;
1832
+
1833
+ let mut activities = Vec :: with_capacity ( index. len ( ) ) ;
1834
+ for item in index {
1835
+ if item. key . starts_with ( PAYMENT_INBOUND_PREFIX_KEY ) {
1836
+ let payment_hash_str =
1837
+ get_payment_hash_from_key ( & item. key , PAYMENT_INBOUND_PREFIX_KEY ) ;
1838
+ let hash = sha256:: Hash :: from_str ( payment_hash_str) ?;
1839
+
1840
+ if payment_hashes. contains ( & hash) {
1841
+ if let Some ( mutiny_invoice) =
1842
+ self . get_invoice_internal ( & item. key , true , & labels_map) ?
1843
+ {
1844
+ activities. push ( ActivityItem :: Lightning ( Box :: new ( mutiny_invoice) ) ) ;
1845
+ }
1846
+ }
1847
+ } else if item. key . starts_with ( PAYMENT_OUTBOUND_PREFIX_KEY ) {
1848
+ let payment_hash_str =
1849
+ get_payment_hash_from_key ( & item. key , PAYMENT_OUTBOUND_PREFIX_KEY ) ;
1850
+ let hash = sha256:: Hash :: from_str ( payment_hash_str) ?;
1851
+
1852
+ if payment_hashes. contains ( & hash) {
1853
+ if let Some ( mutiny_invoice) =
1854
+ self . get_invoice_internal ( & item. key , true , & labels_map) ?
1855
+ {
1856
+ activities. push ( ActivityItem :: Lightning ( Box :: new ( mutiny_invoice) ) ) ;
1857
+ }
1858
+ }
1859
+ }
1860
+ }
1861
+
1862
+ Ok ( activities)
1863
+ }
1864
+
1813
1865
pub fn list_invoices ( & self ) -> Result < Vec < MutinyInvoice > , MutinyError > {
1814
1866
let mut inbound_invoices = self . list_payment_info_from_persisters ( true ) ?;
1815
1867
let mut outbound_invoices = self . list_payment_info_from_persisters ( false ) ?;
0 commit comments