@@ -8,20 +8,16 @@ export class ListTransactionsStream extends Transform {
88 }
99
1010 async _transform ( transaction , _ , done ) {
11- const [ inputs , outputs ] = await Promise . all ( [
12- CoinModel . collection
13- . find (
14- {
15- chain : transaction . chain ,
16- network : transaction . network ,
17- spentTxid : transaction . txid
18- } ,
19- { batchSize : 10000 }
20- )
21- . project ( { address : 1 , wallets : 1 , value : 1 , mintIndex : 1 } )
22- . addCursorFlag ( 'noCursorTimeout' , true )
23- . toArray ( ) ,
24- CoinModel . collection
11+ const sending = ! ! await CoinModel . collection . count ( {
12+ wallets : this . wallet . _id ,
13+ 'wallets.0' : { $exists : true } ,
14+ spentTxid : transaction . txid
15+ } ) ;
16+
17+ const wallet = this . wallet . _id ! . toString ( ) ;
18+
19+ if ( sending ) {
20+ const outputs = await CoinModel . collection
2521 . find (
2622 {
2723 chain : transaction . chain ,
@@ -32,17 +28,7 @@ export class ListTransactionsStream extends Transform {
3228 )
3329 . project ( { address : 1 , wallets : 1 , value : 1 , mintIndex : 1 } )
3430 . addCursorFlag ( 'noCursorTimeout' , true )
35- . toArray ( )
36- ] ) ;
37-
38- const wallet = this . wallet . _id ! . toString ( ) ;
39- const sending = inputs . some ( ( input ) => {
40- return input . wallets . some ( ( inputWallet ) => {
41- return inputWallet . equals ( wallet ) ;
42- } ) ;
43- } ) ;
44-
45- if ( sending ) {
31+ . toArray ( ) ;
4632 outputs . forEach ( ( output ) => {
4733 const sendingToOurself = output . wallets . some ( ( outputWallet ) => {
4834 return outputWallet . equals ( wallet ) ;
@@ -93,6 +79,14 @@ export class ListTransactionsStream extends Transform {
9379 }
9480 return done ( ) ;
9581 } else {
82+ const outputs = await CoinModel . collection . find ( {
83+ wallets : this . wallet . _id ,
84+ 'wallets.0' : { $exists : true } ,
85+ mintTxid : transaction . txid
86+ } )
87+ . project ( { address : 1 , wallets : 1 , value : 1 , mintIndex : 1 } )
88+ . addCursorFlag ( 'noCursorTimeout' , true )
89+ . toArray ( ) ;
9690 outputs . forEach ( ( output ) => {
9791 const weReceived = output . wallets . some ( ( outputWallet ) => {
9892 return outputWallet . equals ( wallet ) ;
0 commit comments