@@ -42,6 +42,8 @@ import { NetworkService } from 'src/endpoints/network/network.service';
4242import { TransactionWithPpu } from './entities/transaction.with.ppu' ;
4343import { GasBucket } from './entities/gas.bucket' ;
4444import { GasBucketConstants } from './constants/gas.bucket.constants' ;
45+ import { TransactionAction } from "./transaction-action/entities/transaction.action" ;
46+ import { TransactionActionCategory } from "./transaction-action/entities/transaction.action.category" ;
4547
4648@Injectable ( )
4749export class TransactionService {
@@ -96,6 +98,32 @@ export class TransactionService {
9698 return await this . indexerService . getTransactionCount ( filter , address ) ;
9799 }
98100
101+ public reorderAccountSentTransactionsByNonce ( transactions : TransactionDetailed [ ] , accountAddress : string ) : TransactionDetailed [ ] {
102+ const sentPositions : number [ ] = [ ] ;
103+ const sentTransactions : TransactionDetailed [ ] = [ ] ;
104+
105+ transactions . forEach ( ( tx , index ) => {
106+ if ( tx . sender === accountAddress ) {
107+ sentPositions . push ( index ) ;
108+ sentTransactions . push ( tx ) ;
109+ }
110+ } ) ;
111+
112+ sentTransactions . sort ( ( a , b ) => {
113+ const nonceA = a . nonce ?? 0 ;
114+ const nonceB = b . nonce ?? 0 ;
115+ return nonceB - nonceA ;
116+ } ) ;
117+
118+ const result = [ ...transactions ] ;
119+
120+ sentPositions . forEach ( ( position , index ) => {
121+ result [ position ] = sentTransactions [ index ] ;
122+ } ) ;
123+
124+ return result ;
125+ }
126+
99127 private getDistinctUserAddressesFromTransactions ( transactions : Transaction [ ] ) : string [ ] {
100128 const allAddresses = [ ] ;
101129 for ( const transaction of transactions ) {
@@ -169,6 +197,13 @@ export class TransactionService {
169197 let transactions : TransactionDetailed [ ] = [ ] ;
170198 transactions = elasticTransactions . map ( x => ApiUtils . mergeObjects ( new TransactionDetailed ( ) , x ) ) ;
171199
200+ const hasSenderFilter = filter . sender || ( filter . senders && filter . senders . length > 0 ) ;
201+ const hasReceiverFilter = filter . receivers && filter . receivers . length > 0 ;
202+
203+ if ( address && ! hasSenderFilter && ! hasReceiverFilter ) {
204+ transactions = this . reorderAccountSentTransactionsByNonce ( transactions , address ) ;
205+ }
206+
172207 if ( filter . hashes ) {
173208 const txHashes : string [ ] = filter . hashes ;
174209 const elasticHashes = elasticTransactions . map ( ( { txHash } : any ) => txHash ) ;
@@ -193,7 +228,6 @@ export class TransactionService {
193228
194229 for ( const transaction of transactions ) {
195230 transaction . type = undefined ;
196- transaction . relayedVersion = this . extractRelayedVersion ( transaction ) ;
197231 }
198232
199233 await this . processTransactions ( transactions , {
@@ -202,6 +236,8 @@ export class TransactionService {
202236 withActionTransferValue : queryOptions ?. withActionTransferValue ?? false ,
203237 } ) ;
204238
239+ this . processRelayedInfo ( transactions ) ;
240+
205241 return transactions ;
206242 }
207243
@@ -225,9 +261,9 @@ export class TransactionService {
225261
226262 if ( transaction !== null ) {
227263 transaction . price = await this . getTransactionPrice ( transaction ) ;
228- transaction . relayedVersion = this . extractRelayedVersion ( transaction ) ;
229264
230265 await this . processTransactions ( [ transaction ] , { withScamInfo : true , withUsername : true , withActionTransferValue } ) ;
266+ this . processRelayedInfo ( [ transaction ] ) ;
231267
232268 if ( transaction . pendingResults === true && transaction . results ) {
233269 for ( const result of transaction . results ) {
@@ -347,6 +383,26 @@ export class TransactionService {
347383 }
348384 }
349385
386+ public processRelayedInfo ( transactions : TransactionDetailed [ ] ) {
387+ for ( const transaction of transactions ) {
388+ transaction . relayedVersion = this . extractRelayedVersion ( transaction ) ;
389+ if ( transaction . relayedVersion && [ "v1" , "v2" ] . includes ( transaction . relayedVersion ) ) {
390+ const shouldSkip = this . apiConfigService . shouldDeprecateRelayedV1V2 ( transaction . epoch ?? 0 ) ;
391+ if ( shouldSkip ) {
392+ transaction . function = undefined ;
393+ transaction . action = new TransactionAction ( {
394+ category : TransactionActionCategory . deprecatedRelayedV1V2 ,
395+ name : "Deprecated transaction action" ,
396+ description : `Relayed v1/v2 transactions are deprecated` ,
397+ } ) ;
398+ }
399+ }
400+ if ( ! transaction . isRelayed ) {
401+ transaction . relayedVersion = undefined ;
402+ }
403+ }
404+ }
405+
350406 async processTransactions ( transactions : Transaction [ ] , options : { withScamInfo : boolean , withUsername : boolean , withActionTransferValue : boolean } ) : Promise < void > {
351407
352408 this . normalizeTimestampMs ( transactions ) ;
@@ -587,7 +643,7 @@ export class TransactionService {
587643 }
588644
589645 private extractRelayedVersion ( transaction : TransactionDetailed ) : string | undefined {
590- if ( transaction . isRelayed == true && transaction . data ) {
646+ if ( transaction . data ) {
591647 const decodedData = BinaryUtils . base64Decode ( transaction . data ) ;
592648
593649 if ( decodedData . startsWith ( 'relayedTx@' ) ) {
0 commit comments