@azpool/chia-client
Version:
TypeScript client for Chia node peer RPC interface
30 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RpcClient = void 0;
const fs_1 = require("fs");
const https_1 = require("https");
const axios_1 = require("axios");
class RpcClient {
constructor(options) {
this.protocol = options.protocol;
this.hostname = options.hostname;
this.port = options.port;
this.agent = new https_1.Agent({
...(typeof options.caCertPath !== 'boolean' ? { ca: fs_1.readFileSync(options.caCertPath) } : {}),
cert: fs_1.readFileSync(options.certPath),
key: fs_1.readFileSync(options.keyPath),
rejectUnauthorized: options.rejectUnauthorized || false,
});
}
baseUri() {
return `${this.protocol}://${this.hostname}:${this.port}`;
}
async request(route, body) {
const { data } = await axios_1.default.post(`${this.baseUri()}/${route}`, body, {
httpsAgent: this.agent,
});
return data;
}
}
exports.RpcClient = RpcClient;
//# sourceMappingURL=RpcClient.js.map