Update jsonrpc2.js

This commit is contained in:
Namhyeon Go 2024-06-26 16:37:04 +09:00 committed by GitHub
parent c9c70d9be6
commit 3733eaea45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,46 +3,8 @@
// https://github.com/gnh1201/welsonjs
var HTTP = require("lib/http");
function encode(method, params, id) {
var data = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": id
};
return JSON.stringify(data);
}
function resultEncode(result, id) {
var data = {
"jsonrpc": "2.0",
"result": result
"id": id
};
return JSON.stringify(data);
}
function errorEncode(error, id) {
var data = {
"jsonrpc": "2.0",
"error": error,
"id": id
}
return JSON.stringify(data);
}
// See also: https://github.com/gnh1201/caterpillar
function JsonRpcObject() {
this.url = "http://localhost:5555";
this.setUrl = function(url) {
this.url = url;
return this;
}
function jsonrpc2(url) {
this.url = url;
this.call = function(method, params, id) {
var result;
var response = HTTP.create("MSXML")
@ -67,16 +29,23 @@ function JsonRpcObject() {
}
}
function create() {
return new JsonRpcObject();
function encode(method, params, id) {
return JSON.stringify({
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": id
});
}
function create(url) {
return new jsonrpc2(url);
}
exports.encode = encode;
exports.resultEncode = resultEncode;
exports.errorEncode = errorEncode;
exports.create = create;
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1";
exports.VERSIONINFO = "JSON-RPC 2.0 Interface (jsonrpc2.js) version 0.1.1";
exports.AUTHOR = "abuse@catswords.net";
exports.global = global;
exports.require = global.require;