@@ -70,6 +70,7 @@ impl TransactionContext {
7070 block_time : u32 ,
7171 price : Option < f64 > ,
7272 ) {
73+ let mut arbitrary_memos_with_txids = Vec :: new ( ) ;
7374 // Remember if this is an outgoing Tx. Useful for when we want to grab the outgoing metadata.
7475 let mut is_outgoing_transaction = false ;
7576
@@ -95,6 +96,7 @@ impl TransactionContext {
9596 block_time,
9697 & mut is_outgoing_transaction,
9798 & mut outgoing_metadatas,
99+ & mut arbitrary_memos_with_txids,
98100 )
99101 . await ;
100102 self . scan_orchard_bundle (
@@ -104,6 +106,7 @@ impl TransactionContext {
104106 block_time,
105107 & mut is_outgoing_transaction,
106108 & mut outgoing_metadatas,
109+ & mut arbitrary_memos_with_txids,
107110 )
108111 . await ;
109112
@@ -152,6 +155,9 @@ impl TransactionContext {
152155 . add_outgoing_metadata ( & transaction. txid ( ) , outgoing_metadatas) ;
153156 }
154157
158+ self . update_outgoing_metadatas_with_uas ( arbitrary_memos_with_txids)
159+ . await ;
160+
155161 // Update price if available
156162 if price. is_some ( ) {
157163 self . transaction_metadata_set
@@ -163,6 +169,52 @@ impl TransactionContext {
163169 //info!("Finished Fetching full transaction {}", tx.txid());
164170 }
165171
172+ async fn update_outgoing_metadatas_with_uas (
173+ & self ,
174+ arbitrary_memos_with_txids : Vec < ( [ u8 ; 511 ] , TxId ) > ,
175+ ) {
176+ for ( wallet_internal_data, txid) in arbitrary_memos_with_txids {
177+ let mut uas_bytes = vec ! [ 0 ; 511 ] ;
178+ wallet_internal_data
179+ . as_slice ( )
180+ . read ( & mut uas_bytes)
181+ . unwrap ( ) ;
182+ let uas_string = String :: from_utf8 ( uas_bytes) ;
183+ if let Ok ( uas_string) = uas_string {
184+ for ua_string in uas_string. split ( '!' ) {
185+ if let Some ( RecipientAddress :: Unified ( ua) ) =
186+ RecipientAddress :: decode ( & self . config . chain , ua_string)
187+ {
188+ if let Some ( transaction) = self
189+ . transaction_metadata_set
190+ . write ( )
191+ . await
192+ . current
193+ . get_mut ( & txid)
194+ {
195+ let outgoing_potential_recievers = [
196+ ua. orchard ( )
197+ . map ( |oaddr| oaddr. b32encode_for_network ( & self . config . chain ) ) ,
198+ ua. sapling ( )
199+ . map ( |zaddr| zaddr. b32encode_for_network ( & self . config . chain ) ) ,
200+ address_from_pubkeyhash ( & self . config , ua. transparent ( ) . cloned ( ) ) ,
201+ ] ;
202+ if let Some ( metadata) =
203+ transaction. outgoing_metadata . iter_mut ( ) . find ( |metadata| {
204+ outgoing_potential_recievers
205+ . contains ( & Some ( metadata. address . clone ( ) ) )
206+ } )
207+ {
208+ metadata. ua = Some ( ua_string. to_string ( ) ) ;
209+ } else {
210+ }
211+ }
212+ }
213+ }
214+ }
215+ }
216+ }
217+
166218 async fn scan_transparent_bundle (
167219 & self ,
168220 transaction : & Transaction ,
@@ -275,6 +327,7 @@ impl TransactionContext {
275327 block_time : u32 ,
276328 is_outgoing_transaction : & mut bool ,
277329 outgoing_metadatas : & mut Vec < OutgoingTxMetadata > ,
330+ arbitrary_memos_with_txids : & mut Vec < ( [ u8 ; 511 ] , TxId ) > ,
278331 ) {
279332 self . scan_bundle :: < SaplingDomain < ChainType > > (
280333 transaction,
@@ -283,6 +336,7 @@ impl TransactionContext {
283336 block_time,
284337 is_outgoing_transaction,
285338 outgoing_metadatas,
339+ arbitrary_memos_with_txids,
286340 )
287341 . await
288342 }
@@ -294,6 +348,7 @@ impl TransactionContext {
294348 block_time : u32 ,
295349 is_outgoing_transaction : & mut bool ,
296350 outgoing_metadatas : & mut Vec < OutgoingTxMetadata > ,
351+ arbitrary_memos_with_txids : & mut Vec < ( [ u8 ; 511 ] , TxId ) > ,
297352 ) {
298353 self . scan_bundle :: < OrchardDomain > (
299354 transaction,
@@ -302,6 +357,7 @@ impl TransactionContext {
302357 block_time,
303358 is_outgoing_transaction,
304359 outgoing_metadatas,
360+ arbitrary_memos_with_txids,
305361 )
306362 . await ;
307363 }
@@ -319,6 +375,7 @@ impl TransactionContext {
319375 block_time : u32 ,
320376 is_outgoing_transaction : & mut bool , // Isn't this also NA for unconfirmed?
321377 outgoing_metadatas : & mut Vec < OutgoingTxMetadata > ,
378+ arbitrary_memos_with_txids : & mut Vec < ( [ u8 ; 511 ] , TxId ) > ,
322379 ) where
323380 D : zingo_traits:: DomainWalletExt < ChainType > ,
324381 D :: Note : Clone + PartialEq ,
@@ -407,48 +464,8 @@ impl TransactionContext {
407464 . try_into ( )
408465 . unwrap_or ( Memo :: Future ( memo_bytes) ) ;
409466 if let Memo :: Arbitrary ( ref wallet_internal_data) = memo {
410- let mut uas_bytes = vec ! [ 0 ; 511 ] ;
411- wallet_internal_data
412- . as_slice ( )
413- . read ( & mut uas_bytes)
414- . unwrap ( ) ;
415- let uas_string = String :: from_utf8 ( uas_bytes) ;
416- if let Ok ( uas_string) = uas_string {
417- for ua_string in uas_string. split ( '!' ) {
418- if let Some ( RecipientAddress :: Unified ( ua) ) =
419- RecipientAddress :: decode ( & self . config . chain , ua_string)
420- {
421- if let Some ( transaction) = self
422- . transaction_metadata_set
423- . write ( )
424- . await
425- . current
426- . get_mut ( & transaction. txid ( ) )
427- {
428- let outgoing_potential_recievers = [
429- ua. orchard ( ) . map ( |oaddr| {
430- oaddr. b32encode_for_network ( & self . config . chain )
431- } ) ,
432- ua. sapling ( ) . map ( |zaddr| {
433- zaddr. b32encode_for_network ( & self . config . chain )
434- } ) ,
435- address_from_pubkeyhash (
436- & self . config ,
437- ua. transparent ( ) . cloned ( ) ,
438- ) ,
439- ] ;
440- if let Some ( metadata) =
441- transaction. outgoing_metadata . iter_mut ( ) . find ( |metadata| {
442- outgoing_potential_recievers
443- . contains ( & Some ( metadata. address . clone ( ) ) )
444- } )
445- {
446- metadata. ua = Some ( ua_string. to_string ( ) ) ;
447- }
448- }
449- }
450- }
451- }
467+ arbitrary_memos_with_txids
468+ . push ( ( * wallet_internal_data. as_ref ( ) , transaction. txid ( ) ) ) ;
452469 }
453470 self . transaction_metadata_set
454471 . write ( )
0 commit comments