Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give option to mongodb for decoded tx #38

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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