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

optimizations

This commit is contained in:
alexcos20 2020-09-30 03:41:56 -07:00
parent a1916b0e04
commit ca5d2c2a54
2 changed files with 17 additions and 20 deletions

View File

@ -427,10 +427,7 @@ export class OceanPool extends Pool {
* Get all actions from a pool (join,exit,swap) * Get all actions from a pool (join,exit,swap)
* @param {String} poolAddress Pool address * @param {String} poolAddress Pool address
* @param {String} account * @param {String} account
* @param {Boolean} swaps Include swaps * @return {PoolTransaction[]}
* @param {Boolean} joins Include joins
* @param {Boolean} exits Include exits
* @return {PoolLogs}
*/ */
public async getPoolLogs( public async getPoolLogs(
poolAddress: string, poolAddress: string,
@ -478,7 +475,7 @@ export class OceanPool extends Pool {
/** /**
* Get all logs on all pools for a specific address * Get all logs on all pools for a specific address
* @param {String} account * @param {String} account
* @return {PoolLogs} * @return {PoolTransaction[]}
*/ */
public async getAllPoolLogs(account: string): Promise<PoolTransaction[]> { public async getAllPoolLogs(account: string): Promise<PoolTransaction[]> {
const results: PoolTransaction[] = [] const results: PoolTransaction[] = []

View File

@ -5,7 +5,7 @@ import { Contract, EventData } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types' import { AbiItem } from 'web3-utils/types'
import Web3 from 'web3' import Web3 from 'web3'
export interface FixedPricedExchange { export interface FixedPriceExchange {
exchangeID?: string exchangeID?: string
exchangeOwner: string exchangeOwner: string
dataToken: string dataToken: string
@ -15,7 +15,7 @@ export interface FixedPricedExchange {
supply: string supply: string
} }
export interface FixedPricedSwap { export interface FixedPriceSwap {
exchangeID: string exchangeID: string
caller: string caller: string
baseTokenAmount: string baseTokenAmount: string
@ -298,8 +298,8 @@ export class OceanFixedRateExchange {
* @param {String} exchangeId ExchangeId * @param {String} exchangeId ExchangeId
* @return {Promise<FixedPricedExchange>} Exchange details * @return {Promise<FixedPricedExchange>} Exchange details
*/ */
public async getExchange(exchangeId: string): Promise<FixedPricedExchange> { public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
const result: FixedPricedExchange = await this.contract.methods const result: FixedPriceExchange = await this.contract.methods
.getExchange(exchangeId) .getExchange(exchangeId)
.call() .call()
return result return result
@ -343,8 +343,8 @@ export class OceanFixedRateExchange {
public async searchforDT( public async searchforDT(
dataTokenAddress: string, dataTokenAddress: string,
minSupply: string minSupply: string
): Promise<FixedPricedExchange[]> { ): Promise<FixedPriceExchange[]> {
const result: FixedPricedExchange[] = [] const result: FixedPriceExchange[] = []
const events = await this.contract.getPastEvents('ExchangeCreated', { const events = await this.contract.getPastEvents('ExchangeCreated', {
filter: { datatoken: dataTokenAddress }, filter: { datatoken: dataTokenAddress },
fromBlock: 0, fromBlock: 0,
@ -369,8 +369,8 @@ export class OceanFixedRateExchange {
* @param {String} account * @param {String} account
* @return {Promise<FixedPricedExchange[]>} * @return {Promise<FixedPricedExchange[]>}
*/ */
public async getExchangesbyCreator(account?: string): Promise<FixedPricedExchange[]> { public async getExchangesbyCreator(account?: string): Promise<FixedPriceExchange[]> {
const result: FixedPricedExchange[] = [] const result: FixedPriceExchange[] = []
const events = await this.contract.getPastEvents('ExchangeCreated', { const events = await this.contract.getPastEvents('ExchangeCreated', {
filter: {}, filter: {},
fromBlock: 0, fromBlock: 0,
@ -394,8 +394,8 @@ export class OceanFixedRateExchange {
public async getExchangeSwaps( public async getExchangeSwaps(
exchangeId: string, exchangeId: string,
account?: string account?: string
): Promise<FixedPricedSwap[]> { ): Promise<FixedPriceSwap[]> {
const result: FixedPricedSwap[] = [] const result: FixedPriceSwap[] = []
const events = await this.contract.getPastEvents('Swapped', { const events = await this.contract.getPastEvents('Swapped', {
filter: { exchangeId: exchangeId }, filter: { exchangeId: exchangeId },
fromBlock: 0, fromBlock: 0,
@ -415,15 +415,15 @@ export class OceanFixedRateExchange {
* @param {String} account * @param {String} account
* @return {Promise<FixedPricedSwap[]>} * @return {Promise<FixedPricedSwap[]>}
*/ */
public async getAllExchangesSwaps(account: string): Promise<FixedPricedSwap[]> { public async getAllExchangesSwaps(account: string): Promise<FixedPriceSwap[]> {
const result: FixedPricedSwap[] = [] const result: FixedPriceSwap[] = []
const events = await this.contract.getPastEvents('ExchangeCreated', { const events = await this.contract.getPastEvents('ExchangeCreated', {
filter: {}, filter: {},
fromBlock: 0, fromBlock: 0,
toBlock: 'latest' toBlock: 'latest'
}) })
for (let i = 0; i < events.length; i++) { for (let i = 0; i < events.length; i++) {
const swaps: FixedPricedSwap[] = await this.getExchangeSwaps( const swaps: FixedPriceSwap[] = await this.getExchangeSwaps(
events[i].returnValues[0], events[i].returnValues[0],
account account
) )
@ -434,8 +434,8 @@ export class OceanFixedRateExchange {
return result return result
} }
private getEventData(data: EventData): FixedPricedSwap { private getEventData(data: EventData): FixedPriceSwap {
const result: FixedPricedSwap = { const result: FixedPriceSwap = {
exchangeID: data.returnValues[0], exchangeID: data.returnValues[0],
caller: data.returnValues[1], caller: data.returnValues[1],
baseTokenAmount: data.returnValues[2], baseTokenAmount: data.returnValues[2],