From fbfdb737196a18f64bb04f4b08d469c83d21cccf Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 27 Feb 2019 21:09:55 +0800 Subject: [PATCH 1/7] Split API Doc to a single file --- API_DOC.md | 404 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 403 +--------------------------------------------------- 2 files changed, 405 insertions(+), 402 deletions(-) create mode 100644 API_DOC.md diff --git a/API_DOC.md b/API_DOC.md new file mode 100644 index 0000000..46d2584 --- /dev/null +++ b/API_DOC.md @@ -0,0 +1,404 @@ +# API Doc + +### JSON-RPC Interface + +JSON-RPC interface, same format with [CITA JSON-RPC](http://docs.citahub.com/en-US/cita/rpc-guide/rpc). + +> POST / + +#### params + +```ruby +{ + "jsonrpc": "2.0", + "id": 83, + "method": "blockNumber", + "params": [] +} +``` + +#### response + +```ruby +{ + "jsonrpc": "2.0", + "id": 83, + "result": "0x7169a" +} +``` + +### System infos + +> GET /api/info/url + +Get the http and websocket url which ReBirth connected. + +#### response + +```ruby +{ + result: { + http_url: "http://localhost:1337", + ws_url: "http://localhost:4337" + } +} +``` + +### Blocks + +Get blocks info list and paginate it. + +> GET /api/blocks + +#### params + +```ruby +{ + "numberFrom": "10" or "0xa", # integer or string of hex number + "numberTo": "20" or "0xa", # integer or string of hex number + "transactionFrom": "min transaction count", # integer or string of hex number + "transactionTo": "max transaction count", # integer or string of hex number + "page": "1", # integer, default 1 + "perPage": "10", # integer, default 10 + # offset and limit has lower priority than page and perPage + "offset": "1", # integer, database offset for pagination + "limit": "10", # integer, database limit for pagination +} +``` + +#### response + +```ruby +{ + "result": { + "count": 111200, + "blocks": [ + { + "version": 0, + "header": { + "proof": { + "Bft": { + "round": 0, + "height": 111198, + "commits": { + "0x31042d4f7662cddf8ded5229db3c5e7302875e10": "0x8132cc5090329854a7dc22300b45c5d972f02a1e558e0b1fa71916316ad2fe061c06829b8b5eb16a7d206f421061a392cd6aad7a1d0a05a8c3e7203fe78a181e00", + "0x486bb688c8d29056bd7f87c26733048b0a6abda6": "0x4aa508798a0b9b77cc1263ae6b64d78977909fd2ce28e4f9322369041a3175cc4f7ad376b122c4b201dc6d2910c515f3d6d94c35dbd13fa6207a91fa8fd649b400", + "0x71b028e49c6f41aaa74932d703c707ecca6d732e": "0xc1e580fa36b0ae5740ca66b612df6d3435c29d20fa21292c93a8bacd7751eee87984a3720576dbad15527bd3a52c9cda42a2d58a382701ab835add5e11bbed1001" + }, + "proposal": "0xc880eb00df297b3c96bc08dca378280f99955816c6f32c08c17f004c0c7dfe75" + } + }, + "number": "0x1b25f", + "quotaUsed": "0x0", + "prevHash": "0x4bf32733fa6ca03326f0cfe7c487d7f8de26ad7c38fcf68959eebc2c0088e279", + "proposer": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", + "stateRoot": "0x7e51d4969381493124b457e57db6dcab48c741a5046c327a43b59593d6a4ab16", + "timestamp": 1532648718735, + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "transactionsCount": 0, + "hash": "0x06208c3b241ff5b8a1fcdec9190abf0cc861d1e5ecdd4f696892fe7ee972473f" + } + ] + } +} +``` + +### Transactions + +Get transactions list and paginate it. + +> GET /api/transactions + +#### params + +```ruby +{ + "account": "the addr transactions related to (from or to)", # hash string + "from": "the addr transactions from", # hash string + "to": "the addr transactions to", # hash string + "valueFormat": "decimal", # set value to decimal number, default hex number + "page": "1", # integer, default 1 + "perPage": "10", # integer, default 10 + # offset and limit has lower priority than page and perPage + "offset": "1", # integer, default to 0 + "limit": "10", # integer, default to 10 +} +``` + +#### response + +```ruby +{ + "result": { + "count": 75178, + "transactions": [ + { + "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal + "to": "0xffffffffffffffffffffffffffffffffff010001", + "gasUsed": "0x45754", + "quotaUsed": "0x45754", + "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", + "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", + "blockNumber": "0xffff", + "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", + "timestamp": 1532511655997, + "chainId": 1, + "chainName": "test-chain", + "errorMessage": "Not enough base gas." + } + ] + } +} +``` + +### Transaction + +Get transactions list and paginate it. + +> GET /api/transactions/:hash + +example +> GET /api/transactions/0x0000000000000000000000000000000000000000000000000000000000000000 + +#### params + +```ruby +{ + "account": "the addr transactions related to (from or to)", # hash string + "from": "the addr transactions from", # hash string + "to": "the addr transactions to", # hash string + "valueFormat": "decimal", # set value to decimal number, default hex number +} +``` + +#### response + +```ruby +{ + "result": { + "transaction": { + "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal + "to": "0xffffffffffffffffffffffffffffffffff010001", + "gasUsed": "0x45754", + "quotaUsed": "0x45754", + "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", + "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", + "blockNumber": "0xffff", + "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", + "timestamp": 1532511655997, + "chainId": 1, + "chainName": "test-chain", + "errorMessage": "Not enough base gas." + } + } +} + +# or not found +{ + "result": { + "transaction": null + } +} +``` + +### Statistics + +Get proposals info or brief info. + +> GET /api/statistics + +#### params + +```ruby +{ + type: "proposals" or "brief" # required +} +``` + +#### response + +```ruby +# when type = "proposals" +{ + "result": [ + { + "validator": "0x0000000000000000000000000000000000000000", # proposer of block header + "count": 1 # count of this proposer + }, + { + "validator": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", + "count": 28514 + }, + { + "validator": "0x486bb688c8d29056bd7f87c26733048b0a6abda6", + "count": 27044 + }, + { + "validator": "0x71b028e49c6f41aaa74932d703c707ecca6d732e", + "count": 27844 + }, + { + "validator": "0xee01b9ba97671e8a1891e85b206b499f106822a1", + "count": 27797 + } + ] +} + +# when type = "brief" +{ + "result": { + "tps": 0, # float number, transaction count per second + "tpb": 0, # float number, transaction count per block + "ipb": 2.97 # float number, average block interval + } +} +``` + +### Status + +Get sync process running status. + +> GET /api/status + +#### response + +```ruby +{ + "result": { + "status": "not running", # sync process running status, "not running" or "running" + "currentBlockNumber": "0x1b25f", # last sync block + "currentChainBlockNumber": "0x717d0" # the chain current block number + } +} +``` + +### SyncErrors + +Get sync errors list, which is the errors while sync from chain. + +> GET /api/sync_errors + +#### params + +```ruby +{ + "page": 1, # integer, default 1 + "perPage": 10, # integer, default 10 + # offset and limit has lower priority than page and perPage + "offset": 1, # integer + "limit": 10, # integer +} +``` + +#### response + +```ruby +{ + "result": { + "count": 4, # total count of sync errors + "syncErrors": [ + { + "params": ["0x123"], # the params you send + "code": -32700, + "message": "invalid format: [0x123]", + "createdAt": "2018-08-07T03:21:15.862Z", + "updatedAt": "2018-08-07T03:21:15.862Z", + "data": null, + "method": "getTransaction" # the method you access + } + ] + } +} +``` + +### ERC20 Transfer event + +Get erc20 contracts transfer event logs by address + +> GET /api/erc20/transfers + +#### params + +```ruby +{ + "address": "0x...", # contract address, required + "account": "from or to", # hash + "from": "from address", # hash + "to": "to address", # hash + "page": 1, # default 1 + "perPage": 10, # default 10 + + # offset and limit has lower priority than page and perPage + "offset": 1, # default 0 + "limit": 10 # default 10 +} +``` + +#### response + +```ruby +{ + "result": { + "count": 1, + "transfers": [ + { + "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", + "from": "0xac30bce77cf849d869aa37e39b983fa50767a2dd", + "to": "0x6005ed6b942c99533b896b95fe8a90c7a7ecbf6a", + "value": 10, + "blockNumber": "0x18a1ec", + "gasUsed": "0x64", + "quotaUsed": "0x64", + "hash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", + "chainId": 1, + "chainName": "test-chain" + } + ] + } +} +``` + +### EventLog by address + +Get event logs by address + +> GET /api/event_logs/:address + +#### params + +```ruby +{ + "page": 1, # default 1 + "perPage": 10, # default 10 +} +``` + +#### response + +```ruby +{ + "result": { + "count": 1, + "eventLogs": [ + { + "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", + "data": "0x000000000000000000000000000000000000000000000000000000000000000a", + "topics": [ + "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", + "0x000000000000000000000000ac30bce77cf849d869aa37e39b983fa50767a2dd", + "0x0000000000000000000000006005ed6b942c99533b896b95fe8a90c7a7ecbf6a" + ], + "blockHash": "0xa2574fbd6fe9083ad8a1729630d1fa2c227f0a6df2dbb1f0d6d69faa4145c5cb", + "blockNumber": "0x18a1ec", + "logIndex": "0x0", + "transactionHash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", + "transactionIndex": "0x0", + "transactionLogIndex": "0x0" + } + ] + } +} +``` +) diff --git a/README.md b/README.md index 99bf6e0..9e0b945 100644 --- a/README.md +++ b/README.md @@ -97,405 +97,4 @@ $ bundle exec yard server ``` ## API Doc - -### JSON-RPC Interface - -JSON-RPC interface, same format with [CITA JSON-RPC](http://docs.citahub.com/en-US/cita/rpc-guide/rpc). - -> POST / - -#### params - -```ruby -{ - "jsonrpc": "2.0", - "id": 83, - "method": "blockNumber", - "params": [] -} -``` - -#### response - -```ruby -{ - "jsonrpc": "2.0", - "id": 83, - "result": "0x7169a" -} -``` - -### System infos - -> GET /api/info/url - -Get the http and websocket url which ReBirth connected. - -#### response - -```ruby -{ - result: { - http_url: "http://localhost:1337", - ws_url: "http://localhost:4337" - } -} -``` - -### Blocks - -Get blocks info list and paginate it. - -> GET /api/blocks - -#### params - -```ruby -{ - "numberFrom": "10" or "0xa", # integer or string of hex number - "numberTo": "20" or "0xa", # integer or string of hex number - "transactionFrom": "min transaction count", # integer or string of hex number - "transactionTo": "max transaction count", # integer or string of hex number - "page": "1", # integer, default 1 - "perPage": "10", # integer, default 10 - # offset and limit has lower priority than page and perPage - "offset": "1", # integer, database offset for pagination - "limit": "10", # integer, database limit for pagination -} -``` - -#### response - -```ruby -{ - "result": { - "count": 111200, - "blocks": [ - { - "version": 0, - "header": { - "proof": { - "Bft": { - "round": 0, - "height": 111198, - "commits": { - "0x31042d4f7662cddf8ded5229db3c5e7302875e10": "0x8132cc5090329854a7dc22300b45c5d972f02a1e558e0b1fa71916316ad2fe061c06829b8b5eb16a7d206f421061a392cd6aad7a1d0a05a8c3e7203fe78a181e00", - "0x486bb688c8d29056bd7f87c26733048b0a6abda6": "0x4aa508798a0b9b77cc1263ae6b64d78977909fd2ce28e4f9322369041a3175cc4f7ad376b122c4b201dc6d2910c515f3d6d94c35dbd13fa6207a91fa8fd649b400", - "0x71b028e49c6f41aaa74932d703c707ecca6d732e": "0xc1e580fa36b0ae5740ca66b612df6d3435c29d20fa21292c93a8bacd7751eee87984a3720576dbad15527bd3a52c9cda42a2d58a382701ab835add5e11bbed1001" - }, - "proposal": "0xc880eb00df297b3c96bc08dca378280f99955816c6f32c08c17f004c0c7dfe75" - } - }, - "number": "0x1b25f", - "quotaUsed": "0x0", - "prevHash": "0x4bf32733fa6ca03326f0cfe7c487d7f8de26ad7c38fcf68959eebc2c0088e279", - "proposer": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", - "stateRoot": "0x7e51d4969381493124b457e57db6dcab48c741a5046c327a43b59593d6a4ab16", - "timestamp": 1532648718735, - "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" - }, - "transactionsCount": 0, - "hash": "0x06208c3b241ff5b8a1fcdec9190abf0cc861d1e5ecdd4f696892fe7ee972473f" - } - ] - } -} -``` - -### Transactions - -Get transactions list and paginate it. - -> GET /api/transactions - -#### params - -```ruby -{ - "account": "the addr transactions related to (from or to)", # hash string - "from": "the addr transactions from", # hash string - "to": "the addr transactions to", # hash string - "valueFormat": "decimal", # set value to decimal number, default hex number - "page": "1", # integer, default 1 - "perPage": "10", # integer, default 10 - # offset and limit has lower priority than page and perPage - "offset": "1", # integer, default to 0 - "limit": "10", # integer, default to 10 -} -``` - -#### response - -```ruby -{ - "result": { - "count": 75178, - "transactions": [ - { - "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal - "to": "0xffffffffffffffffffffffffffffffffff010001", - "gasUsed": "0x45754", - "quotaUsed": "0x45754", - "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", - "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", - "blockNumber": "0xffff", - "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", - "timestamp": 1532511655997, - "chainId": 1, - "chainName": "test-chain", - "errorMessage": "Not enough base gas." - } - ] - } -} -``` - -### Transaction - -Get transactions list and paginate it. - -> GET /api/transactions/:hash - -example -> GET /api/transactions/0x0000000000000000000000000000000000000000000000000000000000000000 - -#### params - -```ruby -{ - "account": "the addr transactions related to (from or to)", # hash string - "from": "the addr transactions from", # hash string - "to": "the addr transactions to", # hash string - "valueFormat": "decimal", # set value to decimal number, default hex number -} -``` - -#### response - -```ruby -{ - "result": { - "transaction": { - "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal - "to": "0xffffffffffffffffffffffffffffffffff010001", - "gasUsed": "0x45754", - "quotaUsed": "0x45754", - "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", - "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", - "blockNumber": "0xffff", - "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", - "timestamp": 1532511655997, - "chainId": 1, - "chainName": "test-chain", - "errorMessage": "Not enough base gas." - } - } -} - -# or not found -{ - "result": { - "transaction": null - } -} -``` - -### Statistics - -Get proposals info or brief info. - -> GET /api/statistics - -#### params - -```ruby -{ - type: "proposals" or "brief" # required -} -``` - -#### response - -```ruby -# when type = "proposals" -{ - "result": [ - { - "validator": "0x0000000000000000000000000000000000000000", # proposer of block header - "count": 1 # count of this proposer - }, - { - "validator": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", - "count": 28514 - }, - { - "validator": "0x486bb688c8d29056bd7f87c26733048b0a6abda6", - "count": 27044 - }, - { - "validator": "0x71b028e49c6f41aaa74932d703c707ecca6d732e", - "count": 27844 - }, - { - "validator": "0xee01b9ba97671e8a1891e85b206b499f106822a1", - "count": 27797 - } - ] -} - -# when type = "brief" -{ - "result": { - "tps": 0, # float number, transaction count per second - "tpb": 0, # float number, transaction count per block - "ipb": 2.97 # float number, average block interval - } -} -``` - -### Status - -Get sync process running status. - -> GET /api/status - -#### response - -```ruby -{ - "result": { - "status": "not running", # sync process running status, "not running" or "running" - "currentBlockNumber": "0x1b25f", # last sync block - "currentChainBlockNumber": "0x717d0" # the chain current block number - } -} -``` - -### SyncErrors - -Get sync errors list, which is the errors while sync from chain. - -> GET /api/sync_errors - -#### params - -```ruby -{ - "page": 1, # integer, default 1 - "perPage": 10, # integer, default 10 - # offset and limit has lower priority than page and perPage - "offset": 1, # integer - "limit": 10, # integer -} -``` - -#### response - -```ruby -{ - "result": { - "count": 4, # total count of sync errors - "syncErrors": [ - { - "params": ["0x123"], # the params you send - "code": -32700, - "message": "invalid format: [0x123]", - "createdAt": "2018-08-07T03:21:15.862Z", - "updatedAt": "2018-08-07T03:21:15.862Z", - "data": null, - "method": "getTransaction" # the method you access - } - ] - } -} -``` - -### ERC20 Transfer event - -Get erc20 contracts transfer event logs by address - -> GET /api/erc20/transfers - -#### params - -```ruby -{ - "address": "0x...", # contract address, required - "account": "from or to", # hash - "from": "from address", # hash - "to": "to address", # hash - "page": 1, # default 1 - "perPage": 10, # default 10 - - # offset and limit has lower priority than page and perPage - "offset": 1, # default 0 - "limit": 10 # default 10 -} -``` - -#### response - -```ruby -{ - "result": { - "count": 1, - "transfers": [ - { - "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", - "from": "0xac30bce77cf849d869aa37e39b983fa50767a2dd", - "to": "0x6005ed6b942c99533b896b95fe8a90c7a7ecbf6a", - "value": 10, - "blockNumber": "0x18a1ec", - "gasUsed": "0x64", - "quotaUsed": "0x64", - "hash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", - "chainId": 1, - "chainName": "test-chain" - } - ] - } -} -``` - -### EventLog by address - -Get event logs by address - -> GET /api/event_logs/:address - -#### params - -```ruby -{ - "page": 1, # default 1 - "perPage": 10, # default 10 -} -``` - -#### response - -```ruby -{ - "result": { - "count": 1, - "eventLogs": [ - { - "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", - "data": "0x000000000000000000000000000000000000000000000000000000000000000a", - "topics": [ - "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", - "0x000000000000000000000000ac30bce77cf849d869aa37e39b983fa50767a2dd", - "0x0000000000000000000000006005ed6b942c99533b896b95fe8a90c7a7ecbf6a" - ], - "blockHash": "0xa2574fbd6fe9083ad8a1729630d1fa2c227f0a6df2dbb1f0d6d69faa4145c5cb", - "blockNumber": "0x18a1ec", - "logIndex": "0x0", - "transactionHash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", - "transactionIndex": "0x0", - "transactionLogIndex": "0x0" - } - ] - } -} -``` +See [API Doc](./API_DOC.md) From f2176d00514a7f47c0ddae0236fd0efb54c99d59 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 27 Feb 2019 21:37:19 +0800 Subject: [PATCH 2/7] Add Chinese version of README --- README-CN.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 README-CN.md diff --git a/README-CN.md b/README-CN.md new file mode 100644 index 0000000..46c3c79 --- /dev/null +++ b/README-CN.md @@ -0,0 +1,102 @@ +# ReBirth + +[![Build Status](https://travis-ci.org/cryptape/re-birth.svg?branch=master)](https://travis-ci.org/cryptape/re-birth) +[![codecov](https://codecov.io/gh/cryptape/re-birth/branch/master/graph/badge.svg)](https://codecov.io/gh/cryptape/re-birth) +[![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/github/cryptape/re-birth/master) + +[English](./README.md) | 简体中文 + +[CITA](http://docs.citahub.com) 缓存服务器 + +适配 CITA v0.20 + +⚠️ NOTE: 如果从 CITA 0.17 更新到 0.18,更新完成之后执行 `rake daemons:sync:stop`,再执行 `rake zero18:update` 来更新数据,然后执行 `rake daemons:sync:start`,完成后重启 server 即可 😄 + +⚠️ NOTE: 当更新到这个版本的时候,应当执行 `bundle exec rake event_logs:fix_old` 去为已经存在的交易同步 event logs。 + +⚠️ NOTE: 执行 `bundle exec rake transactions:add_error_message` 来为旧的交易数据增加 `errorMessage`。 + +⚠️ NOTE: 如果从旧版本 CITA 更新到 0.20,更新完成之后应该执行 `rake daemons:sync:stop` 来停止同步服务,然后执行 `rake zero20:update` 来更新旧的数据,然后执行 `rake daemons:sync:start` 来启动同步服务,最后重启 server 即可。 + +## Docker + +使用 [docker 🐳](https://docs.docker.com/install) 来运行 + +使用 `rails secret` 来生成 secret key 然后写入 `.env.local` 文件(查看 `.env` 文件来获取更多信息) +注意修改 `.env.local` 中的 sidekiq username 和 password + +⚠️ 重要: 你的数据库文件将会保存在 docker/data + +⚠️ 重要: Redis 的数据将会保存在 docker/redis + +程序将会运行在 http://localhost:8888 + +```shell +$ make setup # 如果是第一次运行的话要执行该命令来初始化数据库 +$ make up # 执行这个命令会在后台运行 docker 来运行程序 +$ make update # 执行该命令以更新 +``` + +更多信息可以参见 Makefile + +## 依赖包 + +- [postgresql](https://www.postgresql.org/) 9.4 及以上 +- 安装 [secp256k1](https://github.com/bitcoin-core/secp256k1.git) + + ```shell + $ cd re-birth/tmp && git clone https://github.com/bitcoin-core/secp256k1.git && cd secp256k1 && ./autogen.sh && ./configure --enable-module-recovery && make && sudo make install && cd ../.. + ``` + +## 初始化程序 + +```shell +$ bundle +$ touch .env.local (在 `.env.local` 文件中覆盖 `.env` 中的项, 比如 DB_USERNAME, DB_PASSWORD and CITA_URL...) +$ rails db:setup (或者 rails db:create db:migrate db:seed) +``` + +## 运行测试 + +```shell +$ touch .env.test.local (测试环境下不会读取 `.env.local` 中的信息, 在 `.env.test.local` 覆盖 `.env` 中的项) +$ rails spec +``` + +## 执行程序 + +```shell +$ rails s + +# 启动同步进程 +$ rails daemons:sync:start +# 执行 `rails daemons:sync:stop` 来停止运行 +# 执行 `rails daemons:sync:restart` 来重启服务 +# 执行 `rails daemons:sync:status` 来查看状态 +``` + +## Event Log 处理程序 + +在 `config/customs` 中创建一个 `.yml` 文件,查看 `config/customs/event_log.yml.sample` 来获取更多信息。举个例子,你的文件名为 `contracts.yml`,你可以执行 `bundle exec rake event_log:create[contracts]` 来创建表,然后执行 `bundle exec rake daemons:sync:restart` 来监听你的合约 😝 + +程序会同时使用 `address` 和 `topics` 来通过 jsonrpc 接口 [`getLogs`](http://docs.citahub.com/en-US/cita/rpc-guide/rpc#getlogs) 来筛选数据 + +## Deploy + +可以用 [mina](https://github.com/mina-deploy/mina) 来部署 + +```shell +# 用你的环境变量名来代替 `dev` +$ mina dev deploy +$ mina dev 'rake[daemons:sync:start]' +``` + +## 生成文档 + +```shell +$ bundle exec yard doc +$ bundle exec yard server +``` + +## API 文档 +详见 [API Doc](./API_DOC.md) diff --git a/README.md b/README.md index 9e0b945..96bf673 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![codecov](https://codecov.io/gh/cryptape/re-birth/branch/master/graph/badge.svg)](https://codecov.io/gh/cryptape/re-birth) [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](https://www.rubydoc.info/github/cryptape/re-birth/master) +English | [简体中文](./README-CN.md) + A blockchain explorer cache server for [CITA](http://docs.citahub.com). Now upgrade to work with CITA v0.20 @@ -57,7 +59,7 @@ $ rails db:setup (or rails db:create db:migrate db:seed) ## Running Test ```shell -$ touch .env.test.local (test env will not read `.env.local` file, overwrite in `.env.test.lcoal`) +$ touch .env.test.local (test env will not read `.env.local` file, overwrite in `.env.test.local`) $ rails spec ``` From c62ad8f48968ffbf2fce91fd0d1786a5b692d8e3 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 23 Apr 2019 22:41:04 +0800 Subject: [PATCH 3/7] Add /v2/api/blocks --- API_DOC.md | 2 +- app/controllers/api/v2/blocks_controller.rb | 60 +++++++++++++++++++ config/routes.rb | 4 ++ .../api/v2/blocks_controller_spec.rb | 60 +++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v2/blocks_controller.rb create mode 100644 spec/controllers/api/v2/blocks_controller_spec.rb diff --git a/API_DOC.md b/API_DOC.md index 46d2584..f62fb26 100644 --- a/API_DOC.md +++ b/API_DOC.md @@ -48,7 +48,7 @@ Get the http and websocket url which ReBirth connected. Get blocks info list and paginate it. -> GET /api/blocks +> GET /v2/api/blocks #### params diff --git a/app/controllers/api/v2/blocks_controller.rb b/app/controllers/api/v2/blocks_controller.rb new file mode 100644 index 0000000..0e06262 --- /dev/null +++ b/app/controllers/api/v2/blocks_controller.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +class Api::V2::BlocksController < ApplicationController + # get blocks info list and paginate it. + # + # params + # { + # "numberFrom": "10" or "0xa", // number or integer + # "numberTo": "20", // number or integer + # "transactionFrom": "min transaction count", // integer + # "transactionTo": "max transaction count", // integer + # "page": "1", // default 1 + # "perPage": "10", // default 10 + # + # # offset and limit has lower priority than page and perPage + # "offset": "1", // database offset for pagination + # "limit": "10", //database limit for pagination + # } + # + # GET /v2/api/blocks + def index + options = { + block_number_gteq: parse_hex(params[:numberFrom]), + block_number_lteq: parse_hex(params[:numberTo]), + transaction_count_gteq: parse_hex(params[:transactionFrom]), + transaction_count_lteq: parse_hex(params[:transactionTo]) + } + + blocks = Block.ransack(options).result.order(block_number: :desc) + + if params[:page].nil? && (!params[:offset].nil? || !params[:limit].nil?) + offset = params[:offset] || 0 + limit = params[:limit] || 10 + # use offset and limit + blocks = blocks.offset(offset).limit(limit) + else + # use page and perPage + blocks = blocks.page(params[:page]).per(params[:perPage]) + end + + render json: { + result: { + blocks: ActiveModelSerializers::SerializableResource.new(blocks, each_serializer: ::Api::BlockSerializer) + } + } + end + + private + + # convert hex string which has "0x" prefix to decimal number + # + # @param number [String] hex number string + # + # @return [Integer] + def parse_hex(number) + return number.to_i(16) if number.to_s.downcase.start_with?("0x") + + number + end +end diff --git a/config/routes.rb b/config/routes.rb index 2d5b1de..7c691b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,6 +18,10 @@ get "transactions/:hash", to: "transactions#show" get "event_logs/:address", to: "event_logs#show" get "info/url", to: "info#url" + + namespace :v2 do + resources :blocks, only: [:index] + end end health_check_routes diff --git a/spec/controllers/api/v2/blocks_controller_spec.rb b/spec/controllers/api/v2/blocks_controller_spec.rb new file mode 100644 index 0000000..caf6b2d --- /dev/null +++ b/spec/controllers/api/v2/blocks_controller_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +RSpec.describe Api::V2::BlocksController, type: :controller do + + before do + create :block_zero + create :block_one + end + + let(:result) { Oj.load(response.body).with_indifferent_access[:result] } + let(:count) { result[:blocks].size } + + context "index" do + it "no params" do + post :index, params: {} + expect(count).to eq 2 + end + + it "with page and perPage" do + post :index, params: { page: 1, perPage: 1 } + expect(count).to eq 1 + end + + it "with offset and limit" do + post :index, params: { offset: 0, limit: 1 } + expect(count).to eq 1 + end + + it "with numberFrom" do + post :index, params: { numberFrom: 1 } + expect(count).to eq 1 + end + + it "with numberTo" do + post :index, params: { numberTo: 0 } + expect(count).to eq 1 + end + + it "with numberFrom and NumberTo" do + post :index, params: { numberFrom: 2, numberTo: 1 } + expect(count).to eq 0 + end + + it "with transactionFrom" do + post :index, params: { transactionFrom: 1 } + expect(count).to eq 1 + end + + it "with transactionTo" do + post :index, params: { transactionTo: 0 } + expect(count).to eq 1 + end + + it "with transactionFrom and transactionTo" do + post :index, params: { transactionFrom: 1, transactionTo: 1 } + expect(count).to eq 1 + end + + end +end From 654636964fc4f02c7f40182ee25644004809ccbc Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 24 Apr 2019 10:29:52 +0800 Subject: [PATCH 4/7] Update nokogiri --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5357219..5fb0aab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -157,7 +157,7 @@ GEM msgpack (1.2.4) multipart-post (2.0.0) nio4r (2.3.1) - nokogiri (1.10.1) + nokogiri (1.10.3) mini_portile2 (~> 2.4.0) oj (3.7.0) open4 (1.3.4) From d8f90c3e4a5de9e92628bcaea04bd0952cebf39c Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 24 Apr 2019 10:49:35 +0800 Subject: [PATCH 5/7] Transform v2/blocks keys --- app/controllers/api/v2/blocks_controller.rb | 12 ++++--- .../api/v2/blocks_controller_spec.rb | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v2/blocks_controller.rb b/app/controllers/api/v2/blocks_controller.rb index 0e06262..c915abe 100644 --- a/app/controllers/api/v2/blocks_controller.rb +++ b/app/controllers/api/v2/blocks_controller.rb @@ -19,11 +19,13 @@ class Api::V2::BlocksController < ApplicationController # # GET /v2/api/blocks def index + params.transform_keys!(&:underscore) + options = { - block_number_gteq: parse_hex(params[:numberFrom]), - block_number_lteq: parse_hex(params[:numberTo]), - transaction_count_gteq: parse_hex(params[:transactionFrom]), - transaction_count_lteq: parse_hex(params[:transactionTo]) + block_number_gteq: parse_hex(params[:number_from]), + block_number_lteq: parse_hex(params[:number_to]), + transaction_count_gteq: parse_hex(params[:transaction_from]), + transaction_count_lteq: parse_hex(params[:transaction_to]) } blocks = Block.ransack(options).result.order(block_number: :desc) @@ -35,7 +37,7 @@ def index blocks = blocks.offset(offset).limit(limit) else # use page and perPage - blocks = blocks.page(params[:page]).per(params[:perPage]) + blocks = blocks.page(params[:page]).per(params[:per_page]) end render json: { diff --git a/spec/controllers/api/v2/blocks_controller_spec.rb b/spec/controllers/api/v2/blocks_controller_spec.rb index caf6b2d..e837ca3 100644 --- a/spec/controllers/api/v2/blocks_controller_spec.rb +++ b/spec/controllers/api/v2/blocks_controller_spec.rb @@ -10,6 +10,38 @@ let(:result) { Oj.load(response.body).with_indifferent_access[:result] } let(:count) { result[:blocks].size } + context "params transform" do + let(:params) do + ActionController::Parameters.new({ + numberFrom: 0, + numberTo: 10, + transactionFrom: 20, + transactionTo: 30, + page: 40, + perPage: 50, + offset: 60, + limit: 70 + }) + end + + let(:transformed_params) do + ActionController::Parameters.new({ + number_from: 0, + number_to: 10, + transaction_from: 20, + transaction_to: 30, + page: 40, + per_page: 50, + offset: 60, + limit: 70 + }) + end + + it "transform underscore" do + expect(params.transform_keys!(&:underscore)).to eq transformed_params + end + end + context "index" do it "no params" do post :index, params: {} From f1feb43d58c3f84c7007ceed94b74f2dda1e6e76 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Wed, 24 Apr 2019 12:08:08 +0800 Subject: [PATCH 6/7] Rename /v2/blocks params --- API_DOC.md | 20 +++++----- app/controllers/api/v2/blocks_controller.rb | 20 +++++----- .../api/v2/blocks_controller_spec.rb | 40 +++++++++---------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/API_DOC.md b/API_DOC.md index f62fb26..5e338ad 100644 --- a/API_DOC.md +++ b/API_DOC.md @@ -52,17 +52,20 @@ Get blocks info list and paginate it. #### params +Also Support camelCase. + ```ruby { - "numberFrom": "10" or "0xa", # integer or string of hex number - "numberTo": "20" or "0xa", # integer or string of hex number - "transactionFrom": "min transaction count", # integer or string of hex number - "transactionTo": "max transaction count", # integer or string of hex number - "page": "1", # integer, default 1 - "perPage": "10", # integer, default 10 + "block_number_from": "10" or "0xa", # number or integer + "block_number_to": "20", # number or integer + "min_transaction_count": "min transaction count", # integer + "max_transaction_count": "max transaction count", # integer + "page": "1", # default 1 + "per_page": "10", # default 10 + # offset and limit has lower priority than page and perPage - "offset": "1", # integer, database offset for pagination - "limit": "10", # integer, database limit for pagination + "offset": "1", # database offset for pagination + "limit": "10", # database limit for pagination } ``` @@ -71,7 +74,6 @@ Get blocks info list and paginate it. ```ruby { "result": { - "count": 111200, "blocks": [ { "version": 0, diff --git a/app/controllers/api/v2/blocks_controller.rb b/app/controllers/api/v2/blocks_controller.rb index c915abe..119b65f 100644 --- a/app/controllers/api/v2/blocks_controller.rb +++ b/app/controllers/api/v2/blocks_controller.rb @@ -5,16 +5,16 @@ class Api::V2::BlocksController < ApplicationController # # params # { - # "numberFrom": "10" or "0xa", // number or integer - # "numberTo": "20", // number or integer - # "transactionFrom": "min transaction count", // integer - # "transactionTo": "max transaction count", // integer + # "block_number_from": "10" or "0xa", // number or integer + # "block_number_to": "20", // number or integer + # "min_transaction_count": "min transaction count", // integer + # "max_transaction_count": "max transaction count", // integer # "page": "1", // default 1 - # "perPage": "10", // default 10 + # "per_page": "10", // default 10 # # # offset and limit has lower priority than page and perPage # "offset": "1", // database offset for pagination - # "limit": "10", //database limit for pagination + # "limit": "10", // database limit for pagination # } # # GET /v2/api/blocks @@ -22,10 +22,10 @@ def index params.transform_keys!(&:underscore) options = { - block_number_gteq: parse_hex(params[:number_from]), - block_number_lteq: parse_hex(params[:number_to]), - transaction_count_gteq: parse_hex(params[:transaction_from]), - transaction_count_lteq: parse_hex(params[:transaction_to]) + block_number_gteq: parse_hex(params[:block_number_from]), + block_number_lteq: parse_hex(params[:block_number_to]), + transaction_count_gteq: parse_hex(params[:min_transaction_count]), + transaction_count_lteq: parse_hex(params[:max_transaction_count]) } blocks = Block.ransack(options).result.order(block_number: :desc) diff --git a/spec/controllers/api/v2/blocks_controller_spec.rb b/spec/controllers/api/v2/blocks_controller_spec.rb index e837ca3..78150f3 100644 --- a/spec/controllers/api/v2/blocks_controller_spec.rb +++ b/spec/controllers/api/v2/blocks_controller_spec.rb @@ -13,10 +13,10 @@ context "params transform" do let(:params) do ActionController::Parameters.new({ - numberFrom: 0, - numberTo: 10, - transactionFrom: 20, - transactionTo: 30, + blockNumberFrom: 0, + blockNumberTo: 10, + minTransactionCount: 20, + maxTransactionCount: 30, page: 40, perPage: 50, offset: 60, @@ -26,10 +26,10 @@ let(:transformed_params) do ActionController::Parameters.new({ - number_from: 0, - number_to: 10, - transaction_from: 20, - transaction_to: 30, + block_number_from: 0, + block_number_to: 10, + min_transaction_count: 20, + max_transaction_count: 30, page: 40, per_page: 50, offset: 60, @@ -58,33 +58,33 @@ expect(count).to eq 1 end - it "with numberFrom" do - post :index, params: { numberFrom: 1 } + it "with blockNumberFrom" do + post :index, params: { blockNumberFrom: 1 } expect(count).to eq 1 end - it "with numberTo" do - post :index, params: { numberTo: 0 } + it "with blockNumberTo" do + post :index, params: { blockNumberTo: 0 } expect(count).to eq 1 end - it "with numberFrom and NumberTo" do - post :index, params: { numberFrom: 2, numberTo: 1 } + it "with blockNumberFrom and blockNumberTo" do + post :index, params: { blockNumberFrom: 2, blockNumberTo: 1 } expect(count).to eq 0 end - it "with transactionFrom" do - post :index, params: { transactionFrom: 1 } + it "with minTransactionCount" do + post :index, params: { minTransactionCount: 1 } expect(count).to eq 1 end - it "with transactionTo" do - post :index, params: { transactionTo: 0 } + it "with maxTransactionCount" do + post :index, params: { maxTransactionCount: 0 } expect(count).to eq 1 end - it "with transactionFrom and transactionTo" do - post :index, params: { transactionFrom: 1, transactionTo: 1 } + it "with minTransactionCount and maxTransactionCount" do + post :index, params: { minTransactionCount: 1, maxTransactionCount: 1 } expect(count).to eq 1 end From fc990c8cbe7da0ec567b99f8e066d1d0bdafcec0 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Thu, 25 Apr 2019 19:01:44 +0800 Subject: [PATCH 7/7] Format API doc --- API_DOC.md | 285 ++++++++++++++++++++++++++--------------------------- 1 file changed, 142 insertions(+), 143 deletions(-) diff --git a/API_DOC.md b/API_DOC.md index 5e338ad..e386ffb 100644 --- a/API_DOC.md +++ b/API_DOC.md @@ -37,9 +37,9 @@ Get the http and websocket url which ReBirth connected. ```ruby { - result: { - http_url: "http://localhost:1337", - ws_url: "http://localhost:4337" + "result": { + "http_url": "http://localhost:1337", + "ws_url": "http://localhost:4337" } } ``` @@ -73,37 +73,37 @@ Also Support camelCase. ```ruby { - "result": { - "blocks": [ - { - "version": 0, - "header": { - "proof": { - "Bft": { - "round": 0, - "height": 111198, - "commits": { - "0x31042d4f7662cddf8ded5229db3c5e7302875e10": "0x8132cc5090329854a7dc22300b45c5d972f02a1e558e0b1fa71916316ad2fe061c06829b8b5eb16a7d206f421061a392cd6aad7a1d0a05a8c3e7203fe78a181e00", - "0x486bb688c8d29056bd7f87c26733048b0a6abda6": "0x4aa508798a0b9b77cc1263ae6b64d78977909fd2ce28e4f9322369041a3175cc4f7ad376b122c4b201dc6d2910c515f3d6d94c35dbd13fa6207a91fa8fd649b400", - "0x71b028e49c6f41aaa74932d703c707ecca6d732e": "0xc1e580fa36b0ae5740ca66b612df6d3435c29d20fa21292c93a8bacd7751eee87984a3720576dbad15527bd3a52c9cda42a2d58a382701ab835add5e11bbed1001" - }, - "proposal": "0xc880eb00df297b3c96bc08dca378280f99955816c6f32c08c17f004c0c7dfe75" - } - }, - "number": "0x1b25f", - "quotaUsed": "0x0", - "prevHash": "0x4bf32733fa6ca03326f0cfe7c487d7f8de26ad7c38fcf68959eebc2c0088e279", - "proposer": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", - "stateRoot": "0x7e51d4969381493124b457e57db6dcab48c741a5046c327a43b59593d6a4ab16", - "timestamp": 1532648718735, - "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" - }, - "transactionsCount": 0, - "hash": "0x06208c3b241ff5b8a1fcdec9190abf0cc861d1e5ecdd4f696892fe7ee972473f" + "result": { + "blocks": [ + { + "version": 0, + "header": { + "proof": { + "Bft": { + "round": 0, + "height": 111198, + "commits": { + "0x31042d4f7662cddf8ded5229db3c5e7302875e10": "0x8132cc5090329854a7dc22300b45c5d972f02a1e558e0b1fa71916316ad2fe061c06829b8b5eb16a7d206f421061a392cd6aad7a1d0a05a8c3e7203fe78a181e00", + "0x486bb688c8d29056bd7f87c26733048b0a6abda6": "0x4aa508798a0b9b77cc1263ae6b64d78977909fd2ce28e4f9322369041a3175cc4f7ad376b122c4b201dc6d2910c515f3d6d94c35dbd13fa6207a91fa8fd649b400", + "0x71b028e49c6f41aaa74932d703c707ecca6d732e": "0xc1e580fa36b0ae5740ca66b612df6d3435c29d20fa21292c93a8bacd7751eee87984a3720576dbad15527bd3a52c9cda42a2d58a382701ab835add5e11bbed1001" + }, + "proposal": "0xc880eb00df297b3c96bc08dca378280f99955816c6f32c08c17f004c0c7dfe75" } - ] - } + }, + "number": "0x1b25f", + "quotaUsed": "0x0", + "prevHash": "0x4bf32733fa6ca03326f0cfe7c487d7f8de26ad7c38fcf68959eebc2c0088e279", + "proposer": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", + "stateRoot": "0x7e51d4969381493124b457e57db6dcab48c741a5046c327a43b59593d6a4ab16", + "timestamp": 1532648718735, + "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" + }, + "transactionsCount": 0, + "hash": "0x06208c3b241ff5b8a1fcdec9190abf0cc861d1e5ecdd4f696892fe7ee972473f" + } + ] + } } ``` @@ -133,25 +133,25 @@ Get transactions list and paginate it. ```ruby { - "result": { - "count": 75178, - "transactions": [ - { - "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal - "to": "0xffffffffffffffffffffffffffffffffff010001", - "gasUsed": "0x45754", - "quotaUsed": "0x45754", - "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", - "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", - "blockNumber": "0xffff", - "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", - "timestamp": 1532511655997, - "chainId": 1, - "chainName": "test-chain", - "errorMessage": "Not enough base gas." - } - ] - } + "result": { + "count": 75178, + "transactions": [ + { + "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal + "to": "0xffffffffffffffffffffffffffffffffff010001", + "gasUsed": "0x45754", + "quotaUsed": "0x45754", + "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", + "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", + "blockNumber": "0xffff", + "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", + "timestamp": 1532511655997, + "chainId": 1, + "chainName": "test-chain", + "errorMessage": "Not enough base gas." + } + ] + } } ``` @@ -179,22 +179,22 @@ example ```ruby { - "result": { - "transaction": { - "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal - "to": "0xffffffffffffffffffffffffffffffffff010001", - "gasUsed": "0x45754", - "quotaUsed": "0x45754", - "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", - "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", - "blockNumber": "0xffff", - "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", - "timestamp": 1532511655997, - "chainId": 1, - "chainName": "test-chain", - "errorMessage": "Not enough base gas." - } + "result": { + "transaction": { + "value": "0x0000000000000000000000000000000000000000000000000000000000000000", # 0 if valueFormat=decimal + "to": "0xffffffffffffffffffffffffffffffffff010001", + "gasUsed": "0x45754", + "quotaUsed": "0x45754", + "from": "0x35f8ca15fdeb958d9ad60537bec5e35444dd6d93", + "content": "0x0ae70b0a286666666666666666666666666666666666666666666666666666666666666666666630313030303118c0843d20d480042a8e0bf2356b3877cb8fa08deb57a9ccf4f67e50012a2f5b7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a22616c6c6f7765644d656d62657273222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783164353563336631227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d2c7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c226e616d65223a2261646446696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783234386266633362227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2267657446696c6555726c73222c226f757470757473223a5b7b226e616d65223a2275726c73222c2274797065223a22737472696e67227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783831363234353763227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b5d2c226e616d65223a226f776e6572222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2261646472657373227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230783864613563623562227d2c7b22636f6e7374616e74223a66616c73652c22696e70757473223a5b7b226e616d65223a2266696c65222c2274797065223a22737472696e67227d5d2c226e616d65223a2272656d6f766546696c65222c226f757470757473223a5b7b226e616d65223a2273756363657373222c2274797065223a22626f6f6c227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786631616665303464227d2c7b22636f6e7374616e74223a747275652c22696e70757473223a5b7b226e616d65223a22222c2274797065223a2275696e74323536227d5d2c226e616d65223a2266696c6573222c226f757470757473223a5b7b226e616d65223a22222c2274797065223a2262797465733332227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a2276696577222c2274797065223a2266756e6374696f6e222c227369676e6174757265223a2230786634633731346234227d2c7b22696e70757473223a5b7b226e616d65223a225f616c6c6f7765644d656d62657273222c2274797065223a22616464726573735b5d227d5d2c2270617961626c65223a66616c73652c2273746174654d75746162696c697479223a226e6f6e70617961626c65222c2274797065223a22636f6e7374727563746f72222c227369676e6174757265223a22636f6e7374727563746f72227d5d3220000000000000000000000000000000000000000000000000000000000000000038011241433a04695bfb3f3ada4266494093b80f317b8c795110fc2a223ad2c771377602c810ce591d7ae85695508eafe851ec080602c7fd7e2481bea43f0ece61189d6a01", + "blockNumber": "0xffff", + "hash": "0xf005a3585f9cfce03c7e428b9221eccdedeeae2736c8496c03113f90633135d8", + "timestamp": 1532511655997, + "chainId": 1, + "chainName": "test-chain", + "errorMessage": "Not enough base gas." } + } } # or not found @@ -224,37 +224,37 @@ Get proposals info or brief info. ```ruby # when type = "proposals" { - "result": [ - { - "validator": "0x0000000000000000000000000000000000000000", # proposer of block header - "count": 1 # count of this proposer - }, - { - "validator": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", - "count": 28514 - }, - { - "validator": "0x486bb688c8d29056bd7f87c26733048b0a6abda6", - "count": 27044 - }, - { - "validator": "0x71b028e49c6f41aaa74932d703c707ecca6d732e", - "count": 27844 - }, - { - "validator": "0xee01b9ba97671e8a1891e85b206b499f106822a1", - "count": 27797 - } - ] + "result": [ + { + "validator": "0x0000000000000000000000000000000000000000", # proposer of block header + "count": 1 # count of this proposer + }, + { + "validator": "0x31042d4f7662cddf8ded5229db3c5e7302875e10", + "count": 28514 + }, + { + "validator": "0x486bb688c8d29056bd7f87c26733048b0a6abda6", + "count": 27044 + }, + { + "validator": "0x71b028e49c6f41aaa74932d703c707ecca6d732e", + "count": 27844 + }, + { + "validator": "0xee01b9ba97671e8a1891e85b206b499f106822a1", + "count": 27797 + } + ] } # when type = "brief" { - "result": { - "tps": 0, # float number, transaction count per second - "tpb": 0, # float number, transaction count per block - "ipb": 2.97 # float number, average block interval - } + "result": { + "tps": 0, # float number, transaction count per second + "tpb": 0, # float number, transaction count per block + "ipb": 2.97 # float number, average block interval + } } ``` @@ -268,11 +268,11 @@ Get sync process running status. ```ruby { - "result": { - "status": "not running", # sync process running status, "not running" or "running" - "currentBlockNumber": "0x1b25f", # last sync block - "currentChainBlockNumber": "0x717d0" # the chain current block number - } + "result": { + "status": "not running", # sync process running status, "not running" or "running" + "currentBlockNumber": "0x1b25f", # last sync block + "currentChainBlockNumber": "0x717d0" # the chain current block number + } } ``` @@ -298,20 +298,20 @@ Get sync errors list, which is the errors while sync from chain. ```ruby { - "result": { - "count": 4, # total count of sync errors - "syncErrors": [ - { - "params": ["0x123"], # the params you send - "code": -32700, - "message": "invalid format: [0x123]", - "createdAt": "2018-08-07T03:21:15.862Z", - "updatedAt": "2018-08-07T03:21:15.862Z", - "data": null, - "method": "getTransaction" # the method you access - } - ] - } + "result": { + "count": 4, # total count of sync errors + "syncErrors": [ + { + "params": ["0x123"], # the params you send + "code": -32700, + "message": "invalid format: [0x123]", + "createdAt": "2018-08-07T03:21:15.862Z", + "updatedAt": "2018-08-07T03:21:15.862Z", + "data": null, + "method": "getTransaction" # the method you access + } + ] + } } ``` @@ -325,16 +325,16 @@ Get erc20 contracts transfer event logs by address ```ruby { - "address": "0x...", # contract address, required - "account": "from or to", # hash - "from": "from address", # hash - "to": "to address", # hash - "page": 1, # default 1 - "perPage": 10, # default 10 - - # offset and limit has lower priority than page and perPage - "offset": 1, # default 0 - "limit": 10 # default 10 + "address": "0x...", # contract address, required + "account": "from or to", # hash + "from": "from address", # hash + "to": "to address", # hash + "page": 1, # default 1 + "perPage": 10, # default 10 + + # offset and limit has lower priority than page and perPage + "offset": 1, # default 0 + "limit": 10 # default 10 } ``` @@ -342,23 +342,23 @@ Get erc20 contracts transfer event logs by address ```ruby { - "result": { - "count": 1, - "transfers": [ - { - "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", - "from": "0xac30bce77cf849d869aa37e39b983fa50767a2dd", - "to": "0x6005ed6b942c99533b896b95fe8a90c7a7ecbf6a", - "value": 10, - "blockNumber": "0x18a1ec", - "gasUsed": "0x64", - "quotaUsed": "0x64", - "hash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", - "chainId": 1, - "chainName": "test-chain" - } - ] - } + "result": { + "count": 1, + "transfers": [ + { + "address": "0x0b9a7bad10e78aefbe6d99e61c7ea2a23c3ec888", + "from": "0xac30bce77cf849d869aa37e39b983fa50767a2dd", + "to": "0x6005ed6b942c99533b896b95fe8a90c7a7ecbf6a", + "value": 10, + "blockNumber": "0x18a1ec", + "gasUsed": "0x64", + "quotaUsed": "0x64", + "hash": "0x14b06be4067ba65d05e41d8821e2cf7d572a65b1bf53857a6a504ec42e69fdfd", + "chainId": 1, + "chainName": "test-chain" + } + ] + } } ``` @@ -372,8 +372,8 @@ Get event logs by address ```ruby { - "page": 1, # default 1 - "perPage": 10, # default 10 + "page": 1, # default 1 + "perPage": 10, # default 10 } ``` @@ -403,4 +403,3 @@ Get event logs by address } } ``` -)