@@ -20,7 +20,7 @@ import {
20
20
import { unixToDate } from '../../../../utils/convert' ;
21
21
import { StatsUtil } from '../../../../utils/stats' ;
22
22
import MoralisAPI from '../../external/providers/moralis' ;
23
- import { ExternalApiStream , MergedStream } from '../../external/streams/apiStream' ;
23
+ import { ExternalApiStream , MergedStream , ParseTransform } from '../../external/streams/apiStream' ;
24
24
import { NodeQueryStream } from '../../external/streams/nodeStream' ;
25
25
import { InternalStateProvider } from '../../internal/internal' ;
26
26
import { EVMTransactionStorage } from '../models/transaction' ;
@@ -30,6 +30,8 @@ import {
30
30
getProvider ,
31
31
isValidProviderType
32
32
} from './provider' ;
33
+ import { EVMListTransactionsStream } from './transform' ;
34
+ import { PopulateReceiptTransform } from './populateReceiptTransform' ;
33
35
34
36
35
37
export interface GetWeb3Response { rpc : CryptoRpc ; web3 : Web3 ; dataType : string }
@@ -261,24 +263,32 @@ export class BaseEVMExternalStateProvider extends InternalStateProvider implemen
261
263
throw new Error ( 'Missing wallet' ) ;
262
264
}
263
265
const chainId = await this . getChainId ( { network } ) ;
264
- // Calculate confirmations with tip height
265
266
const tip = await this . getLocalTip ( params ) ;
266
- args . tipHeight = tip ? tip . height : 0 ;
267
- const walletAddresses = ( await this . getWalletAddresses ( wallet . _id ! ) ) . map ( addy => addy . address ) ;
268
- const mergedStream = new MergedStream ( ) ;
267
+ const walletAddresses = ( await this . getWalletAddresses ( wallet . _id ! ) ) . map ( addy => addy . address . toLowerCase ( ) ) ;
269
268
const txStreams : Readable [ ] = [ ] ;
270
- // Only mergedStream writes to res object
271
- const _mergedStream = ExternalApiStream . onStream ( mergedStream , req ! , res ! , { jsonl : true } ) ;
272
-
273
- // Default to pulling only the first 10 transactions per address
269
+ const ethTransactionTransform = new EVMListTransactionsStream ( walletAddresses ) ;
270
+ const populateReceipt = new PopulateReceiptTransform ( ) ;
271
+ const parseStrings = new ParseTransform ( ) ;
272
+ const mergedStream = new MergedStream ( ) ; // Stream to combine the output of multiple streams
273
+ const resultStream = new MergedStream ( ) ; // Stream to write to the res object
274
+
275
+ // Transform transactions proccessed through merged stream
276
+ mergedStream
277
+ . pipe ( parseStrings )
278
+ . pipe ( populateReceipt )
279
+ . pipe ( ethTransactionTransform )
280
+ . pipe ( resultStream ) ;
281
+ // Tip height used to calculate confirmations
282
+ args . tipHeight = tip ? tip . height : 0 ;
283
+ // Defaults to pulling only the first 10 transactions per address
274
284
for ( let i = 0 ; i < walletAddresses . length ; i ++ ) {
275
285
// args / query params are processed at the api provider level
276
286
txStreams . push ( MoralisAPI . streamTransactionsByAddress ( { chainId, chain, network, address : walletAddresses [ i ] , args } ) ) ;
277
287
}
278
288
// Pipe all txStreams to the mergedStream
279
289
ExternalApiStream . mergeStreams ( txStreams , mergedStream ) ;
280
290
// Ensure mergeStream resolves
281
- const result = await _mergedStream ;
291
+ const result = await ExternalApiStream . onStream ( resultStream , req ! , res ! , { jsonl : true } ) ;
282
292
if ( result ?. success === false ) {
283
293
logger . error ( 'Error mid-stream (streamWalletTransactions): %o' , result . error ?. log || result . error ) ;
284
294
}
0 commit comments