1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

multithread search by dt address (#559)

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2021-01-21 17:05:37 +02:00 committed by GitHub
parent d1b28a9e15
commit 316c3f5010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,8 @@ import Web3 from 'web3'
import { SubscribablePromise, Logger, getFairGasPrice } from '../utils' import { SubscribablePromise, Logger, getFairGasPrice } from '../utils'
import { DataTokens } from '../datatokens/Datatokens' import { DataTokens } from '../datatokens/Datatokens'
const MAX_AWAIT_PROMISES = 10
export interface FixedPriceExchange { export interface FixedPriceExchange {
exchangeID?: string exchangeID?: string
exchangeOwner: string exchangeOwner: string
@ -366,18 +368,26 @@ export class OceanFixedRateExchange {
fromBlock: this.startBlock, fromBlock: this.startBlock,
toBlock: 'latest' toBlock: 'latest'
}) })
let promises = []
for (let i = 0; i < events.length; i++) { for (let i = 0; i < events.length; i++) {
const constituents = await this.getExchange(events[i].returnValues[0]) promises.push(this.getExchange(events[i].returnValues[0]))
constituents.exchangeID = events[i].returnValues[0] if (promises.length > MAX_AWAIT_PROMISES || i === events.length - 1) {
if ( const results = await Promise.all(promises)
constituents.active === true && for (let j = 0; j < results.length; j++) {
constituents.dataToken.toLowerCase() === dataTokenAddress.toLowerCase() const constituents = results[j]
) { constituents.exchangeID = events[i].returnValues[0]
const supply = new BigNumber(constituents.supply) if (
const required = new BigNumber(minSupply) constituents.active === true &&
if (supply.gte(required)) { constituents.dataToken.toLowerCase() === dataTokenAddress.toLowerCase()
result.push(constituents) ) {
const supply = new BigNumber(constituents.supply)
const required = new BigNumber(minSupply)
if (supply.gte(required)) {
result.push(constituents)
}
}
} }
promises = []
} }
} }
return result return result