Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcos20 committed Oct 29, 2020
1 parent 9900bb4 commit 694cde2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 45 deletions.
18 changes: 9 additions & 9 deletions src/balancer/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/datatokens/Datatokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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(
Expand Down
39 changes: 9 additions & 30 deletions src/metadatacache/OnChainMetaDataCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
} catch (e) {
estGas = DEFAULT_GAS_LIMIT
}
try {
const trxReceipt = await this.DDOContract.methods
.create(didZeroX(did), flags, data)
.send({ from: consumerAccount, gas: estGas + 1 })
return trxReceipt
.estimateGas((err, estGas) => (err ? gasLimitDefault : estGas))
} catch (e) {
this.logger.error(`ERROR: Failed to publish raw DDO : ${e.message}`)
return null
estGas = gasLimitDefault
}
*/
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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 694cde2

Please sign in to comment.