mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
add estimateGas parameter to Datatoken
This commit is contained in:
parent
88b382a0a9
commit
863ba49154
@ -52,12 +52,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} address User adress
|
* @param {String} address User adress
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async approve(
|
public async approve<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
spender: string,
|
spender: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
@ -66,6 +67,7 @@ export class Datatoken extends SmartContract {
|
|||||||
spender,
|
spender,
|
||||||
this.web3.utils.toWei(amount)
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call mint contract method
|
// Call mint contract method
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -86,11 +88,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {FixedRateParams} fixedRateParams
|
* @param {FixedRateParams} fixedRateParams
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async createFixedRate(
|
public async createFixedRate<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
fixedRateParams: FreCreationParams
|
fixedRateParams: FreCreationParams,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||||
throw new Error(`User is not Datatoken Deployer`)
|
throw new Error(`User is not Datatoken Deployer`)
|
||||||
@ -119,6 +122,7 @@ export class Datatoken extends SmartContract {
|
|||||||
withMint
|
withMint
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -154,12 +158,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} dispenserParams
|
* @param {String} dispenserParams
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async createDispenser(
|
public async createDispenser<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
dispenserAddress: string,
|
dispenserAddress: string,
|
||||||
dispenserParams: DispenserParams
|
dispenserParams: DispenserParams,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||||
throw new Error(`User is not Datatoken Deployer`)
|
throw new Error(`User is not Datatoken Deployer`)
|
||||||
}
|
}
|
||||||
@ -181,6 +186,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dispenserParams.withMint,
|
dispenserParams.withMint,
|
||||||
dispenserParams.allowedSwapper
|
dispenserParams.allowedSwapper
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call createFixedRate contract method
|
// Call createFixedRate contract method
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -207,12 +213,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} toAddress only if toAddress is different from the minter
|
* @param {String} toAddress only if toAddress is different from the minter
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async mint(
|
public async mint<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
toAddress?: string
|
toAddress?: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
if ((await this.getDTPermissions(dtAddress, address)).minter !== true) {
|
if ((await this.getDTPermissions(dtAddress, address)).minter !== true) {
|
||||||
@ -227,6 +234,7 @@ export class Datatoken extends SmartContract {
|
|||||||
toAddress || address,
|
toAddress || address,
|
||||||
this.web3.utils.toWei(amount)
|
this.web3.utils.toWei(amount)
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call mint contract method
|
// Call mint contract method
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -250,11 +258,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} minter User which is going to be a Minter
|
* @param {String} minter User which is going to be a Minter
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async addMinter(
|
public async addMinter<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
minter: string
|
minter: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||||
@ -266,6 +275,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dtContract.methods.addMinter,
|
dtContract.methods.addMinter,
|
||||||
minter
|
minter
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call addMinter function of the contract
|
// Call addMinter function of the contract
|
||||||
const trxReceipt = await dtContract.methods.addMinter(minter).send({
|
const trxReceipt = await dtContract.methods.addMinter(minter).send({
|
||||||
@ -286,11 +296,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
public async removeMinter(
|
public async removeMinter<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
minter: string
|
minter: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||||
@ -302,6 +313,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dtContract.methods.removeMinter,
|
dtContract.methods.removeMinter,
|
||||||
minter
|
minter
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call dtContract function of the contract
|
// Call dtContract function of the contract
|
||||||
const trxReceipt = await dtContract.methods.removeMinter(minter).send({
|
const trxReceipt = await dtContract.methods.removeMinter(minter).send({
|
||||||
@ -321,11 +333,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} paymentManager User which is going to be a Minter
|
* @param {String} paymentManager User which is going to be a Minter
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async addPaymentManager(
|
public async addPaymentManager<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
paymentManager: string
|
paymentManager: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||||
@ -337,6 +350,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dtContract.methods.addPaymentManager,
|
dtContract.methods.addPaymentManager,
|
||||||
paymentManager
|
paymentManager
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call addPaymentManager function of the contract
|
// Call addPaymentManager function of the contract
|
||||||
const trxReceipt = await dtContract.methods.addPaymentManager(paymentManager).send({
|
const trxReceipt = await dtContract.methods.addPaymentManager(paymentManager).send({
|
||||||
@ -356,11 +370,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} paymentManager User which will be removed from paymentManager permission
|
* @param {String} paymentManager User which will be removed from paymentManager permission
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async removePaymentManager(
|
public async removePaymentManager<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
paymentManager: string
|
paymentManager: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
if ((await this.isDatatokenDeployer(dtAddress, address)) !== true) {
|
||||||
@ -372,6 +387,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dtContract.methods.removePaymentManager,
|
dtContract.methods.removePaymentManager,
|
||||||
paymentManager
|
paymentManager
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call removeFeeManager function of the contract
|
// Call removeFeeManager function of the contract
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -394,11 +410,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param paymentCollector User to be set as new payment collector
|
* @param paymentCollector User to be set as new payment collector
|
||||||
* @return {Promise<TransactionReceipt>} trxReceipt
|
* @return {Promise<TransactionReceipt>} trxReceipt
|
||||||
*/
|
*/
|
||||||
public async setPaymentCollector(
|
public async setPaymentCollector<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
paymentCollector: string
|
paymentCollector: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
|
const isPaymentManager = (await this.getDTPermissions(dtAddress, address))
|
||||||
.paymentManager
|
.paymentManager
|
||||||
@ -416,6 +433,7 @@ export class Datatoken extends SmartContract {
|
|||||||
dtContract.methods.setPaymentCollector,
|
dtContract.methods.setPaymentCollector,
|
||||||
paymentCollector
|
paymentCollector
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call setFeeCollector method of the contract
|
// Call setFeeCollector method of the contract
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
@ -465,12 +483,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} address User adress
|
* @param {String} address User adress
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async transferWei(
|
public async transferWei<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
toAddress: string,
|
toAddress: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
address: string
|
address: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
try {
|
try {
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
@ -479,6 +498,8 @@ export class Datatoken extends SmartContract {
|
|||||||
toAddress,
|
toAddress,
|
||||||
amount
|
amount
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call transfer function of the contract
|
// Call transfer function of the contract
|
||||||
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
const trxReceipt = await dtContract.methods.transfer(toAddress, amount).send({
|
||||||
from: address,
|
from: address,
|
||||||
@ -501,14 +522,15 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {consumeMarketFee} ConsumeMarketFee consume market fees
|
* @param {consumeMarketFee} ConsumeMarketFee consume market fees
|
||||||
* @return {Promise<TransactionReceipt>} string
|
* @return {Promise<TransactionReceipt>} string
|
||||||
*/
|
*/
|
||||||
public async startOrder(
|
public async startOrder<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
serviceIndex: number,
|
serviceIndex: number,
|
||||||
providerFees: ProviderFees,
|
providerFees: ProviderFees,
|
||||||
consumeMarketFee?: ConsumeMarketFee
|
consumeMarketFee?: ConsumeMarketFee,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
if (!consumeMarketFee) {
|
if (!consumeMarketFee) {
|
||||||
consumeMarketFee = {
|
consumeMarketFee = {
|
||||||
@ -526,6 +548,7 @@ export class Datatoken extends SmartContract {
|
|||||||
providerFees,
|
providerFees,
|
||||||
consumeMarketFee
|
consumeMarketFee
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
.startOrder(consumer, serviceIndex, providerFees, consumeMarketFee)
|
||||||
@ -550,12 +573,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {providerFees} providerFees provider fees
|
* @param {providerFees} providerFees provider fees
|
||||||
* @return {Promise<TransactionReceipt>} string
|
* @return {Promise<TransactionReceipt>} string
|
||||||
*/
|
*/
|
||||||
public async reuseOrder(
|
public async reuseOrder<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
orderTxId: string,
|
orderTxId: string,
|
||||||
providerFees: ProviderFees
|
providerFees: ProviderFees,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
try {
|
try {
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
@ -564,6 +588,7 @@ export class Datatoken extends SmartContract {
|
|||||||
orderTxId,
|
orderTxId,
|
||||||
providerFees
|
providerFees
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.reuseOrder(orderTxId, providerFees)
|
.reuseOrder(orderTxId, providerFees)
|
||||||
@ -586,12 +611,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {FreParams} freParams Amount of tokens that is going to be transfered
|
* @param {FreParams} freParams Amount of tokens that is going to be transfered
|
||||||
* @return {Promise<TransactionReceipt>}
|
* @return {Promise<TransactionReceipt>}
|
||||||
*/
|
*/
|
||||||
public async buyFromFreAndOrder(
|
public async buyFromFreAndOrder<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
orderParams: OrderParams,
|
orderParams: OrderParams,
|
||||||
freParams: FreOrderParams
|
freParams: FreOrderParams,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
||||||
try {
|
try {
|
||||||
const freContractParams = this.getFreOrderParams(freParams)
|
const freContractParams = this.getFreOrderParams(freParams)
|
||||||
@ -602,6 +628,7 @@ export class Datatoken extends SmartContract {
|
|||||||
orderParams,
|
orderParams,
|
||||||
freContractParams
|
freContractParams
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.buyFromFreAndOrder(orderParams, freContractParams)
|
.buyFromFreAndOrder(orderParams, freContractParams)
|
||||||
@ -624,12 +651,13 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} dispenserContract
|
* @param {String} dispenserContract
|
||||||
* @return {Promise<TransactionReceipt>}
|
* @return {Promise<TransactionReceipt>}
|
||||||
*/
|
*/
|
||||||
public async buyFromDispenserAndOrder(
|
public async buyFromDispenserAndOrder<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
orderParams: OrderParams,
|
orderParams: OrderParams,
|
||||||
dispenserContract: string
|
dispenserContract: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
const dtContract = this.getContract(dtAddress, null, this.abiEnterprise)
|
||||||
try {
|
try {
|
||||||
const estGas = await calculateEstimatedGas(
|
const estGas = await calculateEstimatedGas(
|
||||||
@ -638,6 +666,7 @@ export class Datatoken extends SmartContract {
|
|||||||
orderParams,
|
orderParams,
|
||||||
dispenserContract
|
dispenserContract
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
const trxReceipt = await dtContract.methods
|
const trxReceipt = await dtContract.methods
|
||||||
.buyFromDispenserAndOrder(orderParams, dispenserContract)
|
.buyFromDispenserAndOrder(orderParams, dispenserContract)
|
||||||
@ -661,11 +690,12 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {String} value Data to be stored into 725Y standard
|
* @param {String} value Data to be stored into 725Y standard
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async setData(
|
public async setData<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string,
|
address: string,
|
||||||
value: string
|
value: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
if (!(await this.isDatatokenDeployer(dtAddress, address))) {
|
||||||
throw new Error(`User is not Datatoken Deployer`)
|
throw new Error(`User is not Datatoken Deployer`)
|
||||||
}
|
}
|
||||||
@ -673,6 +703,7 @@ export class Datatoken extends SmartContract {
|
|||||||
const dtContract = this.getContract(dtAddress)
|
const dtContract = this.getContract(dtAddress)
|
||||||
|
|
||||||
const estGas = await calculateEstimatedGas(address, dtContract.methods.setData, value)
|
const estGas = await calculateEstimatedGas(address, dtContract.methods.setData, value)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call setData function of the contract
|
// Call setData function of the contract
|
||||||
const trxReceipt = await dtContract.methods.setData(value).send({
|
const trxReceipt = await dtContract.methods.setData(value).send({
|
||||||
@ -691,10 +722,11 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param address User adress
|
* @param address User adress
|
||||||
* @return {Promise<TransactionReceipt>} transactionId
|
* @return {Promise<TransactionReceipt>} transactionId
|
||||||
*/
|
*/
|
||||||
public async cleanPermissions(
|
public async cleanPermissions<G extends boolean = false>(
|
||||||
dtAddress: string,
|
dtAddress: string,
|
||||||
address: string
|
address: string,
|
||||||
): Promise<TransactionReceipt> {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
if ((await this.nft.getNftOwner(await this.getNFTAddress(dtAddress))) !== address) {
|
if ((await this.nft.getNftOwner(await this.getNFTAddress(dtAddress))) !== address) {
|
||||||
throw new Error('Caller is NOT Nft Owner')
|
throw new Error('Caller is NOT Nft Owner')
|
||||||
}
|
}
|
||||||
@ -704,6 +736,7 @@ export class Datatoken extends SmartContract {
|
|||||||
address,
|
address,
|
||||||
dtContract.methods.cleanPermissions
|
dtContract.methods.cleanPermissions
|
||||||
)
|
)
|
||||||
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
// Call cleanPermissions function of the contract
|
// Call cleanPermissions function of the contract
|
||||||
const trxReceipt = await dtContract.methods.cleanPermissions().send({
|
const trxReceipt = await dtContract.methods.cleanPermissions().send({
|
||||||
@ -792,13 +825,14 @@ export class Datatoken extends SmartContract {
|
|||||||
* @param {string} publishMarketFeeAmount new fee amount
|
* @param {string} publishMarketFeeAmount new fee amount
|
||||||
* @param {String} address user adress
|
* @param {String} address user adress
|
||||||
*/
|
*/
|
||||||
public async setPublishingMarketFee(
|
public async setPublishingMarketFee<G extends boolean = false>(
|
||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
publishMarketFeeAddress: string,
|
publishMarketFeeAddress: string,
|
||||||
publishMarketFeeToken: string,
|
publishMarketFeeToken: string,
|
||||||
publishMarketFeeAmount: string,
|
publishMarketFeeAmount: string,
|
||||||
address: string
|
address: string,
|
||||||
) {
|
estimateGas?: G
|
||||||
|
): Promise<G extends false ? TransactionReceipt : number> {
|
||||||
const dtContract = this.getContract(datatokenAddress, address)
|
const dtContract = this.getContract(datatokenAddress, address)
|
||||||
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
|
const mktFeeAddress = (await dtContract.methods.getPublishingMarketFee().call())[0]
|
||||||
if (mktFeeAddress !== address) {
|
if (mktFeeAddress !== address) {
|
||||||
@ -811,7 +845,9 @@ export class Datatoken extends SmartContract {
|
|||||||
publishMarketFeeToken,
|
publishMarketFeeToken,
|
||||||
publishMarketFeeAmount
|
publishMarketFeeAmount
|
||||||
)
|
)
|
||||||
await dtContract.methods
|
if (estimateGas) return estGas
|
||||||
|
|
||||||
|
const trxReceipt = await dtContract.methods
|
||||||
.setPublishingMarketFee(
|
.setPublishingMarketFee(
|
||||||
publishMarketFeeAddress,
|
publishMarketFeeAddress,
|
||||||
publishMarketFeeToken,
|
publishMarketFeeToken,
|
||||||
@ -822,6 +858,8 @@ export class Datatoken extends SmartContract {
|
|||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
gasPrice: await this.getFairGasPrice()
|
gasPrice: await this.getFairGasPrice()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return trxReceipt
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user