dotbit
Version:
A complete .bit SDK and utilities in TypeScript
43 lines • 1.42 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.JSONRPC = void 0;
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const DotbitError_1 = require("../errors/DotbitError");
class JSONRPC {
constructor(url) {
this.url = url;
this.id = 0;
}
request(method, params = []) {
return (0, cross_fetch_1.default)(this.url, {
method: 'POST',
body: JSON.stringify({
jsonrpc: '2.0',
id: this.id++,
method,
params,
}),
headers: {
'Content-Type': 'application/json',
},
})
.then(res => res.json())
.then(res => {
if (res.error) {
throw new DotbitError_1.DotbitError(res.error.message, res.error.code);
}
if (res.result.errno) {
throw new DotbitError_1.DotbitError(res.result.errmsg, res.result.errno);
}
if (res.result.err_msg) {
throw new DotbitError_1.DotbitError(res.result.err_msg, res.result.err_no);
}
return res.result;
});
}
}
exports.JSONRPC = JSONRPC;
//# sourceMappingURL=JSON-RPC.js.map
;