From 694cde2a1359aacb03f9a09dd70a5b6770b2a031 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 29 Oct 2020 04:01:19 -0700 Subject: [PATCH] more fixes --- src/balancer/Pool.ts | 18 +++++------ src/datatokens/Datatokens.ts | 12 +++---- src/metadatacache/OnChainMetaDataCache.ts | 39 ++++++----------------- 3 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/balancer/Pool.ts b/src/balancer/Pool.ts index 28ab0f6d..f19c8242 100644 --- a/src/balancer/Pool.ts +++ b/src/balancer/Pool.ts @@ -85,7 +85,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -158,7 +158,7 @@ export class Pool extends PoolFactory { .approve(spender, amount) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { @@ -549,7 +549,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -608,7 +608,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -663,7 +663,7 @@ export class Pool extends PoolFactory { .joinPool(this.web3.utils.toWei(poolAmountOut), weiMaxAmountsIn) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -710,7 +710,7 @@ export class Pool extends PoolFactory { .exitPool(this.web3.utils.toWei(poolAmountIn), weiMinAmountsOut) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -753,7 +753,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -805,7 +805,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods @@ -856,7 +856,7 @@ export class Pool extends PoolFactory { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } try { result = await pool.methods diff --git a/src/datatokens/Datatokens.ts b/src/datatokens/Datatokens.ts index 92b8cc7c..4311aded 100644 --- a/src/datatokens/Datatokens.ts +++ b/src/datatokens/Datatokens.ts @@ -99,7 +99,7 @@ export class DataTokens { .createToken(metadataCacheUri, name, symbol, this.web3.utils.toWei(cap)) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } // Invoke createToken function of the contract @@ -144,7 +144,7 @@ export class DataTokens { .approve(spender, this.web3.utils.toWei(amount)) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } const trxReceipt = await datatoken.methods .approve(spender, this.web3.utils.toWei(amount)) @@ -181,7 +181,7 @@ export class DataTokens { .mint(destAddress, this.web3.utils.toWei(amount)) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } const trxReceipt = await datatoken.methods .mint(destAddress, this.web3.utils.toWei(amount)) @@ -253,7 +253,7 @@ export class DataTokens { .transfer(toAddress, amount) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } const trxReceipt = await datatoken.methods.transfer(toAddress, amount).send({ from: address, @@ -287,7 +287,7 @@ export class DataTokens { .transferFrom(fromAddress, address, this.web3.utils.toWei(amount)) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } const trxReceipt = await datatoken.methods .transferFrom(fromAddress, address, this.web3.utils.toWei(amount)) @@ -421,7 +421,7 @@ export class DataTokens { ) .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = this.GASLIMIT_DEFAULT + estGas = gasLimitDefault } const trxReceipt = await datatoken.methods .startOrder( diff --git a/src/metadatacache/OnChainMetaDataCache.ts b/src/metadatacache/OnChainMetaDataCache.ts index 581c761d..adbe5844 100644 --- a/src/metadatacache/OnChainMetaDataCache.ts +++ b/src/metadatacache/OnChainMetaDataCache.ts @@ -8,12 +8,13 @@ import { didZeroX, Logger, getFairGasPrice } 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. */ export class OnChainMetadataCache { + public GASLIMIT_DEFAULT = 1000000 public DDOContractAddress: string public DDOContractABI: AbiItem | AbiItem[] public web3: Web3 @@ -105,38 +106,21 @@ export class OnChainMetadataCache { this.logger.error('ERROR: Missing DDOContract') return null } + const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas - /* try { estGas = await this.DDOContract.methods .create(didZeroX(did), flags, data) - .estimateGas(function (err, estGas) { - if (err) { - // console.error('ERROR: OnChainMetadataCacheEstimateGas: ' + err) - return DEFAULT_GAS_LIMIT - } - return estGas - }) + .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = DEFAULT_GAS_LIMIT + estGas = gasLimitDefault } - - try { - const trxReceipt = await this.DDOContract.methods - .create(didZeroX(did), flags, data) - .send({ from: consumerAccount, gas: estGas + 1 }) - return trxReceipt - } catch (e) { - this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`) - return null - } - */ try { const trxReceipt = await this.DDOContract.methods .create(didZeroX(did), flags, data) .send({ from: consumerAccount, - gas: DEFAULT_GAS_LIMIT, + gas: estGas + 1, gasPrice: await getFairGasPrice(this.web3) }) return trxReceipt @@ -164,19 +148,14 @@ export class OnChainMetadataCache { this.logger.error('ERROR: Missing DDOContract') return null } + const gasLimitDefault = this.GASLIMIT_DEFAULT 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 - }) + .estimateGas((err, estGas) => (err ? gasLimitDefault : estGas)) } catch (e) { - estGas = DEFAULT_GAS_LIMIT + estGas = gasLimitDefault } try { const trxReceipt = await this.DDOContract.methods