@taquito/taquito
Version:
High level functionality that builds upon the other packages in the Tezos Typescript Library Suite.
73 lines (72 loc) • 2.59 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContractMethodObject = void 0;
const constants_1 = require("../constants");
/**
* @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() {
const generatedSchema = this.parameterSchema.generateSchema();
if (this.isAnonymous) {
const schemaObj = generatedSchema.schema;
return schemaObj === null || schemaObj === void 0 ? void 0 : schemaObj[this.name];
}
return generatedSchema;
}
/**
*
* @description Send the smart contract operation
*
* @param Options generic operation parameter
*/
send(params = {}) {
// provider is either ContractProvider | Wallet but pkh method is unique to Wallet
if (this.provider && 'pkh' in this.provider) {
return this.provider
.transfer(this.toTransferParams(params))
.send();
}
else {
return this.provider.transfer(this.toTransferParams(params));
}
}
/**
*
* @description Create transfer params to be used with TezosToolkit.contract.transfer methods
*
* @param Options generic transfer operation parameters
*/
toTransferParams({ fee, gasLimit, storageLimit, source, amount = 0, mutez = false, } = {}) {
const fullTransferParams = {
to: this.address,
amount,
fee,
mutez,
source,
gasLimit,
storageLimit,
parameter: {
entrypoint: this.isMultipleEntrypoint ? this.name : constants_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;