Skip to content

Commit

Permalink
Give option to mongodb for decoded tx (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
leojacob1 authored Aug 19, 2022
1 parent 6294587 commit cfe7bae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,12 @@ class Translator {
/****** DB ONLY CALLs ********/
/**********************************************/

async getManyDecodedTxFromDB(txHashArr: string[]): Promise<(DecodedTx | null)[]> {
async getManyDecodedTxFromDB(txHashArr: string[], options?: any): Promise<(DecodedTx | null)[]> {
if (!(this.databaseInterface instanceof MongooseDatabaseInterface)) {
throw new Error('This function only works with MongodB')
}
await this.initializeMongoose()
const txArr = await this.databaseInterface.getManyDecodedTxArr(txHashArr)
const txArr = await this.databaseInterface.getManyDecodedTxArr(txHashArr, 50, options)
return txArr
}

Expand Down
8 changes: 6 additions & 2 deletions src/utils/mongoose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class MongooseDatabaseInterface extends DatabaseInterface {
// return here instead of in the try, so that it still works if the db is down
return decodedTxMap
}
async getManyDecodedTxArr(txHashes: string[], maxAddresses = 50): Promise<DecodedTx[]> {
async getManyDecodedTxArr(txHashes: string[], maxAddresses = 50, options: any = {}): Promise<DecodedTx[]> {
let decodedTxArr = []

// hack for $in being n * log(m) where n = chunk.length and m = db size
Expand All @@ -265,7 +265,11 @@ export class MongooseDatabaseInterface extends DatabaseInterface {
.map((chunk: any) => chunk.all())

const promises = chunks.map((chunk) => {
return DecodedTxModel.find({ txHash: { $in: chunk }, [`allAddresses.${maxAddresses}`]: { $exists: false } })
return DecodedTxModel.find({
txHash: { $in: chunk },
[`allAddresses.${maxAddresses}`]: { $exists: false },
timestamp: { $gte: options.tsStart || 0 },
})
})

try {
Expand Down

0 comments on commit cfe7bae

Please sign in to comment.