Reinitialize repository... hacked by muscleman...
This commit is contained in:
128
config_examples/bytecoin/apiInterfaces.js
Normal file
128
config_examples/bytecoin/apiInterfaces.js
Normal file
@@ -0,0 +1,128 @@
|
||||
/**
|
||||
* Cryptonote Node.JS Pool
|
||||
* https://github.com/dvandal/cryptonote-nodejs-pool
|
||||
*
|
||||
* Handle communications to APIs
|
||||
**/
|
||||
|
||||
// Load required modules
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
/**
|
||||
* Send API request using JSON HTTP
|
||||
**/
|
||||
function jsonHttpRequest (host, port, data, callback, path) {
|
||||
path = path || '/json_rpc';
|
||||
|
||||
|
||||
var options = {
|
||||
hostname: host,
|
||||
port: port,
|
||||
path: path,
|
||||
method: data ? 'POST' : 'GET',
|
||||
headers: {
|
||||
'Authorization': 'Basic ' + Buffer.from("user:pass")
|
||||
.toString('base64'),
|
||||
'Content-Length': data.length,
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
};
|
||||
|
||||
var req = (port === 443 ? https : http)
|
||||
.request(options, function (res) {
|
||||
var replyData = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', function (chunk) {
|
||||
replyData += chunk;
|
||||
});
|
||||
res.on('end', function () {
|
||||
var replyJson;
|
||||
try {
|
||||
replyJson = JSON.parse(replyData);
|
||||
} catch (e) {
|
||||
callback(e, {});
|
||||
return;
|
||||
}
|
||||
callback(null, replyJson);
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', function (e) {
|
||||
callback(e, {});
|
||||
});
|
||||
|
||||
req.end(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send RPC request
|
||||
**/
|
||||
function rpc (host, port, method, params, callback, password) {
|
||||
var request = {
|
||||
id: "0",
|
||||
jsonrpc: "2.0",
|
||||
method: method,
|
||||
params: params
|
||||
};
|
||||
if (password !== undefined) {
|
||||
request['password'] = password;
|
||||
}
|
||||
var data = JSON.stringify(request);
|
||||
jsonHttpRequest(host, port, data, function (error, replyJson) {
|
||||
if (error) {
|
||||
callback(error, {});
|
||||
return;
|
||||
}
|
||||
callback(replyJson.error, replyJson.result)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send RPC requests in batch mode
|
||||
**/
|
||||
function batchRpc (host, port, array, callback) {
|
||||
var rpcArray = [];
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
rpcArray.push({
|
||||
id: i.toString(),
|
||||
jsonrpc: "2.0",
|
||||
method: array[i][0],
|
||||
params: array[i][1]
|
||||
});
|
||||
}
|
||||
var data = JSON.stringify(rpcArray);
|
||||
jsonHttpRequest(host, port, data, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send RPC request to pool API
|
||||
**/
|
||||
function poolRpc (host, port, path, callback) {
|
||||
jsonHttpRequest(host, port, '', callback, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports API interfaces functions
|
||||
**/
|
||||
module.exports = function (daemonConfig, walletConfig, poolApiConfig) {
|
||||
return {
|
||||
batchRpcDaemon: function (batchArray, callback) {
|
||||
batchRpc(daemonConfig.host, daemonConfig.port, batchArray, callback);
|
||||
},
|
||||
rpcDaemon: function (method, params, callback) {
|
||||
rpc(daemonConfig.host, daemonConfig.port, method, params, callback);
|
||||
},
|
||||
rpcWallet: function (method, params, callback) {
|
||||
rpc(walletConfig.host, walletConfig.port, method, params, callback,
|
||||
walletConfig.password);
|
||||
},
|
||||
pool: function (path, callback) {
|
||||
var bindIp = config.api.bindIp ? config.api.bindIp : "0.0.0.0";
|
||||
var poolApi = (bindIp !== "0.0.0.0" ? poolApiConfig.bindIp : "127.0.0.1");
|
||||
poolRpc(poolApi, poolApiConfig.port, path, callback);
|
||||
},
|
||||
jsonHttpRequest: jsonHttpRequest
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user