Skip to content

Commit

Permalink
Re-order json rpc methods in network.js
Browse files Browse the repository at this point in the history
  • Loading branch information
platfowner committed Mar 8, 2024
1 parent 5fd5e43 commit f800bc4
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions json_rpc/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@ const { JSON_RPC_METHODS } = require('./constants');

module.exports = function getNetworkApis(node, p2pServer) {
return {
[JSON_RPC_METHODS.NET_LISTENING]: function(args, done) {
[JSON_RPC_METHODS.NET_GET_NETWORK_ID]: function(args, done) {
const beginTime = Date.now();
const peerCount = Object.keys(p2pServer.inbound).length;
const result = !!peerCount;
const result = node.getBlockchainParam('genesis/network_id');
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
},

[JSON_RPC_METHODS.NET_PEER_COUNT]: function(args, done) {
[JSON_RPC_METHODS.NET_GET_CHAIN_ID]: function(args, done) {
const beginTime = Date.now();
const peerCount = Object.keys(p2pServer.inbound).length;
const result = node.getBlockchainParam('genesis/chain_id');
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result: peerCount }));
done(null, JsonRpcUtil.addProtocolVersion({ result }));
},

[JSON_RPC_METHODS.NET_SYNCING]: function(args, done) {
[JSON_RPC_METHODS.NET_LISTENING]: function(args, done) {
const beginTime = Date.now();
const result = (node.state === BlockchainNodeStates.CHAIN_SYNCING);
const peerCount = Object.keys(p2pServer.inbound).length;
const result = !!peerCount;
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
// TODO(liayoo): Return { starting, latest } with block numbers
// if the node is currently syncing.
done(null, JsonRpcUtil.addProtocolVersion({ result }));
},

[JSON_RPC_METHODS.NET_GET_NETWORK_ID]: function(args, done) {
[JSON_RPC_METHODS.NET_SYNCING]: function(args, done) {
const beginTime = Date.now();
const result = node.getBlockchainParam('genesis/network_id');
const result = (node.state === BlockchainNodeStates.CHAIN_SYNCING);
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
// TODO(liayoo): Return { starting, latest } with block numbers
// if the node is currently syncing.
done(null, JsonRpcUtil.addProtocolVersion({ result }));
},

[JSON_RPC_METHODS.NET_GET_CHAIN_ID]: function(args, done) {
[JSON_RPC_METHODS.NET_PEER_COUNT]: function(args, done) {
const beginTime = Date.now();
const result = node.getBlockchainParam('genesis/chain_id');
const peerCount = Object.keys(p2pServer.inbound).length;
const latency = Date.now() - beginTime;
trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency);
done(null, JsonRpcUtil.addProtocolVersion({ result }));
done(null, JsonRpcUtil.addProtocolVersion({ result: peerCount }));
},

[JSON_RPC_METHODS.NET_CONSENSUS_STATUS]: function(args, done) {
Expand Down

0 comments on commit f800bc4

Please sign in to comment.