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

logs/history speed optimizations

This commit is contained in:
alexcos20 2020-11-06 07:34:23 -08:00
parent 38c8b00400
commit d361298039
8 changed files with 37 additions and 21 deletions

View File

@ -54,6 +54,7 @@ export enum PoolCreateProgressStep {
export class OceanPool extends Pool {
public oceanAddress: string = null
public dtAddress: string = null
public startBlock: number
constructor(
web3: Web3,
@ -62,12 +63,14 @@ export class OceanPool extends Pool {
poolABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
oceanAddress: string = null,
gaslimit?: number
startBlock?: number
) {
super(web3, logger, factoryABI, poolABI, factoryAddress, gaslimit)
super(web3, logger, factoryABI, poolABI, factoryAddress)
if (oceanAddress) {
this.oceanAddress = oceanAddress
}
if (startBlock) this.startBlock = startBlock
else this.startBlock = 0
}
/**
@ -855,7 +858,7 @@ export class OceanPool extends Pool {
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
const events = await factory.getPastEvents('BPoolRegistered', {
filter: {},
fromBlock: BPFACTORY_DEPLOY_BLOCK,
fromBlock: this.startBlock,
toBlock: 'latest'
})
events.sort((a, b) => (a.blockNumber > b.blockNumber ? 1 : -1))
@ -920,7 +923,7 @@ export class OceanPool extends Pool {
const events = await factory.getPastEvents('BPoolRegistered', {
filter: account ? { registeredBy: account } : {},
fromBlock: BPFACTORY_DEPLOY_BLOCK,
fromBlock: this.startBlock,
toBlock: 'latest'
})
for (let i = 0; i < events.length; i++) {
@ -941,7 +944,7 @@ export class OceanPool extends Pool {
const events = await factory.getPastEvents('BPoolRegistered', {
filter: {},
fromBlock: BPFACTORY_DEPLOY_BLOCK,
fromBlock: this.startBlock,
toBlock: 'latest'
})
for (let i = 0; i < events.length; i++) {
@ -988,7 +991,7 @@ export class OceanPool extends Pool {
const dtAddress = await this.getDTAddress(poolAddress)
const filter: Filter = account ? { caller: account } : {}
let events: EventData[]
if (startBlock === 0) startBlock = this.startBlock
events = await pool.getPastEvents('LOG_SWAP', {
filter,
fromBlock: startBlock,
@ -1034,7 +1037,7 @@ export class OceanPool extends Pool {
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
const events = await factory.getPastEvents('BPoolRegistered', {
filter: {},
fromBlock: BPFACTORY_DEPLOY_BLOCK,
fromBlock: this.startBlock,
toBlock: 'latest'
})
for (let i = 0; i < events.length; i++) {

View File

@ -26,10 +26,9 @@ export class Pool extends PoolFactory {
logger: Logger,
factoryABI: AbiItem | AbiItem[] = null,
poolABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
gaslimit?: number
factoryAddress: string = null
) {
super(web3, logger, factoryABI, factoryAddress, gaslimit)
super(web3, logger, factoryABI, factoryAddress)
if (poolABI) this.poolABI = poolABI
else this.poolABI = jsonpoolABI.abi as AbiItem[]
}

View File

@ -15,8 +15,7 @@ export class PoolFactory {
web3: Web3,
logger: Logger,
factoryABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
gaslimit?: number
factoryAddress: string = null
) {
this.web3 = web3
@ -25,7 +24,6 @@ export class PoolFactory {
if (factoryAddress) {
this.factoryAddress = factoryAddress
}
if (gaslimit) this.GASLIMIT_DEFAULT = gaslimit
this.logger = logger
}

View File

@ -39,6 +39,7 @@ export class OceanFixedRateExchange {
public contract: Contract = null
private logger: Logger
public datatokens: DataTokens
public startBlock: number
/**
* Instantiate FixedRateExchange
@ -53,10 +54,13 @@ export class OceanFixedRateExchange {
fixedRateExchangeAddress: string = null,
fixedRateExchangeABI: AbiItem | AbiItem[] = null,
oceanAddress: string = null,
datatokens: DataTokens
datatokens: DataTokens,
startBlock?: number
) {
this.web3 = web3
this.fixedRateExchangeAddress = fixedRateExchangeAddress
if (startBlock) this.startBlock = startBlock
else this.startBlock = 0
this.fixedRateExchangeABI =
fixedRateExchangeABI || (defaultFixedRateExchangeABI.abi as AbiItem[])
this.oceanAddress = oceanAddress

View File

@ -96,6 +96,11 @@ export class Config {
* @type {any}
*/
public metadataContractABI?: AbiItem | AbiItem[]
/**
* block number of the deployment
* @type {number}
*/
public startBlock?: number
/**
* Log level.
* @type {boolean | LogLevel}

View File

@ -59,7 +59,8 @@ export class Ocean extends Instantiable {
instanceConfig.config.poolFactoryABI,
instanceConfig.config.poolABI,
instanceConfig.config.poolFactoryAddress,
instanceConfig.config.oceanTokenAddress
instanceConfig.config.oceanTokenAddress,
instanceConfig.config.startBlock
)
instance.fixedRateExchange = new OceanFixedRateExchange(
instanceConfig.config.web3Provider,
@ -67,7 +68,8 @@ export class Ocean extends Instantiable {
instanceConfig.config.fixedRateExchangeAddress,
instanceConfig.config.fixedRateExchangeAddressABI,
instanceConfig.config.oceanTokenAddress,
instance.datatokens
instance.datatokens,
instanceConfig.config.startBlock
)
instance.OnChainMetadataCache = new OnChainMetadataCache(
instanceConfig.config.web3Provider,

View File

@ -27,7 +27,8 @@ const configs: ConfigHelperConfig[] = [
factoryAddress: '0x1234',
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
metadataContractAddress: null,
startBlock: 0
},
{
// barge
@ -40,7 +41,8 @@ const configs: ConfigHelperConfig[] = [
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
metadataContractAddress: null,
startBlock: 0
},
{
networkId: 4,
@ -52,7 +54,8 @@ const configs: ConfigHelperConfig[] = [
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
metadataContractAddress: null,
startBlock: 7294090
},
{
networkId: 1,
@ -64,7 +67,8 @@ const configs: ConfigHelperConfig[] = [
factoryAddress: null,
poolFactoryAddress: null,
fixedRateExchangeAddress: null,
metadataContractAddress: null
metadataContractAddress: null,
startBlock: 11105522
}
]

View File

@ -109,7 +109,8 @@ describe('Balancer flow', () => {
OceanPoolFactory.abi as AbiItem[],
OceanSPool.abi as AbiItem[],
OceanPoolFactoryAddress,
oceanTokenAddress
oceanTokenAddress,
0
)
assert(Pool !== null)
})