23
23
24
24
const connector = require ( './connector' ) ;
25
25
const { convertToLong, buildOffsetCondition } = require ( './dbUtils' ) ;
26
+ const MultisigDb = require ( '../plugins/multisig/MultisigDb' ) ;
26
27
const catapult = require ( 'catapult-sdk' ) ;
27
28
const MongoDb = require ( 'mongodb' ) ;
28
29
@@ -304,24 +305,33 @@ class CatapultDb {
304
305
* `pageSize` and `pageNumber`. 'sortField' must be within allowed 'sortingOptions'.
305
306
* @returns {Promise.<object> } Transactions page.
306
307
*/
307
- transactions ( group , filters , options ) {
308
+ async transactions ( group , filters , options ) {
308
309
const sortingOptions = { id : '_id' } ;
309
310
310
- const buildAccountConditions = ( ) => {
311
- if ( undefined !== filters . address )
311
+ const buildAccountConditions = async ( ) => {
312
+ // Check multisig graph if address is used in search criteria for cosigning,
313
+ // Then, show transactions for other cosigers.
314
+ if ( undefined !== filters . address ) {
315
+ if ( 'partial' === group ) {
316
+ const multisigEntries = await new MultisigDb ( this ) . multisigsByAddresses ( [ filters . address ] ) ;
317
+
318
+ if ( multisigEntries . length && multisigEntries [ 0 ] . multisig . multisigAddresses . length ) {
319
+ const buffers = multisigEntries [ 0 ] . multisig . multisigAddresses . map ( address => address . buffer ) ;
320
+ buffers . push ( Buffer . from ( filters . address ) ) ;
321
+ return { 'meta.addresses' : { $in : buffers } } ;
322
+ }
323
+ }
312
324
return { 'meta.addresses' : Buffer . from ( filters . address ) } ;
313
-
325
+ }
314
326
const accountConditions = { } ;
315
327
if ( undefined !== filters . signerPublicKey )
316
328
accountConditions [ 'transaction.signerPublicKey' ] = Buffer . from ( filters . signerPublicKey ) ;
317
-
318
329
if ( undefined !== filters . recipientAddress )
319
330
accountConditions [ 'transaction.recipientAddress' ] = Buffer . from ( filters . recipientAddress ) ;
320
-
321
331
return accountConditions ;
322
332
} ;
323
333
324
- const buildConditions = ( ) => {
334
+ const buildConditions = async ( ) => {
325
335
let conditions = { } ;
326
336
327
337
const offsetCondition = buildOffsetCondition ( options , sortingOptions ) ;
@@ -363,7 +373,7 @@ class CatapultDb {
363
373
conditions [ amountPath ] . $lte = convertToLong ( filters . toTransferAmount ) ;
364
374
}
365
375
366
- const accountConditions = buildAccountConditions ( ) ;
376
+ const accountConditions = await buildAccountConditions ( ) ;
367
377
if ( accountConditions )
368
378
conditions = Object . assign ( conditions , accountConditions ) ;
369
379
@@ -372,7 +382,7 @@ class CatapultDb {
372
382
373
383
const removedFields = [ 'meta.addresses' ] ;
374
384
const sortConditions = { [ sortingOptions [ options . sortField ] ] : options . sortDirection } ;
375
- const conditions = buildConditions ( ) ;
385
+ const conditions = await buildConditions ( ) ;
376
386
377
387
return this . queryPagedDocuments ( conditions , removedFields , sortConditions , TransactionGroup [ group ] , options ) ;
378
388
}
@@ -470,17 +480,18 @@ class CatapultDb {
470
480
// fetch result sorted by specific mosaic amount, this unwinds mosaics and only returns matching mosaics (incomplete response)
471
481
queryPromise = this . database . collection ( 'accounts' )
472
482
. aggregate ( [ ] , { promoteLongs : false } )
473
- . skip ( pageSize * pageIndex )
474
- . limit ( pageSize )
475
483
. unwind ( '$account.mosaics' )
476
484
. match ( conditions )
477
485
. sort ( sortConditions )
486
+ . skip ( pageSize * pageIndex )
487
+ . limit ( pageSize )
478
488
. toArray ( )
479
489
. then ( accounts => {
480
490
const accountIds = accounts . map ( account => account . _id ) ;
481
491
const newConditions = { _id : { $in : accountIds } } ;
482
-
483
492
// repeat the response with the found and sorted account ids, so that the result can be complete with all the mosaics
493
+ // Second query set pageIndex to 0;
494
+ options . pageNumber = 1 ;
484
495
return this . queryPagedDocuments ( newConditions , [ ] , { } , 'accounts' , options )
485
496
. then ( fullAccountsPage => {
486
497
// $in results do not preserve query order
0 commit comments