@@ -8,20 +8,16 @@ export class ListTransactionsStream extends Transform {
8
8
}
9
9
10
10
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
25
21
. find (
26
22
{
27
23
chain : transaction . chain ,
@@ -32,17 +28,7 @@ export class ListTransactionsStream extends Transform {
32
28
)
33
29
. project ( { address : 1 , wallets : 1 , value : 1 , mintIndex : 1 } )
34
30
. 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 ( ) ;
46
32
outputs . forEach ( ( output ) => {
47
33
const sendingToOurself = output . wallets . some ( ( outputWallet ) => {
48
34
return outputWallet . equals ( wallet ) ;
@@ -93,6 +79,14 @@ export class ListTransactionsStream extends Transform {
93
79
}
94
80
return done ( ) ;
95
81
} 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 ( ) ;
96
90
outputs . forEach ( ( output ) => {
97
91
const weReceived = output . wallets . some ( ( outputWallet ) => {
98
92
return outputWallet . equals ( wallet ) ;
0 commit comments