mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
typing updates, small refactor
This commit is contained in:
parent
63e01ee858
commit
54cb529ff3
@ -2,7 +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'
|
import { EventData, Filter } from 'web3-eth-contract'
|
||||||
|
|
||||||
export interface PoolDetails {
|
export interface PoolDetails {
|
||||||
poolAddress: string
|
poolAddress: string
|
||||||
@ -395,22 +395,18 @@ export class OceanPool extends Pool {
|
|||||||
/**
|
/**
|
||||||
* Search all pools created by an address
|
* Search all pools created by an address
|
||||||
* @param {String} account If empty, will return all pools ever created by anybody
|
* @param {String} account If empty, will return all pools ever created by anybody
|
||||||
* @return {String[]}
|
* @return {PoolDetails[]}
|
||||||
*/
|
*/
|
||||||
public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> {
|
public async getPoolsbyCreator(account?: string): Promise<PoolDetails[]> {
|
||||||
const result: PoolDetails[] = []
|
const result: PoolDetails[] = []
|
||||||
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
|
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress)
|
||||||
let myFilter
|
|
||||||
if (account) {
|
|
||||||
myFilter = { registeredBy: account }
|
|
||||||
} else {
|
|
||||||
myFilter = {}
|
|
||||||
}
|
|
||||||
const events = await factory.getPastEvents('BPoolRegistered', {
|
const events = await factory.getPastEvents('BPoolRegistered', {
|
||||||
filter: myFilter,
|
filter: account ? { registeredBy: account } : {},
|
||||||
fromBlock: 0,
|
fromBlock: 0,
|
||||||
toBlock: 'latest'
|
toBlock: 'latest'
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[1] === account) {
|
if (events[i].returnValues[1] === account) {
|
||||||
@ -420,16 +416,15 @@ export class OceanPool extends Pool {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get pool details
|
* Get pool details
|
||||||
* @param {String} poolAddress Pool address
|
* @param {String} poolAddress Pool address
|
||||||
* @return {PoolDetails[]}
|
* @return {PoolDetails}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async getPoolDetails(poolAddress: string): Promise<PoolDetails> {
|
public async getPoolDetails(poolAddress: string): Promise<PoolDetails> {
|
||||||
const details: PoolDetails = { poolAddress: null, tokens: null }
|
const tokens = await super.getFinalTokens(poolAddress)
|
||||||
details.poolAddress = poolAddress
|
const details: PoolDetails = { poolAddress, tokens }
|
||||||
details.tokens = await super.getFinalTokens(poolAddress)
|
|
||||||
return details
|
return details
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +435,7 @@ export class OceanPool extends Pool {
|
|||||||
* @param {Boolean} swaps Include swaps
|
* @param {Boolean} swaps Include swaps
|
||||||
* @param {Boolean} joins Include joins
|
* @param {Boolean} joins Include joins
|
||||||
* @param {Boolean} exits Include exits
|
* @param {Boolean} exits Include exits
|
||||||
* @return {PoolLogs[]}
|
* @return {PoolLogs}
|
||||||
*/
|
*/
|
||||||
public async getPoolLogs(
|
public async getPoolLogs(
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
@ -450,15 +445,9 @@ export class OceanPool extends Pool {
|
|||||||
exits?: boolean
|
exits?: boolean
|
||||||
): Promise<PoolLogs> {
|
): Promise<PoolLogs> {
|
||||||
const results: PoolLogs = { joins: [], exits: [], 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
|
const myFilter: Filter = account ? { caller: account } : {}
|
||||||
})
|
|
||||||
|
|
||||||
let events: EventData[]
|
let events: EventData[]
|
||||||
let myFilter
|
|
||||||
|
|
||||||
if (account) myFilter = { caller: account }
|
|
||||||
else myFilter = {}
|
|
||||||
|
|
||||||
if (swaps) {
|
if (swaps) {
|
||||||
events = await pool.getPastEvents('LOG_SWAP', {
|
events = await pool.getPastEvents('LOG_SWAP', {
|
||||||
@ -555,7 +544,11 @@ export class OceanPool extends Pool {
|
|||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
private getEventData(action: string, poolAddress: string, data: EventData): PoolAction {
|
private getEventData(
|
||||||
|
action: 'swap' | 'join' | 'exit',
|
||||||
|
poolAddress: string,
|
||||||
|
data: EventData
|
||||||
|
): PoolAction {
|
||||||
let result: PoolAction = {
|
let result: PoolAction = {
|
||||||
poolAddress,
|
poolAddress,
|
||||||
caller: data.returnValues[0],
|
caller: data.returnValues[0],
|
||||||
|
@ -404,8 +404,8 @@ export class OceanFixedRateExchange {
|
|||||||
for (let i = 0; i < events.length; i++) {
|
for (let i = 0; i < events.length; i++) {
|
||||||
if (account) {
|
if (account) {
|
||||||
if (events[i].returnValues[1] === account)
|
if (events[i].returnValues[1] === account)
|
||||||
result.push(await this.getEventData(events[i]))
|
result.push(this.getEventData(events[i]))
|
||||||
} else result.push(await this.getEventData(events[i]))
|
} else result.push(this.getEventData(events[i]))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user