From 5fd5e4351dc9ec6f41328cf6b3dbb1b61e6d1dcd Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 8 Mar 2024 11:53:52 +0900 Subject: [PATCH 1/2] Tweak net apis on JSON_RPC_API.md --- JSON_RPC_API.md | 146 ++++++++++++++++++++++++------------------------ 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 770f5dc14..ef032811e 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -3,54 +3,54 @@ ## Table of Contents - [Database API](#database-api) - - [ain_get](#ain_get) - - [ain_matchFunction](#ain_matchfunction) - - [ain_matchRule](#ain_matchrule) - - [ain_matchOwner](#ain_matchowner) - - [ain_evalRule](#ain_evalrule) - - [ain_evalOwner](#ain_evalowner) - - [ain_getStateProof](#ain_getstateproof) - - [ain_getProofHash](#ain_getproofhash) - - [ain_getStateInfo](#ain_getstateinfo) - - [ain_getStateUsage](#ain_getstateusage) + - [ain_get](#ain_get) + - [ain_matchFunction](#ain_matchfunction) + - [ain_matchRule](#ain_matchrule) + - [ain_matchOwner](#ain_matchowner) + - [ain_evalRule](#ain_evalrule) + - [ain_evalOwner](#ain_evalowner) + - [ain_getStateProof](#ain_getstateproof) + - [ain_getProofHash](#ain_getproofhash) + - [ain_getStateInfo](#ain_getstateinfo) + - [ain_getStateUsage](#ain_getstateusage) - [Account API](#account-api) - [ain_getAddress](#ain_getaddress) - - [ain_getBalance](#ain_getbalance) - - [ain_getNonce](#ain_getnonce) - - [ain_getTimestamp](#ain_gettimestamp) + - [ain_getBalance](#ain_getbalance) + - [ain_getNonce](#ain_getnonce) + - [ain_getTimestamp](#ain_gettimestamp) - [Transaction API](#transaction-api) - - [ain_getPendingTransactions](#ain_getpendingtransactions) - - [ain_getTransactionPoolSizeUtilization](#ain_gettransactionpoolsizeutilization) - - [ain_getTransactionByHash](#ain_gettransactionbyhash) - - [ain_getTransactionByBlockHashAndIndex](#ain_gettransactionbyblockhashandindex) - - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) - - [ain_sendSignedTransactionDryrun](#ain_sendsignedtransactiondryrun) - - [ain_sendSignedTransaction](#ain_sendsignedtransaction) - - [ain_sendSignedTransactionBatch](#ain_sendsignedtransactionbatch) + - [ain_getPendingTransactions](#ain_getpendingtransactions) + - [ain_getTransactionPoolSizeUtilization](#ain_gettransactionpoolsizeutilization) + - [ain_getTransactionByHash](#ain_gettransactionbyhash) + - [ain_getTransactionByBlockHashAndIndex](#ain_gettransactionbyblockhashandindex) + - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) + - [ain_sendSignedTransactionDryrun](#ain_sendsignedtransactiondryrun) + - [ain_sendSignedTransaction](#ain_sendsignedtransaction) + - [ain_sendSignedTransactionBatch](#ain_sendsignedtransactionbatch) - [Block API](#block-api) - - [ain_getLastBlock](#ain_getlastblock) - - [ain_getLastBlockNumber](#ain_getlastblocknumber) - - [ain_getBlockByNumber](#ain_getblockbynumber) - - [ain_getBlockByHash](#ain_getblockbyhash) - - [ain_getBlockList](#ain_getblocklist) - - [ain_getBlockHeadersList](#ain_getblockheaderslist) - - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) - - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) + - [ain_getLastBlock](#ain_getlastblock) + - [ain_getLastBlockNumber](#ain_getlastblocknumber) + - [ain_getBlockByNumber](#ain_getblockbynumber) + - [ain_getBlockByHash](#ain_getblockbyhash) + - [ain_getBlockList](#ain_getblocklist) + - [ain_getBlockHeadersList](#ain_getblockheaderslist) + - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) + - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) - [Blockchain Node API](#blockchain-node-api) - - [ain_getValidatorInfo](#ain_getvalidatorinfo) - - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) - - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) - - [ain_getProposerByNumber](#ain_getproposerbynumber) - - [ain_getProposerByHash](#ain_getproposerbyhash) + - [ain_getValidatorInfo](#ain_getvalidatorinfo) + - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) + - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) + - [ain_getProposerByNumber](#ain_getproposerbynumber) + - [ain_getProposerByHash](#ain_getproposerbyhash) - [Network API](#network-api) - - [net_listening](#net_listening) - - [net_peerCount](#net_peercount) - - [net_syncing](#net_syncing) - - [net_getNetworkId](#net_getnetworkid) - - [net_getChainId](#net_getchainid) - - [net_consensusStatus](#net_consensusstatus) - - [net_rawConsensusStatus](#net_rawconsensusstatus) - - [p2p_getPeerCandidateInfo](#p2p_getpeercandidateinfo) + - [net_getNetworkId](#net_getnetworkid) + - [net_getChainId](#net_getchainid) + - [net_listening](#net_listening) + - [net_syncing](#net_syncing) + - [net_peerCount](#net_peercount) + - [net_consensusStatus](#net_consensusstatus) + - [net_rawConsensusStatus](#net_rawconsensusstatus) + - [p2p_getPeerCandidateInfo](#p2p_getpeercandidateinfo) --- @@ -2791,9 +2791,9 @@ Response ## Network API -### net_listening +### net_getNetworkId -Returns whether the node is listening for network connections. +Returns the blockchain node's network id. **Parameters** @@ -2803,8 +2803,11 @@ An object with properties: **Returns** -`Boolean` - true is the node is listening for connections; otherwise, false. +`Number` - the network id. +- 0: mainnet network +- 1: testnet network + **Example** Request @@ -2812,7 +2815,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_listening", + "method": "net_getNetworkId", "params": { "protoVer": "1.1.3" } @@ -2825,15 +2828,15 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": true, + "result": 0, "protoVer": "1.1.3" } } ``` -### net_peerCount +### net_getChainId -Returns the number of peers the node is connected to. +Returns the blockchain node's chain id. **Parameters** @@ -2843,8 +2846,11 @@ An object with properties: **Returns** -`Number` - number of peers. +`Number` - the chain id. +- 0: mainnet chain +- 1: testnet chain + **Example** Request @@ -2852,7 +2858,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_peerCount", + "method": "net_getChainId", "params": { "protoVer": "1.1.3" } @@ -2865,15 +2871,15 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": 3, + "result": 0, "protoVer": "1.1.3" } } ``` -### net_syncing +### net_listening -Returns whether the node is syncing with the network or not. +Returns whether the node is listening for network connections. **Parameters** @@ -2883,7 +2889,7 @@ An object with properties: **Returns** -`Boolean` - true if the node is syncing, false otherwise. +`Boolean` - true is the node is listening for connections; otherwise, false. **Example** @@ -2892,7 +2898,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_syncing", + "method": "net_listening", "params": { "protoVer": "1.1.3" } @@ -2905,15 +2911,15 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": false, + "result": true, "protoVer": "1.1.3" } } ``` -### net_getNetworkId +### net_syncing -Returns the blockchain node's network id. +Returns whether the node is syncing with the network or not. **Parameters** @@ -2923,11 +2929,8 @@ An object with properties: **Returns** -`Number` - the network id. +`Boolean` - true if the node is syncing, false otherwise. -- 0: mainnet network -- 1: testnet network - **Example** Request @@ -2935,7 +2938,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_getNetworkId", + "method": "net_syncing", "params": { "protoVer": "1.1.3" } @@ -2948,15 +2951,15 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": 0, + "result": false, "protoVer": "1.1.3" } } ``` -### net_getChainId +### net_peerCount -Returns the blockchain node's chain id. +Returns the number of peers the node is connected to. **Parameters** @@ -2966,11 +2969,8 @@ An object with properties: **Returns** -`Number` - the chain id. +`Number` - number of peers. -- 0: mainnet chain -- 1: testnet chain - **Example** Request @@ -2978,7 +2978,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_getChainId", + "method": "net_peerCount", "params": { "protoVer": "1.1.3" } @@ -2991,7 +2991,7 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": 0, + "result": 3, "protoVer": "1.1.3" } } From f800bc42e3197695315dca326873883f456a5014 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 8 Mar 2024 11:58:13 +0900 Subject: [PATCH 2/2] Re-order json rpc methods in network.js --- json_rpc/network.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/json_rpc/network.js b/json_rpc/network.js index 68c82c310..bc903677b 100644 --- a/json_rpc/network.js +++ b/json_rpc/network.js @@ -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) {