mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Merge pull request #406 from oceanprotocol/feature/gas_optimizations
gas optimisations
This commit is contained in:
commit
9b4bff4233
@ -5,7 +5,7 @@ import jsonFactoryABI from '@oceanprotocol/contracts/artifacts/BFactory.json'
|
|||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
|
|
||||||
export class PoolFactory {
|
export class PoolFactory {
|
||||||
public GASLIMIT_DEFAULT = 5000000
|
public GASLIMIT_DEFAULT = 8000000
|
||||||
public web3: Web3 = null
|
public web3: Web3 = null
|
||||||
public factoryABI: AbiItem | AbiItem[]
|
public factoryABI: AbiItem | AbiItem[]
|
||||||
public factoryAddress: string
|
public factoryAddress: string
|
||||||
|
@ -102,8 +102,7 @@ export class DataTokens {
|
|||||||
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1
|
||||||
gasPrice: '3000000000'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let tokenAddress = null
|
let tokenAddress = null
|
||||||
@ -167,8 +166,7 @@ export class DataTokens {
|
|||||||
.mint(destAddress, this.web3.utils.toWei(amount))
|
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1
|
||||||
gasPrice: '3000000000'
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
@ -365,6 +363,18 @@ export class DataTokens {
|
|||||||
})
|
})
|
||||||
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
|
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
|
||||||
try {
|
try {
|
||||||
|
const estGas = await datatoken.methods
|
||||||
|
.startOrder(
|
||||||
|
consumer,
|
||||||
|
this.web3.utils.toWei(amount),
|
||||||
|
String(serviceId),
|
||||||
|
mpFeeAddress
|
||||||
|
)
|
||||||
|
.estimateGas(function (err, estGas) {
|
||||||
|
if (err) console.error(`ERROR: Datatokens : ${err}`)
|
||||||
|
return estGas
|
||||||
|
})
|
||||||
|
|
||||||
const trxReceipt = await datatoken.methods
|
const trxReceipt = await datatoken.methods
|
||||||
.startOrder(
|
.startOrder(
|
||||||
consumer,
|
consumer,
|
||||||
@ -372,7 +382,7 @@ export class DataTokens {
|
|||||||
String(serviceId),
|
String(serviceId),
|
||||||
mpFeeAddress
|
mpFeeAddress
|
||||||
)
|
)
|
||||||
.send({ from: address, gas: 600000 })
|
.send({ from: address, gas: estGas + 1 })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
|
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
|
||||||
|
@ -29,7 +29,7 @@ export enum FixedRateCreateProgressStep {
|
|||||||
ApprovingDatatoken
|
ApprovingDatatoken
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_GAS_LIMIT = 300000
|
const DEFAULT_GAS_LIMIT = 1000000
|
||||||
|
|
||||||
export class OceanFixedRateExchange {
|
export class OceanFixedRateExchange {
|
||||||
/** Ocean related functions */
|
/** Ocean related functions */
|
||||||
|
@ -8,7 +8,7 @@ import { didZeroX, Logger } from '../utils'
|
|||||||
// Using limited, compress-only version
|
// Using limited, compress-only version
|
||||||
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
||||||
import { LZMA } from 'lzma/src/lzma-c'
|
import { LZMA } from 'lzma/src/lzma-c'
|
||||||
|
const DEFAULT_GAS_LIMIT = 1000000
|
||||||
/**
|
/**
|
||||||
* Provides an interface with Metadata Cache.
|
* Provides an interface with Metadata Cache.
|
||||||
* Metadata Cache provides an off-chain database store for metadata about data assets.
|
* Metadata Cache provides an off-chain database store for metadata about data assets.
|
||||||
@ -105,17 +105,24 @@ export class OnChainMetadataCache {
|
|||||||
this.logger.error('ERROR: Missing DDOContract')
|
this.logger.error('ERROR: Missing DDOContract')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
let estGas
|
||||||
try {
|
try {
|
||||||
/* const estGas = await this.DDOContract.methods
|
estGas = await this.DDOContract.methods
|
||||||
.create(didZeroX(did), flags, data)
|
.create(didZeroX(did), flags, data)
|
||||||
.estimateGas(function (err, estGas) {
|
.estimateGas(function (err, estGas) {
|
||||||
if (err) console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
if (err) {
|
||||||
|
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
||||||
|
return DEFAULT_GAS_LIMIT
|
||||||
|
}
|
||||||
return estGas
|
return estGas
|
||||||
})
|
})
|
||||||
*/
|
} catch (e) {
|
||||||
|
estGas = DEFAULT_GAS_LIMIT
|
||||||
|
}
|
||||||
|
try {
|
||||||
const trxReceipt = await this.DDOContract.methods
|
const trxReceipt = await this.DDOContract.methods
|
||||||
.create(didZeroX(did), flags, data)
|
.create(didZeroX(did), flags, data)
|
||||||
.send({ from: consumerAccount })
|
.send({ from: consumerAccount, gas: estGas + 1 })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
||||||
@ -141,10 +148,24 @@ export class OnChainMetadataCache {
|
|||||||
this.logger.error('ERROR: Missing DDOContract')
|
this.logger.error('ERROR: Missing DDOContract')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
let estGas
|
||||||
|
try {
|
||||||
|
estGas = await this.DDOContract.methods
|
||||||
|
.update(didZeroX(did), flags, data)
|
||||||
|
.estimateGas(function (err, estGas) {
|
||||||
|
if (err) {
|
||||||
|
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
||||||
|
return DEFAULT_GAS_LIMIT
|
||||||
|
}
|
||||||
|
return estGas
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
estGas = DEFAULT_GAS_LIMIT
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.DDOContract.methods
|
const trxReceipt = await this.DDOContract.methods
|
||||||
.update(didZeroX(did), flags, data)
|
.update(didZeroX(did), flags, data)
|
||||||
.send({ from: consumerAccount })
|
.send({ from: consumerAccount, gas: estGas + 1 })
|
||||||
return trxReceipt
|
return trxReceipt
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user