MCPcopy Create free account
hub / github.com/Snipa22/nodejs-pool / jsonRequest

Function jsonRequest

lib/support.js:61–106  ·  view source on GitHub ↗
(host, port, data, callback, path)

Source from the content-addressed store, hash-verified

59}
60
61function jsonRequest(host, port, data, callback, path) {
62 path = path || 'json_rpc';
63 let uri;
64 if (global.config.rpc.https) {
65 uri = "https://" + host + ":" + port + "/";
66 } else {
67 uri = "http://" + host + ":" + port + "/";
68 }
69 debug("JSON URI: " + uri + path + " Args: " + JSON.stringify(data));
70 let client = requestJson.createClient(uri, {timeout: 300000});
71 client.headers["Content-Type"] = "application/json";
72 client.headers["Content-Length"] = data.length;
73 client.headers["Accept"] = "application/json";
74 if (global.config.payout.rpcPasswordEnabled && host === global.config.wallet.address && port === global.config.wallet.port){
75 fs.readFile(global.config.payout.rpcPasswordPath, 'utf8', function(err, data){
76 if (err){
77 console.error("RPC password enabled, unable to read the file due to: " + JSON.stringify(err));
78 return;
79 }
80 let passData = data.split(":");
81 client.setBasicAuth(passData[0], passData[1]);
82 request.post(uri, {
83 auth:{
84 user: passData[0],
85 pass: passData[1],
86 sendImmediately: false
87 },
88 data: JSON.stringify(data)
89 }, function (err, res, body) {
90 if (err) {
91 return callback(err);
92 }
93 debug("JSON result: " + JSON.stringify(body));
94 return callback(body);
95 });
96 });
97 } else {
98 client.post(path, data, function (err, res, body) {
99 if (err) {
100 return callback(err);
101 }
102 debug("JSON result: " + JSON.stringify(body));
103 return callback(body);
104 });
105 }
106}
107
108function rpc(host, port, method, params, callback) {
109

Callers 1

rpcFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected