Javascript/NodeJS Function to Check the Plugins on Steem Blockchain RPC Nodes


The Steem Blockchain RPC nodes have a few plugins that can be configured enabled/disabled. We can use the following Javascript function (NodeJS) to check if those plugins are enabled or disabled.

To check if a plugin is enabled or not, we need to sent the API (POST) with the corresponding parameters to invoke some API of that plugin. If it returns errors containing the “cannot find method”, the plugin is disabled.

See below JS function callAPI which takes the RPC Node Server, the Plugin Name, the API Method, and its parameters. It returns true if the plugin has been enabled – otherwise meaning the plugin has been deactivated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
async function callAPI(server, plugin, api, params) {
  try {
    const body = JSON.stringify({"id":1,"jsonrpc":"2.0","method":plugin+"."+api,"params":params});
    const response = await fetch(server, {
      method: "POST",
      headers: {
        'Content-Type': 'application/json'
      },
      body: body
    });
    if (response.ok) {
      const data = await response.text();      
      const jsonData = JSON.parse(data);  
      const magicString = "Assert Exception:api_itr != _registered_apis.end()";
      const succ = (!jsonData["error"]) || (!jsonData["error"]["message"].includes(magicString));
      return succ;
    } else {
      return false;
    }
  } catch (ex) {
    return false;
  }
}
async function callAPI(server, plugin, api, params) {
  try {
    const body = JSON.stringify({"id":1,"jsonrpc":"2.0","method":plugin+"."+api,"params":params});
    const response = await fetch(server, {
      method: "POST",
      headers: {
        'Content-Type': 'application/json'
      },
      body: body
    });
    if (response.ok) {
      const data = await response.text();      
      const jsonData = JSON.parse(data);  
      const magicString = "Assert Exception:api_itr != _registered_apis.end()";
      const succ = (!jsonData["error"]) || (!jsonData["error"]["message"].includes(magicString));
      return succ;
    } else {
      return false;
    }
  } catch (ex) {
    return false;
  }
}

The list of plugins, and their one example API, with parameters can be defined as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  const plugins = {
    "account_by_key_api": ["get_key_references", {"keys":["STM5jZtLoV8YbxCxr4imnbWn61zMB24wwonpnVhfXRmv7j6fk3dTH"]}],
    "account_history_api": ["get_account_history", {"account":"steemit", "start":1000, "limit":1000}],
    "block_api": ["get_block",{"block_num":1}],
    "database_api": ["list_account_recovery_requests",{"start":"", "limit":10, "order":"by_account"}],  
    "condenser_api": ["get_accounts", [["justyy"]]],
    "debug_node_api": ["debug_pop_block"],
    "follow_api": ["get_account_reputations",{"account_lower_bound":"steemit", "limit":1}],
    "market_history_api": ["get_ticker"],
    "rc_api": ["find_rc_accounts",{"accounts":["alice","bob"]}],
    "reputation_api": ["get_account_reputations",{"account_lower_bound": "steem"}],
    "rewards_api": ["simulate_curve_payouts",{"curve": "quadratic", "var1": "2000000000000"}],
    "tags_api": ["get_discussion",{"author":"alice", "permlink":"a-post-by-alice"}],
    "transaction_status_api": ["find_transaction",{"transaction_id": "0000000000000000000000000000000000000000", "expiration":"2016-03-24T18:00:21"}],
    "network_broadcast_api": ["broadcast_block",{"trx":{"ref_block_num":1097,"ref_block_prefix":2181793527,"expiration":"2016-03-24T18:00:21","operations":[{"type":"vote_operation","value":{"voter":"steemit","author":"alice","permlink":"a-post-by-alice","weight":10000}}],"extensions":[],"signatures":[]},"max_block_age":50}],
  };
  const plugins = {
    "account_by_key_api": ["get_key_references", {"keys":["STM5jZtLoV8YbxCxr4imnbWn61zMB24wwonpnVhfXRmv7j6fk3dTH"]}],
    "account_history_api": ["get_account_history", {"account":"steemit", "start":1000, "limit":1000}],
    "block_api": ["get_block",{"block_num":1}],
    "database_api": ["list_account_recovery_requests",{"start":"", "limit":10, "order":"by_account"}],	
    "condenser_api": ["get_accounts", [["justyy"]]],
    "debug_node_api": ["debug_pop_block"],
    "follow_api": ["get_account_reputations",{"account_lower_bound":"steemit", "limit":1}],
    "market_history_api": ["get_ticker"],
    "rc_api": ["find_rc_accounts",{"accounts":["alice","bob"]}],
    "reputation_api": ["get_account_reputations",{"account_lower_bound": "steem"}],
    "rewards_api": ["simulate_curve_payouts",{"curve": "quadratic", "var1": "2000000000000"}],
    "tags_api": ["get_discussion",{"author":"alice", "permlink":"a-post-by-alice"}],
    "transaction_status_api": ["find_transaction",{"transaction_id": "0000000000000000000000000000000000000000", "expiration":"2016-03-24T18:00:21"}],
    "network_broadcast_api": ["broadcast_block",{"trx":{"ref_block_num":1097,"ref_block_prefix":2181793527,"expiration":"2016-03-24T18:00:21","operations":[{"type":"vote_operation","value":{"voter":"steemit","author":"alice","permlink":"a-post-by-alice","weight":10000}}],"extensions":[],"signatures":[]},"max_block_age":50}],
  };

And we can test each plugin one by one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  let result = {
    "node": node,
    "enabled_plugins": [],
    "disabled_plugins": [],
  };
  const pluginNames = Object.keys(plugins);
  for (let i = 0; i < pluginNames.length; ++ i) {
    const plugin = pluginNames[i];
    const api = plugins[plugin];
    const params = api.slice(1)[0];
    const succ = await callAPI(node, plugin, api[0], params);
    if (succ) {
      result["enabled_plugins"].push(plugin);
    } else {
      result["disabled_plugins"].push(plugin);
    }
  }
  let result = {
    "node": node,
    "enabled_plugins": [],
    "disabled_plugins": [],
  };
  const pluginNames = Object.keys(plugins);
  for (let i = 0; i < pluginNames.length; ++ i) {
    const plugin = pluginNames[i];
    const api = plugins[plugin];
    const params = api.slice(1)[0];
    const succ = await callAPI(node, plugin, api[0], params);
    if (succ) {
      result["enabled_plugins"].push(plugin);
    } else {
      result["disabled_plugins"].push(plugin);
    }
  }

See also: How to Get Blockchain Version of Steem RPC Node using Javascript?

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
523 words
Last Post: Teaching Kids Programming - Sum of Two Numbers Less Than Target using Two Pointer Algorithm
Next Post: Teaching Kids Programming - Breadth First Search Algorithm to Determine Sum Binary Tree

The Permanent URL is: Javascript/NodeJS Function to Check the Plugins on Steem Blockchain RPC Nodes

Leave a Reply