Add use_rpc setting
This commit is contained in:
+35
-8
@@ -6,6 +6,9 @@ var base_server = 'http://127.0.0.1:' + settings.port + "/";
|
||||
|
||||
var base_url = base_server + 'api/';
|
||||
|
||||
const Client = require('node');
|
||||
const client = new Client(settings.wallet);
|
||||
|
||||
// returns coinbase total sent as current coin supply
|
||||
function coinbase_supply(cb) {
|
||||
Address.findOne({a_id: 'coinbase'}, function(err, address) {
|
||||
@@ -106,17 +109,41 @@ module.exports = {
|
||||
},
|
||||
|
||||
get_blockhash: function(height, cb) {
|
||||
var uri = base_url + 'getblockhash?height=' + height;
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
if (settings.use_rpc) {
|
||||
var uri = base_url + 'getblockhash?height=' + height;
|
||||
request({uri: uri, json: true}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
} else {
|
||||
client.command([{method:'getblockhash', parameters: [height]}], function(err, response){
|
||||
if(err){console.log('Error: ', err); onlyConsole.trace(err)}
|
||||
else{
|
||||
if(response[0].name == 'RpcError'){
|
||||
return cb('There was an error. Check your console.');
|
||||
}
|
||||
return cb(response[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get_block: function(hash, cb) {
|
||||
var uri = base_url + 'getblock?hash=' + hash;
|
||||
request({uri: uri, json: true, headers: {'User-Agent': 'eiquidus'}}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
if (settings.use_rpc) {
|
||||
var uri = base_url + 'getblock?hash=' + hash;
|
||||
request({uri: uri, json: true}, function (error, response, body) {
|
||||
return cb(body);
|
||||
});
|
||||
} else {
|
||||
client.command([{method:'getblock', parameters: [hash]}], function(err, response){
|
||||
if(err){console.log('Error: ', err); onlyConsole.trace(err)}
|
||||
else{
|
||||
if(response[0].name == 'RpcError'){
|
||||
return cb('There was an error. Check your console.');
|
||||
}
|
||||
return cb(response[0]);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
get_rawtransaction: function(hash, cb) {
|
||||
|
||||
Reference in New Issue
Block a user