UNPKG

@mavrykdynamics/taquito

Version:

High level functionality that builds upon the other packages in the Mavryk Typescript Library Suite.

68 lines (67 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContractMethodObject = void 0; const wallet_1 = require("../../wallet"); const contract_1 = require("../contract"); /** * @description Utility class to send smart contract operation * The format for the arguments is the object representation */ class ContractMethodObject { constructor(provider, address, parameterSchema, name, args = 'unit', isMultipleEntrypoint = true, isAnonymous = false) { this.provider = provider; this.address = address; this.parameterSchema = parameterSchema; this.name = name; this.args = args; this.isMultipleEntrypoint = isMultipleEntrypoint; this.isAnonymous = isAnonymous; } /** * @description Get the signature of the smart contract method */ getSignature() { return this.isAnonymous ? this.parameterSchema.ExtractSchema()[this.name] : this.parameterSchema.ExtractSchema(); } /** * * @description Send the smart contract operation * * @param Options generic operation parameter */ send(params = {}) { if (this.provider instanceof wallet_1.Wallet) { return this.provider.transfer(this.toTransferParams(params)).send(); } else { return this.provider.transfer(this.toTransferParams(params)); } } /** * * @description Create transfer params to be used with MavrykToolkit.contract.transfer methods * * @param Options generic transfer operation parameters */ toTransferParams({ fee, gasLimit, storageLimit, source, amount = 0, mumav = false, } = {}) { const fullTransferParams = { to: this.address, amount, fee, mumav, source, gasLimit, storageLimit, parameter: { entrypoint: this.isMultipleEntrypoint ? this.name : contract_1.DEFAULT_SMART_CONTRACT_METHOD_NAME, value: this.isAnonymous ? this.parameterSchema.EncodeObject({ [this.name]: this.args }) : this.parameterSchema.EncodeObject(this.args), }, }; return fullTransferParams; } } exports.ContractMethodObject = ContractMethodObject;