Added an rpc cmd queue

This commit is contained in:
Joe Uhren
2023-05-16 20:29:57 -06:00
parent e5bd30a457
commit 2e7c8ea201
4 changed files with 16 additions and 7 deletions
+1 -1
View File
@@ -19,7 +19,7 @@ const { exec } = require('child_process');
nodeapi.setWalletDetails(settings.wallet);
// dynamically build the nodeapi cmd access list by adding all non-blockchain-specific api cmds that have a value
Object.keys(settings.api_cmds).forEach(function(key, index, map) {
if (key != 'use_rpc' && settings.api_cmds[key] != null && settings.api_cmds[key] != '')
if (key != 'use_rpc' && key != 'rpc_concurrent_tasks' && settings.api_cmds[key] != null && settings.api_cmds[key] != '')
apiAccessList.push(key);
});
// dynamically find and add additional blockchain_specific api cmds
+11 -6
View File
@@ -1,4 +1,5 @@
var request = require('postman-request'),
async = require('async'),
settings = require('./settings'),
locale = require('./locale'),
Address = require('../models/address');
@@ -8,6 +9,15 @@ var base_url = base_server + 'api/';
const onode = require('./node');
const client = new onode.Client(settings.wallet);
const rpc_queue = async.queue((task_params, cb) => {
client.cmd([task_params], function(err, response) {
if (err)
return cb('There was an error. Check your console.');
else
return cb(response);
});
}, settings.api_cmds.rpc_concurrent_tasks);
// returns coinbase total sent as current coin supply
function coinbase_supply(cb) {
Address.findOne({a_id: 'coinbase'}).then((address) => {
@@ -22,12 +32,7 @@ function coinbase_supply(cb) {
}
function rpcCommand(params, cb) {
client.cmd([{method: params[0].method, params: params[0].parameters}], function(err, response) {
if (err)
return cb('There was an error. Check your console.');
else
return cb(response);
});
rpc_queue.push({method: params[0].method, params: params[0].parameters}, cb);
}
function prepareRpcCommand(cmd, addParams) {
+2
View File
@@ -1258,6 +1258,8 @@ exports.api_cmds = {
// use_rpc: Determine whether to call rpc api cmds directly using the faster rpc method or using the older method via internal http api (true/false)
// NOTE: This should always be set to true unless there is a specific need to test or log certain apis
"use_rpc": true,
// rpc_concurrent_tasks: The maximum number of rpc cmds that can be run simultaneously. Additional rpc cmds will go into a queue and be run on a first-in-first-out basis
"rpc_concurrent_tasks": 1,
// getnetworkhashps: Returns the estimated network hashes per second. This should be a positive whole number
"getnetworkhashps": "getnetworkhashps",
// getmininginfo: Returns a json object containing mining-related information
+2
View File
@@ -1375,6 +1375,8 @@
// use_rpc: Determine whether to call rpc api cmds directly using the faster rpc method or using the older method via internal http api (true/false)
// NOTE: This should always be set to true unless there is a specific need to test or log certain apis
"use_rpc": true,
// rpc_concurrent_tasks: The maximum number of rpc cmds that can be run simultaneously. Additional rpc cmds will go into a queue and be run on a first-in-first-out basis
"rpc_concurrent_tasks": 1,
// getnetworkhashps: Returns the estimated network hashes per second. This should be a positive whole number
"getnetworkhashps": "getnetworkhashps",
// getmininginfo: Returns a json object containing mining-related information