mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Remove try...catch from Datatoken
This commit is contained in:
parent
59eb56b9ee
commit
792387cc6c
@ -491,26 +491,22 @@ export class Datatoken extends SmartContract {
|
|||||||
estimateGas?: G
|
estimateGas?: G
|
||||||
): Promise<G extends false ? TransactionReceipt : number> {
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
try {
|
|
||||||
const estGas = await calculateEstimatedGas(
|
|
||||||
address,
|
|
||||||
dtContract.methods.transfer,
|
|
||||||
toAddress,
|
|
||||||
amount
|
|
||||||
)
|
|
||||||
if (estimateGas) return estGas
|
|
||||||
|
|
||||||
// Call transfer function of the contract
|
const estGas = await calculateEstimatedGas(
|
||||||
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
address,
|
||||||
from: address,
|
dtContract.methods.transfer,
|
||||||
gas: estGas + 1,
|
toAddress,
|
||||||
gasPrice: await this.getFairGasPrice()
|
amount
|
||||||
})
|
)
|
||||||
return trxReceipt
|
if (estimateGas) return estGas
|
||||||
} catch (e) {
|
|
||||||
LoggerInstance.error(`ERROR: Failed to transfer tokens: ${e.message}`)
|
// Call transfer function of the contract
|
||||||
throw new Error(`Failed Failed to transfer tokens: ${e.message}`)
|
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
||||||
}
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await this.getFairGasPrice()
|
||||||
|
})
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Start Order: called by payer or consumer prior ordering a service consume on a marketplace.
|
/** Start Order: called by payer or consumer prior ordering a service consume on a marketplace.
|
||||||
@ -539,29 +535,25 @@ export class Datatoken extends SmartContract {
|
|||||||
consumeMarketFeeAmount: '0'
|
consumeMarketFeeAmount: '0'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
const estGas = await calculateEstimatedGas(
|
|
||||||
address,
|
|
||||||
dtContract.methods.startOrder,
|
|
||||||
consumer,
|
|
||||||
serviceIndex,
|
|
||||||
providerFees,
|
|
||||||
consumeMarketFee
|
|
||||||
)
|
|
||||||
if (estimateGas) return estGas
|
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const estGas = await calculateEstimatedGas(
|
||||||
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
address,
|
||||||
.send({
|
dtContract.methods.startOrder,
|
||||||
from: address,
|
consumer,
|
||||||
gas: estGas + 1,
|
serviceIndex,
|
||||||
gasPrice: await this.getFairGasPrice()
|
providerFees,
|
||||||
})
|
consumeMarketFee
|
||||||
return trxReceipt
|
)
|
||||||
} catch (e) {
|
if (estimateGas) return estGas
|
||||||
LoggerInstance.error(`ERROR: Failed to start order : ${e.message}`)
|
|
||||||
throw new Error(`Failed to start order: ${e.message}`)
|
const trxReceipt = await dtContract.methods
|
||||||
}
|
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
||||||
|
.send({
|
||||||
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await this.getFairGasPrice()
|
||||||
|
})
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reuse Order: called by payer or consumer having a valid order, but with expired provider access.
|
/** Reuse Order: called by payer or consumer having a valid order, but with expired provider access.
|
||||||
@ -581,27 +573,21 @@ export class Datatoken extends SmartContract {
|
|||||||
estimateGas?: G
|
estimateGas?: G
|
||||||
): Promise<G extends false ? TransactionReceipt : number> {
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
try {
|
|
||||||
const estGas = await calculateEstimatedGas(
|
|
||||||
address,
|
|
||||||
dtContract.methods.reuseOrder,
|
|
||||||
orderTxId,
|
|
||||||
providerFees
|
|
||||||
)
|
|
||||||
if (estimateGas) return estGas
|
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const estGas = await calculateEstimatedGas(
|
||||||
.reuseOrder(orderTxId, providerFees)
|
address,
|
||||||
.send({
|
dtContract.methods.reuseOrder,
|
||||||
from: address,
|
orderTxId,
|
||||||
gas: estGas + 1,
|
providerFees
|
||||||
gasPrice: await this.getFairGasPrice()
|
)
|
||||||
})
|
if (estimateGas) return estGas
|
||||||
return trxReceipt
|
|
||||||
} catch (e) {
|
const trxReceipt = await dtContract.methods.reuseOrder(orderTxId, providerFees).send({
|
||||||
LoggerInstance.error(`ERROR: Failed to call reuse order order : ${e.message}`)
|
from: address,
|
||||||
throw new Error(`Failed to start order: ${e.message}`)
|
gas: estGas + 1,
|
||||||
}
|
gasPrice: await this.getFairGasPrice()
|
||||||
|
})
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Buys 1 DT from the FRE and then startsOrder, while burning that DT
|
/** Buys 1 DT from the FRE and then startsOrder, while burning that DT
|
||||||
@ -619,29 +605,25 @@ export class Datatoken extends SmartContract {
|
|||||||
estimateGas?: G
|
estimateGas?: G
|
||||||
): Promise<G extends false ? TransactionReceipt : number> {
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
||||||
try {
|
|
||||||
const freContractParams = this.getFreOrderParams(freParams)
|
|
||||||
|
|
||||||
const estGas = await calculateEstimatedGas(
|
const freContractParams = this.getFreOrderParams(freParams)
|
||||||
address,
|
|
||||||
dtContract.methods.buyFromFreAndOrder,
|
|
||||||
orderParams,
|
|
||||||
freContractParams
|
|
||||||
)
|
|
||||||
if (estimateGas) return estGas
|
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const estGas = await calculateEstimatedGas(
|
||||||
.buyFromFreAndOrder(orderParams, freContractParams)
|
address,
|
||||||
.send({
|
dtContract.methods.buyFromFreAndOrder,
|
||||||
from: address,
|
orderParams,
|
||||||
gas: estGas + 1,
|
freContractParams
|
||||||
gasPrice: await this.getFairGasPrice()
|
)
|
||||||
})
|
if (estimateGas) return estGas
|
||||||
return trxReceipt
|
|
||||||
} catch (e) {
|
const trxReceipt = await dtContract.methods
|
||||||
LoggerInstance.error(`ERROR: Failed to buy DT From Fre And Order : ${e.message}`)
|
.buyFromFreAndOrder(orderParams, freContractParams)
|
||||||
throw new Error(`Failed to buy DT From Fre And Order: ${e.message}`)
|
.send({
|
||||||
}
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await this.getFairGasPrice()
|
||||||
|
})
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets DT from dispenser and then startsOrder, while burning that DT
|
/** Gets DT from dispenser and then startsOrder, while burning that DT
|
||||||
@ -659,27 +641,23 @@ export class Datatoken extends SmartContract {
|
|||||||
estimateGas?: G
|
estimateGas?: G
|
||||||
): Promise<G extends false ? TransactionReceipt : number> {
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
||||||
try {
|
|
||||||
const estGas = await calculateEstimatedGas(
|
|
||||||
address,
|
|
||||||
dtContract.methods.buyFromDispenserAndOrder,
|
|
||||||
orderParams,
|
|
||||||
dispenserContract
|
|
||||||
)
|
|
||||||
if (estimateGas) return estGas
|
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const estGas = await calculateEstimatedGas(
|
||||||
.buyFromDispenserAndOrder(orderParams, dispenserContract)
|
address,
|
||||||
.send({
|
dtContract.methods.buyFromDispenserAndOrder,
|
||||||
from: address,
|
orderParams,
|
||||||
gas: estGas + 1,
|
dispenserContract
|
||||||
gasPrice: await this.getFairGasPrice()
|
)
|
||||||
})
|
if (estimateGas) return estGas
|
||||||
return trxReceipt
|
|
||||||
} catch (e) {
|
const trxReceipt = await dtContract.methods
|
||||||
LoggerInstance.error(`ERROR: Failed to buy DT From Fre And Order : ${e.message}`)
|
.buyFromDispenserAndOrder(orderParams, dispenserContract)
|
||||||
throw new Error(`Failed to buy DT From Fre And Order: ${e.message}`)
|
.send({
|
||||||
}
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await this.getFairGasPrice()
|
||||||
|
})
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/** setData
|
/** setData
|
||||||
|
Loading…
x
Reference in New Issue
Block a user