lisk-framework
Version:
Lisk blockchain application platform
38 lines • 1.48 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.Request = void 0;
const assert_1 = require("assert");
const constants_1 = require("../constants");
const endpoint_1 = require("../endpoint");
const jsonrpc_1 = require("./jsonrpc");
class Request {
constructor(id, name, params) {
(0, assert_1.strict)(constants_1.actionWithModuleNameReg.test(name), `Request name "${name.replace(constants_1.controlReg, '')}" must be a valid name with module name and action name.`);
this.id = id;
[this.namespace, this.name] = name.split('_');
this.params = params !== null && params !== void 0 ? params : {};
}
static fromJSONRPCRequest(data) {
const { id, method, params } = typeof data === 'string' ? JSON.parse(data) : data;
return new Request(id, method, params);
}
toJSONRPCRequest() {
return {
jsonrpc: jsonrpc_1.VERSION,
id: this.id,
method: (0, endpoint_1.getEndpointPath)(this.namespace, this.name),
params: this.params,
};
}
buildJSONRPCResponse({ error, result, }) {
if (error) {
return { id: this.id, jsonrpc: jsonrpc_1.VERSION, error };
}
return { id: this.id, jsonrpc: jsonrpc_1.VERSION, result: result };
}
key() {
return (0, endpoint_1.getEndpointPath)(this.namespace, this.name);
}
}
exports.Request = Request;
//# sourceMappingURL=request.js.map
;