@pokt-network/pocket-js
Version:
Pocket-js core package with the main functionalities to interact with the Pocket Network.
99 lines • 3.19 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResponseDeliverTx = void 0;
var __1 = require("../..");
/**
*
*
* @class ResponseDeliverTx
*/
var ResponseDeliverTx = /** @class */ (function () {
/**
* Creates a ResponseDeliverTx.
* @constructor
* @param {number} code -
* @param {string[]} data -
* @param {string} log -
* @param {string} info -
* @param {string} recipient -
* @param {string} signer -
* @param {string} messageType -
* @param {Event[]} events -
* @param {string} codespace -
*/
function ResponseDeliverTx(code, data, log, info, recipient, signer, messageType, events, codespace) {
this.code = code;
this.data = data;
this.log = log;
this.info = info;
this.recipient = recipient;
this.signer = signer;
this.messageType = messageType;
this.events = events;
this.codespace = codespace;
if (!this.isValid()) {
throw new TypeError("Invalid ResponseDeliverTx properties.");
}
}
/**
*
* Creates a ResponseDeliverTx object using a JSON string
* @param {String} json - JSON string.
* @returns {ResponseDeliverTx} - ResponseDeliverTx object.
* @memberof ResponseDeliverTx
*/
ResponseDeliverTx.fromJSON = function (json) {
try {
var jsonObject = JSON.parse(json);
var events_1 = [];
if (jsonObject.events) {
jsonObject.events.forEach(function (eventObj) {
var event = __1.Event.fromJSON(JSON.stringify(eventObj));
events_1.push(event);
});
}
var data = jsonObject.data !== undefined && jsonObject.data !== null ? jsonObject.data : "";
return new ResponseDeliverTx(jsonObject.code, data, jsonObject.log, jsonObject.info, jsonObject.recipient, jsonObject.signer, jsonObject.message_type, events_1, jsonObject.codespace);
}
catch (error) {
throw error;
}
};
/**
*
* Creates a JSON object with the ResponseDeliverTx properties
* @returns {JSON} - JSON Object.
* @memberof ResponseDeliverTx
*/
ResponseDeliverTx.prototype.toJSON = function () {
var events = [];
if (this.events.length > 0) {
this.events.forEach(function (event) {
events.push(event.toJSON());
});
}
return {
code: this.code,
codespace: this.codespace,
data: this.data,
log: this.log,
info: this.info,
recipient: this.recipient,
signer: this.signer,
messageType: this.messageType,
events: events
};
};
/**
*
* Verify if all properties are valid
* @returns {boolean} - True or false.
* @memberof ResponseDeliverTx
*/
ResponseDeliverTx.prototype.isValid = function () {
return true;
};
return ResponseDeliverTx;
}());
exports.ResponseDeliverTx = ResponseDeliverTx;
//# sourceMappingURL=response-deliver-tx.js.map