diff --git a/src/contracts/Datatoken4.ts b/src/contracts/Datatoken4.ts index 6e5b4b60..57025643 100644 --- a/src/contracts/Datatoken4.ts +++ b/src/contracts/Datatoken4.ts @@ -151,4 +151,94 @@ export class Datatoken4 extends Datatoken { return >trxReceipt } + + /** addConsumer + * This function allows to add consumer + * only DatatokenDeployer can succeed + * @param {String} dtAddress Datatoken address + * @param {String} consumer User address + * @param {Boolean} estimateGas if True, return gas estimate + * @return {Promise} transactionId + */ + public async addConsumer( + dtAddress: string, + consumer: string, + estimateGas?: G + ): Promise> { + const dtContract = this.getContract(dtAddress) + const estGas = await dtContract.estimateGas.addConsumer(consumer) + if (estimateGas) return >estGas + + const trxReceipt = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + dtContract.addConsumer, + consumer + ) + + return >trxReceipt + } + + /** checkConsumer + * This function allows to add consumer + * only DatatokenDeployer can succeed + * @param {String} dtAddress Datatoken address + * @param {Number} serviceId Service Identifier + * @param {String} consumer User address + * @param {Boolean} estimateGas if True, return gas estimate + * @return {Promise} transactionId + */ + public async checkConsumer( + dtAddress: string, + serviceId: number, + consumer: string, + estimateGas?: G + ): Promise> { + const dtContract = this.getContract(dtAddress) + const estGas = await dtContract.estimateGas.checkConsumer(serviceId, consumer) + if (estimateGas) return >estGas + + const trxReceipt = await sendTx( + estGas, + this.signer, + this.config?.gasFeeMultiplier, + dtContract.checkConsumer, + serviceId, + consumer + ) + return >trxReceipt + } + + /** + * getFileObject - It returns the consumer's file object encrypted format. + * @param {String} dtAddress datatoken address + * @param {Number} serviceId - service identifier + * @param {String} providerAddress + * @param {Bytes} providerSignature + * @param {Bytes} consumerData + * @param {Bytes} consumerSignature + * @param {String} consumerAddress + * @return {Promise} + */ + public async getFileObject( + dtAddress: string, + serviceId: number, + providerAddress: string, + providerSignature: Bytes, + consumerData: Bytes, + consumerSignature: Bytes, + consumerAddress: string + ): Promise { + const dtContract = this.getContract(dtAddress) + const fileObject = await dtContract.getFileObject( + serviceId, + providerAddress, + providerSignature, + consumerData, + consumerSignature, + consumerAddress + ) + return fileObject + } }