@near-lake/primitives
Version:
Near Protocol primitive datatypes utilized by near-lake-framework and QueryAPI
99 lines (98 loc) • 2.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionCallView = void 0;
const helpers_1 = require("../helpers");
/**
* Represents a Function Call to a smart cotract
*
*/
class FunctionCallView {
constructor(
/**
* The account ID of the contract that is called.
*/
receiverId,
/**
* The method name of the contract that was invoked.
*/
methodName,
/**
* Base64 encoded arguments to the method.
*/
args,
/**
* gas amount.
*/
gas,
/**
* deposit amount in yoctoNEAR.
*/
deposit, action) {
this.receiverId = receiverId;
this.methodName = methodName;
this.args = args;
this.gas = gas;
this.deposit = deposit;
this.action = action;
}
/**
* receiptId in which this call was executed.
*/
get receiptId() {
return this.action.receiptId;
}
/**
* whether the call was successful.
*/
get isSuccessful() {
return (0, helpers_1.isSuccessfulReceipt)(this.action.receiptStatus);
}
/**
* Execution status object of the corresponding receipt.
*/
get receiptStatus() {
return this.action.receiptStatus;
}
/**
* predecessorId: the contract that invoked this call.
*/
get predecessorId() {
return this.action.predecessorId;
}
/**
* original signer of the transaction.
*/
get signerId() {
return this.action.signerId;
}
/**
* array of parsed events complying with NEP-297 emitted in this call.
*/
get events() {
return this.action.events;
}
/**
* array of logs produced in this call.
*/
get logs() {
return this.action.logs;
}
/**
* arguments, decoded from base64 and parsed to JSON
* @param encoding encoding of the args, default is utf-8
* @returns JSON object of the arguments
* @throws Error if failed to parse the args as JSON
*/
argsAsJSON(encoding = "utf-8") {
try {
return JSON.parse(Buffer.from(this.args, "base64").toString(encoding));
}
catch (e) {
throw new Error(`Failed to parse args '${this.args}' on method '${this.methodName}' as JSON: ${e.message}`);
}
}
static fromFunctionCall(functionCall, action) {
return new FunctionCallView(action.receiverId, functionCall.methodName, functionCall.args, functionCall.gas, functionCall.deposit, action);
}
}
exports.FunctionCallView = FunctionCallView;