UNPKG

near-typechain

Version:

74 lines (73 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NearContract = exports.NearContractBase = exports.CallOverridesPayable = exports.CallOverrides = void 0; const bn_js_1 = require("bn.js"); class CallOverrides { } exports.CallOverrides = CallOverrides; class CallOverridesPayable { } exports.CallOverridesPayable = CallOverridesPayable; class NearContractBase { constructor(contractId, signerAccount) { this._contractId = contractId; this._signer = signerAccount; } get contractId() { return this._contractId; } get signer() { return this._signer; } functionCall({ methodName, args, overrides = {}, }) { var _a, _b; if (!this._signer) throw new Error('Signer is not defined'); return this._signer.functionCall({ contractId: this.contractId, methodName, args: args !== null && args !== void 0 ? args : {}, gas: (overrides === null || overrides === void 0 ? void 0 : overrides.gas) ? new bn_js_1.BN((_a = overrides === null || overrides === void 0 ? void 0 : overrides.gas) === null || _a === void 0 ? void 0 : _a.toString()) : undefined, attachedDeposit: (overrides === null || overrides === void 0 ? void 0 : overrides.attachedDeposit) ? new bn_js_1.BN((_b = overrides === null || overrides === void 0 ? void 0 : overrides.attachedDeposit) === null || _b === void 0 ? void 0 : _b.toString()) : undefined, }); } functionView({ methodName, args, }) { if (!this._signer) throw new Error('Signer is not defined'); return this._signer.viewFunctionV2({ contractId: this.contractId, methodName, args: args !== null && args !== void 0 ? args : {}, parse: (resp) => { return JSON.parse(Buffer.from(resp).toString('utf8')); }, stringify: (req) => { return Buffer.from(JSON.stringify(req), 'utf8'); }, }); } } exports.NearContractBase = NearContractBase; class NearContract extends NearContractBase { constructor(contractId, signerAccount) { super(contractId, signerAccount); this.call = new Proxy({}, { get: (_, key) => { return (args, overrides) => { return this.functionCall({ methodName: key, args, overrides }); }; }, }); this.view = new Proxy({}, { get: (_, key) => { return (args) => { return this.functionView({ methodName: key, args }); }; }, }); } connect(account) { return new NearContract(this.contractId, account); } } exports.NearContract = NearContract;