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'
|
||||
|
||||
export class PoolFactory {
|
||||
public GASLIMIT_DEFAULT = 5000000
|
||||
public GASLIMIT_DEFAULT = 8000000
|
||||
public web3: Web3 = null
|
||||
public factoryABI: AbiItem | AbiItem[]
|
||||
public factoryAddress: string
|
||||
|
@ -102,8 +102,7 @@ export class DataTokens {
|
||||
.createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap))
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
gas: estGas + 1
|
||||
})
|
||||
|
||||
let tokenAddress = null
|
||||
@ -167,8 +166,7 @@ export class DataTokens {
|
||||
.mint(destAddress, this.web3.utils.toWei(amount))
|
||||
.send({
|
||||
from: address,
|
||||
gas: estGas + 1,
|
||||
gasPrice: '3000000000'
|
||||
gas: estGas + 1
|
||||
})
|
||||
|
||||
return trxReceipt
|
||||
@ -365,6 +363,18 @@ export class DataTokens {
|
||||
})
|
||||
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
|
||||
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
|
||||
.startOrder(
|
||||
consumer,
|
||||
@ -372,7 +382,7 @@ export class DataTokens {
|
||||
String(serviceId),
|
||||
mpFeeAddress
|
||||
)
|
||||
.send({ from: address, gas: 600000 })
|
||||
.send({ from: address, gas: estGas + 1 })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
this.logger.error(`ERROR: Failed to start order : ${e.message}`)
|
||||
|
@ -29,7 +29,7 @@ export enum FixedRateCreateProgressStep {
|
||||
ApprovingDatatoken
|
||||
}
|
||||
|
||||
const DEFAULT_GAS_LIMIT = 300000
|
||||
const DEFAULT_GAS_LIMIT = 1000000
|
||||
|
||||
export class OceanFixedRateExchange {
|
||||
/** Ocean related functions */
|
||||
|
@ -8,7 +8,7 @@ import { didZeroX, Logger } from '../utils'
|
||||
// Using limited, compress-only version
|
||||
// See https://github.com/LZMA-JS/LZMA-JS#but-i-dont-want-to-use-web-workers
|
||||
import { LZMA } from 'lzma/src/lzma-c'
|
||||
|
||||
const DEFAULT_GAS_LIMIT = 1000000
|
||||
/**
|
||||
* Provides an interface with Metadata Cache.
|
||||
* 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')
|
||||
return null
|
||||
}
|
||||
let estGas
|
||||
try {
|
||||
/* const estGas = await this.DDOContract.methods
|
||||
estGas = await this.DDOContract.methods
|
||||
.create(didZeroX(did), flags, data)
|
||||
.estimateGas(function (err, estGas) {
|
||||
if (err) console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
||||
if (err) {
|
||||
// console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err)
|
||||
return DEFAULT_GAS_LIMIT
|
||||
}
|
||||
return estGas
|
||||
})
|
||||
*/
|
||||
} catch (e) {
|
||||
estGas = DEFAULT_GAS_LIMIT
|
||||
}
|
||||
try {
|
||||
const trxReceipt = await this.DDOContract.methods
|
||||
.create(didZeroX(did), flags, data)
|
||||
.send({ from: consumerAccount })
|
||||
.send({ from: consumerAccount, gas: estGas + 1 })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
|
||||
@ -141,10 +148,24 @@ export class OnChainMetadataCache {
|
||||
this.logger.error('ERROR: Missing DDOContract')
|
||||
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 {
|
||||
const trxReceipt = await this.DDOContract.methods
|
||||
.update(didZeroX(did), flags, data)
|
||||
.send({ from: consumerAccount })
|
||||
.send({ from: consumerAccount, gas: estGas + 1 })
|
||||
return trxReceipt
|
||||
} catch (e) {
|
||||
this.logger.error(`ERROR: Failed to update raw DDO : ${e.message}`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user