From 58fc00724e55c4ba4796e442f9586930dcfc1657 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 19 Dec 2023 15:51:27 +0900 Subject: [PATCH 01/38] Tweak README.md --- README.md | 86 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 03b870346..d46f05435 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,16 @@ Official Javascript implementation of AI Network Blockchain. ## Install Environment (Last update at 6th of Dec 2021) ### OS -- macOS 10.15 (macos-latest) -- Ubuntu 20.04 (ubuntu-latest) +- macOS 13.5 (macos-latest) +- Ubuntu 22.04 (ubuntu-latest) -### Node version +### NodeJs version -- v16.x -- v14.x +- v18.x ## Tracker -Tracker server is required by new peers who wish to join the AIN network. Each peer is sent the ipaddress of 2 other nodes in the network. These nodes then gossip information through the network of all transactions and blocks. +Tracker server is required by new peers who wish to join the AIN network. Each peer is sent the ip address of 2 other nodes in the network. These nodes then gossip information through the network of all transactions and blocks. NOTE: Tracker Server must be started first before starting any blockchain node instances. @@ -44,22 +43,18 @@ You can override default port numbering system by setting `PORT` and `P2P_PORT` ``` gcloud init # For genesis deploy -bash deploy_blockchain_genesis_gcp.sh {dev|staging|spring|summer} <# of Shards> [--setup] +bash deploy_blockchain_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--kill-only|--skip-kill] # For incremental deploy -bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <# of Shards> [--setup] +bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] ``` - Set up Ubuntu machine (if it's on a new VM) ``` bash setup_blockchain_ubuntu.sh ``` -- Copy files to a sharable folder & install yarn packages -``` -source setup_tracker_gcp.sh -``` - Start tracker server job ``` cd ain-blockchain/ -bash start_tracker_genesis_gcp.sh +bash start_tracker_genesis_gcp.sh [--keep-code|--no-keep-code] ``` -### Client API for development and debugging +### Client API for development and testing purposes -#### Tracker health check +#### Tracker protocol version check & health check -GET http://:5000/ +GET http://:8080/ -#### Node status check +#### Network status check -GET http://:5000/peer_nodes +GET http://:8080/network_status ## Node @@ -131,21 +126,17 @@ BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/afan-shard MIN_NUM_VALIDATORS=1 DEBUG= ``` gcloud init # For genesis deploy -bash deploy_blockchain_genesis_gcp.sh {dev|staging|spring|summer} <# of Shards> [--setup] +bash deploy_blockchain_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--kill-only|--skip-kill] # For incremental deploy -bash deploy_blockchain_incremental_gcp.sh {dev|staging|spring|summer} <# of Shards> [--setup] +bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] ``` - Set up Ubuntu machine (if it's on a new VM) ``` bash setup_blockchain_ubuntu.sh ``` -- Copy files to a sharable folder & install yarn packages -``` -source setup_node_gcp.sh -``` - Start Node server job (set shard index to 0 if you're running a root chain node) ``` -bash start_node_genesis_gcp.sh {dev|spring|summer} +bash start_node_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler] ``` ### Running with Docker @@ -217,14 +208,35 @@ yarn run test_integration Some individual tests already definded in the package.json. ``` -yarn run test_chain_util -yarn run test_state_util -yarn run test_block_pool -yarn run test_db -yarn run test_node -yarn run test_blockchain -yarn run test_dapp -yarn run test_sharding +yarn run test_unit_block_pool +yarn run test_unit_blockchain +yarn run test_unit_common_util +yarn run test_unit_consensus +yarn run test_unit_db +yarn run test_unit_event_handler +yarn run test_unit_functions +yarn run test_unit_object_util +yarn run test_unit_p2p +yarn run test_unit_p2p_util +yarn run test_unit_radix_node +yarn run test_unit_radix_tree +yarn run test_unit_rule_util +yarn run test_unit_state_manager +yarn run test_unit_state_node +yarn run test_unit_state_util +yarn run test_unit_traffic_db +yarn run test_unit_traffic_sm +yarn run test_unit_tx +yarn run test_unit_tx_pool +yarn run test_integration_dapp +yarn run test_integration_blockchain +yarn run test_integration_consensus +yarn run test_integration_event_handler +yarn run test_integration_function +yarn run test_integration_node +yarn run test_integration_he_protocol +yarn run test_integration_he_sharding +yarn run test_integration_sharding ``` The load test is also supported. @@ -232,12 +244,16 @@ The load test is also supported. yarn run loadtest ``` -### Client API for development and debugging +### Client API for development and testing purposes -#### Node health check +#### Node protocol version check GET http://:8080/ +#### Node health check + +GET http://:8080/health_check + #### Fetch latest blocks in the blockchain (up to 20 blocks) GET http://:8080/blocks From 51a139ce47f4e5919804843d2fc679355980473a Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 2 Jan 2024 15:10:32 +0900 Subject: [PATCH 02/38] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d46f05435..25374e365 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Tracker server is required by new peers who wish to join the AIN network. Each p NOTE: Tracker Server must be started first before starting any blockchain node instances. -### Running without Docker +### Running Tracker without Docker #### Local @@ -58,7 +58,7 @@ bash start_tracker_genesis_gcp.sh [--keep-code|--no-keep-code] ``` -### Client API for development and testing purposes +### Tracker Client API for development and testing purposes #### Tracker protocol version check & health check @@ -85,11 +85,11 @@ GET http://:8080/ GET http://:8080/network_status -## Node +## Blockchain Node Operates a single peer node instance of the AIN blockchain. A single blockchain node instance processes incoming transaction requests and maintains a local copy of the entire blockchain. The blockchain node first queries the tracker-server for ip addresses of other peers, and then syncs its local blockchain to the network consensus blockchain. If a node is included in the whitelist and has staked appropriate amount of AIN, it will then take part in the consensus protocol. -### Running without Docker +### Running Blockchain Node without Docker #### Local @@ -139,7 +139,7 @@ bash setup_blockchain_ubuntu.sh bash start_node_genesis_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler] ``` -### Running with Docker +### Running Blockchain Node with Docker - Pull Docker image from [Docker Hub](https://hub.docker.com/repository/docker/ainblockchain/ain-blockchain) ``` @@ -198,7 +198,7 @@ cat logger/logs/8080/ ``` --> -### How to run tests +### Testing How-Tos How to run unit test and integration test all around. ``` @@ -244,7 +244,7 @@ The load test is also supported. yarn run loadtest ``` -### Client API for development and testing purposes +### Blockchain Node Client API for development and testing purposes #### Node protocol version check From f423aa4f1596aca7ff9c9191847713431a99443d Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 2 Jan 2024 16:07:58 +0900 Subject: [PATCH 03/38] Add JSON_RPC_API.md with transaction apis --- JSON_RPC_API.md | 365 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 365 insertions(+) create mode 100644 JSON_RPC_API.md diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md new file mode 100644 index 000000000..2a878c1cb --- /dev/null +++ b/JSON_RPC_API.md @@ -0,0 +1,365 @@ +# AIN Blockchain JSON-RPC API + +## Transaction API + +### ain_getPendingTransactions + +Returns currently pending transactions. + +**Parameters** + +None. + +**Returns** + +`Array` - A list of pending transactions. + +**Example** + +Request +``` +curl -X POST --header 'Content-Type: application/json' --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getPendingTransactions", + "params": { + "protoVer": "1.0.9" + } +}' https://testnet-api.ainetwork.ai/json-rpc +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":[ + { + "status":"PENDING", + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", + "timestamp":1566736760322, + "nonce":-1, + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", + }, + { + "status":"PENDING", + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "timestamp":1566736800358, + "nonce":99 + } + ] +} +``` + +### ain_getTransactionByBlockNumberAndIndex + +Returns the transaction at the {index} position within the block with the {block_number}. + +**Parameters** + +An object with 2 properties: +- block_number: `Number` - block number +- index: `Number` - index of the transaction within the block + +**Returns** + +`Object` - The transaction. + +**Example** + +Request +``` +curl -X POST --header 'Content-Type: application/json' --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getTransactionByBlockNumberAndIndex", + "params": { + "protoVer": "1.0.9", + "block_number": 1018739, + "index": 1 + } +}' https://testnet-api.ainetwork.ai/json-rpc +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": {json + "transaction": { + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/apps/collaborative_ai/worker_info/w2udhcx6tzbqxqf0@0xd377ab38E8C9267ce0f85613680b327069d51752/status", + "value": { + "workerStatus": "running", + "currentNumberOfContainer": 0, + "updatedAt": 1661420944081 + } + }, + "nonce": -1, + "timestamp": 1661420944081, + "gas_price": 0 + }, + "signature": "0x6d652a4e0b8517bb6277db4c2679ec9da4e0f2c9166359361088fa0157288b6ca2bd756e674352fd42713d5b659b240a5ace66a24fc8abdaa995ae8f1b04bbf124aa38111e495dd7aa7502acdf789d2ff18d360d59f42780ac17ac76fa1d92771b", + "hash": "0x6d652a4e0b8517bb6277db4c2679ec9da4e0f2c9166359361088fa0157288b6c", + "address": "0xd377ab38E8C9267ce0f85613680b327069d51752" + }, + "is_executed": true, + "is_finalized": true + }, + "protoVer": "1.0.9" + } +} +``` + +### ain_getTransactionByBlockHashAndIndex + +Returns the transaction at the {index} position in the block with the {block_hash}. + +**Parameters** + +An object with 2 properties: + +- block_hash: `String` - block hash +- index: `Number` - index of the transaction within the block + +**Returns** + +`Object` - The transaction. + +### + +**Example**[](#example-2) + +Request +``` +curl -X POST --header 'Content-Type: application/json' --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getTransactionByBlockHashAndIndex", + "params": { + "protoVer": "1.0.9", + "block_hash": "0x38635f8c1b3ecfaa8314698ac241341dc3ba82bc1d26e4fb5c20e21fe9ce2645", + "index": 0 + } +}' https://testnet-api.ainetwork.ai/json-rpc +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "transaction": { + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/apps/collaborative_ai/worker_info/w2udhcx6tzbqxqf0@0xd377ab38E8C9267ce0f85613680b327069d51752", + "value": { + "ethAddress": "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E", + "containerSpec": { + "cpu": { + "name": "Intel® Xeon®", + "vcpu": 1 + }, + "gpu": { + "name": "nvidia-tesla-t4", + "memoryGB": 16, + "count": 1 + }, + "memory": { + "maxGB": 4 + }, + "storage": { + "maxGB": 128 + }, + "maxNumberOfContainer": 1, + "hasEndpoint": true + }, + "labels": { + "spec": "nc6", + "managedBy": "run-your-node" + }, + "createdAt": 1661420943970 + } + }, + "nonce": -1, + "timestamp": 1661420943970, + "gas_price": 0 + }, + "signature": "0x2c9ffeb45b3377471b8c88e07159cfe0156278338a6763f0e9437f059623997398bd5469498192da259a90e279d4c85510341d05c8ff268f62d4d1299965a503148ad4e1430ab91734764cf0ed048d8a8df4e80c64f4cd3e1a10e0358e447f6c1c", + "hash": "0x2c9ffeb45b3377471b8c88e07159cfe0156278338a6763f0e9437f0596239973", + "address": "0xd377ab38E8C9267ce0f85613680b327069d51752" + }, + "is_executed": true, + "is_finalized": true + }, + "protoVer": "1.0.9" + } +} +``` + +### ain_getTransactionByHash + +Returns the transaction with the hash. + +**Parameters** + +An object with a property: + +- hash: `String` - transaction hash + +**Returns** + +`Object` - the transaction. + +**Example** + +Request +``` +curl -X POST --header 'Content-Type: application/json' --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getTransactionByHash", + "params": { + "protoVer": "1.0.9", + "hash": "0xa38fabd1daa7d7d0488275d146bebcacd088eda0069987606a61407c680eb8d9", + "index": 0 + } +}' https://testnet-api.ainetwork.ai/json-rpc +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "state": "FINALIZED", + "number": 1161159, + "index": 0, + "address": "0x4db42BDE411AfC23B8F3b26EE7AE73DA28c9e470", + "timestamp": 1664272982427, + "is_executed": true, + "is_finalized": true, + "tracked_at": 1664273029387, + "executed_at": 1664272982539, + "finalized_at": 1664273029387, + "transaction": "0xa38fabd1daa7d7d0488275d146bebcacd088eda0069987606a61407c680eb8d9", + "receipt": { + "code": 0, + "gas_amount_charged": 0, + "gas_cost_total": 0 + } + }, + "protoVer": "1.0.9" + } +} +``` + +### ain_sendSignedTransaction + +Sends the signature and the transaction object to the node. + +**Parameters** + +An object with following properties: + +- signature: `String` - signature of the transaction +- transaction: `Object` - transaction object + +**Returns** + +`String` - the transaction's hash. + +**Example** + +Request +``` +curl -X POST --header 'Content-Type: application/json' --data '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_sendSignedTransaction", + "params": { + "protoVer": "1.0.9", + "signature": "0xdb61ef...FILL_THIS", + "transaction":{ + "nonce":123, + "timestamp":1566736760322, + "operation":{ + "ref":"/account/0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812/balance", + "type":"SET_VALUE", + "value":1000 + }, + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56..." + } + } +}' https://testnet-api.ainetwork.ai/json-rpc +``` + +### ain_sendSignedTransactionBatch + +Sends multiple transactions at once. + +**Parameters** + +An object with a property: + +- `Array` - an array of transaction objects (with signature and transaction properties) + +**Returns** + +`Array` - an array of transaction hashes. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_sendSignedTransactionBatch", + "params":{"tx_list":[ + { + "signature":"0xaabc9ddafffb2ae0bac4107697547d22d9383...", + "transaction":{ + "nonce":120, + "timestamp":1566736760322, + "operation":{"ref":"path/","value":"value","type":"SET_VALUE"} + } + }, + { + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "transaction":{ + "nonce":121, + "timestamp":1566736760400, + "operation":{"ref":"path/path/","value":100,"type":"SET_VALUE"} + } + } + ]} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":[ + "0x88df016429689c079f3b2f6ad39fa052532c56795b733da7...", + "0x8e4340ea3983d86e4b6c44249362f716ec9e09849ef9b6e3..." + ] +} +``` + From 9a0fcad823575cc99359682549086555a9144586 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 3 Jan 2024 12:49:14 +0900 Subject: [PATCH 04/38] Add block apis to JSON_RPC_API.md --- JSON_RPC_API.md | 574 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 574 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 2a878c1cb..ebae95806 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -363,3 +363,577 @@ Response } ``` +--- + +## Block API + +### ain_getPendingTransactions + +Returns the most recent block. + +**Parameters** + +None. + +**Returns** + +`Object` - The most recent block. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getRecentBlock"}' +``` +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":{ + "timestamp":1564845946382, + "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", + "number":675, + "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812", + "validators":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ], + "size":163591, + "transactions":[ + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", + "timestamp":1566736760322, + "nonce":-1, + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", + "operation":{ ... } + }, + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "timestamp":1566736780022, + "nonce":99, + "operation":{ ... } + }, + ... + ] + } +} +``` + +## ain_getRecentBlockNumber + +Returns the most recent block's block number. + +**Parameters** + +None. + +**Returns** + +`Number` - The most recent block's block number. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getRecentBlockNumber"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":98347 +} +``` + +## ain_getBlockByNumber + +Returns the block with the given block number. + +**Parameters** + +An object with properties: + +- number: `Number` - the block number +- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. + +**Returns** + +`Object` - A block object. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getBlockByNumber","params":{"number":675,"getFullTransactions":true}}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":{ + "timestamp":1564845946382, + "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", + "number":675, + "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812", + "validators":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ], + "size":163591, + "transactions":[ + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", + "timestamp":1566736760322, + "nonce":-1, + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", + "operation":{ ... } + }, + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "timestamp":1566736780022, + "nonce":99, + "operation":{ ... } + }, + ... + ] + } +} +``` + +## ain_getBlockByHash + +Returns the block with the specified block hash. + +**Parameters** + +An object with properties: + +- hash: `String` - block hash +- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. + +**Returns** + +`Object` - The block. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBlockByHash", + "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "getFullTransactions":true} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":{ + "timestamp":1564845946382, + "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", + "number":67526, + "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", + "validators":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ], + "size":163591, + "transactions":[ + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", + "timestamp":1566736760322, + "nonce":-1 + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", + "operation":{ ... } + }, + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "timestamp":1566736760400, + "nonce":99, + "operation":{ ... } + }, + ... + ] + } +} +``` + +## ain_getBlocks + +Returns a list of blocks that have a block number between "from" block number and "to" block number. + +**Parameters** + +An object with properties: + +- from: `Number` - the block number of the starting block +- to: `Number` - the block number of the last block to get + +**Returns** + +`Array` - The list of blocks. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBlocks", + "params":{"from":0,"to":100} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result": + [ + { + "timestamp":1564845946382, + "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "parent_hash":"", + "number":0, + "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", + "validators":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ], + "size":163591, + "transactions":[ + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", + "timestamp":1566736760322, + "nonce":-1 + "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", + "operation":{ ... } + }, + { + "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", + "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", + "signature":"0x1ec191ef20b0e9628c4397665977cb...", + "timestamp":1566736760400, + "nonce":99, + "operation":{ ... } + }, + ... + ] + }, + ... + ] +} +``` + +## ain_getBlockHeaders + +Returns a list of block headers that have a block number between "from" block number and "to" block number. + +**Parameters** + +An object with properties: + +- from: `Number` - the block number of the starting block +- to: `Number` - the block number of the last block to get + +**Returns** + +`Array` - The list of block headers. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBlockHeaders", + "params":{"from":0,"to":100} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result": + [ + { + "timestamp":1564845946382, + "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "parent_hash":"", + "number":0, + "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", + "validators":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ], + "size":163591, + }, + ... + ] +} +``` + +## ain_getBlockTransactionCountByNumber + +Returns the number of transactions in the block with the specified block number. + +**Parameters** + +An object with a property: + +- number: `Number` - block number + +**Returns** + +`Number` - Number of transactions in the block. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBlockTransactionCountByNumber", + "params":{"number":"123"} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":11 +} +``` + +## ain_getBlockTransactionCountByHash + +Returns the number of transactions in the block with the specified block hash. + +**Parameters** + +An object with a property: + +- hash: `String` - block hash + +**Returns** + +`Number` - Number of transactions + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBlockTransactionCountByNumber", + "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":11 +} +``` + +## ain_getProposerByHash + +Returns the proposer who produced the block with the given block hash. + +**Parameters** + +An object with a property: + +- hash: `String` - block hash + +**Returns** + +`String` - The address of the proposer. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getProposerByHash", + "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" +} +``` + +## ain_getProposerByNumber + +Returns the proposer who produced the block with the given block number. + +**Parameters** + +An object with a property: + +- number: `Number` - block number + +**Returns** + +`String` - The proposer's address. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getProposerByNumber", + "params":{"number":456} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" +} +``` + +## ain_getValidatorsByHash + +Returns the validators who validated the block. + +**Parameters** + +An object with a property: + +- hash: `String` - block hash + +**Returns** + +`Array` - The list of validators. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getValidatorsByHash", + "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ] +} +``` + +## ain_getValidatorsByNumber + +Returns the validators who validated the block. + +**Parameters** + +An object with a property: + +- number: `Number` - block number + +**Returns** + +`Array` - The list of validators. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getValidatorsByNumber", + "params":{"number":2143} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ] +} +``` + From 2809a22014b7c60684251f238b856d3f74695deb Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 4 Jan 2024 15:02:26 +0900 Subject: [PATCH 05/38] Add database api and account api to json_rpc_api.md file --- JSON_RPC_API.md | 192 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index ebae95806..934613bb7 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -1,5 +1,196 @@ # AIN Blockchain JSON-RPC API +## Database API + +### ain_get + +Returns the value, write rule, owner rule, or function at the given path in the global state tree. + +**Parameters** + + +**Returns** + +The Array of data/rule/owner data/function hash at each path. The order will be preserved, and if there isn't data present at the path, `null` will be at the path's index. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_get", + "params":{ + "type": "GET" + "op_list": [ + {"ref": "afan/user123/balance","type": "GET_VALUE"}, + {"ref": "afan/$userId","type": "GET_RULE"} + ] + } +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":[1000, {".rule": {"write": "'$userId' === auth"}}] +} +``` + +--- + +## Account API + +### ain_getBalance + +Returns the balance of an account. + +**Parameters** + +An object with a property: + +- address: `String` - address of the account to get the balance of. + +**Returns** + +`Number` - The balance. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getBalance", + "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":98347 +} +``` + +### ain_getConsensusStakeAmount + +Returns the amount of AIN the account (node) is staking for participating in the consensus protocol. + +**Parameters**[](#parameters-1) + +An object with a property: + +- address: `String` - address of the account. + +**Returns** + +`Number` - The amount at stake. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getConsensusStakeAmount", + "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":1000 +} +``` + +### ain_getNonce + +Returns the nonce (= number of transactions an address has sent) of an address. + +**Parameters** + +An object with a property: + +- address: `String` - address of the account to get the transaction count of + +**Returns** + +`Number` - The nonce. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_getNonce", + "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":10 +} +``` + +### ain_isValidator + +Returns whether the node is currently a validator or not. + +**Parameters** + +An object with a property: + +- address: `String` - address of the account to check if it's currently in the validator set + +**Returns** + +`Boolean` - Whether the node is a validator or not. + +**Example** + +Request +``` +curl -X POST --data +'{ + "jsonrpc":"2.0", + "id":1, + "method":"ain_isValidator", + "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":true +} +``` + +--- + ## Transaction API ### ain_getPendingTransactions @@ -937,3 +1128,4 @@ Response } ``` +--- \ No newline at end of file From bf80b2b5d784d2add1bd123502a40a57844b998a Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 8 Jan 2024 10:14:05 +0900 Subject: [PATCH 06/38] Add network api to json_rpc_api.md file --- JSON_RPC_API.md | 151 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 934613bb7..be5862f87 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -1128,4 +1128,155 @@ Response } ``` +--- + +## Network API + +### net_listening + +Returns whether the node is listening for network connections. + +**Parameters** + +None. + +**Returns** + +`Boolean` - true is the node is listening for connections; otherwise, false. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_listening"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":true +} +``` + +### net_nodeInfo + +Returns the node's information. + +**Parameters** + +None. + +**Returns** + +`Object` - the object containing node's information. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_nodeInfo"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":{ + "name":"comcom_node", + "location":"KOR", + "version":"1.0.0" + } +} +``` + +### net_peerCount + +Returns the number of peers the node is connected to. + +**Parameters** + +None. + +**Returns** + +`Number` - number of peers. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_peerCount"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":7 +} +``` + +### net_syncing + +Returns whether the node is syncing with the network or not. + +**Parameters** + +None. + +**Returns** + +`Boolean` - true if the node is syncing, false otherwise. + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_syncing"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":true +} +``` + +### net_id + +Returns the network id. + +**Parameters** + +None. + +**Returns** + +`Number` - the network id. + +- 0: main network +- 1: test network + +**Example** + +Request +``` +curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_id"}' +``` + +Response +``` +{ + "jsonrpc":"2.0", + "id":1, + "result":0 +} +``` + --- \ No newline at end of file From a7d1502696ce649a3a8ac5317724ce5ffadadf3e Mon Sep 17 00:00:00 2001 From: platfowner Date: Wed, 10 Jan 2024 14:48:02 +0900 Subject: [PATCH 07/38] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 25374e365..abe9ebad3 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ ### [AI Network](https://ainetwork.ai) | [Whitepaper](https://c9ede755-23ca-410d-8a9d-e5b895cd95bb.filesusr.com/ugd/4f6eb2_482a2386addb4c3283ee6e26f8ad42e6.pdf) | [Documentation](https://docs.ainetwork.ai/) Official Javascript implementation of AI Network Blockchain. +## JSON-RPC API + +For accessing AIN Blockchain nodes, see [JSON_RPC_API.md](./JSON_RPC_API.md). + ## Install Environment (Last update at 6th of Dec 2021) ### OS From c71603b0b6c21cc34679aa41ebe6d2490aee006a Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 11 Jan 2024 15:36:12 +0900 Subject: [PATCH 08/38] Update JSON_RPC_API.md Add table of contents. --- JSON_RPC_API.md | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index be5862f87..f80f49d0e 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -1,5 +1,43 @@ # AIN Blockchain JSON-RPC API +## Table of Contents + +- [Database API](#database-api) + - [ain_get](#ain_get) +- [Account API](#account-api) + - [ain_getBalance](#ain_getbalance) + - [ain_getConsensusStakeAmount](#ain_getconsensusstakeamount) + - [ain_getNonce](#ain_getnonce) + - [ain_isValidator](#ain_isvalidator) +- [Transaction API](#transaction-api) + - [ain_getPendingTransactions](#ain_getpendingtransactions) + - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) + - [ain_getTransactionByBlockHashAndIndex](#ain_gettransactionbyblockhashandindex) + - [ain_getTransactionByHash](#ain_gettransactionbyhash) + - [ain_sendSignedTransaction](#ain_sendsignedtransaction) + - [ain_sendSignedTransactionBatch](#ain_sendsignedtransactionbatch) +- [Block API](#block-api) + - [ain_getRecentBlock](#ain_getrecentblock) + - [ain_getRecentBlockNumber](#ain_getrecentblocknumber) + - [ain_getBlockByNumber](#ain_getblockbynumber) + - [ain_getBlockByHash](#ain_getblockbyhash) + - [ain_getBlocks](#ain_getblocks) + - [ain_getBlockHeaders](#ain_getblockheaders) + - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) + - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) + - [ain_getProposerByHash](#ain_getproposerbyhash) + - [ain_getProposerByNumber](#ain_getproposerbynumber) + - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) + - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) +- [Network API](#network-api) + - [net_listening](#net_listening) + - [net_nodeInfo](#net_nodeinfo) + - [net_peerCount](#net_peercount) + - [net_syncing](#net_syncing) + - [net_id](#net_id) + +--- + ## Database API ### ain_get @@ -558,7 +596,7 @@ Response ## Block API -### ain_getPendingTransactions +### ain_getRecentBlock Returns the most recent block. @@ -1279,4 +1317,4 @@ Response } ``` ---- \ No newline at end of file +--- From 47f7aa13f5a0113a301ef41e6309c23934a36d33 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Tue, 30 Jan 2024 14:14:18 +0900 Subject: [PATCH 09/38] Fix curl command line options in the json rpc md file --- JSON_RPC_API.md | 539 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 406 insertions(+), 133 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index f80f49d0e..5590000de 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -51,20 +51,34 @@ Returns the value, write rule, owner rule, or function at the given path in the The Array of data/rule/owner data/function hash at each path. The order will be preserved, and if there isn't data present at the path, `null` will be at the path's index. -**Example** +**Examples** Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_get", - "params":{ - "type": "GET" +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_get", + "params": { + "protoVer": "1.1.3", + "type": "GET", "op_list": [ - {"ref": "afan/user123/balance","type": "GET_VALUE"}, - {"ref": "afan/$userId","type": "GET_RULE"} + { + "type": "GET_VALUE", + "ref": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" + }, + { + "type": "GET_RULE", + "ref": "/accounts" + }, + { + "type": "GET_FUNCTION", + "ref": "/transfer" + }, + { + "type": "GET_OWNER", + "ref": "/apps/consensus" + } ] } }' @@ -72,10 +86,209 @@ curl -X POST --data Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":[1000, {".rule": {"write": "'$userId' === auth"}}] +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": [ + { + "0": { + "value": 11000000 + } + }, + { + "$user_addr": { + "balance": { + ".rule": { + "write": "auth.fid === '_transfer'" + } + } + } + }, + { + "$from": { + "$to": { + "$key": { + "value": { + ".function": { + "_transfer": { + "function_type": "NATIVE", + "function_id": "_transfer" + } + } + } + } + } + } + }, + { + ".owner": { + "owners": { + "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc": { + "branch_owner": true, + "write_function": true, + "write_owner": true, + "write_rule": true + } + } + } + } + ], + "protoVer": "1.1.3" + } +} +``` + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_get", + "params": { + "protoVer": "1.1.3", + "type": "GET_VALUE", + "ref": "/blockchain_params" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "token": { + "name": "AI Network", + "symbol": "AIN", + "total_supply": 700000000, + "bridge": { + "ETH": { + "3": { + "0xB16c0C80a81f73204d454426fC413CAe455525A7": { + "token_pool": "0x00AA7d797FB091AF6dD57ec71Abac8D2066BE298", + "min_checkout_per_request": 10000, + "max_checkout_per_request": 100000, + "max_checkout_per_day": 1000000, + "checkout_fee_rate": 0.001, + "token_exchange_rate": 1, + "token_exchange_scheme": "FIXED" + } + } + } + } + }, + "consensus": { + "min_stake_for_proposer": 10000000, + "max_stake_for_proposer": 10000000, + "min_num_validators": 5, + "max_num_validators": 20, + "genesis_proposer_whitelist": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": true, + "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d": true, + "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211": true, + "0x003AD6FdB06684175e7D95EcC36758B014517E4b": true, + "0x004A2550661c8a306207C9dabb279d5701fFD66e": true + }, + "genesis_validator_whitelist": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": true, + "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d": true, + "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211": true, + "0x003AD6FdB06684175e7D95EcC36758B014517E4b": true, + "0x004A2550661c8a306207C9dabb279d5701fFD66e": true, + "0x005A3c55EcE1A593b761D408B6E6BC778E0a638B": true, + "0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe": true, + "0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74": true, + "0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba": true, + "0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD": true + }, + "genesis_validators": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d": { + "stake": 10000000, + "proposal_right": true + }, + "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211": { + "stake": 10000000, + "proposal_right": true + }, + "0x003AD6FdB06684175e7D95EcC36758B014517E4b": { + "stake": 10000000, + "proposal_right": true + }, + "0x004A2550661c8a306207C9dabb279d5701fFD66e": { + "stake": 10000000, + "proposal_right": true + } + }, + "health_threshold_epoch": 10, + "stake_lockup_extension": 2592000000, + "max_invalid_blocks_on_mem": 100 + }, + "genesis": { + "genesis_addr": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc", + "genesis_timestamp": 1640995199999, + "num_genesis_accounts": 10, + "epoch_ms": 20000, + "chain_id": 0, + "network_id": 0 + }, + "resource": { + "state_tree_height_limit": 30, + "state_tree_bytes_limit": 5000000000, + "state_label_length_limit": 150, + "bandwidth_budget_per_block": 1000000, + "service_state_budget_ratio": 0.5, + "apps_state_budget_ratio": 0.495, + "free_state_budget_ratio": 0.005, + "max_state_tree_size_per_byte": 0.00625, + "state_gas_coefficient": 1, + "unit_write_gas_amount": 1, + "account_registration_gas_amount": 2000, + "rest_function_call_gas_amount": 100, + "gas_price_unit": 0.000001, + "service_bandwidth_budget_ratio": 0.05, + "apps_bandwidth_budget_ratio": 0.9495, + "free_bandwidth_budget_ratio": 0.0005, + "min_staking_for_app_tx": 0, + "min_balance_for_service_tx": 0, + "max_function_urls_per_developer": 3, + "default_developers_url_whitelist": { + "0": "https://*.ainetwork.ai", + "1": "https://*.ainize.ai", + "2": "https://*.afan.ai", + "3": "http://localhost:3000" + }, + "tx_bytes_limit": 10000, + "batch_tx_list_size_limit": 50, + "set_op_list_size_limit": 50, + "min_gc_num_siblings_deleted": 10, + "snapshot_chunk_size": 1000000, + "min_gas_price": 500, + "app_creation_gas_amount": 2000 + }, + "reward": { + "type": "FIXED", + "annual_rate": 0.08 + }, + "sharding": { + "shard_owner": "", + "shard_reporter": "", + "sharding_protocol": "NONE", + "sharding_path": "/", + "parent_chain_poc": "", + "reporting_period": 0, + "max_shard_report": 100, + "num_shard_report_deleted": 100 + } + }, + "protoVer": "1.1.3" + } } ``` @@ -101,12 +314,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBalance", - "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBalance", + "params": { + "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + } }' ``` @@ -137,12 +351,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getConsensusStakeAmount", - "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getConsensusStakeAmount", + "params": { + "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + } }' ``` @@ -173,12 +388,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getNonce", - "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getNonce", + "params": { + "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + } }' ``` @@ -209,12 +425,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_isValidator", - "params":{"address":"0xc94770007dda54cF92009BFF0dE90c06F603a09f"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_isValidator", + "params": { + "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + } }' ``` @@ -247,14 +464,14 @@ None. Request ``` -curl -X POST --header 'Content-Type: application/json' --data '{ +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "ain_getPendingTransactions", "params": { "protoVer": "1.0.9" } -}' https://testnet-api.ainetwork.ai/json-rpc +}' ``` Response @@ -302,7 +519,7 @@ An object with 2 properties: Request ``` -curl -X POST --header 'Content-Type: application/json' --data '{ +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "ain_getTransactionByBlockNumberAndIndex", @@ -311,7 +528,7 @@ curl -X POST --header 'Content-Type: application/json' --data '{ "block_number": 1018739, "index": 1 } -}' https://testnet-api.ainetwork.ai/json-rpc +}' ``` Response @@ -369,7 +586,7 @@ An object with 2 properties: Request ``` -curl -X POST --header 'Content-Type: application/json' --data '{ +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "ain_getTransactionByBlockHashAndIndex", @@ -378,7 +595,7 @@ curl -X POST --header 'Content-Type: application/json' --data '{ "block_hash": "0x38635f8c1b3ecfaa8314698ac241341dc3ba82bc1d26e4fb5c20e21fe9ce2645", "index": 0 } -}' https://testnet-api.ainetwork.ai/json-rpc +}' ``` Response @@ -455,7 +672,7 @@ An object with a property: Request ``` -curl -X POST --header 'Content-Type: application/json' --data '{ +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "ain_getTransactionByHash", @@ -464,7 +681,7 @@ curl -X POST --header 'Content-Type: application/json' --data '{ "hash": "0xa38fabd1daa7d7d0488275d146bebcacd088eda0069987606a61407c680eb8d9", "index": 0 } -}' https://testnet-api.ainetwork.ai/json-rpc +}' ``` Response @@ -515,7 +732,7 @@ An object with following properties: Request ``` -curl -X POST --header 'Content-Type: application/json' --data '{ +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, "method": "ain_sendSignedTransaction", @@ -533,7 +750,7 @@ curl -X POST --header 'Content-Type: application/json' --data '{ "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56..." } } -}' https://testnet-api.ainetwork.ai/json-rpc +}' ``` ### ain_sendSignedTransactionBatch @@ -554,29 +771,38 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_sendSignedTransactionBatch", - "params":{"tx_list":[ - { - "signature":"0xaabc9ddafffb2ae0bac4107697547d22d9383...", - "transaction":{ - "nonce":120, - "timestamp":1566736760322, - "operation":{"ref":"path/","value":"value","type":"SET_VALUE"} - } - }, - { - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "transaction":{ - "nonce":121, - "timestamp":1566736760400, - "operation":{"ref":"path/path/","value":100,"type":"SET_VALUE"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_sendSignedTransactionBatch", + "params": { + "tx_list": [ + { + "signature": "0xaabc9ddafffb2ae0bac4107697547d22d9383...", + "transaction": { + "nonce": 120, + "timestamp": 1566736760322, + "operation": { + "ref": "path/", + "value": "value", + "type": "SET_VALUE" + } + } + }, + { + "signature": "0x1ec191ef20b0e9628c4397665977cb...", + "transaction": { + "nonce": 121, + "timestamp": 1566736760400, + "operation": { + "ref": "path/path/", + "value": 100, + "type": "SET_VALUE" + } + } } - } - ]} + ] + } }' ``` @@ -612,7 +838,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getRecentBlock"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getRecentBlock" +}' ``` Response ``` @@ -671,7 +901,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getRecentBlockNumber"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getRecentBlockNumber" +}' ``` Response @@ -702,7 +936,15 @@ An object with properties: Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"ain_getBlockByNumber","params":{"number":675,"getFullTransactions":true}}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlockByNumber", + "params": { + "number": 675, + "getFullTransactions": true + } +}' ``` Response @@ -765,13 +1007,14 @@ An object with properties: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBlockByHash", - "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "getFullTransactions":true} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlockByHash", + "params": { + "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "getFullTransactions": true + } }' ``` @@ -835,12 +1078,14 @@ An object with properties: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBlocks", - "params":{"from":0,"to":100} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlocks", + "params": { + "from": 0, + "to": 100 + } }' ``` @@ -908,12 +1153,14 @@ An object with properties: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBlockHeaders", - "params":{"from":0,"to":100} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlockHeaders", + "params": { + "from": 0, + "to": 100 + } }' ``` @@ -960,12 +1207,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBlockTransactionCountByNumber", - "params":{"number":"123"} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlockTransactionCountByNumber", + "params": { + "number": "123" + } }' ``` @@ -996,12 +1244,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getBlockTransactionCountByNumber", - "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getBlockTransactionCountByNumber", + "params": { + "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + } }' ``` @@ -1032,12 +1281,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getProposerByHash", - "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getProposerByHash", + "params": { + "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + } }' ``` @@ -1068,12 +1318,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getProposerByNumber", - "params":{"number":456} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getProposerByNumber", + "params": { + "number": 456 + } }' ``` @@ -1104,12 +1355,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getValidatorsByHash", - "params":{"hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484..."} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getValidatorsByHash", + "params": { + "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + } }' ``` @@ -1144,12 +1396,13 @@ An object with a property: Request ``` -curl -X POST --data -'{ - "jsonrpc":"2.0", - "id":1, - "method":"ain_getValidatorsByNumber", - "params":{"number":2143} +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getValidatorsByNumber", + "params": { + "number": 2143 + } }' ``` @@ -1186,7 +1439,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_listening"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_listening" +}' ``` Response @@ -1214,7 +1471,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_nodeInfo"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_nodeInfo" +}' ``` Response @@ -1246,7 +1507,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_peerCount"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_peerCount" +}' ``` Response @@ -1274,7 +1539,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_syncing"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_syncing" +}' ``` Response @@ -1305,7 +1574,11 @@ None. Request ``` -curl -X POST --data '{"jsonrpc":"2.0","id":1,"method":"net_id"}' +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_id" +}' ``` Response From 54b87d575b4d3d1d59750df2e39acf664f198014 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 31 Jan 2024 16:39:34 +0900 Subject: [PATCH 10/38] Add match apis to json rpc api md file --- JSON_RPC_API.md | 205 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 1 deletion(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 5590000de..c17b4941f 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -46,10 +46,13 @@ Returns the value, write rule, owner rule, or function at the given path in the **Parameters** +An array of objects with a property: + +- ref: `String` - reference path **Returns** -The Array of data/rule/owner data/function hash at each path. The order will be preserved, and if there isn't data present at the path, `null` will be at the path's index. +The array of data/rule/owner data/function hash at each path. The order will be preserved, and if there isn't data present at the path, `null` will be at the path's index. **Examples** @@ -292,6 +295,206 @@ Response } ``` +### ain_matchFunction + +Returns the functions matched at the given value path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference value path + +**Returns** + +The matched functions. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_matchFunction", + "params": { + "protoVer": "1.1.3", + "ref": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/1/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "matched_path": { + "target_path": "/transfer/$from/$to/$key/value", + "ref_path": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/1/value", + "path_vars": { + "$key": "1", + "$to": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "$from": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" + } + }, + "matched_config": { + "path": "/transfer/$from/$to/$key/value", + "config": { + "_transfer": { + "function_type": "NATIVE", + "function_id": "_transfer" + } + } + }, + "subtree_configs": [] + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_matchRule + +Returns the rules matched at the given value path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference value path + +**Returns** + +The matched rules. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_matchRule", + "params": { + "protoVer": "1.1.3", + "ref": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/1/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "write": { + "matched_path": { + "target_path": "/transfer/$from/$to/$key/value", + "ref_path": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/1/value", + "path_vars": { + "$key": "1", + "$to": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "$from": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" + } + }, + "matched_config": { + "path": "/transfer/$from/$to/$key/value", + "config": { + "write": "(auth.addr === $from || auth.fid === '_stake' || auth.fid === '_unstake' || auth.fid === '_pay' || auth.fid === '_claim' || auth.fid === '_hold' || auth.fid === '_release' || auth.fid === '_collectFee' || auth.fid === '_claimReward' || auth.fid === '_openCheckout' || auth.fid === '_closeCheckout' || auth.fid === '_closeCheckin') && !getValue('transfer/' + $from + '/' + $to + '/' + $key) && (util.isServAcntName($from, blockNumber) || util.isCksumAddr($from)) && (util.isServAcntName($to, blockNumber) || util.isCksumAddr($to)) && $from !== $to && util.isNumber(newData) && newData > 0 && util.countDecimals(newData) <= 6 && util.getBalance($from, getValue) >= newData" + } + }, + "subtree_configs": [] + }, + "state": { + "matched_path": { + "target_path": "/transfer/$from/$to/$key/value", + "ref_path": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/1/value", + "path_vars": { + "$key": "1", + "$to": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "$from": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" + } + }, + "matched_config": { + "path": "/transfer/$from/$to/$key", + "config": { + "state": { + "gc_max_siblings": 10, + "gc_num_siblings_deleted": 10 + } + } + } + } + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_matchOwner + +Returns the owners matched at the given value path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference value path + +**Returns** + +The matched owners. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_matchOwner", + "params": { + "protoVer": "1.1.3", + "ref": "/apps/consensus" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "matched_path": { + "target_path": "/apps/consensus" + }, + "matched_config": { + "path": "/apps/consensus", + "config": { + "owners": { + "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc": { + "branch_owner": true, + "write_function": true, + "write_owner": true, + "write_rule": true + } + } + } + }, + "subtree_configs": [] + }, + "protoVer": "1.1.3" + } +} +``` + --- ## Account API From 783232aa5b0bdbb6e8393b255c5220766ae6e761 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 31 Jan 2024 18:16:33 +0900 Subject: [PATCH 11/38] Add eval apis to json rpc api md file --- JSON_RPC_API.md | 192 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index c17b4941f..1526d0431 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -495,6 +495,198 @@ Response } ``` +### ain_evalRule + +Evaluates the rule configs matched with the given value path in the global state tree with the given parameters. + +**Parameters** + +An object with a property: + +- ref: `String` - reference value path +- value: `String|Number|Boolean|Object` - value to write +- address: `String` - account address (optional) +- fid: `String` - function id (optional) +- timestamp: `Number` - timestamp in milliseconds (optional) + +**Returns** + +The rule evaluation result. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_evalRule", + "params": { + "protoVer": "1.1.3", + "ref": "/transfer/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4/100000/value", + "address": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc", + "value": 100, + "timestamp": 1706691334000 + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "code": 0, + "matched": { + "write": { + "matchedValuePath": [ + "transfer", + "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc", + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "100000", + "value" + ], + "matchedRulePath": [ + "transfer", + "$from", + "$to", + "$key", + "value" + ], + "pathVars": { + "$key": "100000", + "$to": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "$from": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" + }, + "closestRule": { + "path": [ + "transfer", + "$from", + "$to", + "$key", + "value" + ], + "config": { + "write": "(auth.addr === $from || auth.fid === '_stake' || auth.fid === '_unstake' || auth.fid === '_pay' || auth.fid === '_claim' || auth.fid === '_hold' || auth.fid === '_release' || auth.fid === '_collectFee' || auth.fid === '_claimReward' || auth.fid === '_openCheckout' || auth.fid === '_closeCheckout' || auth.fid === '_closeCheckin') && !getValue('transfer/' + $from + '/' + $to + '/' + $key) && (util.isServAcntName($from, blockNumber) || util.isCksumAddr($from)) && (util.isServAcntName($to, blockNumber) || util.isCksumAddr($to)) && $from !== $to && util.isNumber(newData) && newData > 0 && util.countDecimals(newData) <= 6 && util.getBalance($from, getValue) >= newData" + } + }, + "subtreeRules": [] + }, + "state": { + "matchedValuePath": [ + "transfer", + "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc", + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "100000", + "value" + ], + "matchedRulePath": [ + "transfer", + "$from", + "$to", + "$key", + "value" + ], + "pathVars": { + "$key": "100000", + "$to": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "$from": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" + }, + "closestRule": { + "path": [ + "transfer", + "$from", + "$to", + "$key" + ], + "config": { + "state": { + "gc_max_siblings": 10, + "gc_num_siblings_deleted": 10 + } + } + } + } + } + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_evalOwner + +Evaluates the owner configs matched with the given value path in the global state tree with the given parameters. + +**Parameters** + +An object with a property: + +- ref: `String` - reference value path +- permission: `'write_rule'|'write_function'|'write_owner'|'branch_owner'` - permission to evaluate with +- address: `String` - account address (optional) +- fid: `String` - function id (optional) + +**Returns** + +The owner evaluation result. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_evalOwner", + "params": { + "protoVer": "1.1.3", + "ref": "/apps/consensus", + "address": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc", + "permission": "write_rule" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "code": 0, + "matched": { + "matchedOwnerPath": [ + "apps", + "consensus" + ], + "closestOwner": { + "path": [ + "apps", + "consensus" + ], + "config": { + "owners": { + "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc": { + "branch_owner": true, + "write_function": true, + "write_owner": true, + "write_rule": true + } + } + } + }, + "subtreeOwners": [] + } + }, + "protoVer": "1.1.3" + } +} +``` + --- ## Account API From 57a62c0f2a0aed2fa436f82c069cefc898d054c9 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 31 Jan 2024 18:40:04 +0900 Subject: [PATCH 12/38] Add ain_getStateProof api to JSON_RPC_API.md file --- JSON_RPC_API.md | 343 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 343 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 1526d0431..1c0b01808 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -295,6 +295,36 @@ Response } ``` +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_get", + "params": { + "protoVer": "1.1.3", + "type": "GET_RULE", + "ref": "/transfer/$from/$to/$key/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + ".rule": { + "write": "(auth.addr === $from || auth.fid === '_stake' || auth.fid === '_unstake' || auth.fid === '_pay' || auth.fid === '_claim' || auth.fid === '_hold' || auth.fid === '_release' || auth.fid === '_collectFee' || auth.fid === '_claimReward' || auth.fid === '_openCheckout' || auth.fid === '_closeCheckout' || auth.fid === '_closeCheckin') && !getValue('transfer/' + $from + '/' + $to + '/' + $key) && (util.isServAcntName($from, blockNumber) || util.isCksumAddr($from)) && (util.isServAcntName($to, blockNumber) || util.isCksumAddr($to)) && $from !== $to && util.isNumber(newData) && newData > 0 && util.countDecimals(newData) <= 6 && util.getBalance($from, getValue) >= newData" + } + }, + "protoVer": "1.1.3" + } +} +``` + ### ain_matchFunction Returns the functions matched at the given value path in the global state tree. @@ -687,6 +717,319 @@ Response } ``` +### ain_getStateProof + +Returns the state proof of the given path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. + +**Returns** + +The state proof. + +**Examples** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getStateProof", + "params": { + "protoVer": "1.1.3", + "ref": "/values/accounts/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/balance" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "#state_ph": "0x10f836de97cced7bcea17d012e3a4a328b7d5f9ce016c69e01eead63bb14e7f2", + "#radix:6": { + "#radix_ph": "0xb1ee79c294caa1b2cfc76f2cb5e0204927e7f7583810b0c175915914dba859d8" + }, + "#radix:7": { + "#radix_ph": "0xb338802f148a20b6dda118cc2929794542eff272ee2c781c9aa8ce6138c3c381", + "#radix:2756c6573": { + "#radix_ph": "0x92bf1f2761726c8ff84afed4384e717c83cd5250c5e2d7acce6bad31b0829eb3" + }, + "#radix:6616c756573": { + "#radix_ph": "0x4029c9643c09aace2e958f578f930ea6563713dc4fc7d037b435acd73c0bee0d", + "#state:values": { + "#state_ph": "0x1ab3c3ec336fa9790b4706a1c3edca44613a3bab2d3bb86507a05625ce93e4c8", + "#radix:6": { + "#radix_ph": "0x5ead39186a85688c5c267bf57c21e8e813c2be8f27cfd8214ed0df605d60e836", + "#radix:1": { + "#radix_ph": "0x327ac0aaa1913dd4eac6717a5be650808d02c0df3515d48876e01092b017b09d", + "#radix:63636f756e7473": { + "#radix_ph": "0x2d8fd7d2c1650bbcd9cf8847405d3adcd66a31726fbf3d8c658230e1dcc65596", + "#state:accounts": { + "#state_ph": "0x389ef90cca395cfff34daaf1af6e8987494b75ad8a0fca9e0ec19c5ff9a0febf", + "#radix:0": { + "#radix_ph": "0x14a34c98383845ddc3736e9de2bd1966599f6c2e1ab284d6385abeff401bd6d4" + }, + "#radix:1": { + "#radix_ph": "0x00f5dc96dee4a091cbbec25cae427ead56ddd2592db2633b88680733dca4caa6" + }, + "#radix:2": { + "#radix_ph": "0x2e89ea1805894ed85b3ee1d333e356407921593b0178065a0f6d4b891859dde4" + }, + "#radix:3": { + "#radix_ph": "0xdafca44f4568ad6b86e8f6d16a4b976dc07044ac21c5f5864554c43976c0e161" + }, + "#radix:4": { + "#radix_ph": "0x7c5f33dc684e432673b1deb3e052d5af8527c6ec8b9c11354db1246287195760" + }, + "#radix:5": { + "#radix_ph": "0xb6b0149833a58d1ce778ba567e8c0a4f85290184e83317f7f055f7b0bafb9c68" + }, + "#radix:6": { + "#radix_ph": "0x3c33cc686e7fd521e81fae32c701e13bdbe6539a2ccc79f70129bb721f1cf82e" + }, + "#radix:7": { + "#radix_ph": "0x56b5e5306dbe9a372eb1d217081ef8d4b3dc101027f6019409170edfd3a4e689" + }, + "#radix:8": { + "#radix_ph": "0x61e6f316aba28f5fabf444ee65675bd7bca88ee6ea55396f39896fae52edb1ad" + }, + "#radix:9": { + "#radix_ph": "0x3656ae6b72eddf9e32c8a72727770b9e5632c28ac89cfe1f1b8df4e08b1077f0" + }, + "#radix:a": { + "#radix_ph": "0x5aa705a9892359dd62a564df75bfdd869a15b39d33cc36a801261b7b2369f856", + "#radix:0": { + "#radix_ph": "0x9cd19010900d9cebfa2c0944f3277386b5ee80206a1ae753af8f59610918086d" + }, + "#radix:1": { + "#radix_ph": "0x9f486ee766bb3e01c551c64d5ffc7448cec7a01c8a272cbf53f1bf0051494034" + }, + "#radix:2": { + "#radix_ph": "0x1177aa473e0414cf70c1aa74887cfafa1b689366116e5d0019a8861601d8d0c3" + }, + "#radix:3": { + "#radix_ph": "0x83258f3df41b6c09c741b79a2d367e695702985b55e7dd0a1376d61e9ac98f3e" + }, + "#radix:4": { + "#radix_ph": "0x7acd3dcd62dc7bd9c60752c06a7061fab0a6e18f54e45bf7871c9104bc4eaee6" + }, + "#radix:5a181bf80366ae376a10fbe1dc8bf534b8cbdfb": { + "#radix_ph": "0xd70a5e2fb33e720b1c25e42bf64d9184d111f6a2a5372bed556d152627191a51" + }, + "#radix:6": { + "#radix_ph": "0x7fd474d8d0552cf6c23e6b6c6b3cc4c53baabf939e3d2977e6c36570acc5cd74" + }, + "#radix:7": { + "#radix_ph": "0xbff4f0c2bf36bec6ed93ff94c2cc8889931cf2ba317aeabb74a42b0b69a31d57" + }, + "#radix:8": { + "#radix_ph": "0x851ab0e647e09c19440713056d3d7a8fe05e61806de9eb6f306ba2fc2dc74a24" + }, + "#radix:990a29ecfb3815c893177b22051f6fe5c71ec8f": { + "#radix_ph": "0xfe2b320ca54a98774eac7536d2fbd62c511f70ac73af2b523b4f1a4e24e39613" + }, + "#radix:a": { + "#radix_ph": "0x2b487ba0eb74c253544ebf06395109f854febe61ea8620b751f43851ff727d2a", + "#radix:3a053e56c9fc77f69298673e69ea6d5e031442": { + "#radix_ph": "0xde15c7a2e88bed3255856d9c544c749c34743f7d7273306ad13b65ccbb4f9574" + }, + "#radix:4cf08b1d0b08bb1831f14510f984e5ea5aa74f": { + "#radix_ph": "0x673899ca7db6352a28d96579afd4a21ed4ecf9eac112985c48ec6e0d2294e76d" + }, + "#radix:7ec983d5415ebedba041ca4b5e08cf7a6d0a1d": { + "#radix_ph": "0xa232d40a6240b60203f631535fa3fd7174ae719779a4e0d846ddaab08e45f857" + }, + "#radix:9bcfed3426a5bb709d1606fb1271dadc9d8d60": { + "#radix_ph": "0x673899ca7db6352a28d96579afd4a21ed4ecf9eac112985c48ec6e0d2294e76d" + }, + "#radix:aaeedff1d2cd909465182165ccc267549554fc": { + "#radix_ph": "0x84498a5b76b0e6f2ec826171e2c829856e1392c6de7a642efae1d4a990ecb0ad", + "#state:0xAAAAeEDFf1d2cD909465182165ccc267549554Fc": { + "#state_ph": "0x118f633ae944e43b9434d314875c57466b519e07ddd6b845a250d005a24fe6db", + "#radix:6": { + "#radix_ph": "0xea3ec1aaf3333a130649c66855cca3f70ca43099b1359bf84380e3eaee2efb83", + "#radix:2616c616e6365": { + "#radix_ph": "0xf7f54de888b15f1de6b2df4751aa0200b5a9d9a298bade55e6b5b9bb855541b7", + "#state:balance": { + "#state_ph": "0x48d7d6569b6ce84dbba4d36dc6fbd8457d700cfcb7a30705dc692ba07d545662" + } + }, + "#radix:e6f6e6365": { + "#radix_ph": "0x3a592cd35b802b59d3eecf39aad5ca136b013251d36a2a4af7ff054aca5f011b" + } + } + } + } + }, + "#radix:b": { + "#radix_ph": "0x363fa5c5488fac592c828defdd7b007e56eb3e538fa8280a00e2ba1dd51e1dad" + }, + "#radix:c": { + "#radix_ph": "0xc6a04610c5835fd0a3b33a71d57f4635f03566c9805b328641a401448a00c2b3" + }, + "#radix:df98a5effc56cadb8859f2cf2e5422afe9ce787": { + "#radix_ph": "0xc7b3114b7ecc3f24c84c063fd679a67a13b8963a33c6f68c6f12300d52b1d1cf" + }, + "#radix:e": { + "#radix_ph": "0xc2221b21e103d725fafb8fa5d62dde70f02f305d33e2928ae53243aa9499fdfd" + }, + "#radix:f": { + "#radix_ph": "0x0266d65bfcbed60f986b420d2ea68fd72271ec63f9b6a5f3e68c24a6c48895de" + } + }, + "#radix:b": { + "#radix_ph": "0xf68a4e7e4d7f9a71c2975519f61807bcde9a0721d92c7ddbd68d4f4f7cd103c0" + }, + "#radix:c": { + "#radix_ph": "0xce878100c7c3ef6eda8e5f78f82e884741963edc9bfa370626d16da5683e2b04" + }, + "#radix:d": { + "#radix_ph": "0xbe6155bac97c220873c5790bc3633eea252b24184436d9cc0e20d2aa9aa445e8" + }, + "#radix:e": { + "#radix_ph": "0xf2365aa692679db520c761bc5616ea8e78e7d66e8e5b7fa62f5ccede3c4ad21d" + }, + "#radix:f": { + "#radix_ph": "0x5d5f1af4318fd0ce355a0c658f8d1695c0a1f00587edf9b9543887955c15fe12" + } + } + }, + "#radix:707073": { + "#radix_ph": "0x8e3709e38db2e60381f0359985a9b11da39b69c436d91fb9fed4fe7956176bfa" + } + }, + "#radix:26c6f636b636861696e5f706172616d73": { + "#radix_ph": "0x0db35261beb8f805e4ced018ff3f0466b6f8536d5d190ef15d6ad7bb1a14bb0b" + }, + "#radix:36": { + "#radix_ph": "0x4d38d68552a062ed3da9978081154a50e24d072da2d94e8a05bf321f243167f5" + }, + "#radix:46576656c6f70657273": { + "#radix_ph": "0x6eed3986e6ce5982579a76c50ad98718dc3aa93eeae2724c9dc629264bbfb144" + }, + "#radix:57363726f77": { + "#radix_ph": "0x985b5bc09f0751dd9b36a01ef5480c0a13220b381d56ea987731a024da3ca0b9" + }, + "#radix:761735f666565": { + "#radix_ph": "0x73ef1cf919a1af7d1fc1474f98015db7921cdd4279fb73fd833958dd4d6c322a" + }, + "#radix:d616e6167655f617070": { + "#radix_ph": "0x09c91d8b6ec15ac74bee4b86f27e91a08320b817f98b906401f221fcdc7098d5" + } + }, + "#radix:7": { + "#radix_ph": "0x8b6f952e411eff64c653014abad49a9f16022c57055690a10d1d8c8a2febe566" + } + } + } + } + }, + "protoVer": "1.1.3" + } +} +``` + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getStateProof", + "params": { + "protoVer": "1.1.3", + "ref": "/rules/transfer/$from/$to/$key/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "#state_ph": "0x0f8b8321926d6b97202e1235f132b7b5abbd215ccb89a23f3a586039a8ba8eae", + "#radix:6": { + "#radix_ph": "0xb1ee79c294caa1b2cfc76f2cb5e0204927e7f7583810b0c175915914dba859d8" + }, + "#radix:7": { + "#radix_ph": "0x83ab7a2bb8e72434b1b2e4a44865b5e5651b9f11b7acff8ce79539a1ae1a31d3", + "#radix:2756c6573": { + "#radix_ph": "0x92bf1f2761726c8ff84afed4384e717c83cd5250c5e2d7acce6bad31b0829eb3", + "#state:rules": { + "#state_ph": "0xfcbc1bf027604a07c667f0c8117c4172ad03f331c940371d63b8148a8f3d0229", + "#radix:2e72756c65": { + "#radix_ph": "0xc81213b5048a9d36df0ba967b41e5e6fd91cb23fa34d7865b77d84834fe45609" + }, + "#radix:6": { + "#radix_ph": "0xc4a5af3b1505e23b6a56dc26a986f5816a03759f54a6b0198e29099cfe7a6cbc" + }, + "#radix:7": { + "#radix_ph": "0x0a601b4a4f14d03418df9a45d2fe89070fb73e1291b1e4c5c0ebf243851f353a", + "#radix:061796d656e7473": { + "#radix_ph": "0x43100c4e84ea4aaa52fa7d8178b4e2d0f1ecf48a3bbe5f386ac8eb30468ce7a6" + }, + "#radix:265636569707473": { + "#radix_ph": "0x74c9d75b14aa15aacfed1dd234afb9eb76a51e7b52de60f9b44bd1ba5bfda45a" + }, + "#radix:3": { + "#radix_ph": "0x3acc464caf851b9b4b17380651b391924bdd8d97f5d93485558cceb2b5c6de3b" + }, + "#radix:472616e73666572": { + "#radix_ph": "0xbe2ed91f86677d8fad068cc52741a20001b3bc2f1561cc252f546416165c27b6", + "#state:transfer": { + "#state_ph": "0x0141303f991e7fb0fc33c06c61cb1d3efd5ba32298216f635fd0bb2e52cdc445", + "#radix:2466726f6d": { + "#radix_ph": "0xe9d9b329ee30ad1b8b39d12bfe388fb9495eb01099acc024297b9f9ff5355f8f", + "#state:$from": { + "#state_ph": "0x7f30b158f29ae89cac37111984b773500b9560533a1418ca06e2ec84599ba9ab", + "#radix:24746f": { + "#radix_ph": "0x957b4f5e1c03df8409548cad92fe23150f3138e0aec1369d688d513d12fc3954", + "#state:$to": { + "#state_ph": "0x3f2681f1f6baadf68f7c0d6092b3bad6cfcfc237a5c4e7259515f2969eccebab", + "#radix:246b6579": { + "#radix_ph": "0xdfa83c70fa73726e41f9131659c7682216329cc53bbc2de8cde970abe8920eb2", + "#state:$key": { + "#state_ph": "0x2130187b66a8d0d04b67a3bf400c4f80e157cde53831ce6a64c9ee46a0d14a83", + "#radix:2e72756c65": { + "#radix_ph": "0x879dd0ff6e90ca3e3185cc1e302abdfe361fb97016fbedbb5949b754d7473621" + }, + "#radix:76616c7565": { + "#radix_ph": "0x621192b54cc0b6c2947e3e0c1c4b213c0803dc6961f8e5e05b1707eac55cbd1e", + "#state:value": { + "#state_ph": "0x985a1f057d5047b1dee392127eb776571fbbe79da7ae6114f8f8f18c4f786135" + } + } + } + } + } + } + } + } + } + } + } + } + }, + "#radix:6616c756573": { + "#radix_ph": "0xf59d499293446f3aef6df58e521162601cf56700e15d20105efe69fb908f515d" + } + } + }, + "protoVer": "1.1.3" + } +} +``` + --- ## Account API From 2efaeb76d16e37aeee34f4b93547d4bd424fa777 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 31 Jan 2024 19:53:11 +0900 Subject: [PATCH 13/38] Add ain_getProofHash api to JSON_RPC_API.md file --- JSON_RPC_API.md | 222 +++++++++++++++++------------------------------- 1 file changed, 78 insertions(+), 144 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 1c0b01808..eb7fce6ad 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -741,7 +741,7 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "method": "ain_getStateProof", "params": { "protoVer": "1.1.3", - "ref": "/values/accounts/0xAAAAeEDFf1d2cD909465182165ccc267549554Fc/balance" + "ref": "/values/blockchain_params" } }' ``` @@ -753,164 +753,32 @@ Response "id": 1, "result": { "result": { - "#state_ph": "0x10f836de97cced7bcea17d012e3a4a328b7d5f9ce016c69e01eead63bb14e7f2", + "#state_ph": "0xdf8694f052e026a8afeea926a69591ba24cd2b5ae16a1cb51058ad5880027602", "#radix:6": { "#radix_ph": "0xb1ee79c294caa1b2cfc76f2cb5e0204927e7f7583810b0c175915914dba859d8" }, "#radix:7": { - "#radix_ph": "0xb338802f148a20b6dda118cc2929794542eff272ee2c781c9aa8ce6138c3c381", + "#radix_ph": "0xadcddbecf4c4a26056c59784786f2fc0ed977829fc00c931e96b8d4e166af015", "#radix:2756c6573": { "#radix_ph": "0x92bf1f2761726c8ff84afed4384e717c83cd5250c5e2d7acce6bad31b0829eb3" }, "#radix:6616c756573": { - "#radix_ph": "0x4029c9643c09aace2e958f578f930ea6563713dc4fc7d037b435acd73c0bee0d", + "#radix_ph": "0xf9996bca1a7f41d9a2ffd67ea086fe215dcc678c9861e17bb6ccb051fdfd63ad", "#state:values": { - "#state_ph": "0x1ab3c3ec336fa9790b4706a1c3edca44613a3bab2d3bb86507a05625ce93e4c8", + "#state_ph": "0x2f5e6dcbc67c8b47b354584084afd8230cc88df6d54df181ea80fbf2281c3140", "#radix:6": { - "#radix_ph": "0x5ead39186a85688c5c267bf57c21e8e813c2be8f27cfd8214ed0df605d60e836", + "#radix_ph": "0xf17f4966c6480df406af1f4305d8f71df8704089a20bc2244ff6d9009278bafe", "#radix:1": { - "#radix_ph": "0x327ac0aaa1913dd4eac6717a5be650808d02c0df3515d48876e01092b017b09d", - "#radix:63636f756e7473": { - "#radix_ph": "0x2d8fd7d2c1650bbcd9cf8847405d3adcd66a31726fbf3d8c658230e1dcc65596", - "#state:accounts": { - "#state_ph": "0x389ef90cca395cfff34daaf1af6e8987494b75ad8a0fca9e0ec19c5ff9a0febf", - "#radix:0": { - "#radix_ph": "0x14a34c98383845ddc3736e9de2bd1966599f6c2e1ab284d6385abeff401bd6d4" - }, - "#radix:1": { - "#radix_ph": "0x00f5dc96dee4a091cbbec25cae427ead56ddd2592db2633b88680733dca4caa6" - }, - "#radix:2": { - "#radix_ph": "0x2e89ea1805894ed85b3ee1d333e356407921593b0178065a0f6d4b891859dde4" - }, - "#radix:3": { - "#radix_ph": "0xdafca44f4568ad6b86e8f6d16a4b976dc07044ac21c5f5864554c43976c0e161" - }, - "#radix:4": { - "#radix_ph": "0x7c5f33dc684e432673b1deb3e052d5af8527c6ec8b9c11354db1246287195760" - }, - "#radix:5": { - "#radix_ph": "0xb6b0149833a58d1ce778ba567e8c0a4f85290184e83317f7f055f7b0bafb9c68" - }, - "#radix:6": { - "#radix_ph": "0x3c33cc686e7fd521e81fae32c701e13bdbe6539a2ccc79f70129bb721f1cf82e" - }, - "#radix:7": { - "#radix_ph": "0x56b5e5306dbe9a372eb1d217081ef8d4b3dc101027f6019409170edfd3a4e689" - }, - "#radix:8": { - "#radix_ph": "0x61e6f316aba28f5fabf444ee65675bd7bca88ee6ea55396f39896fae52edb1ad" - }, - "#radix:9": { - "#radix_ph": "0x3656ae6b72eddf9e32c8a72727770b9e5632c28ac89cfe1f1b8df4e08b1077f0" - }, - "#radix:a": { - "#radix_ph": "0x5aa705a9892359dd62a564df75bfdd869a15b39d33cc36a801261b7b2369f856", - "#radix:0": { - "#radix_ph": "0x9cd19010900d9cebfa2c0944f3277386b5ee80206a1ae753af8f59610918086d" - }, - "#radix:1": { - "#radix_ph": "0x9f486ee766bb3e01c551c64d5ffc7448cec7a01c8a272cbf53f1bf0051494034" - }, - "#radix:2": { - "#radix_ph": "0x1177aa473e0414cf70c1aa74887cfafa1b689366116e5d0019a8861601d8d0c3" - }, - "#radix:3": { - "#radix_ph": "0x83258f3df41b6c09c741b79a2d367e695702985b55e7dd0a1376d61e9ac98f3e" - }, - "#radix:4": { - "#radix_ph": "0x7acd3dcd62dc7bd9c60752c06a7061fab0a6e18f54e45bf7871c9104bc4eaee6" - }, - "#radix:5a181bf80366ae376a10fbe1dc8bf534b8cbdfb": { - "#radix_ph": "0xd70a5e2fb33e720b1c25e42bf64d9184d111f6a2a5372bed556d152627191a51" - }, - "#radix:6": { - "#radix_ph": "0x7fd474d8d0552cf6c23e6b6c6b3cc4c53baabf939e3d2977e6c36570acc5cd74" - }, - "#radix:7": { - "#radix_ph": "0xbff4f0c2bf36bec6ed93ff94c2cc8889931cf2ba317aeabb74a42b0b69a31d57" - }, - "#radix:8": { - "#radix_ph": "0x851ab0e647e09c19440713056d3d7a8fe05e61806de9eb6f306ba2fc2dc74a24" - }, - "#radix:990a29ecfb3815c893177b22051f6fe5c71ec8f": { - "#radix_ph": "0xfe2b320ca54a98774eac7536d2fbd62c511f70ac73af2b523b4f1a4e24e39613" - }, - "#radix:a": { - "#radix_ph": "0x2b487ba0eb74c253544ebf06395109f854febe61ea8620b751f43851ff727d2a", - "#radix:3a053e56c9fc77f69298673e69ea6d5e031442": { - "#radix_ph": "0xde15c7a2e88bed3255856d9c544c749c34743f7d7273306ad13b65ccbb4f9574" - }, - "#radix:4cf08b1d0b08bb1831f14510f984e5ea5aa74f": { - "#radix_ph": "0x673899ca7db6352a28d96579afd4a21ed4ecf9eac112985c48ec6e0d2294e76d" - }, - "#radix:7ec983d5415ebedba041ca4b5e08cf7a6d0a1d": { - "#radix_ph": "0xa232d40a6240b60203f631535fa3fd7174ae719779a4e0d846ddaab08e45f857" - }, - "#radix:9bcfed3426a5bb709d1606fb1271dadc9d8d60": { - "#radix_ph": "0x673899ca7db6352a28d96579afd4a21ed4ecf9eac112985c48ec6e0d2294e76d" - }, - "#radix:aaeedff1d2cd909465182165ccc267549554fc": { - "#radix_ph": "0x84498a5b76b0e6f2ec826171e2c829856e1392c6de7a642efae1d4a990ecb0ad", - "#state:0xAAAAeEDFf1d2cD909465182165ccc267549554Fc": { - "#state_ph": "0x118f633ae944e43b9434d314875c57466b519e07ddd6b845a250d005a24fe6db", - "#radix:6": { - "#radix_ph": "0xea3ec1aaf3333a130649c66855cca3f70ca43099b1359bf84380e3eaee2efb83", - "#radix:2616c616e6365": { - "#radix_ph": "0xf7f54de888b15f1de6b2df4751aa0200b5a9d9a298bade55e6b5b9bb855541b7", - "#state:balance": { - "#state_ph": "0x48d7d6569b6ce84dbba4d36dc6fbd8457d700cfcb7a30705dc692ba07d545662" - } - }, - "#radix:e6f6e6365": { - "#radix_ph": "0x3a592cd35b802b59d3eecf39aad5ca136b013251d36a2a4af7ff054aca5f011b" - } - } - } - } - }, - "#radix:b": { - "#radix_ph": "0x363fa5c5488fac592c828defdd7b007e56eb3e538fa8280a00e2ba1dd51e1dad" - }, - "#radix:c": { - "#radix_ph": "0xc6a04610c5835fd0a3b33a71d57f4635f03566c9805b328641a401448a00c2b3" - }, - "#radix:df98a5effc56cadb8859f2cf2e5422afe9ce787": { - "#radix_ph": "0xc7b3114b7ecc3f24c84c063fd679a67a13b8963a33c6f68c6f12300d52b1d1cf" - }, - "#radix:e": { - "#radix_ph": "0xc2221b21e103d725fafb8fa5d62dde70f02f305d33e2928ae53243aa9499fdfd" - }, - "#radix:f": { - "#radix_ph": "0x0266d65bfcbed60f986b420d2ea68fd72271ec63f9b6a5f3e68c24a6c48895de" - } - }, - "#radix:b": { - "#radix_ph": "0xf68a4e7e4d7f9a71c2975519f61807bcde9a0721d92c7ddbd68d4f4f7cd103c0" - }, - "#radix:c": { - "#radix_ph": "0xce878100c7c3ef6eda8e5f78f82e884741963edc9bfa370626d16da5683e2b04" - }, - "#radix:d": { - "#radix_ph": "0xbe6155bac97c220873c5790bc3633eea252b24184436d9cc0e20d2aa9aa445e8" - }, - "#radix:e": { - "#radix_ph": "0xf2365aa692679db520c761bc5616ea8e78e7d66e8e5b7fa62f5ccede3c4ad21d" - }, - "#radix:f": { - "#radix_ph": "0x5d5f1af4318fd0ce355a0c658f8d1695c0a1f00587edf9b9543887955c15fe12" - } - } - }, - "#radix:707073": { - "#radix_ph": "0x8e3709e38db2e60381f0359985a9b11da39b69c436d91fb9fed4fe7956176bfa" - } + "#radix_ph": "0x3b5f61c11f36018bcb5d320e5b98c9d5f69463d95ef1cee71503f6e19d3a1b3e" }, "#radix:26c6f636b636861696e5f706172616d73": { - "#radix_ph": "0x0db35261beb8f805e4ced018ff3f0466b6f8536d5d190ef15d6ad7bb1a14bb0b" + "#radix_ph": "0x0db35261beb8f805e4ced018ff3f0466b6f8536d5d190ef15d6ad7bb1a14bb0b", + "#state:blockchain_params": { + "#state_ph": "0x743b16391b5100908951fb9e33308c95a30570de399616a616a682d8c6d4b0b3" + } }, "#radix:36": { - "#radix_ph": "0x4d38d68552a062ed3da9978081154a50e24d072da2d94e8a05bf321f243167f5" + "#radix_ph": "0x6a9192e77bae6f4a56eb719ad42467ad3ba0ba13ca895e1ec9b783661d6c3288" }, "#radix:46576656c6f70657273": { "#radix_ph": "0x6eed3986e6ce5982579a76c50ad98718dc3aa93eeae2724c9dc629264bbfb144" @@ -1030,6 +898,72 @@ Response } ``` +### ain_getProofHash + +Returns the state proof hash of the given path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. + +**Returns** + +The state proof hash. + +**Examples** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getProofHash", + "params": { + "protoVer": "1.1.3", + "ref": "/values/blockchain_params" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": "0x743b16391b5100908951fb9e33308c95a30570de399616a616a682d8c6d4b0b3", + "protoVer": "1.1.3" + } +} +``` + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getProofHash", + "params": { + "protoVer": "1.1.3", + "ref": "/rules/transfer/$from/$to/$key/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": "0x985a1f057d5047b1dee392127eb776571fbbe79da7ae6114f8f8f18c4f786135", + "protoVer": "1.1.3" + } +} +``` + --- ## Account API From 2ef360b4e7adcb3263f51c715a3ab8992d459a7f Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Wed, 31 Jan 2024 20:00:25 +0900 Subject: [PATCH 14/38] Add ain_getStateInfo, ain_getStateUsage apis to JSON_RPC_API.md file --- JSON_RPC_API.md | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index eb7fce6ad..88dbeb2d3 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -964,6 +964,113 @@ Response } ``` +### ain_getStateInfo + +Returns the state information of the given path in the global state tree. + +**Parameters** + +An object with a property: + +- ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. + +**Returns** + +The state information. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getStateInfo", + "params": { + "protoVer": "1.1.3", + "ref": "/rules/transfer/$from/$to/$key/value" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "#num_children": 1, + "#tree_height": 2, + "#tree_size": 3, + "#tree_bytes": 1840, + "#tree_max_siblings": 1, + "#state_ph": "0x985a1f057d5047b1dee392127eb776571fbbe79da7ae6114f8f8f18c4f786135", + "#version": "POOL:3062598:3062599:1702353330546:0" + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_getStateUsage + +Returns the state usage of the given app name. + +**Parameters** + +An object with a property: + +- app_name: `String` - app name + +**Returns** + +The state usage. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getStateUsage", + "params": { + "protoVer": "1.1.3", + "app_name": "consensus" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "usage": { + "tree_height": 6, + "tree_size": 11, + "tree_bytes": 2114, + "tree_max_siblings": 5 + }, + "available": { + "tree_height": 30, + "tree_bytes": 12291542508.778091, + "tree_size": 76822140.67986308 + }, + "staking": { + "app": 50500000, + "total": 10168575.540000014, + "unstakeable": 50500000 + } + }, + "protoVer": "1.1.3" + } +} +``` + --- ## Account API From 29e25387f8e96ff65ff386a4c59ed90ab5c893a8 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 1 Feb 2024 10:04:47 +0900 Subject: [PATCH 15/38] Update contents table of JSON_RPC_API.md file --- JSON_RPC_API.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 88dbeb2d3..a344160ac 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -4,6 +4,15 @@ - [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) - [Account API](#account-api) - [ain_getBalance](#ain_getbalance) - [ain_getConsensusStakeAmount](#ain_getconsensusstakeamount) From 37fbe9a99923c26c038b44abb0d8bf48b48b2486 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Thu, 1 Feb 2024 17:26:14 +0900 Subject: [PATCH 16/38] Add or update account APIs of JSON_RPC_API.md file --- JSON_RPC_API.md | 136 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 40 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index a344160ac..e07b46644 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -14,10 +14,11 @@ - [ain_getStateInfo](#ain_getstateinfo) - [ain_getStateUsage](#ain_getstateusage) - [Account API](#account-api) + - [ain_getAddress](#ain_getaddress) - [ain_getBalance](#ain_getbalance) - - [ain_getConsensusStakeAmount](#ain_getconsensusstakeamount) - [ain_getNonce](#ain_getnonce) - - [ain_isValidator](#ain_isvalidator) + - [ain_getTimestamp](#ain_gettimestamp) + - [ain_getValidatorInfo](#ain_getvalidatorinfo) - [Transaction API](#transaction-api) - [ain_getPendingTransactions](#ain_getpendingtransactions) - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) @@ -1084,15 +1085,51 @@ Response ## Account API +### ain_getAddress + +Returns the address of the blockchain node's account. + +**Parameters** + +**Returns** + +`String` - The address. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getAddress", + "params": { + "protoVer": "1.1.3" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "protoVer": "1.1.3" + } +} +``` + ### ain_getBalance -Returns the balance of an account. +Returns the balance of the given account. **Parameters** An object with a property: -- address: `String` - address of the account to get the balance of. +- address: `String` - address of the account. **Returns** @@ -1107,33 +1144,37 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_getBalance", "params": { - "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + "protoVer": "1.1.3", + "address": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":98347 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 578990573.3755, + "protoVer": "1.1.3" + } } ``` -### ain_getConsensusStakeAmount +### ain_getNonce -Returns the amount of AIN the account (node) is staking for participating in the consensus protocol. +Returns the nonce, number of transactions an address has sent, of the given account -**Parameters**[](#parameters-1) +**Parameters** An object with a property: -- address: `String` - address of the account. +- address: `String` - address of the account **Returns** -`Number` - The amount at stake. +`Number` - The nonce. **Example** @@ -1142,35 +1183,39 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getConsensusStakeAmount", + "method": "ain_getNonce", "params": { - "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + "protoVer": "1.1.3", + "address": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":1000 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 91, + "protoVer": "1.1.3" + } } ``` -### ain_getNonce +### ain_getTimestamp -Returns the nonce (= number of transactions an address has sent) of an address. +Returns the timestamp of the given account **Parameters** An object with a property: -- address: `String` - address of the account to get the transaction count of +- address: `String` - address of the account **Returns** -`Number` - The nonce. +`Number` - The timestamp. **Example** @@ -1179,35 +1224,39 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getNonce", + "method": "ain_getTimestamp", "params": { - "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + "protoVer": "1.1.3", + "address": "0xAAAAeEDFf1d2cD909465182165ccc267549554Fc" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":10 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 0, + "protoVer": "1.1.3" + } } ``` -### ain_isValidator +### ain_getValidatorInfo -Returns whether the node is currently a validator or not. +Returns the information of the given block validator **Parameters** An object with a property: -- address: `String` - address of the account to check if it's currently in the validator set +- address: `String` - address of the block validator's account **Returns** -`Boolean` - Whether the node is a validator or not. +`Object` - The validator's information. **Example** @@ -1216,19 +1265,26 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_isValidator", + "method": "ain_getValidatorInfo", "params": { - "address": "0xc94770007dda54cF92009BFF0dE90c06F603a09f" + "protoVer": "1.1.3", + "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":true +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "isWhitelisted": true, + "stake": 0 + }, + "protoVer": "1.1.3" + } } ``` From 15ecd679fe6abe30db691f1687e4816e4005c330 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Fri, 2 Feb 2024 18:54:16 +0900 Subject: [PATCH 17/38] Update or add transaction APIs to JSON_RPC_API.md file --- JSON_RPC_API.md | 584 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 452 insertions(+), 132 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index e07b46644..235c9a2c5 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -21,11 +21,13 @@ - [ain_getValidatorInfo](#ain_getvalidatorinfo) - [Transaction API](#transaction-api) - [ain_getPendingTransactions](#ain_getpendingtransactions) - - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) - - [ain_getTransactionByBlockHashAndIndex](#ain_gettransactionbyblockhashandindex) + - [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_sendSignedTransactionBatch] - [Block API](#block-api) - [ain_getRecentBlock](#ain_getrecentblock) - [ain_getRecentBlockNumber](#ain_getrecentblocknumber) @@ -1313,51 +1315,132 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_getPendingTransactions", "params": { - "protoVer": "1.0.9" + "protoVer": "1.1.3" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":[ - { - "status":"PENDING", - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", - "timestamp":1566736760322, - "nonce":-1, - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204": [ + [ + { + "tx_body": { + "operation": { + "type": "SET", + "op_list": [ + { + "type": "SET_VALUE", + "ref": "/consensus/number/1/propose", + "value": { + "number": 1, + "epoch": 3293579, + "validators": { + "0x00ADEc28B6a845a085e03591bE7550dd68673C1C": { + "stake": 10000000, + "proposal_right": true + }, + "0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204": { + "stake": 10000000, + "proposal_right": true + }, + "0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00": { + "stake": 10000000, + "proposal_right": true + } + }, + "total_at_stake": 30000000, + "proposer": "0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204", + "block_hash": "0x227903519aa2e8810b4f962352278a66e87ba94ce38b1ad24191298d2da5f029", + "last_hash": "0x31075a91beeea98fe8030c848d40b592411f2533c77d347d7937be84eae83745", + "timestamp": 1706866780852, + "gas_cost_total": 0 + } + } + ] + }, + "nonce": -1, + "gas_price": 0, + "timestamp": 1706866780900 + }, + "signature": "0xd2b9af94907ee0b766eb9dace532be79b1a7ce525c3e8560cc44100fed7e8f7f35fdc552a52761fb43923cd6b320e6e02339ea96e9eaeef6df84134cb7581f9c3dff7714e3f8487eb31f838833486747fec77cc484df5d0bf9808e37c1b1b15e1b", + "hash": "0xd2b9af94907ee0b766eb9dace532be79b1a7ce525c3e8560cc44100fed7e8f7f", + "address": "0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204", + "extra": { + "created_at": 1706866780973, + "executed_at": 1706866780973, + "gas": { + "bandwidth": { + "service": 1 + }, + "state": { + "service": 4348 + } + } + } + }, + ... + ] + ], + "0x00ADEc28B6a845a085e03591bE7550dd68673C1C": [ + [ + { + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/consensus/number/1/0x227903519aa2e8810b4f962352278a66e87ba94ce38b1ad24191298d2da5f029/vote/0x00ADEc28B6a845a085e03591bE7550dd68673C1C", + "value": { + "block_hash": "0x227903519aa2e8810b4f962352278a66e87ba94ce38b1ad24191298d2da5f029", + "stake": 10000000, + "is_against": false, + "vote_nonce": 1706866780979 + } + }, + "nonce": -1, + "gas_price": 0, + "timestamp": 1706866780979 + }, + "signature": "0xaead9b8bb1d894facf76dfa25765d80c11beaa7da1b19b5b4f90cf6b6ba314b45790b5d2be212b5f41a556322cee7ce7540266c9ab9ba61400705e1ef3401f476f8e08bf38ab0bb47df040d594f1bbf3a61dd8697ed5acf26e2d8e726563891e1b", + "hash": "0xaead9b8bb1d894facf76dfa25765d80c11beaa7da1b19b5b4f90cf6b6ba314b4", + "address": "0x00ADEc28B6a845a085e03591bE7550dd68673C1C", + "extra": { + "created_at": 1706866780981, + "executed_at": 1706866780982, + "gas": { + "bandwidth": { + "service": 1 + }, + "state": { + "service": 1900 + } + } + } + } + ] + ], + ... }, - { - "status":"PENDING", - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "timestamp":1566736800358, - "nonce":99 - } - ] + "protoVer": "1.1.3" + } } ``` -### ain_getTransactionByBlockNumberAndIndex +### ain_getTransactionPoolSizeUtilization -Returns the transaction at the {index} position within the block with the {block_number}. +Returns the transaction pool size utilization. **Parameters** -An object with 2 properties: -- block_number: `Number` - block number -- index: `Number` - index of the transaction within the block - +None. + **Returns** -`Object` - The transaction. +`Object` - An object containing transaction pool size utilization information. **Example** @@ -1366,11 +1449,9 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getTransactionByBlockNumberAndIndex", + "method": "ain_getTransactionPoolSizeUtilization", "params": { - "protoVer": "1.0.9", - "block_number": 1018739, - "index": 1 + "protoVer": "1.1.3" } }' ``` @@ -1381,30 +1462,115 @@ Response "jsonrpc": "2.0", "id": 1, "result": { - "result": {json + "result": { + "limit": 1000, + "used": 12, + "free_limit": 100, + "free_used": 12 + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_getTransactionByHash + +Returns the transaction with the hash. + +**Parameters** + +An object with a property: + +- hash: `String` - transaction hash + +**Returns** + +`Object` - the transaction. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getTransactionByHash", + "params": { + "protoVer": "1.1.3", + "hash": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc8401", + "index": 0 + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "state": "FINALIZED", + "number": 3286991, + "index": 0, + "address": "0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0", + "timestamp": 1706843368852, + "is_executed": true, + "is_finalized": true, + "tracked_at": 1706843414080, + "executed_at": 1706843369274, + "finalized_at": 1706843414080, + "exec_result": { + "gas_amount_total": { + "bandwidth": { + "service": 0, + "app": { + "openai_ainize3": 101 + } + }, + "state": { + "service": 0, + "app": { + "openai_ainize3": 806 + } + } + }, + "gas_cost_total": 0, + "func_results": { + "service-trigger": { + "code": 0, + "bandwidth_gas_amount": 100 + } + }, + "code": 0, + "bandwidth_gas_amount": 1, + "gas_amount_charged": 0 + }, "transaction": { "tx_body": { "operation": { "type": "SET_VALUE", - "ref": "/apps/collaborative_ai/worker_info/w2udhcx6tzbqxqf0@0xd377ab38E8C9267ce0f85613680b327069d51752/status", + "ref": "/apps/openai_ainize3/service/0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0/1706843368851/request", "value": { - "workerStatus": "running", - "currentNumberOfContainer": 0, - "updatedAt": 1661420944081 + "assistantId": "asst_jU5mgKHZgw61MKP2mVev0KAA", + "jobType": "delete_assistant" } }, "nonce": -1, - "timestamp": 1661420944081, - "gas_price": 0 + "timestamp": 1706843368852, + "gas_price": 500 }, - "signature": "0x6d652a4e0b8517bb6277db4c2679ec9da4e0f2c9166359361088fa0157288b6ca2bd756e674352fd42713d5b659b240a5ace66a24fc8abdaa995ae8f1b04bbf124aa38111e495dd7aa7502acdf789d2ff18d360d59f42780ac17ac76fa1d92771b", - "hash": "0x6d652a4e0b8517bb6277db4c2679ec9da4e0f2c9166359361088fa0157288b6c", - "address": "0xd377ab38E8C9267ce0f85613680b327069d51752" + "signature": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc84018f207a2a0f41b2fbba4bd3a04a4a687ed43484418547ef1a70847830fa0b0b747d64f52f53776fc7d2d3e2615b011adafc56b9abb941296e1fce87330292b5151c", + "hash": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc8401", + "address": "0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0" }, - "is_executed": true, - "is_finalized": true + "receipt": { + "code": 0, + "gas_amount_charged": 0, + "gas_cost_total": 0 + } }, - "protoVer": "1.0.9" + "protoVer": "1.1.3" } } ``` @@ -1435,8 +1601,8 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_getTransactionByBlockHashAndIndex", "params": { - "protoVer": "1.0.9", - "block_hash": "0x38635f8c1b3ecfaa8314698ac241341dc3ba82bc1d26e4fb5c20e21fe9ce2645", + "protoVer": "1.1.3", + "block_hash": "0x406f4a46cf8434c59777ee73e1834b0109950b74159100ab7920a7a53e9f50af", "index": 0 } }' @@ -1453,64 +1619,41 @@ Response "tx_body": { "operation": { "type": "SET_VALUE", - "ref": "/apps/collaborative_ai/worker_info/w2udhcx6tzbqxqf0@0xd377ab38E8C9267ce0f85613680b327069d51752", + "ref": "/apps/openai_ainize3/service/0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0/1706843368851/request", "value": { - "ethAddress": "0xbDA5747bFD65F08deb54cb465eB87D40e51B197E", - "containerSpec": { - "cpu": { - "name": "Intel® Xeon®", - "vcpu": 1 - }, - "gpu": { - "name": "nvidia-tesla-t4", - "memoryGB": 16, - "count": 1 - }, - "memory": { - "maxGB": 4 - }, - "storage": { - "maxGB": 128 - }, - "maxNumberOfContainer": 1, - "hasEndpoint": true - }, - "labels": { - "spec": "nc6", - "managedBy": "run-your-node" - }, - "createdAt": 1661420943970 + "assistantId": "asst_jU5mgKHZgw61MKP2mVev0KAA", + "jobType": "delete_assistant" } }, "nonce": -1, - "timestamp": 1661420943970, - "gas_price": 0 + "timestamp": 1706843368852, + "gas_price": 500 }, - "signature": "0x2c9ffeb45b3377471b8c88e07159cfe0156278338a6763f0e9437f059623997398bd5469498192da259a90e279d4c85510341d05c8ff268f62d4d1299965a503148ad4e1430ab91734764cf0ed048d8a8df4e80c64f4cd3e1a10e0358e447f6c1c", - "hash": "0x2c9ffeb45b3377471b8c88e07159cfe0156278338a6763f0e9437f0596239973", - "address": "0xd377ab38E8C9267ce0f85613680b327069d51752" + "signature": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc84018f207a2a0f41b2fbba4bd3a04a4a687ed43484418547ef1a70847830fa0b0b747d64f52f53776fc7d2d3e2615b011adafc56b9abb941296e1fce87330292b5151c", + "hash": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc8401", + "address": "0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0" }, "is_executed": true, "is_finalized": true }, - "protoVer": "1.0.9" + "protoVer": "1.1.3" } } ``` -### ain_getTransactionByHash +### ain_getTransactionByBlockNumberAndIndex -Returns the transaction with the hash. +Returns the transaction at the {index} position within the block with the {block_number}. **Parameters** -An object with a property: - -- hash: `String` - transaction hash - +An object with 2 properties: +- block_number: `Number` - block number +- index: `Number` - index of the transaction within the block + **Returns** -`Object` - the transaction. +`Object` - The transaction. **Example** @@ -1519,10 +1662,10 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getTransactionByHash", + "method": "ain_getTransactionByBlockNumberAndIndex", "params": { - "protoVer": "1.0.9", - "hash": "0xa38fabd1daa7d7d0488275d146bebcacd088eda0069987606a61407c680eb8d9", + "protoVer": "1.1.3", + "block_number": 3286991, "index": 0 } }' @@ -1535,42 +1678,137 @@ Response "id": 1, "result": { "result": { - "state": "FINALIZED", - "number": 1161159, - "index": 0, - "address": "0x4db42BDE411AfC23B8F3b26EE7AE73DA28c9e470", - "timestamp": 1664272982427, + "transaction": { + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/apps/openai_ainize3/service/0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0/1706843368851/request", + "value": { + "assistantId": "asst_jU5mgKHZgw61MKP2mVev0KAA", + "jobType": "delete_assistant" + } + }, + "nonce": -1, + "timestamp": 1706843368852, + "gas_price": 500 + }, + "signature": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc84018f207a2a0f41b2fbba4bd3a04a4a687ed43484418547ef1a70847830fa0b0b747d64f52f53776fc7d2d3e2615b011adafc56b9abb941296e1fce87330292b5151c", + "hash": "0x5d4c7de40b158024e2c351460dcbdaea06ced92e623b22930f27ef871dbc8401", + "address": "0x7ed9c30C9F3A31Daa9614b90B4a710f61Bd585c0" + }, "is_executed": true, - "is_finalized": true, - "tracked_at": 1664273029387, - "executed_at": 1664272982539, - "finalized_at": 1664273029387, - "transaction": "0xa38fabd1daa7d7d0488275d146bebcacd088eda0069987606a61407c680eb8d9", - "receipt": { + "is_finalized": true + }, + "protoVer": "1.1.3" + } +} +``` + +### ain_sendSignedTransactionDryrun + +Sends a transaction body and its signature to the blockchain node as a dryrun. + +**Parameters** + +An object with following properties: + +- tx_body: `Object` - transaction body object +- signature: `String` - signature of the transaction + +**Returns** + +`Object` - the transaction hash and the execution result from the dryrun. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_sendSignedTransactionDryrun", + "params": { + "protoVer": "1.1.3", + "signature": "0x40a183b409b54a6d0cb7a68853a05c41af0b9fccf442b9249fde64ff62bc6e54072e60fea9b591130b7a17838db05ef8d50782ada6251064256f517bbb85ed7b09e5bbec43ab1a3724a4df4e4088b1392336d371ce6a8881f6d0e080b4304d701b", + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/transfer/0xb16DF4D61Aa206096FE2E705497B91951852989F/0xEfa713E7f2C0cE5f89ae746e91DD476979967EBD/1706853750720/value", + "value": 10 + }, + "gas_price": 500, + "timestamp": 1706853750720, + "nonce": -1 + } + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "tx_hash": "0x40a183b409b54a6d0cb7a68853a05c41af0b9fccf442b9249fde64ff62bc6e54", + "result": { + "gas_amount_total": { + "bandwidth": { + "service": 3 + }, + "state": { + "service": 364 + } + }, + "gas_cost_total": 0.1835, + "func_results": { + "_transfer": { + "op_results": { + "0": { + "path": "/accounts/0xb16DF4D61Aa206096FE2E705497B91951852989F/balance", + "result": { + "code": 0, + "bandwidth_gas_amount": 1 + } + }, + "1": { + "path": "/accounts/0xEfa713E7f2C0cE5f89ae746e91DD476979967EBD/balance", + "result": { + "code": 0, + "bandwidth_gas_amount": 1 + } + } + }, + "code": 0, + "bandwidth_gas_amount": 0 + } + }, "code": 0, - "gas_amount_charged": 0, - "gas_cost_total": 0 + "bandwidth_gas_amount": 1, + "is_dryrun": true, + "gas_amount_charged": 367 } }, - "protoVer": "1.0.9" + "protoVer": "1.1.3" } } ``` ### ain_sendSignedTransaction -Sends the signature and the transaction object to the node. +Sends a transaction body and its signature to the blockchain node. **Parameters** An object with following properties: +- tx_body: `Object` - transaction body object - signature: `String` - signature of the transaction -- transaction: `Object` - transaction object **Returns** -`String` - the transaction's hash. +`Object` - the transaction hash and the execution result. **Example** @@ -1581,31 +1819,81 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_sendSignedTransaction", "params": { - "protoVer": "1.0.9", - "signature": "0xdb61ef...FILL_THIS", - "transaction":{ - "nonce":123, - "timestamp":1566736760322, - "operation":{ - "ref":"/account/0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812/balance", - "type":"SET_VALUE", - "value":1000 - }, - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56..." - } + "protoVer": "1.1.3", + "signature": "0x40a183b409b54a6d0cb7a68853a05c41af0b9fccf442b9249fde64ff62bc6e54072e60fea9b591130b7a17838db05ef8d50782ada6251064256f517bbb85ed7b09e5bbec43ab1a3724a4df4e4088b1392336d371ce6a8881f6d0e080b4304d701b", + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/transfer/0xb16DF4D61Aa206096FE2E705497B91951852989F/0xEfa713E7f2C0cE5f89ae746e91DD476979967EBD/1706853750720/value", + "value": 10 + }, + "gas_price": 500, + "timestamp": 1706853750720, + "nonce": -1 + } } }' ``` +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "tx_hash": "0x40a183b409b54a6d0cb7a68853a05c41af0b9fccf442b9249fde64ff62bc6e54", + "result": { + "gas_amount_total": { + "bandwidth": { + "service": 3 + }, + "state": { + "service": 364 + } + }, + "gas_cost_total": 0.1835, + "func_results": { + "_transfer": { + "op_results": { + "0": { + "path": "/accounts/0xb16DF4D61Aa206096FE2E705497B91951852989F/balance", + "result": { + "code": 0, + "bandwidth_gas_amount": 1 + } + }, + "1": { + "path": "/accounts/0xEfa713E7f2C0cE5f89ae746e91DD476979967EBD/balance", + "result": { + "code": 0, + "bandwidth_gas_amount": 1 + } + } + }, + "code": 0, + "bandwidth_gas_amount": 0 + } + }, + "code": 0, + "bandwidth_gas_amount": 1, + "gas_amount_charged": 367 + } + }, + "protoVer": "1.1.3" + } +} +``` + ### ain_sendSignedTransactionBatch -Sends multiple transactions at once. +Sends multiple transactions at once to the blockchain node. **Parameters** An object with a property: -- `Array` - an array of transaction objects (with signature and transaction properties) +- `Array` - an array of transaction objects (with signature and transaction body) **Returns** @@ -1620,10 +1908,11 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_sendSignedTransactionBatch", "params": { + "protoVer": "1.1.3", "tx_list": [ { "signature": "0xaabc9ddafffb2ae0bac4107697547d22d9383...", - "transaction": { + "tx_body": { "nonce": 120, "timestamp": 1566736760322, "operation": { @@ -1635,7 +1924,7 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica }, { "signature": "0x1ec191ef20b0e9628c4397665977cb...", - "transaction": { + "tx_body": { "nonce": 121, "timestamp": 1566736760400, "operation": { @@ -1653,12 +1942,43 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica Response ``` { - "jsonrpc":"2.0", - "id":1, - "result":[ - "0x88df016429689c079f3b2f6ad39fa052532c56795b733da7...", - "0x8e4340ea3983d86e4b6c44249362f716ec9e09849ef9b6e3..." - ] + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": [ + { + "tx_hash": "0x88df016429689c079f3b2f6ad39fa052532c56795b733da7...", + "result": { + "code": 0, + "bandwidth_gas_amount": 1, + "gas_amount_charged": 367, + "gas_amount_total": { + ... + }, + "gas_cost_total": 0.1835, + "func_results": { + ... + } + } + }, + { + "tx_hash": "0x8e4340ea3983d86e4b6c44249362f716ec9e09849ef9b6e3...", + "result": { + "code": 0, + "bandwidth_gas_amount": 1, + "gas_amount_charged": 367, + "gas_amount_total": { + ... + }, + "gas_cost_total": 0.1835, + "func_results": { + ... + } + } + } + ], + "protoVer": "1.1.3" + } } ``` From 9c554873d9937f4d7466665950c3a13aaca98014 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 14:32:57 +0900 Subject: [PATCH 18/38] Fix ain_getPendingTransactions API --- json_rpc/transaction.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/json_rpc/transaction.js b/json_rpc/transaction.js index ac8b61294..86a318d20 100644 --- a/json_rpc/transaction.js +++ b/json_rpc/transaction.js @@ -63,7 +63,13 @@ module.exports = function getTransactionApis(node, p2pServer) { return { [JSON_RPC_METHODS.AIN_GET_PENDING_TRANSACTIONS]: function(args, done) { const beginTime = Date.now(); - const result = node.tp.transactions; + const result = {}; + for (let [key, value] of node.tp.transactions.entries()) { + if (!result[key]) { + result[key] = []; + } + result[key].push(value) + } const latency = Date.now() - beginTime; trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); done(null, JsonRpcUtil.addProtocolVersion({ result })); From 53db36fbc960d6ec881b281dd4f503578bdcb364 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 14:47:20 +0900 Subject: [PATCH 19/38] Spin off Consensus section from Block secsion --- JSON_RPC_API.md | 97 ++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 46 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 235c9a2c5..4569f0773 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -18,7 +18,6 @@ - [ain_getBalance](#ain_getbalance) - [ain_getNonce](#ain_getnonce) - [ain_getTimestamp](#ain_gettimestamp) - - [ain_getValidatorInfo](#ain_getvalidatorinfo) - [Transaction API](#transaction-api) - [ain_getPendingTransactions](#ain_getpendingtransactions) - [ain_getTransactionPoolSizeUtilization](#ain_gettransactionpoolsizeutilization) @@ -27,7 +26,7 @@ - [ain_getTransactionByBlockNumberAndIndex](#ain_gettransactionbyblocknumberandindex) - [ain_sendSignedTransactionDryrun](#ain_sendsignedtransactiondryrun) - [ain_sendSignedTransaction](#ain_sendsignedtransaction) - - [ain_sendSignedTransactionBatch] + - [ain_sendSignedTransactionBatch](#ain_sendsignedtransactionbatch) - [Block API](#block-api) - [ain_getRecentBlock](#ain_getrecentblock) - [ain_getRecentBlockNumber](#ain_getrecentblocknumber) @@ -37,6 +36,8 @@ - [ain_getBlockHeaders](#ain_getblockheaders) - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) +- [Consensus API](#consensus-api) + - [ain_getValidatorInfo](#ain_getvalidatorinfo) - [ain_getProposerByHash](#ain_getproposerbyhash) - [ain_getProposerByNumber](#ain_getproposerbynumber) - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) @@ -1246,50 +1247,6 @@ Response } ``` -### ain_getValidatorInfo - -Returns the information of the given block validator - -**Parameters** - -An object with a property: - -- address: `String` - address of the block validator's account - -**Returns** - -`Object` - The validator's information. - -**Example** - -Request -``` -curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ - "jsonrpc": "2.0", - "id": 1, - "method": "ain_getValidatorInfo", - "params": { - "protoVer": "1.1.3", - "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" - } -}' -``` - -Response -``` -{ - "jsonrpc": "2.0", - "id": 1, - "result": { - "result": { - "isWhitelisted": true, - "stake": 0 - }, - "protoVer": "1.1.3" - } -} -``` - --- ## Transaction API @@ -2427,6 +2384,54 @@ Response } ``` +--- + +## Consensus API + +### ain_getValidatorInfo + +Returns the information of the given block validator + +**Parameters** + +An object with a property: + +- address: `String` - address of the block validator's account + +**Returns** + +`Object` - The validator's information. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "ain_getValidatorInfo", + "params": { + "protoVer": "1.1.3", + "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "isWhitelisted": true, + "stake": 0 + }, + "protoVer": "1.1.3" + } +} +``` + ## ain_getProposerByHash Returns the proposer who produced the block with the given block hash. From 917909195836eafaacb9c16714f7c8d39ad9b761 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 16:13:36 +0900 Subject: [PATCH 20/38] Re-arrange block apis --- JSON_RPC_API.md | 68 ++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 4569f0773..a5e795249 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -38,10 +38,10 @@ - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) - [Consensus API](#consensus-api) - [ain_getValidatorInfo](#ain_getvalidatorinfo) - - [ain_getProposerByHash](#ain_getproposerbyhash) - - [ain_getProposerByNumber](#ain_getproposerbynumber) - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) + - [ain_getProposerByHash](#ain_getproposerbyhash) + - [ain_getProposerByNumber](#ain_getproposerbynumber) - [Network API](#network-api) - [net_listening](#net_listening) - [net_nodeInfo](#net_nodeinfo) @@ -2432,9 +2432,9 @@ Response } ``` -## ain_getProposerByHash +## ain_getValidatorsByHash -Returns the proposer who produced the block with the given block hash. +Returns the validators who validated the block. **Parameters** @@ -2444,7 +2444,7 @@ An object with a property: **Returns** -`String` - The address of the proposer. +`Array` - The list of validators. **Example** @@ -2453,7 +2453,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getProposerByHash", + "method": "ain_getValidatorsByHash", "params": { "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." } @@ -2465,13 +2465,17 @@ Response { "jsonrpc":"2.0", "id":1, - "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" + "result":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ] } ``` -## ain_getProposerByNumber +## ain_getValidatorsByNumber -Returns the proposer who produced the block with the given block number. +Returns the validators who validated the block. **Parameters** @@ -2481,7 +2485,7 @@ An object with a property: **Returns** -`String` - The proposer's address. +`Array` - The list of validators. **Example** @@ -2489,10 +2493,10 @@ Request ``` curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", - "id": 1, - "method": "ain_getProposerByNumber", + "id": 1, + "method": "ain_getValidatorsByNumber", "params": { - "number": 456 + "number": 2143 } }' ``` @@ -2502,13 +2506,17 @@ Response { "jsonrpc":"2.0", "id":1, - "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" + "result":[ + "0x4e65fda2159562a496f9f3522f89122a3088497a", + "0xd46e8dd67c5d32be8058bb8eb970870f07244567", + "0xb60e8dd61c5d32be8058bb8eb970870f07233155" + ] } ``` -## ain_getValidatorsByHash +## ain_getProposerByHash -Returns the validators who validated the block. +Returns the proposer who produced the block with the given block hash. **Parameters** @@ -2518,7 +2526,7 @@ An object with a property: **Returns** -`Array` - The list of validators. +`String` - The address of the proposer. **Example** @@ -2527,7 +2535,7 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getValidatorsByHash", + "method": "ain_getProposerByHash", "params": { "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." } @@ -2539,17 +2547,13 @@ Response { "jsonrpc":"2.0", "id":1, - "result":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ] + "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" } ``` -## ain_getValidatorsByNumber +## ain_getProposerByNumber -Returns the validators who validated the block. +Returns the proposer who produced the block with the given block number. **Parameters** @@ -2559,7 +2563,7 @@ An object with a property: **Returns** -`Array` - The list of validators. +`String` - The proposer's address. **Example** @@ -2567,10 +2571,10 @@ Request ``` curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", - "id": 1, - "method": "ain_getValidatorsByNumber", + "id": 1, + "method": "ain_getProposerByNumber", "params": { - "number": 2143 + "number": 456 } }' ``` @@ -2580,11 +2584,7 @@ Response { "jsonrpc":"2.0", "id":1, - "result":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ] + "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" } ``` From d5071e715810b3696a1f28e1baf27ff77a298ee2 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 16:15:52 +0900 Subject: [PATCH 21/38] Fix or update block apis --- JSON_RPC_API.md | 444 ++++++++++++++++++++++++++---------------------- 1 file changed, 245 insertions(+), 199 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index a5e795249..6904b03e7 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -28,12 +28,12 @@ - [ain_sendSignedTransaction](#ain_sendsignedtransaction) - [ain_sendSignedTransactionBatch](#ain_sendsignedtransactionbatch) - [Block API](#block-api) - - [ain_getRecentBlock](#ain_getrecentblock) - - [ain_getRecentBlockNumber](#ain_getrecentblocknumber) + - [ain_getLastBlock](#ain_getlastblock) + - [ain_getLastBlockNumber](#ain_getlastblocknumber) - [ain_getBlockByNumber](#ain_getblockbynumber) - [ain_getBlockByHash](#ain_getblockbyhash) - - [ain_getBlocks](#ain_getblocks) - - [ain_getBlockHeaders](#ain_getblockheaders) + - [ain_getBlockList](#ain_getblocklist) + - [ain_getBlockHeadersList](#ain_getblockheaderslist) - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) - [Consensus API](#consensus-api) @@ -1943,9 +1943,9 @@ Response ## Block API -### ain_getRecentBlock +### ain_getLastBlock -Returns the most recent block. +Returns the last block. **Parameters** @@ -1953,7 +1953,7 @@ None. **Returns** -`Object` - The most recent block. +`Object` - The last block. **Example** @@ -1962,53 +1962,51 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getRecentBlock" + "method": "ain_getLastBlock", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":{ - "timestamp":1564845946382, - "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", - "number":675, - "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812", - "validators":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ], - "size":163591, - "transactions":[ - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", - "timestamp":1566736760322, - "nonce":-1, - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", - "operation":{ ... } - }, - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "timestamp":1566736780022, - "nonce":99, - "operation":{ ... } +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "last_votes": [ + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0x79a17e333d600d234e0eabe103288eeb3fd01f9c0227dd66fd5ad037af07331d", + "last_votes_hash": "0x934f7d6b833aa268d7c67af0a75d10ab0fe916f746979b94446c802b31d93768", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3300494, + "epoch": 3305917, + "timestamp": 1707113548716, + "state_proof_hash": "0xfc95cc439ea82935eb739a94cdc655cee15266dc6254844d5d92585ccf320592", + "proposer": "0x003AD6FdB06684175e7D95EcC36758B014517E4b", + "validators": { + ... }, - ... - ] + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0x1656a691b9b2007d6f16dc7127f4cdb7f461303cb240c42bc0d6b6016bd5d9f8", + "size": 11888 + }, + "protoVer": "1.1.3" } } ``` -## ain_getRecentBlockNumber +## ain_getLastBlockNumber -Returns the most recent block's block number. +Returns the last block number. **Parameters** @@ -2016,7 +2014,7 @@ None. **Returns** -`Number` - The most recent block's block number. +`Number` - The last block number. **Example** @@ -2025,16 +2023,22 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getRecentBlockNumber" + "method": "ain_getLastBlockNumber", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":98347 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 3300526, + "protoVer": "1.1.3" + } } ``` @@ -2062,7 +2066,8 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_getBlockByNumber", "params": { - "number": 675, + "protoVer": "1.1.3", + "number": 3300526, "getFullTransactions": true } }' @@ -2070,41 +2075,36 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":{ - "timestamp":1564845946382, - "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", - "number":675, - "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed812", - "validators":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ], - "size":163591, - "transactions":[ - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", - "timestamp":1566736760322, - "nonce":-1, - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", - "operation":{ ... } - }, - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "timestamp":1566736780022, - "nonce":99, - "operation":{ ... } +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "last_votes": [ + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0xe4ec974b210f26f66a0b005a87ea4ea8b74e507ece9ae4219a130fca19c1f15f", + "last_votes_hash": "0x670bd883418c7b14847dbc315a3a0b4ea23cad091667d5807005026bae7c1600", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3300526, + "epoch": 3305949, + "timestamp": 1707114196712, + "state_proof_hash": "0x5966358621862d6f29926921738381944e77365df449b898aaed309090a849e7", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... }, - ... - ] + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", + "size": 11888 + }, + "protoVer": "1.1.3" } } ``` @@ -2122,7 +2122,7 @@ An object with properties: **Returns** -`Object` - The block. +`Object` - The block object. **Example** @@ -2130,10 +2130,11 @@ Request ``` curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", - "id": 1, + "id": 1, "method": "ain_getBlockByHash", "params": { - "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484...", + "protoVer": "1.1.3", + "hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", "getFullTransactions": true } }' @@ -2141,46 +2142,41 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":{ - "timestamp":1564845946382, - "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "parent_hash":"0xe670ec64341771606e55d6b4ca35a1a6b75...", - "number":67526, - "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", - "validators":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ], - "size":163591, - "transactions":[ - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", - "timestamp":1566736760322, - "nonce":-1 - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", - "operation":{ ... } - }, - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "timestamp":1566736760400, - "nonce":99, - "operation":{ ... } +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "last_votes": [ + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0xe4ec974b210f26f66a0b005a87ea4ea8b74e507ece9ae4219a130fca19c1f15f", + "last_votes_hash": "0x670bd883418c7b14847dbc315a3a0b4ea23cad091667d5807005026bae7c1600", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3300526, + "epoch": 3305949, + "timestamp": 1707114196712, + "state_proof_hash": "0x5966358621862d6f29926921738381944e77365df449b898aaed309090a849e7", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... }, - ... - ] + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", + "size": 11888 + }, + "protoVer": "1.1.3" } } ``` -## ain_getBlocks +## ain_getBlockList Returns a list of blocks that have a block number between "from" block number and "to" block number. @@ -2202,60 +2198,79 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getBlocks", + "method": "ain_getBlockList", "params": { - "from": 0, - "to": 100 + "protoVer": "1.1.3", + "from": 3300526, + "to": 3300528 } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result": - [ - { - "timestamp":1564845946382, - "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "parent_hash":"", - "number":0, - "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", - "validators":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ], - "size":163591, - "transactions":[ - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f3...", - "timestamp":1566736760322, - "nonce":-1 - "parent_tx_hash":"0x88df016429689c079f3b2f6ad39fa052532c56...", - "operation":{ ... } +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": [ + { + "last_votes": [ + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0xe4ec974b210f26f66a0b005a87ea4ea8b74e507ece9ae4219a130fca19c1f15f", + "last_votes_hash": "0x670bd883418c7b14847dbc315a3a0b4ea23cad091667d5807005026bae7c1600", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3300526, + "epoch": 3305949, + "timestamp": 1707114196712, + "state_proof_hash": "0x5966358621862d6f29926921738381944e77365df449b898aaed309090a849e7", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... }, - { - "hash":"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99...", - "address":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d", - "signature":"0x1ec191ef20b0e9628c4397665977cb...", - "timestamp":1566736760400, - "nonce":99, - "operation":{ ... } + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", + "size": 11888 + }, + { + "last_votes": [ + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", + "last_votes_hash": "0x204b100233731f4b6e8cd8e260d3bb427ff8337764429f37a92262c8018de8b1", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3300527, + "epoch": 3305950, + "timestamp": 1707114216713, + "state_proof_hash": "0xd187d996f1106468f4dbba9f535112f7d3c30faee78bc1eb259fafa33dd9a5db", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... }, - ... - ] - }, - ... - ] + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0xf0f5e395461d9ad197bf7b8a10722be993dd7a564af2e3e84431764eff9734ee", + "size": 11888 + } + ], + "protoVer": "1.1.3" + } } ``` -## ain_getBlockHeaders +## ain_getBlockHeadersList Returns a list of block headers that have a block number between "from" block number and "to" block number. @@ -2277,36 +2292,59 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getBlockHeaders", + "method": "ain_getBlockHeadersList", "params": { - "from": 0, - "to": 100 + "protoVer": "1.1.3", + "from": 3300526, + "to": 3300528 } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result": - [ - { - "timestamp":1564845946382, - "hash":"0x7a6c2a5a91ce3731310885eff761f7ee39484...", - "parent_hash":"", - "number":0, - "proposer":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81", - "validators":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ], - "size":163591, - }, - ... - ] +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": [ + { + "last_hash": "0xe4ec974b210f26f66a0b005a87ea4ea8b74e507ece9ae4219a130fca19c1f15f", + "last_votes_hash": "0x670bd883418c7b14847dbc315a3a0b4ea23cad091667d5807005026bae7c1600", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "number": 3300526, + "epoch": 3305949, + "timestamp": 1707114196712, + "state_proof_hash": "0x5966358621862d6f29926921738381944e77365df449b898aaed309090a849e7", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... + }, + "gas_amount_total": 0, + "gas_cost_total": 0 + }, + { + "last_hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9", + "last_votes_hash": "0x204b100233731f4b6e8cd8e260d3bb427ff8337764429f37a92262c8018de8b1", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "number": 3300527, + "epoch": 3305950, + "timestamp": 1707114216713, + "state_proof_hash": "0xd187d996f1106468f4dbba9f535112f7d3c30faee78bc1eb259fafa33dd9a5db", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + ... + }, + "gas_amount_total": 0, + "gas_cost_total": 0 + } + ], + "protoVer": "1.1.3" + } } ``` @@ -2333,17 +2371,21 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "id": 1, "method": "ain_getBlockTransactionCountByNumber", "params": { - "number": "123" + "protoVer": "1.1.3", + "number": 3300526 } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":11 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 0, + "protoVer": "1.1.3" + } } ``` @@ -2368,19 +2410,23 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getBlockTransactionCountByNumber", + "method": "ain_getBlockTransactionCountByHash", "params": { - "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + "protoVer": "1.1.3", + "hash": "0xfb3f0cf12c57238c509cc0abeed503cc1eb837b67840210fe8ec0bd4ce96b8d9" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":11 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 0, + "protoVer": "1.1.3" + } } ``` From 5ba09ad6055f0f0ffcac0a4c09c7b31004ade0a9 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 16:19:44 +0900 Subject: [PATCH 22/38] Re-arrange block apis in json_rpc/block.js --- json_rpc/block.js | 53 ++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/json_rpc/block.js b/json_rpc/block.js index dfa70b412..905394785 100644 --- a/json_rpc/block.js +++ b/json_rpc/block.js @@ -2,19 +2,12 @@ const { TrafficEventTypes, trafficStatsManager, } = require('../common/constants'); +const CommonUtil = require('../common/common-util'); const JsonRpcUtil = require('./json-rpc-util'); const { JSON_RPC_METHODS } = require('./constants'); module.exports = function getBlockApis(node) { return { - [JSON_RPC_METHODS.AIN_GET_BLOCK_LIST]: function(args, done) { - const beginTime = Date.now(); - const blocks = node.bc.getBlockList(args.from, args.to); - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result: blocks })); - }, - [JSON_RPC_METHODS.AIN_GET_LAST_BLOCK]: function(args, done) { const beginTime = Date.now(); const result = node.bc.lastBlock(); @@ -31,22 +24,21 @@ module.exports = function getBlockApis(node) { done(null, JsonRpcUtil.addProtocolVersion({ result })); }, - [JSON_RPC_METHODS.AIN_GET_BLOCK_HEADERS_LIST]: function(args, done) { + [JSON_RPC_METHODS.AIN_GET_BLOCK_BY_NUMBER]: function(args, done) { const beginTime = Date.now(); - const blocks = node.bc.getBlockList(args.from, args.to); - const blockHeaders = []; - blocks.forEach((block) => { - blockHeaders.push(block.header); - }); + const block = node.bc.getBlockByNumber(args.number); + if (block && !CommonUtil.toBool(args.getFullTransactions)) { + block.transactions = JsonRpcUtil.extractTransactionHashes(block); + } const latency = Date.now() - beginTime; trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result: blockHeaders })); + done(null, JsonRpcUtil.addProtocolVersion({ result: block })); }, [JSON_RPC_METHODS.AIN_GET_BLOCK_BY_HASH]: function(args, done) { const beginTime = Date.now(); const block = node.bc.getBlockByHash(args.hash); - if (block && !args.getFullTransactions) { + if (block && !CommonUtil.toBool(args.getFullTransactions)) { block.transactions = JsonRpcUtil.extractTransactionHashes(block); } const latency = Date.now() - beginTime; @@ -54,19 +46,24 @@ module.exports = function getBlockApis(node) { done(null, JsonRpcUtil.addProtocolVersion({ result: block })); }, - [JSON_RPC_METHODS.AIN_GET_BLOCK_BY_NUMBER]: function(args, done) { + [JSON_RPC_METHODS.AIN_GET_BLOCK_LIST]: function(args, done) { const beginTime = Date.now(); - const block = node.bc.getBlockByNumber(args.number); - if (!block || args.getFullTransactions) { - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result: block })); - } else { - block.transactions = JsonRpcUtil.extractTransactionHashes(block); - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result: block })); - } + const blocks = node.bc.getBlockList(args.from, args.to); + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result: blocks })); + }, + + [JSON_RPC_METHODS.AIN_GET_BLOCK_HEADERS_LIST]: function(args, done) { + const beginTime = Date.now(); + const blocks = node.bc.getBlockList(args.from, args.to); + const blockHeaders = []; + blocks.forEach((block) => { + blockHeaders.push(block.header); + }); + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result: blockHeaders })); }, [JSON_RPC_METHODS.AIN_GET_PROPOSER_BY_HASH]: function(args, done) { From af9e3368e9d1e2dfac4b0d35f037b559540d4ceb Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 5 Feb 2024 16:41:33 +0900 Subject: [PATCH 23/38] Spin off consensus apis from block apis in json_rpc/block.js --- json_rpc/account.js | 15 ----------- json_rpc/block.js | 40 ++-------------------------- json_rpc/consensus.js | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 53 deletions(-) create mode 100644 json_rpc/consensus.js diff --git a/json_rpc/account.js b/json_rpc/account.js index c7773239e..7852222ba 100644 --- a/json_rpc/account.js +++ b/json_rpc/account.js @@ -40,20 +40,5 @@ module.exports = function getAccountApis(node) { trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); done(null, JsonRpcUtil.addProtocolVersion({ result })); }, - - [JSON_RPC_METHODS.AIN_GET_VALIDATOR_INFO]: function(args, done) { - const beginTime = Date.now(); - const addr = args.address; - const isWhitelisted = node.db.getValue(PathUtil.getConsensusProposerWhitelistAddrPath(addr)) || false; - const stake = node.db.getValue(PathUtil.getServiceAccountBalancePath(addr)) || 0; - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ - result: { - isWhitelisted, - stake, - } - })); - }, }; }; diff --git a/json_rpc/block.js b/json_rpc/block.js index 905394785..e07ad89e5 100644 --- a/json_rpc/block.js +++ b/json_rpc/block.js @@ -66,37 +66,10 @@ module.exports = function getBlockApis(node) { done(null, JsonRpcUtil.addProtocolVersion({ result: blockHeaders })); }, - [JSON_RPC_METHODS.AIN_GET_PROPOSER_BY_HASH]: function(args, done) { - const beginTime = Date.now(); - const block = node.bc.getBlockByHash(args.hash); - const result = block ? block.proposer : null; - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result })); - }, - - [JSON_RPC_METHODS.AIN_GET_PROPOSER_BY_NUMBER]: function(args, done) { - const beginTime = Date.now(); - const block = node.bc.getBlockByNumber(args.number); - const result = block ? block.proposer : null; - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result })); - }, - - [JSON_RPC_METHODS.AIN_GET_VALIDATORS_BY_NUMBER]: function(args, done) { + [JSON_RPC_METHODS.AIN_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER]: function(args, done) { const beginTime = Date.now(); const block = node.bc.getBlockByNumber(args.number); - const result = block ? block.validators : null; - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result })); - }, - - [JSON_RPC_METHODS.AIN_GET_VALIDATORS_BY_HASH]: function(args, done) { - const beginTime = Date.now(); - const block = node.bc.getBlockByHash(args.hash); - const result = block ? block.validators : null; + const result = block ? block.transactions.length : null; const latency = Date.now() - beginTime; trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); done(null, JsonRpcUtil.addProtocolVersion({ result })); @@ -110,14 +83,5 @@ module.exports = function getBlockApis(node) { trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); done(null, JsonRpcUtil.addProtocolVersion({ result })); }, - - [JSON_RPC_METHODS.AIN_GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER]: function(args, done) { - const beginTime = Date.now(); - const block = node.bc.getBlockByNumber(args.number); - const result = block ? block.transactions.length : null; - const latency = Date.now() - beginTime; - trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); - done(null, JsonRpcUtil.addProtocolVersion({ result })); - }, }; }; diff --git a/json_rpc/consensus.js b/json_rpc/consensus.js new file mode 100644 index 000000000..a9726ef38 --- /dev/null +++ b/json_rpc/consensus.js @@ -0,0 +1,61 @@ +const { + TrafficEventTypes, + trafficStatsManager, +} = require('../common/constants'); +const JsonRpcUtil = require('./json-rpc-util'); +const { JSON_RPC_METHODS } = require('./constants'); + +module.exports = function getBlockApis(node) { + return { + [JSON_RPC_METHODS.AIN_GET_VALIDATOR_INFO]: function(args, done) { + const beginTime = Date.now(); + const addr = args.address; + const isWhitelisted = node.db.getValue(PathUtil.getConsensusProposerWhitelistAddrPath(addr)) || false; + const stake = node.db.getValue(PathUtil.getServiceAccountBalancePath(addr)) || 0; + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ + result: { + isWhitelisted, + stake, + } + })); + }, + + [JSON_RPC_METHODS.AIN_GET_VALIDATORS_BY_NUMBER]: function(args, done) { + const beginTime = Date.now(); + const block = node.bc.getBlockByNumber(args.number); + const result = block ? block.validators : null; + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result })); + }, + + [JSON_RPC_METHODS.AIN_GET_VALIDATORS_BY_HASH]: function(args, done) { + const beginTime = Date.now(); + const block = node.bc.getBlockByHash(args.hash); + const result = block ? block.validators : null; + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result })); + }, + + [JSON_RPC_METHODS.AIN_GET_PROPOSER_BY_NUMBER]: function(args, done) { + const beginTime = Date.now(); + const block = node.bc.getBlockByNumber(args.number); + const result = block ? block.proposer : null; + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result })); + }, + + [JSON_RPC_METHODS.AIN_GET_PROPOSER_BY_HASH]: function(args, done) { + const beginTime = Date.now(); + const block = node.bc.getBlockByHash(args.hash); + const result = block ? block.proposer : null; + const latency = Date.now() - beginTime; + trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); + done(null, JsonRpcUtil.addProtocolVersion({ result })); + }, + }; +}; From cbe033e58c2ae1430837f3e431db9827a42d1204 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Feb 2024 15:36:39 +0900 Subject: [PATCH 24/38] Fix or update Consensus APIs in JSON_RPC_API.md file --- JSON_RPC_API.md | 205 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 148 insertions(+), 57 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 6904b03e7..dcf809c76 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -38,10 +38,10 @@ - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) - [Consensus API](#consensus-api) - [ain_getValidatorInfo](#ain_getvalidatorinfo) - - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) - - [ain_getProposerByHash](#ain_getproposerbyhash) + - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) - [ain_getProposerByNumber](#ain_getproposerbynumber) + - [ain_getProposerByHash](#ain_getproposerbyhash) - [Network API](#network-api) - [net_listening](#net_listening) - [net_nodeInfo](#net_nodeinfo) @@ -1132,7 +1132,7 @@ Returns the balance of the given account. An object with a property: -- address: `String` - address of the account. +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -1173,7 +1173,7 @@ Returns the nonce, number of transactions an address has sent, of the given acco An object with a property: -- address: `String` - address of the account +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -1214,7 +1214,7 @@ Returns the timestamp of the given account An object with a property: -- address: `String` - address of the account +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -2436,13 +2436,13 @@ Response ### ain_getValidatorInfo -Returns the information of the given block validator +Returns the information of the given block validator. **Parameters** An object with a property: -- address: `String` - address of the block validator's account +- address: `String` - address of the block validator's account, which should be a checksum address **Returns** @@ -2458,7 +2458,7 @@ curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: applica "method": "ain_getValidatorInfo", "params": { "protoVer": "1.1.3", - "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" + "address": "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d" } }' ``` @@ -2470,23 +2470,24 @@ Response "id": 1, "result": { "result": { + "address": "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d", "isWhitelisted": true, - "stake": 0 + "stake": 10000000 }, "protoVer": "1.1.3" } } ``` -## ain_getValidatorsByHash +## ain_getValidatorsByNumber -Returns the validators who validated the block. +Returns the validators who validated the block. **Parameters** An object with a property: -- hash: `String` - block hash +- number: `Number` - block number **Returns** @@ -2499,35 +2500,76 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getValidatorsByHash", + "method": "ain_getValidatorsByNumber", "params": { - "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + "protoVer": "1.1.3", + "number": 3313267 } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ] +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + "0x003AD6FdB06684175e7D95EcC36758B014517E4b": { + "stake": 10000000, + "proposal_right": true + }, + "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d": { + "stake": 10000000, + "proposal_right": true + }, + "0x004A2550661c8a306207C9dabb279d5701fFD66e": { + "stake": 10000000, + "proposal_right": true + }, + "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211": { + "stake": 10000000, + "proposal_right": true + }, + "0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD": { + "stake": 100000, + "proposal_right": false + }, + "0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba": { + "stake": 100000, + "proposal_right": false + }, + "0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74": { + "stake": 100000, + "proposal_right": false + }, + "0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe": { + "stake": 100000, + "proposal_right": false + }, + "0x005A3c55EcE1A593b761D408B6E6BC778E0a638B": { + "stake": 100000, + "proposal_right": false + } + }, + "protoVer": "1.1.3" + } } ``` -## ain_getValidatorsByNumber +## ain_getValidatorsByHash -Returns the validators who validated the block. +Returns the validators who validated the block. **Parameters** An object with a property: -- number: `Number` - block number +- hash: `String` - block hash **Returns** @@ -2540,39 +2582,80 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "ain_getValidatorsByNumber", + "method": "ain_getValidatorsByHash", "params": { - "number": 2143 + "protoVer": "1.1.3", + "hash": "0x3e1a023e77ad5b909ce3610b2dad921c3b0a5cae33e75676470c8f75eb08860c" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":[ - "0x4e65fda2159562a496f9f3522f89122a3088497a", - "0xd46e8dd67c5d32be8058bb8eb970870f07244567", - "0xb60e8dd61c5d32be8058bb8eb970870f07233155" - ] +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + "0x003AD6FdB06684175e7D95EcC36758B014517E4b": { + "stake": 10000000, + "proposal_right": true + }, + "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d": { + "stake": 10000000, + "proposal_right": true + }, + "0x004A2550661c8a306207C9dabb279d5701fFD66e": { + "stake": 10000000, + "proposal_right": true + }, + "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211": { + "stake": 10000000, + "proposal_right": true + }, + "0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD": { + "stake": 100000, + "proposal_right": false + }, + "0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba": { + "stake": 100000, + "proposal_right": false + }, + "0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74": { + "stake": 100000, + "proposal_right": false + }, + "0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe": { + "stake": 100000, + "proposal_right": false + }, + "0x005A3c55EcE1A593b761D408B6E6BC778E0a638B": { + "stake": 100000, + "proposal_right": false + } + }, + "protoVer": "1.1.3" + } } ``` -## ain_getProposerByHash +## ain_getProposerByNumber -Returns the proposer who produced the block with the given block hash. +Returns the proposer who produced the block with the given block number. **Parameters** An object with a property: -- hash: `String` - block hash +- number: `Number` - block number **Returns** -`String` - The address of the proposer. +`String` - The proposer's address. **Example** @@ -2580,36 +2663,40 @@ Request ``` curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", - "id": 1, - "method": "ain_getProposerByHash", + "id": 1, + "method": "ain_getProposerByNumber", "params": { - "hash": "0x7a6c2a5a91ce3731310885eff761f7ee39484..." + "protoVer": "1.1.3", + "number": 3313267 } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d", + "protoVer": "1.1.3" + } } ``` -## ain_getProposerByNumber +## ain_getProposerByHash -Returns the proposer who produced the block with the given block number. +Returns the proposer who produced the block with the given block hash. **Parameters** An object with a property: -- number: `Number` - block number +- hash: `String` - block hash **Returns** -`String` - The proposer's address. +`String` - The address of the proposer. **Example** @@ -2617,20 +2704,24 @@ Request ``` curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", - "id": 1, - "method": "ain_getProposerByNumber", + "id": 1, + "method": "ain_getProposerByHash", "params": { - "number": 456 + "protoVer": "1.1.3", + "hash": "0x3e1a023e77ad5b909ce3610b2dad921c3b0a5cae33e75676470c8f75eb08860c" } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":"0x04aac78e17374fd075d1f11bfe95ef7d8e4ed81" +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": "0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d", + "protoVer": "1.1.3" + } } ``` From f6ade8c880ae3786e691eae6c1ec9a20a5835692 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Feb 2024 15:41:27 +0900 Subject: [PATCH 25/38] Fix consensus api import issue --- json_rpc/consensus.js | 3 ++- json_rpc/index.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/json_rpc/consensus.js b/json_rpc/consensus.js index a9726ef38..9af727797 100644 --- a/json_rpc/consensus.js +++ b/json_rpc/consensus.js @@ -2,10 +2,11 @@ const { TrafficEventTypes, trafficStatsManager, } = require('../common/constants'); +const PathUtil = require('../common/path-util'); const JsonRpcUtil = require('./json-rpc-util'); const { JSON_RPC_METHODS } = require('./constants'); -module.exports = function getBlockApis(node) { +module.exports = function getConsensusApis(node) { return { [JSON_RPC_METHODS.AIN_GET_VALIDATOR_INFO]: function(args, done) { const beginTime = Date.now(); diff --git a/json_rpc/index.js b/json_rpc/index.js index 8a8a87026..4c8d453f5 100644 --- a/json_rpc/index.js +++ b/json_rpc/index.js @@ -6,6 +6,7 @@ const getAccountApis = require('./account'); const getAppApis = require('./app'); const getAdminApis = require('./admin'); const getBlockApis = require('./block'); +const getConsensusApis = require('./consensus'); const getDatabaseApis = require('./database'); const getEventHandlerApis = require('./event-handler'); const getNetworkApis = require('./network'); @@ -36,6 +37,7 @@ module.exports = function getApis(node, p2pServer, minProtocolVersion, maxProtoc ...getAccountApis(node), ...getAppApis(node), ...getBlockApis(node), + ...getConsensusApis(node), ...getDatabaseApis(node), ...getNetworkApis(node, p2pServer), ...getTransactionApis(node, p2pServer), From 8a415da90adebaff5ccc454a1701ca43c71ba855 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 8 Feb 2024 15:42:33 +0900 Subject: [PATCH 26/38] Fix validator info stake balance bug --- json_rpc/consensus.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/json_rpc/consensus.js b/json_rpc/consensus.js index 9af727797..b3e8310ae 100644 --- a/json_rpc/consensus.js +++ b/json_rpc/consensus.js @@ -12,11 +12,12 @@ module.exports = function getConsensusApis(node) { const beginTime = Date.now(); const addr = args.address; const isWhitelisted = node.db.getValue(PathUtil.getConsensusProposerWhitelistAddrPath(addr)) || false; - const stake = node.db.getValue(PathUtil.getServiceAccountBalancePath(addr)) || 0; + const stake = node.db.getValue(PathUtil.getConsensusStakingAccountBalancePath(addr)) || 0; const latency = Date.now() - beginTime; trafficStatsManager.addEvent(TrafficEventTypes.JSON_RPC_GET, latency); done(null, JsonRpcUtil.addProtocolVersion({ result: { + address: addr, isWhitelisted, stake, } From e0b508e6bf13c884a9502020183de90528dee90e Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Feb 2024 12:12:00 +0900 Subject: [PATCH 27/38] Update network apis in JSON_RPC_API.md file --- JSON_RPC_API.md | 492 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 448 insertions(+), 44 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index dcf809c76..70d12c739 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -44,10 +44,13 @@ - [ain_getProposerByHash](#ain_getproposerbyhash) - [Network API](#network-api) - [net_listening](#net_listening) - - [net_nodeInfo](#net_nodeinfo) - [net_peerCount](#net_peercount) - [net_syncing](#net_syncing) - - [net_id](#net_id) + - [net_getNetworkId](#net_getnetworkid) + - [net_getChainId](#net_getchainid) + - [net_consensusStatus](#net_consensusstatus) + - [net_rawConsensusStatus](#net_rawconsensusstatus) + - [p2p_getPeerCandidateInfo](#p2p_getpeercandidateinfo) --- @@ -2748,22 +2751,28 @@ 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_listening", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":true +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": true, + "protoVer": "1.1.3" + } } ``` -### net_nodeInfo +### net_peerCount -Returns the node's information. +Returns the number of peers the node is connected to. **Parameters** @@ -2771,7 +2780,7 @@ None. **Returns** -`Object` - the object containing node's information. +`Number` - number of peers. **Example** @@ -2780,26 +2789,28 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_nodeInfo" + "method": "net_peerCount", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":{ - "name":"comcom_node", - "location":"KOR", - "version":"1.0.0" +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 3, + "protoVer": "1.1.3" } } ``` -### net_peerCount +### net_syncing -Returns the number of peers the node is connected to. +Returns whether the node is syncing with the network or not. **Parameters** @@ -2807,7 +2818,7 @@ None. **Returns** -`Number` - number of peers. +`Boolean` - true if the node is syncing, false otherwise. **Example** @@ -2816,22 +2827,28 @@ 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_syncing", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":7 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": false, + "protoVer": "1.1.3" + } } ``` -### net_syncing +### net_getNetworkId -Returns whether the node is syncing with the network or not. +Returns the blockchain node's network id. **Parameters** @@ -2839,8 +2856,11 @@ None. **Returns** -`Boolean` - true if the node is syncing, false otherwise. +`Number` - the network id. +- 0: mainnet network +- 1: testnet network + **Example** Request @@ -2848,22 +2868,28 @@ 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_getNetworkId", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":true +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 0, + "protoVer": "1.1.3" + } } ``` -### net_id +### net_getChainId -Returns the network id. +Returns the blockchain node's chain id. **Parameters** @@ -2871,10 +2897,10 @@ None. **Returns** -`Number` - the network id. +`Number` - the chain id. -- 0: main network -- 1: test network +- 0: mainnet chain +- 1: testnet chain **Example** @@ -2883,16 +2909,394 @@ Request curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 1, - "method": "net_id" + "method": "net_getChainId", + "params": { + "protoVer": "1.1.3" + } }' ``` Response ``` -{ - "jsonrpc":"2.0", - "id":1, - "result":0 +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": 0, + "protoVer": "1.1.3" + } +} +``` + +### net_consensusStatus + +Returns the blockchain node's consensus status. + +**Parameters** + +None. + +**Returns** + +`Object` - an object containing the consensus status. + +- `STARTING`: consensus process starting +- `RUNNING`: consensus process running +- `STOPPED`: consensus process stopped + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_consensusStatus", + "params": { + "protoVer": "1.1.3" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "health": true, + "state": "RUNNING", + "stateNumeric": 1, + "epoch": 3339699, + "isInEpochTransition": false, + "validators": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true, + "voting_right": true + }, + ... + }, + "globalTimeSyncStatus": { + "averageNTPDelta": 0.25, + "averageNTPLatency": 14, + "minimalNTPLatencyDelta": 13, + "minimalNTPLatency": 6, + "totalSampleCount": 4, + "syncedAt": 1707789022964 + }, + "rewards": { + "unclaimed": 1690211.830771636, + "cumulative": 1690211.830771636 + } + }, + "protoVer": "1.1.3" + } +} +``` + +### net_rawConsensusStatus + +Returns the blockchain node's raw consensus status. + +**Parameters** + +None. + +**Returns** + +`Object` - an object containing the raw consensus status. + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "net_rawConsensusStatus", + "params": { + "protoVer": "1.1.3" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "consensus": { + "epoch": 3339714, + "proposer": "0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211", + "state": "RUNNING" + }, + "block_pool": { + "hashToBlockInfo": { + "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c": { + "block": { + "last_votes": [ + { + "tx_body": { + "operation": { + "type": "SET", + "op_list": [ + { + "type": "SET_VALUE", + "ref": "/consensus/number/3334275/propose", + "value": { + "number": 3334275, + "epoch": 3339711, + "validators": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + ... + }, + "total_at_stake": 50500000, + "proposer": "0x003AD6FdB06684175e7D95EcC36758B014517E4b", + "block_hash": "0x6b148d07060f58bdd8301416f9df9b1225591297ec4eeceff9c1de19748e4a38", + "last_hash": "0xc62c681c7d9015505cf2ce01c5a1251e4fb6d56b25069fbaa91d7561d99314fa", + "timestamp": 1707789435127, + "gas_cost_total": 0 + } + } + ] + }, + "nonce": -1, + "gas_price": 0, + "timestamp": 1707789435176 + }, + "signature": "0x19f276213d95bcb4d3a6ff52a105b0bc711d9d742af568d11ddc007cd0bf2b136dbc4d77e0d2709fdf8fa3b360f4500407f2ccbfa8c83658f24cb864065332c853f2ae50b4c54c960c999ddb9efd2c71126ed91ba605270d41dffca60d0271cb1c", + "hash": "0x19f276213d95bcb4d3a6ff52a105b0bc711d9d742af568d11ddc007cd0bf2b13", + "address": "0x003AD6FdB06684175e7D95EcC36758B014517E4b" + }, + ... + ], + "evidence": {}, + "transactions": [], + "receipts": [], + "last_hash": "0x6b148d07060f58bdd8301416f9df9b1225591297ec4eeceff9c1de19748e4a38", + "last_votes_hash": "0xe9f92185d91193a9c253e9953a126bb29838bb3c18ffcbfc513633c23ed739eb", + "evidence_hash": "0xd35126dcb36a3c4b4ef04c4eff63edecbc9eacff867d1c348c1abaf82567a8f8", + "transactions_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "receipts_hash": "0x853fb99c831d4952ff90b897bd7d7c5c2f3747e8eda8ad13e7359b731eadc299", + "number": 3334276, + "epoch": 3339712, + "timestamp": 1707789453632, + "state_proof_hash": "0x4771b8960f7e3d332729f7238aafe418179daca65ddba2471aa2f2edd6dc93fb", + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "validators": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + ... + }, + "gas_amount_total": 0, + "gas_cost_total": 0, + "hash": "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c", + "size": 11888 + }, + "proposal": { + "tx_body": { + "operation": { + "type": "SET", + "op_list": [ + { + "type": "SET_VALUE", + "ref": "/consensus/number/3334276/propose", + "value": { + "number": 3334276, + "epoch": 3339712, + "validators": { + "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4": { + "stake": 10000000, + "proposal_right": true + }, + ... + }, + "total_at_stake": 50500000, + "proposer": "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "block_hash": "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c", + "last_hash": "0x6b148d07060f58bdd8301416f9df9b1225591297ec4eeceff9c1de19748e4a38", + "timestamp": 1707789453632, + "gas_cost_total": 0 + } + } + ] + }, + "nonce": -1, + "gas_price": 0, + "timestamp": 1707789453675 + }, + "signature": "0x88cb6d7433691e59995bffa619515df098bb228a6bad46e75017a948b74166ab303e2e09e94fbe2c499cd4fb3329250f6f4390b32478750cd2e48e6468b398a76003e668a9208432f1f2b2212ad806c2ef8d1b22dd927fc3e8ba29570a000cb91c", + "hash": "0x88cb6d7433691e59995bffa619515df098bb228a6bad46e75017a948b74166ab", + "address": "0x004A2550661c8a306207C9dabb279d5701fFD66e" + }, + "votes": [ + { + "tx_body": { + "operation": { + "type": "SET_VALUE", + "ref": "/consensus/number/3334276/0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c/vote/0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "value": { + "block_hash": "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c", + "stake": 10000000, + "is_against": false, + "vote_nonce": 1707789453959 + } + }, + "nonce": -1, + "gas_price": 0, + "timestamp": 1707789453959 + }, + "signature": "0x88d0589161197857d0ca90a004674fb39d87556d67b5065a2cae0e2720688f2dead4c555eeca90b5c64c433adcff740870644cd4b30f912efb4e7cd9ca6704d775bf08dd8ec595e235fe3663ef329f3b24b87f793427d0f5534fc4c452ea18cf1c", + "hash": "0x88d0589161197857d0ca90a004674fb39d87556d67b5065a2cae0e2720688f2d", + "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4" + }, + ... + ], + "tallied": 50000000, + "notarized": true + }, + ... + }, + "hashToInvalidBlockInfo": {}, + "hashToDb": [ + "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c", + "0xf45a08f6a6859f4fe3cd712beb07d11e633adb2eccc608c0ce71601b06e08390" + ], + "hashToNextBlockSet": { + "0x0d595aabdf8105a2e147d92c1ad263302eea1783bebba67d5295cccb3affba3f": [ + "0x89045524ffed88d8e04d942269a249463951627eb5ee9bdd6da4a7f8ae902f09" + ], + "0xcdc74d17d84ed8b75c5ed4a02d54c3c6011c2d7f7ce7f5b6dd9a0b82b8a4a20c": [ + "0xf45a08f6a6859f4fe3cd712beb07d11e633adb2eccc608c0ce71601b06e08390" + ] + }, + "epochToBlock": [ + 3339712, + 3339713 + ], + "numberToBlockSet": [ + 3334276, + "3334276", + 3334277, + "3334277" + ], + "longestNotarizedChainTips": [ + "0xf45a08f6a6859f4fe3cd712beb07d11e633adb2eccc608c0ce71601b06e08390" + ] + } + }, + "protoVer": "1.1.3" + } +} +``` + +### p2p_getPeerCandidateInfo + +Returns the blockchain node's peer candidate information. + +**Parameters** + +None. + +**Returns** + +`Object` - an object containing the peer candidate information. + +- `STARTING`: p2p connection starting +- `EXPANDING`: p2p connection expanding +- `STEADY`: p2p connection steady + +**Example** + +Request +``` +curl https://testnet-api.ainetwork.ai/json-rpc -X POST -H "Content-Type: application/json" -d '{ + "jsonrpc": "2.0", + "id": 1, + "method": "p2p_getPeerCandidateInfo", + "params": { + "protoVer": "1.1.3" + } +}' +``` + +Response +``` +{ + "jsonrpc": "2.0", + "id": 1, + "result": { + "result": { + "address": "0x000AF024FEDb636294867bEff390bCE6ef9C5fc4", + "isAvailableForConnection": true, + "networkStatus": { + "urls": { + "ip": "35.221...", + "p2p": { + "url": "ws://35.221...:5000/", + "port": 5000 + }, + "clientApi": { + "url": "http://35.221...:8080/", + "port": 8080 + }, + "jsonRpc": { + "url": "http://35.221...:8080/json-rpc", + "port": 8080 + } + }, + "connectionStatus": { + "state": "STEADY", + "stateNumeric": 2, + "isConnectingToPeerCandidates": false, + "peerConnectionStartedAt": 1707790289596, + "peerConnectionElapsedTime": 155538, + "maxInbound": 6, + "targetOutBound": 3, + "peerConnectionsInProgress": [], + "peerCandidates": [ + "http://35.221...:8080/json-rpc", + "http://35.199...:8080/json-rpc", + "http://35.223...:8080/json-rpc", + "http://35.240...:8080/json-rpc", + "http://34.90...:8080/json-rpc", + "http://34.80...:8080/json-rpc", + "http://23.88...:8080/json-rpc" + ], + "numInbound": 3, + "numOutbound": 3, + "numConnections": 6, + "numPeerConnectionsInProgress": 0, + "numPeerCandidates": 7, + "incomingPeers": [ + "0xA20D01638DB479bc5a4cC90577CB7A61D2EB22FE", + "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "0x76F114dAC5593f671E965DE5912D73dBe7215D5E" + ], + "outgoingPeers": [ + "0xA20D01638DB479bc5a4cC90577CB7A61D2EB22FE", + "0x004A2550661c8a306207C9dabb279d5701fFD66e", + "0x76F114dAC5593f671E965DE5912D73dBe7215D5E" + ] + } + }, + "peerCandidateJsonRpcUrlList": { + "0xA20D01638DB479bc5a4cC90577CB7A61D2EB22FE": "http://23.88...:8080/json-rpc", + "0x004A2550661c8a306207C9dabb279d5701fFD66e": "http://34.90...:8080/json-rpc", + "0x76F114dAC5593f671E965DE5912D73dBe7215D5E": "http://34.80...:8080/json-rpc" + } + }, + "protoVer": "1.1.3" + } } ``` From b5456ad380fc3e97df8b9152c9c3dcdcd423d4a0 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Feb 2024 12:24:33 +0900 Subject: [PATCH 28/38] Consensus API -> Blockchain Node API --- JSON_RPC_API.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 70d12c739..72b3111b2 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -36,7 +36,7 @@ - [ain_getBlockHeadersList](#ain_getblockheaderslist) - [ain_getBlockTransactionCountByNumber](#ain_getblocktransactioncountbynumber) - [ain_getBlockTransactionCountByHash](#ain_getblocktransactioncountbyhash) -- [Consensus API](#consensus-api) +- [Blockchain Node API](#blockchain-node-api) - [ain_getValidatorInfo](#ain_getvalidatorinfo) - [ain_getValidatorsByNumber](#ain_getvalidatorsbynumber) - [ain_getValidatorsByHash](#ain_getvalidatorsbyhash) @@ -2435,7 +2435,7 @@ Response --- -## Consensus API +## Blockchain Node API ### ain_getValidatorInfo From 8fd922783d73ec8053330b9a7794386f19fc73f4 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Feb 2024 12:48:26 +0900 Subject: [PATCH 29/38] Add descriptions about protoVer parameter --- JSON_RPC_API.md | 193 +++++++++++++++++++++++++++++++----------------- 1 file changed, 126 insertions(+), 67 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 72b3111b2..1a5b61770 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -62,8 +62,9 @@ Returns the value, write rule, owner rule, or function at the given path in the **Parameters** -An array of objects with a property: +An array of objects with properties: +- protoVer: `String` - protocol version - ref: `String` - reference path **Returns** @@ -347,9 +348,10 @@ Returns the functions matched at the given value path in the global state tree. **Parameters** -An object with a property: +An object with properties: -- ref: `String` - reference value path +- protoVer: `String` - protocol version +- ref: `String` - reference value path **Returns** @@ -408,8 +410,9 @@ Returns the rules matched at the given value path in the global state tree. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference value path **Returns** @@ -488,8 +491,9 @@ Returns the owners matched at the given value path in the global state tree. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference value path **Returns** @@ -547,8 +551,9 @@ Evaluates the rule configs matched with the given value path in the global state **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference value path - value: `String|Number|Boolean|Object` - value to write - address: `String` - account address (optional) @@ -668,8 +673,9 @@ Evaluates the owner configs matched with the given value path in the global stat **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference value path - permission: `'write_rule'|'write_function'|'write_owner'|'branch_owner'` - permission to evaluate with - address: `String` - account address (optional) @@ -739,8 +745,9 @@ Returns the state proof of the given path in the global state tree. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. **Returns** @@ -920,8 +927,9 @@ Returns the state proof hash of the given path in the global state tree. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. **Returns** @@ -986,8 +994,9 @@ Returns the state information of the given path in the global state tree. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - ref: `String` - reference path prefixed with data type. e.g., /values/accounts/0x..., /rules/transfer/\$from/\$to/value, /functions/transfer/\$from/\$to/\$key/value, /owners/apps/consensus. **Returns** @@ -1035,8 +1044,9 @@ Returns the state usage of the given app name. **Parameters** -An object with a property: +An object with properties: +- protoVer: `String` - protocol version - app_name: `String` - app name **Returns** @@ -1097,6 +1107,10 @@ Returns the address of the blockchain node's account. **Parameters** +An object with properties: + +- protoVer: `String` - protocol version + **Returns** `String` - The address. @@ -1133,9 +1147,10 @@ Returns the balance of the given account. **Parameters** -An object with a property: +An object with properties: -- address: `String` - address of the account, which should be a checksum address +- protoVer: `String` - protocol version +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -1174,9 +1189,10 @@ Returns the nonce, number of transactions an address has sent, of the given acco **Parameters** -An object with a property: +An object with properties: -- address: `String` - address of the account, which should be a checksum address +- protoVer: `String` - protocol version +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -1215,9 +1231,10 @@ Returns the timestamp of the given account **Parameters** -An object with a property: +An object with properties: -- address: `String` - address of the account, which should be a checksum address +- protoVer: `String` - protocol version +- address: `String` - address of the account, which should be a checksum address **Returns** @@ -1260,7 +1277,9 @@ Returns currently pending transactions. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -1396,7 +1415,9 @@ Returns the transaction pool size utilization. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -1439,9 +1460,10 @@ Returns the transaction with the hash. **Parameters** -An object with a property: +An object with properties: -- hash: `String` - transaction hash +- protoVer: `String` - protocol version +- hash: `String` - transaction hash **Returns** @@ -1541,10 +1563,11 @@ Returns the transaction at the {index} position in the block with the {block_has **Parameters** -An object with 2 properties: +An object with properties: -- block_hash: `String` - block hash -- index: `Number` - index of the transaction within the block +- protoVer: `String` - protocol version +- block_hash: `String` - block hash +- index: `Number` - index of the transaction within the block **Returns** @@ -1607,9 +1630,11 @@ Returns the transaction at the {index} position within the block with the {block **Parameters** -An object with 2 properties: -- block_number: `Number` - block number -- index: `Number` - index of the transaction within the block +An object with properties: + +- protoVer: `String` - protocol version +- block_number: `Number` - block number +- index: `Number` - index of the transaction within the block **Returns** @@ -1670,10 +1695,11 @@ Sends a transaction body and its signature to the blockchain node as a dryrun. **Parameters** -An object with following properties: +An object with properties: -- tx_body: `Object` - transaction body object -- signature: `String` - signature of the transaction +- protoVer: `String` - protocol version +- tx_body: `Object` - transaction body object +- signature: `String` - signature of the transaction **Returns** @@ -1761,10 +1787,11 @@ Sends a transaction body and its signature to the blockchain node. **Parameters** -An object with following properties: +An object with properties: -- tx_body: `Object` - transaction body object -- signature: `String` - signature of the transaction +- protoVer: `String` - protocol version +- tx_body: `Object` - transaction body object +- signature: `String` - signature of the transaction **Returns** @@ -1851,9 +1878,10 @@ Sends multiple transactions at once to the blockchain node. **Parameters** -An object with a property: +An object with properties: -- `Array` - an array of transaction objects (with signature and transaction body) +- protoVer: `String` - protocol version +- `Array` - an array of transaction objects (with signature and transaction body) **Returns** @@ -1952,7 +1980,9 @@ Returns the last block. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2013,7 +2043,9 @@ Returns the last block number. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2053,8 +2085,9 @@ Returns the block with the given block number. An object with properties: -- number: `Number` - the block number -- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. +- protoVer: `String` - protocol version +- number: `Number` - the block number +- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. **Returns** @@ -2120,8 +2153,9 @@ Returns the block with the specified block hash. An object with properties: -- hash: `String` - block hash -- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. +- protoVer: `String` - protocol version +- hash: `String` - block hash +- getFullTransactions: `Boolean` - if true, it returns full transaction objects; if false or undefined, it returns the transaction hashes only. **Returns** @@ -2187,8 +2221,9 @@ Returns a list of blocks that have a block number between "from" block number an An object with properties: -- from: `Number` - the block number of the starting block -- to: `Number` - the block number of the last block to get +- protoVer: `String` - protocol version +- from: `Number` - the block number of the starting block +- to: `Number` - the block number of the last block to get **Returns** @@ -2281,8 +2316,9 @@ Returns a list of block headers that have a block number between "from" block nu An object with properties: -- from: `Number` - the block number of the starting block -- to: `Number` - the block number of the last block to get +- protoVer: `String` - protocol version +- from: `Number` - the block number of the starting block +- to: `Number` - the block number of the last block to get **Returns** @@ -2357,9 +2393,10 @@ Returns the number of transactions in the block with the specified block number. **Parameters** -An object with a property: +An object with properties: -- number: `Number` - block number +- protoVer: `String` - protocol version +- number: `Number` - block number **Returns** @@ -2398,9 +2435,10 @@ Returns the number of transactions in the block with the specified block hash. **Parameters** -An object with a property: +An object with properties: -- hash: `String` - block hash +- protoVer: `String` - protocol version +- hash: `String` - block hash **Returns** @@ -2443,9 +2481,10 @@ Returns the information of the given block validator. **Parameters** -An object with a property: +An object with properties: -- address: `String` - address of the block validator's account, which should be a checksum address +- protoVer: `String` - protocol version +- address: `String` - address of the block validator's account, which should be a checksum address **Returns** @@ -2488,9 +2527,10 @@ Returns the validators who validated the block. **Parameters** -An object with a property: +An object with properties: -- number: `Number` - block number +- protoVer: `String` - protocol version +- number: `Number` - block number **Returns** @@ -2570,9 +2610,10 @@ Returns the validators who validated the block. **Parameters** -An object with a property: +An object with properties: -- hash: `String` - block hash +- protoVer: `String` - protocol version +- hash: `String` - block hash **Returns** @@ -2652,9 +2693,10 @@ Returns the proposer who produced the block with the given block number. **Parameters** -An object with a property: +An object with properties: -- number: `Number` - block number +- protoVer: `String` - protocol version +- number: `Number` - block number **Returns** @@ -2693,9 +2735,10 @@ Returns the proposer who produced the block with the given block hash. **Parameters** -An object with a property: +An object with properties: -- hash: `String` - block hash +- protoVer: `String` - protocol version +- hash: `String` - block hash **Returns** @@ -2738,7 +2781,9 @@ Returns whether the node is listening for network connections. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2776,7 +2821,9 @@ Returns the number of peers the node is connected to. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2814,7 +2861,9 @@ Returns whether the node is syncing with the network or not. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2852,7 +2901,9 @@ Returns the blockchain node's network id. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2893,7 +2944,9 @@ Returns the blockchain node's chain id. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -2934,7 +2987,9 @@ Returns the blockchain node's consensus status. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -3002,7 +3057,9 @@ Returns the blockchain node's raw consensus status. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** @@ -3205,7 +3262,9 @@ Returns the blockchain node's peer candidate information. **Parameters** -None. +An object with properties: + +- protoVer: `String` - protocol version **Returns** From 50367162a0c25c6d550a8e4c29ef94f0be87f16c Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 13 Feb 2024 12:53:34 +0900 Subject: [PATCH 30/38] Rename: Consensus API -> Blockchain Node API --- json_rpc/{consensus.js => blockchain-node.js} | 2 +- json_rpc/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename json_rpc/{consensus.js => blockchain-node.js} (97%) diff --git a/json_rpc/consensus.js b/json_rpc/blockchain-node.js similarity index 97% rename from json_rpc/consensus.js rename to json_rpc/blockchain-node.js index b3e8310ae..da19ba7a1 100644 --- a/json_rpc/consensus.js +++ b/json_rpc/blockchain-node.js @@ -6,7 +6,7 @@ const PathUtil = require('../common/path-util'); const JsonRpcUtil = require('./json-rpc-util'); const { JSON_RPC_METHODS } = require('./constants'); -module.exports = function getConsensusApis(node) { +module.exports = function getBlockchainNodeApis(node) { return { [JSON_RPC_METHODS.AIN_GET_VALIDATOR_INFO]: function(args, done) { const beginTime = Date.now(); diff --git a/json_rpc/index.js b/json_rpc/index.js index 4c8d453f5..fe29ef616 100644 --- a/json_rpc/index.js +++ b/json_rpc/index.js @@ -6,7 +6,7 @@ const getAccountApis = require('./account'); const getAppApis = require('./app'); const getAdminApis = require('./admin'); const getBlockApis = require('./block'); -const getConsensusApis = require('./consensus'); +const getBlockchainNodeApis = require('./blockchain-node'); const getDatabaseApis = require('./database'); const getEventHandlerApis = require('./event-handler'); const getNetworkApis = require('./network'); @@ -37,7 +37,7 @@ module.exports = function getApis(node, p2pServer, minProtocolVersion, maxProtoc ...getAccountApis(node), ...getAppApis(node), ...getBlockApis(node), - ...getConsensusApis(node), + ...getBlockchainNodeApis(node), ...getDatabaseApis(node), ...getNetworkApis(node, p2pServer), ...getTransactionApis(node, p2pServer), From c3b26244bc949f8d01ec27fd9b68a86fa00f9d1b Mon Sep 17 00:00:00 2001 From: platfowner Date: Wed, 14 Feb 2024 14:12:18 +0900 Subject: [PATCH 31/38] Add descriptions about get and set operations to JSON_RPC_API.md --- JSON_RPC_API.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 1a5b61770..f4b3c8bca 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -65,7 +65,15 @@ Returns the value, write rule, owner rule, or function at the given path in the An array of objects with properties: - protoVer: `String` - protocol version -- ref: `String` - reference path +- type: `String` - "GET_VALUE" | "GET_RULE" | "GET_FUNCTION" | "GET_OWNER" | "GET" +- ref: `String` - reference path to get a value/rule/owner/function of. Only required if the type is not "GET". +- op_list: `Array` - array of get operations ({ type, ref, [is_shallow, is_global, is_final, include_tree_info, include_proof, include_version] }). Only required if the type is "GET". +- is_shallow: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the shallow result (only the keys of the children) will be returned. +- is_global: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the given ref will be interpreted as a global path. +- is_final: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the finalization result will be returned. +- include_tree_info: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the result will include additional state tree information. +- include_proof: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the result will include state proof hashes. +- include_version: `Boolean` | `undefined` - an optional get request parameter. When specified as `true`, the result will include state versions. **Returns** @@ -1698,7 +1706,7 @@ Sends a transaction body and its signature to the blockchain node as a dryrun. An object with properties: - protoVer: `String` - protocol version -- tx_body: `Object` - transaction body object +- tx_body: `Object` - transaction body object (see [ain_sendSignedTransaction](#ain_sendsignedtransaction) for the details) - signature: `String` - signature of the transaction **Returns** @@ -1790,7 +1798,15 @@ Sends a transaction body and its signature to the blockchain node. An object with properties: - protoVer: `String` - protocol version -- tx_body: `Object` - transaction body object +- tx_body: `Object` - transaction body object with properties: + - operation: `Object` - transaction operation with properties: + - type: `String` - "SET_VALUE" | "SET_RULE" | "SET_FUNCTION" | "SET_OWNER" | "SET". When type = "SET", op_list is used instead of ref and value. + - ref: `String` - reference path to get a value/rule/owner/function of. Only required if the type is not "SET". + - value: `Any` - value/rule/function/owner to set + - op_list: `Array` - array of set operations ({ type, ref, value }). Only required if the type is "SET". + - timestamp: `Number()` - timestamp when the transaction was created + - nonce: `-2|-1|Number()` - nonce value where `-2` means _unordered_ transaction, `-1` means _ordered_ transaction (using timestamp), and `Number` means _numbered (or indexed)_ transaction (like the Ethereum Network). + - gas_price: `Number()` - gas price value in micro unit (10-6) to apply to compute the gas cost of the transaction. The gas cost computation rule is _gas_cost_ = _gas_amount_ x _gas_price_ x _106_ where the gas amount is the basically the number of DB write operations of the transaction and gas cost is charged in AIN unit. - signature: `String` - signature of the transaction **Returns** @@ -1881,11 +1897,11 @@ Sends multiple transactions at once to the blockchain node. An object with properties: - protoVer: `String` - protocol version -- `Array` - an array of transaction objects (with signature and transaction body) +- tx_list: `Array` - an array of objects with signature and transaction body (see [ain_sendSignedTransaction](#ain_sendsignedtransaction) for the details) **Returns** -`Array` - an array of transaction hashes. +`Array` - an array of the transaction hashes and the execution results. **Example** From 46e15a918b68982fd0bf4ed8a65b09dc16136082 Mon Sep 17 00:00:00 2001 From: platfowner Date: Wed, 14 Feb 2024 14:19:51 +0900 Subject: [PATCH 32/38] Fix descriptions about unordered nonce and ordered nonce --- JSON_RPC_API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index f4b3c8bca..9ec76df8b 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -1805,7 +1805,7 @@ An object with properties: - value: `Any` - value/rule/function/owner to set - op_list: `Array` - array of set operations ({ type, ref, value }). Only required if the type is "SET". - timestamp: `Number()` - timestamp when the transaction was created - - nonce: `-2|-1|Number()` - nonce value where `-2` means _unordered_ transaction, `-1` means _ordered_ transaction (using timestamp), and `Number` means _numbered (or indexed)_ transaction (like the Ethereum Network). + - nonce: `-2|-1|Number()` - nonce value where `-2` means _ordered_ transaction, `-1` means _unordered_ transaction (using timestamp), and `Number` means _numbered (or indexed)_ transaction (like the Ethereum Network). - gas_price: `Number()` - gas price value in micro unit (10-6) to apply to compute the gas cost of the transaction. The gas cost computation rule is _gas_cost_ = _gas_amount_ x _gas_price_ x _106_ where the gas amount is the basically the number of DB write operations of the transaction and gas cost is charged in AIN unit. - signature: `String` - signature of the transaction From 45282f6314be6b82489576fe2e049e55a9616442 Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 22 Feb 2024 15:46:39 +0900 Subject: [PATCH 33/38] Fix JSON_RPC_API.md --- JSON_RPC_API.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index 9ec76df8b..d55ebb658 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -4,11 +4,11 @@ - [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_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) From 27f2508fe8ca7975ca0c0f6b75366c2283c7dd01 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 26 Feb 2024 10:31:50 +0900 Subject: [PATCH 34/38] Fix a typo --- JSON_RPC_API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JSON_RPC_API.md b/JSON_RPC_API.md index d55ebb658..770f5dc14 100644 --- a/JSON_RPC_API.md +++ b/JSON_RPC_API.md @@ -1419,7 +1419,7 @@ Response ### ain_getTransactionPoolSizeUtilization -Returns the transaction pool size utilization. +Returns the transaction pool size utilization. **Parameters** From 5fd5e4351dc9ec6f41328cf6b3dbb1b61e6d1dcd Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 8 Mar 2024 11:53:52 +0900 Subject: [PATCH 35/38] 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 36/38] 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) { From 1c97cc6d74c89ea0a50ececda7be4a685599312e Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 15 Mar 2024 11:15:59 +0900 Subject: [PATCH 37/38] Increase GET_RESP_MAX_SIBLINGS node param to 20000 from 5000 --- blockchain-configs/afan-shard/node_params.json | 2 +- blockchain-configs/base/node_params.json | 2 +- blockchain-configs/he-shard/node_params.json | 2 +- blockchain-configs/mainnet-prod/node_params.json | 2 +- blockchain-configs/sim-shard/node_params.json | 2 +- blockchain-configs/testnet-dev/node_params.json | 2 +- blockchain-configs/testnet-exp/node_params.json | 2 +- blockchain-configs/testnet-prod/node_params.json | 2 +- blockchain-configs/testnet-sandbox/node_params.json | 2 +- blockchain-configs/testnet-staging/node_params.json | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/blockchain-configs/afan-shard/node_params.json b/blockchain-configs/afan-shard/node_params.json index fdd40f3f8..4a4b33eb3 100644 --- a/blockchain-configs/afan-shard/node_params.json +++ b/blockchain-configs/afan-shard/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "local", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/base/node_params.json b/blockchain-configs/base/node_params.json index d77c82163..a31d11087 100644 --- a/blockchain-configs/base/node_params.json +++ b/blockchain-configs/base/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "local", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/he-shard/node_params.json b/blockchain-configs/he-shard/node_params.json index 35cf4364c..7f5d44d25 100644 --- a/blockchain-configs/he-shard/node_params.json +++ b/blockchain-configs/he-shard/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "local", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/mainnet-prod/node_params.json b/blockchain-configs/mainnet-prod/node_params.json index d71d40653..66037136f 100644 --- a/blockchain-configs/mainnet-prod/node_params.json +++ b/blockchain-configs/mainnet-prod/node_params.json @@ -35,7 +35,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/sim-shard/node_params.json b/blockchain-configs/sim-shard/node_params.json index 976e5c022..b64f7d0a2 100644 --- a/blockchain-configs/sim-shard/node_params.json +++ b/blockchain-configs/sim-shard/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "local", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/testnet-dev/node_params.json b/blockchain-configs/testnet-dev/node_params.json index 3a92ad891..bd25ec961 100644 --- a/blockchain-configs/testnet-dev/node_params.json +++ b/blockchain-configs/testnet-dev/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/testnet-exp/node_params.json b/blockchain-configs/testnet-exp/node_params.json index 3ae64a51c..35a4a77d6 100644 --- a/blockchain-configs/testnet-exp/node_params.json +++ b/blockchain-configs/testnet-exp/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/testnet-prod/node_params.json b/blockchain-configs/testnet-prod/node_params.json index c33f8be73..2f04e8409 100644 --- a/blockchain-configs/testnet-prod/node_params.json +++ b/blockchain-configs/testnet-prod/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/testnet-sandbox/node_params.json b/blockchain-configs/testnet-sandbox/node_params.json index fc0767bb3..0089bd695 100644 --- a/blockchain-configs/testnet-sandbox/node_params.json +++ b/blockchain-configs/testnet-sandbox/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, diff --git a/blockchain-configs/testnet-staging/node_params.json b/blockchain-configs/testnet-staging/node_params.json index 67358eeda..36d7f95ec 100644 --- a/blockchain-configs/testnet-staging/node_params.json +++ b/blockchain-configs/testnet-staging/node_params.json @@ -36,7 +36,7 @@ "FREE_TX_POOL_SIZE_LIMIT_RATIO_PER_ACCOUNT": 0.1, "GET_OP_LIST_SIZE_LIMIT": 50, "GET_RESP_BYTES_LIMIT": 20000000, - "GET_RESP_MAX_SIBLINGS": 5000, + "GET_RESP_MAX_SIBLINGS": 20000, "HOSTING_ENV": "gcp", "LIGHTWEIGHT": false, "MAX_BLOCKCHAIN_API_RATE_LIMIT": 20, From 8028d6de97565ae6da6b393209cbc13f5b9fbe10 Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 19 Mar 2024 11:45:34 +0900 Subject: [PATCH 38/38] Upgrade blockchain package version to v1.1.4 --- client/protocol_versions.json | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/protocol_versions.json b/client/protocol_versions.json index 8fbd9754e..68cf1c450 100644 --- a/client/protocol_versions.json +++ b/client/protocol_versions.json @@ -134,5 +134,8 @@ }, "1.1.3": { "min": "1.0.0" + }, + "1.1.4": { + "min": "1.0.0" } } \ No newline at end of file diff --git a/package.json b/package.json index edeb8d7fa..6860319ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ain-blockchain", "description": "AI Network Blockchain", - "version": "1.1.3", + "version": "1.1.4", "private": true, "license": "MIT", "author": "dev@ainetwork.ai",