1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
This commit is contained in:
Matthias Kretschmann 2020-09-29 17:40:50 +02:00
parent 8bd80d96b1
commit 122fc40f63
Signed by: m
GPG Key ID: 606EEEF3C479A91F

View File

@ -2,6 +2,7 @@ import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types' import { AbiItem } from 'web3-utils/types'
import { TransactionReceipt } from 'web3-core' import { TransactionReceipt } from 'web3-core'
import { Pool } from './Pool' import { Pool } from './Pool'
import { EventData } from 'web3-eth-contract'
export interface PoolDetails { export interface PoolDetails {
poolAddress: string poolAddress: string
@ -21,7 +22,7 @@ export interface PoolAction {
export interface PoolLogs { export interface PoolLogs {
joins?: PoolAction[] joins?: PoolAction[]
exists?: PoolAction[] exits?: PoolAction[]
swaps?: PoolAction[] swaps?: PoolAction[]
} }
/** /**
@ -438,7 +439,7 @@ export class OceanPool extends Pool {
* @param {String} account * @param {String} account
* @param {Boolean} swaps Include swaps * @param {Boolean} swaps Include swaps
* @param {Boolean} joins Include joins * @param {Boolean} joins Include joins
* @param {Boolean} exists Include exits * @param {Boolean} exits Include exits
* @return {PoolLogs[]} * @return {PoolLogs[]}
*/ */
public async getPoolLogs( public async getPoolLogs(
@ -448,14 +449,17 @@ export class OceanPool extends Pool {
joins?: boolean, joins?: boolean,
exits?: boolean exits?: boolean
): Promise<PoolLogs> { ): Promise<PoolLogs> {
const results: PoolLogs = { joins: [], exists: [], swaps: [] } const results: PoolLogs = { joins: [], exits: [], swaps: [] }
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account from: account
}) })
let events
let events: EventData[]
let myFilter let myFilter
if (account) myFilter = { caller: account } if (account) myFilter = { caller: account }
else myFilter = {} else myFilter = {}
if (swaps) { if (swaps) {
events = await pool.getPastEvents('LOG_SWAP', { events = await pool.getPastEvents('LOG_SWAP', {
filter: myFilter, filter: myFilter,
@ -497,10 +501,10 @@ export class OceanPool extends Pool {
for (let i = 0; i < events.length; i++) { for (let i = 0; i < events.length; i++) {
if (account) { if (account) {
if (events[i].returnValues[0] === account) { if (events[i].returnValues[0] === account) {
results.exists.push(this.getEventData('exit', poolAddress, events[i])) results.exits.push(this.getEventData('exit', poolAddress, events[i]))
} }
} else { } else {
results.exists.push(this.getEventData('exit', poolAddress, events[i])) results.exits.push(this.getEventData('exit', poolAddress, events[i]))
} }
} }
} }
@ -512,7 +516,7 @@ export class OceanPool extends Pool {
* @param {String} account * @param {String} account
* @param {Boolean} swaps Include swaps * @param {Boolean} swaps Include swaps
* @param {Boolean} joins Include joins * @param {Boolean} joins Include joins
* @param {Boolean} exists Include exits * @param {Boolean} exits Include exits
* @return {PoolLogs} * @return {PoolLogs}
*/ */
public async getAllPoolLogs( public async getAllPoolLogs(
@ -521,7 +525,7 @@ export class OceanPool extends Pool {
joins?: boolean, joins?: boolean,
exits?: boolean exits?: boolean
): Promise<PoolLogs> { ): Promise<PoolLogs> {
const results: PoolLogs = { joins: [], exists: [], swaps: [] } const results: PoolLogs = { joins: [], exits: [], swaps: [] }
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, { const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
from: account from: account
}) })
@ -541,8 +545,8 @@ export class OceanPool extends Pool {
logs.joins.forEach((log) => { logs.joins.forEach((log) => {
results.joins.push(log) results.joins.push(log)
}) })
logs.exists.forEach((log) => { logs.exits.forEach((log) => {
results.exists.push(log) results.exits.push(log)
}) })
logs.swaps.forEach((log) => { logs.swaps.forEach((log) => {
results.swaps.push(log) results.swaps.push(log)