diff --git a/openapi.yaml b/openapi.yaml index 45a42ed5d..70a8a8649 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -11,153 +11,17 @@ info: servers: - url: http://localhost:8232 paths: - /getnetworksolps: - post: - tags: - - mining - description: Returns the estimated network solutions per second based on the last `num_blocks` before - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[]' - method: - type: string - default: getnetworksolps - id: - type: number - default: '123' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '0' - /z_validateaddress: - post: - tags: - - util - description: |- - Checks if a zcash address is valid. - - **Request body `params` arguments:** - - - `address` - The zcash address to validate. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - method: - type: string - default: z_validateaddress - id: - type: number - default: '123' - params: - type: array - items: {} - default: '[]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"isvalid":false}' - /getrawmempool: + /getblock: post: tags: - blockchain - description: Returns all transaction ids in the memory pool, as a JSON array. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - method: - type: string - default: getrawmempool - params: - type: array - items: {} - default: '[]' - id: - type: number - default: '123' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '[]' - /getdifficulty: - post: - tags: - - blockchain - description: Returns the proof-of-work difficulty as a multiple of the minimum difficulty. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - id: - type: number - default: '123' - method: - type: string - default: getdifficulty - params: - type: array - items: {} - default: '[]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '0.0' - /z_listunifiedreceivers: - post: - tags: - - wallet description: |- - Returns the list of individual payment addresses given a unified address. + Returns the requested block by hash or height, as a [`GetBlock`] JSON string. **Request body `params` arguments:** - - `address` - The zcash unified address to get the list from. + - `hash_or_height` - The hash or height for the block to be returned. + - `verbosity` - 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data. requestBody: required: true content: @@ -165,65 +29,17 @@ paths: schema: type: object properties: - method: - type: string - default: z_listunifiedreceivers id: type: number default: '123' params: type: array items: {} - default: '[]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"orchard":"orchard address if any","sapling":"sapling address if any","p2pkh":"p2pkh address if any","p2sh":"p2sh address if any"}' - /getaddresstxids: - post: - tags: - - address - description: |- - Returns the transaction ids made by the provided transparent addresses. - - **Request body `params` arguments:** - - - `request` - A struct with the following named fields: - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[{"addresses": ["tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ"], "start": 1000, "end": 2000}]' + default: '["1", 1]' method: type: string - default: getaddresstxids - id: - type: number - default: '123' + default: getblock responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '[]' '400': description: Bad request content: @@ -234,34 +50,6 @@ paths: error: type: string default: Invalid parameters - /getblockhash: - post: - tags: - - blockchain - description: |- - Returns the hash of the block of a given height iff the index argument correspond - - **Request body `params` arguments:** - - - `index` - The block index. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - method: - type: string - default: getblockhash - id: - type: number - default: '123' - params: - type: array - items: {} - default: '[1]' - responses: '200': description: OK content: @@ -271,7 +59,36 @@ paths: properties: result: type: object - default: '"0000000000000000000000000000000000000000000000000000000000000000"' + default: '{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"tx":[],"trees":{}}' + /getrawtransaction: + post: + tags: + - transaction + description: |- + Returns the raw transaction data, as a [`GetRawTransaction`] JSON string or structure. + + **Request body `params` arguments:** + + - `txid` - The transaction ID of the transaction to be returned. + - `verbose` - If 0, return a string of hex-encoded data, otherwise return a JSON object. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: getrawtransaction + id: + type: number + default: '123' + params: + type: array + items: {} + default: '["mytxid", 1]' + responses: '400': description: Bad request content: @@ -282,11 +99,21 @@ paths: error: type: string default: Invalid parameters - /getbestblockhash: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"hex":"0000000000000000000000000000000000000000","height":0,"confirmations":0}' + /getblockchaininfo: post: tags: - blockchain - description: Returns the hash of the current best blockchain tip block, as a [`GetBlockHash`] JSON string. + description: Returns blockchain state information, as a [`GetBlockChainInfo`] JSON struct. requestBody: required: true content: @@ -294,12 +121,12 @@ paths: schema: type: object properties: - method: - type: string - default: getbestblockhash id: type: number default: '123' + method: + type: string + default: getblockchaininfo params: type: array items: {} @@ -314,7 +141,7 @@ paths: properties: result: type: object - default: '"0000000000000000000000000000000000000000000000000000000000000000"' + default: '{"chain":"main","blocks":1,"bestblockhash":"0000000000000000000000000000000000000000000000000000000000000000","estimatedheight":1,"upgrades":{},"consensus":{"chaintip":"00000000","nextblock":"00000000"}}' /z_gettreestate: post: tags: @@ -332,16 +159,16 @@ paths: schema: type: object properties: + method: + type: string + default: z_gettreestate + id: + type: number + default: '123' params: type: array items: {} default: '["00000000febc373a1da2bd9f887b105ad79ddc26ac26c2b28652d64e5207c5b5"]' - id: - type: number - default: '123' - method: - type: string - default: z_gettreestate responses: '200': description: OK @@ -363,410 +190,6 @@ paths: error: type: string default: Invalid parameters - /getaddressutxos: - post: - tags: - - address - description: |- - Returns all unspent outputs for a list of addresses. - - **Request body `params` arguments:** - - - `addresses` - The addresses to get outputs from. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - method: - type: string - default: getaddressutxos - id: - type: number - default: '123' - params: - type: array - items: {} - default: '[{"addresses": ["tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ"]}]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"address":"t1Hsc1LR8yKnbbe3twRp88p6vFfC5t7DLbs","txid":"0000000000000000000000000000000000000000000000000000000000000000","outputIndex":0,"script":"00000000000000000000","satoshis":0,"height":0}' - '400': - description: Bad request - content: - application/json: - schema: - type: object - properties: - error: - type: string - default: Invalid parameters - /getblockcount: - post: - tags: - - blockchain - description: Returns the height of the most recent block in the best valid block chain (equivalently, - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[]' - id: - type: number - default: '123' - method: - type: string - default: getblockcount - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '0' - /getblocksubsidy: - post: - tags: - - mining - description: |- - Returns the block subsidy reward of the block at `height`, taking into account the mining slow start. - - **Request body `params` arguments:** - - - `height` - Can be any valid current or future height. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - id: - type: number - default: '123' - params: - type: array - items: {} - default: '[1]' - method: - type: string - default: getblocksubsidy - responses: - '400': - description: Bad request - content: - application/json: - schema: - type: object - properties: - error: - type: string - default: Invalid parameters - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"fundingstreams":[],"miner":0.0,"founders":0.0}' - /getrawtransaction: - post: - tags: - - transaction - description: |- - Returns the raw transaction data, as a [`GetRawTransaction`] JSON string or structure. - - **Request body `params` arguments:** - - - `txid` - The transaction ID of the transaction to be returned. - - `verbose` - If 0, return a string of hex-encoded data, otherwise return a JSON object. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - id: - type: number - default: '123' - params: - type: array - items: {} - default: '["mytxid", 1]' - method: - type: string - default: getrawtransaction - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"hex":"0000000000000000000000000000000000000000","height":0,"confirmations":0}' - '400': - description: Bad request - content: - application/json: - schema: - type: object - properties: - error: - type: string - default: Invalid parameters - /getmininginfo: - post: - tags: - - mining - description: Returns mining-related information. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[]' - method: - type: string - default: getmininginfo - id: - type: number - default: '123' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"networksolps":0,"networkhashps":0,"chain":"","testnet":false}' - /getblock: - post: - tags: - - blockchain - description: |- - Returns the requested block by hash or height, as a [`GetBlock`] JSON string. - - **Request body `params` arguments:** - - - `hash_or_height` - The hash or height for the block to be returned. - - `verbosity` - 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - method: - type: string - default: getblock - id: - type: number - default: '123' - params: - type: array - items: {} - default: '["1", 1]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"hash":"0000000000000000000000000000000000000000000000000000000000000000","confirmations":0,"tx":[],"trees":{}}' - '400': - description: Bad request - content: - application/json: - schema: - type: object - properties: - error: - type: string - default: Invalid parameters - /z_getsubtreesbyindex: - post: - tags: - - blockchain - description: |- - Returns information about a range of Sapling or Orchard subtrees. - - **Request body `params` arguments:** - - - `pool` - The pool from which subtrees should be returned. Either \"sapling\" or \"orchard\". - - `start_index` - The index of the first 2^16-leaf subtree to return. - - `limit` - The maximum number of subtree values to return. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - id: - type: number - default: '123' - params: - type: array - items: {} - default: '[]' - method: - type: string - default: z_getsubtreesbyindex - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{}' - /getblocktemplate: - post: - tags: - - mining - description: |- - Returns a block template for mining new Zcash blocks. - - **Request body `params` arguments:** - - - `jsonrequestobject` - A JSON object containing arguments. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[]' - method: - type: string - default: getblocktemplate - id: - type: number - default: '123' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{}' - /getinfo: - post: - tags: - - control - description: Returns software information from the RPC server, as a [`GetInfo`] JSON struct. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - id: - type: number - default: '123' - method: - type: string - default: getinfo - params: - type: array - items: {} - default: '[]' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"build":"some build version","subversion":"some subversion"}' - /getblockchaininfo: - post: - tags: - - blockchain - description: Returns blockchain state information, as a [`GetBlockChainInfo`] JSON struct. - requestBody: - required: true - content: - application/json: - schema: - type: object - properties: - params: - type: array - items: {} - default: '[]' - method: - type: string - default: getblockchaininfo - id: - type: number - default: '123' - responses: - '200': - description: OK - content: - application/json: - schema: - type: object - properties: - result: - type: object - default: '{"chain":"main","blocks":1,"bestblockhash":"0000000000000000000000000000000000000000000000000000000000000000","estimatedheight":1,"upgrades":{},"consensus":{"chaintip":"00000000","nextblock":"00000000"}}' /getaddressbalance: post: tags: @@ -815,6 +238,327 @@ paths: error: type: string default: Invalid parameters + /getaddresstxids: + post: + tags: + - address + description: |- + Returns the transaction ids made by the provided transparent addresses. + + **Request body `params` arguments:** + + - `request` - A struct with the following named fields: + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[{"addresses": ["tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ"], "start": 1000, "end": 2000}]' + method: + type: string + default: getaddresstxids + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '[]' + '400': + description: Bad request + content: + application/json: + schema: + type: object + properties: + error: + type: string + default: Invalid parameters + /getmininginfo: + post: + tags: + - mining + description: Returns mining-related information. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[]' + method: + type: string + default: getmininginfo + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"networksolps":0,"networkhashps":0,"chain":"","testnet":false}' + /sendrawtransaction: + post: + tags: + - transaction + description: |- + Sends the raw bytes of a signed transaction to the local node''s mempool, if the transaction is valid. + + **Request body `params` arguments:** + + - `raw_transaction_hex` - The hex-encoded raw transaction bytes. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + method: + type: string + default: sendrawtransaction + params: + type: array + items: {} + default: '["signedhex"]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '"0000000000000000000000000000000000000000000000000000000000000000"' + '400': + description: Bad request + content: + application/json: + schema: + type: object + properties: + error: + type: string + default: Invalid parameters + /getblockcount: + post: + tags: + - blockchain + description: Returns the height of the most recent block in the best valid block chain (equivalently, + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: getblockcount + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '0' + /z_validateaddress: + post: + tags: + - util + description: |- + Checks if a zcash address is valid. + + **Request body `params` arguments:** + + - `address` - The zcash address to validate. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + params: + type: array + items: {} + default: '[]' + id: + type: number + default: '123' + method: + type: string + default: z_validateaddress + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"isvalid":false}' + /getblockhash: + post: + tags: + - blockchain + description: |- + Returns the hash of the block of a given height iff the index argument correspond + + **Request body `params` arguments:** + + - `index` - The block index. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + method: + type: string + default: getblockhash + params: + type: array + items: {} + default: '[1]' + responses: + '400': + description: Bad request + content: + application/json: + schema: + type: object + properties: + error: + type: string + default: Invalid parameters + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '"0000000000000000000000000000000000000000000000000000000000000000"' + /z_getsubtreesbyindex: + post: + tags: + - blockchain + description: |- + Returns information about a range of Sapling or Orchard subtrees. + + **Request body `params` arguments:** + + - `pool` - The pool from which subtrees should be returned. Either \"sapling\" or \"orchard\". + - `start_index` - The index of the first 2^16-leaf subtree to return. + - `limit` - The maximum number of subtree values to return. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: z_getsubtreesbyindex + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"pool":"","start_index":0,"subtrees":[]}' + /getnetworkhashps: + post: + tags: + - mining + description: Returns the estimated network solutions per second based on the last `num_blocks` before + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: getnetworkhashps + params: + type: array + items: {} + default: '[]' + id: + type: number + default: '123' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '0' /getpeerinfo: post: tags: @@ -827,13 +571,13 @@ paths: schema: type: object properties: + method: + type: string + default: getpeerinfo params: type: array items: {} default: '[]' - method: - type: string - default: getpeerinfo id: type: number default: '123' @@ -868,13 +612,13 @@ paths: id: type: number default: '123' + method: + type: string + default: validateaddress params: type: array items: {} default: '[]' - method: - type: string - default: validateaddress responses: '200': description: OK @@ -886,16 +630,11 @@ paths: result: type: object default: '{"isvalid":false}' - /sendrawtransaction: + /getnetworksolps: post: tags: - - transaction - description: |- - Sends the raw bytes of a signed transaction to the local node''s mempool, if the transaction is valid. - - **Request body `params` arguments:** - - - `raw_transaction_hex` - The hex-encoded raw transaction bytes. + - mining + description: Returns the estimated network solutions per second based on the last `num_blocks` before requestBody: required: true content: @@ -905,14 +644,123 @@ paths: properties: method: type: string - default: sendrawtransaction + default: getnetworksolps id: type: number default: '123' params: type: array items: {} - default: '["signedhex"]' + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '0' + /submitblock: + post: + tags: + - mining + description: |- + Submits block to the node to be validated and committed. + + **Request body `params` arguments:** + + - `jsonparametersobject` - - currently ignored + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: submitblock + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '"rejected"' + /getinfo: + post: + tags: + - control + description: Returns software information from the RPC server, as a [`GetInfo`] JSON struct. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: getinfo + params: + type: array + items: {} + default: '[]' + id: + type: number + default: '123' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"build":"some build version","subversion":"some subversion"}' + /getblocksubsidy: + post: + tags: + - mining + description: |- + Returns the block subsidy reward of the block at `height`, taking into account the mining slow start. + + **Request body `params` arguments:** + + - `height` - Can be any valid current or future height. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + method: + type: string + default: getblocksubsidy + id: + type: number + default: '123' + params: + type: array + items: {} + default: '[1]' responses: '400': description: Bad request @@ -924,6 +772,72 @@ paths: error: type: string default: Invalid parameters + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"fundingstreams":[],"miner":0.0,"founders":0.0}' + /getdifficulty: + post: + tags: + - blockchain + description: Returns the proof-of-work difficulty as a multiple of the minimum difficulty. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + method: + type: string + default: getdifficulty + params: + type: array + items: {} + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '0.0' + /getbestblockhash: + post: + tags: + - blockchain + description: Returns the hash of the current best blockchain tip block, as a [`GetBlockHash`] JSON string. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + params: + type: array + items: {} + default: '[]' + id: + type: number + default: '123' + method: + type: string + default: getbestblockhash + responses: '200': description: OK content: @@ -934,16 +848,97 @@ paths: result: type: object default: '"0000000000000000000000000000000000000000000000000000000000000000"' - /submitblock: + /getrawmempool: + post: + tags: + - blockchain + description: Returns all transaction ids in the memory pool, as a JSON array. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + id: + type: number + default: '123' + method: + type: string + default: getrawmempool + params: + type: array + items: {} + default: '[]' + responses: + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '[]' + /getaddressutxos: + post: + tags: + - address + description: |- + Returns all unspent outputs for a list of addresses. + + **Request body `params` arguments:** + + - `addresses` - The addresses to get outputs from. + requestBody: + required: true + content: + application/json: + schema: + type: object + properties: + params: + type: array + items: {} + default: '[{"addresses": ["tmYXBYJj1K7vhejSec5osXK2QsGa5MTisUQ"]}]' + method: + type: string + default: getaddressutxos + id: + type: number + default: '123' + responses: + '400': + description: Bad request + content: + application/json: + schema: + type: object + properties: + error: + type: string + default: Invalid parameters + '200': + description: OK + content: + application/json: + schema: + type: object + properties: + result: + type: object + default: '{"address":"t1Hsc1LR8yKnbbe3twRp88p6vFfC5t7DLbs","txid":"0000000000000000000000000000000000000000000000000000000000000000","outputIndex":0,"script":"00000000000000000000","satoshis":0,"height":0}' + /getblocktemplate: post: tags: - mining description: |- - Submits block to the node to be validated and committed. + Returns a block template for mining new Zcash blocks. **Request body `params` arguments:** - - `jsonparametersobject` - - currently ignored + - `jsonrequestobject` - A JSON object containing arguments. requestBody: required: true content: @@ -951,6 +946,9 @@ paths: schema: type: object properties: + method: + type: string + default: getblocktemplate id: type: number default: '123' @@ -958,9 +956,6 @@ paths: type: array items: {} default: '[]' - method: - type: string - default: submitblock responses: '200': description: OK @@ -971,12 +966,17 @@ paths: properties: result: type: object - default: '"rejected"' - /getnetworkhashps: + default: '{}' + /z_listunifiedreceivers: post: tags: - - mining - description: Returns the estimated network solutions per second based on the last `num_blocks` before + - wallet + description: |- + Returns the list of individual payment addresses given a unified address. + + **Request body `params` arguments:** + + - `address` - The zcash unified address to get the list from. requestBody: required: true content: @@ -986,7 +986,7 @@ paths: properties: method: type: string - default: getnetworkhashps + default: z_listunifiedreceivers params: type: array items: {} @@ -1004,4 +1004,4 @@ paths: properties: result: type: object - default: '0' + default: '{"orchard":"orchard address if any","sapling":"sapling address if any","p2pkh":"p2pkh address if any","p2sh":"p2sh address if any"}' diff --git a/zebra-rpc/src/methods.rs b/zebra-rpc/src/methods.rs index ec07b5cd1..a9ed4bc34 100644 --- a/zebra-rpc/src/methods.rs +++ b/zebra-rpc/src/methods.rs @@ -1417,20 +1417,12 @@ impl AddressStrings { } /// The transparent balance of a set of addresses. -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, serde::Serialize)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash, serde::Serialize)] pub struct AddressBalance { /// The total transparent balance. balance: u64, } -impl Default for AddressBalance { - fn default() -> Self { - Self { - balance: u64::default(), - } - } -} - /// A hex-encoded [`ConsensusBranchId`] string. #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize)] struct ConsensusBranchIdHex(#[serde(with = "hex")] ConsensusBranchId); diff --git a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs index d658fb396..a14d4a081 100644 --- a/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs +++ b/zebra-rpc/src/methods/get_block_template_rpcs/types/get_mining_info.rs @@ -3,7 +3,7 @@ use zebra_chain::parameters::Network; /// Response to a `getmininginfo` RPC request. -#[derive(Debug, PartialEq, Eq, serde::Serialize)] +#[derive(Debug, Default, PartialEq, Eq, serde::Serialize)] pub struct Response { /// The estimated network solution rate in Sol/s. networksolps: u64, @@ -29,14 +29,3 @@ impl Response { } } } - -impl Default for Response { - fn default() -> Self { - Self { - networksolps: u64::default(), - networkhashps: u64::default(), - chain: String::default(), - testnet: bool::default(), - } - } -} diff --git a/zebra-rpc/src/methods/trees.rs b/zebra-rpc/src/methods/trees.rs index 81b87227b..4f26e7a95 100644 --- a/zebra-rpc/src/methods/trees.rs +++ b/zebra-rpc/src/methods/trees.rs @@ -32,6 +32,16 @@ pub struct GetSubtrees { pub subtrees: Vec, } +impl Default for GetSubtrees { + fn default() -> Self { + Self { + pool: String::default(), + start_index: NoteCommitmentSubtreeIndex(u16::default()), + subtrees: vec![], + } + } +} + /// Response to a `z_gettreestate` RPC request. /// /// Contains hex-encoded Sapling & Orchard note commitment trees and their corresponding diff --git a/zebra-utils/src/bin/openapi-generator/main.rs b/zebra-utils/src/bin/openapi-generator/main.rs index 23e22b11a..42e9ba332 100644 --- a/zebra-utils/src/bin/openapi-generator/main.rs +++ b/zebra-utils/src/bin/openapi-generator/main.rs @@ -453,294 +453,103 @@ fn add_params_to_description(description: &str, params_description: &str) -> Str new_description } +fn default_property( + type_: &str, + items: Option, + default_value: T, +) -> Result> { + Ok(Property { + type_: type_.to_string(), + items, + default: serde_json::to_string(&default_value)?, + }) +} + // Get requests examples by using defaults from the Zebra RPC methods fn get_default_properties(method_name: &str) -> Result, Box> { - // TODO: Complete the list of methods - - let type_ = "object".to_string(); + let type_ = "object"; let items = None; let mut props = HashMap::new(); - let properties = match method_name { - "getinfo" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetInfo::default())?, - }, - ); - props - } - "getbestblockhash" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetBlockHash::default())?, - }, - ); - props - } + // TODO: An entry has to be added here manually for each new RPC method introduced, can we automate? + let default_result = match method_name { + // mining + // TODO: missing `getblocktemplate`. It's a complex method that requires a lot of parameters. + "getnetworkhashps" => default_property(type_, items.clone(), u64::default())?, + "getblocksubsidy" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::subsidy::BlockSubsidy::default(), + )?, + "getmininginfo" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::get_mining_info::Response::default(), + )?, + "getnetworksolps" => default_property(type_, items.clone(), u64::default())?, + "submitblock" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::submit_block::Response::default(), + )?, + // util + "validateaddress" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::validate_address::Response::default(), + )?, + "z_validateaddress" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::z_validate_address::Response::default(), + )?, + // address + "getaddressbalance" => default_property(type_, items.clone(), AddressBalance::default())?, + "getaddressutxos" => default_property(type_, items.clone(), GetAddressUtxos::default())?, + "getaddresstxids" => default_property(type_, items.clone(), Vec::::default())?, + // network + "getpeerinfo" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::peer_info::PeerInfo::default(), + )?, + // blockchain + "getdifficulty" => default_property(type_, items.clone(), f64::default())?, "getblockchaininfo" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetBlockChainInfo::default())?, - }, - ); - props + default_property(type_, items.clone(), GetBlockChainInfo::default())? } - "getblock" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetBlock::default())?, - }, - ); - props - } - "getblockhash" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetBlockHash::default())?, - }, - ); - props - } - "z_gettreestate" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetTreestate::default())?, - }, - ); - props - } - "getpeerinfo" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::peer_info::PeerInfo::default(), - )?, - }, - ); - props - } - "getblocksubsidy" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::subsidy::BlockSubsidy::default(), - )?, - }, - ); - props - } - "getmininginfo" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::get_mining_info::Response::default(), - )?, - }, - ); - props - } - "getblockcount" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&u32::default())?, - }, - ); - props - } - "getaddressbalance" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&AddressBalance::default())?, - }, - ); - props - } - "getaddressutxos" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetAddressUtxos::default())?, - }, - ); - props - } - "getaddresstxids" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&Vec::::default())?, - }, - ); - props - } - "validateaddress" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::validate_address::Response::default(), - )?, - }, - ); - props - } - "z_validateaddress" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::z_validate_address::Response::default(), - )?, - }, - ); - props - } - "getrawmempool" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&Vec::::default())?, - }, - ); - props - } - "getdifficulty" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&f64::default())?, - }, - ); - props + "getrawmempool" => default_property(type_, items.clone(), Vec::::default())?, + "getblockhash" => default_property(type_, items.clone(), GetBlockHash::default())?, + "z_getsubtreesbyindex" => { + default_property(type_, items.clone(), trees::GetSubtrees::default())? } + "z_gettreestate" => default_property(type_, items.clone(), GetTreestate::default())?, + "getblockcount" => default_property(type_, items.clone(), u32::default())?, + "getbestblockhash" => default_property(type_, items.clone(), GetBlockHash::default())?, + "getblock" => default_property(type_, items.clone(), GetBlock::default())?, + // wallet + "z_listunifiedreceivers" => default_property( + type_, + items.clone(), + get_block_template_rpcs::types::unified_address::Response::default(), + )?, + // control + "getinfo" => default_property(type_, items.clone(), GetInfo::default())?, + // transaction "sendrawtransaction" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&SentTransactionHash::default())?, - }, - ); - props + default_property(type_, items.clone(), SentTransactionHash::default())? } "getrawtransaction" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&GetRawTransaction::default())?, - }, - ); - props - } - "getnetworksolps" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&u64::default())?, - }, - ); - props - } - "getnetworkhashps" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string(&u64::default())?, - }, - ); - props - } - "submitblock" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::submit_block::Response::default(), - )?, - }, - ); - props - } - "z_listunifiedreceivers" => { - props.insert( - "result".to_string(), - Property { - type_, - items, - default: serde_json::to_string( - &get_block_template_rpcs::types::unified_address::Response::default(), - )?, - }, - ); - props - } - - _ => { - props.insert( - "result".to_string(), - Property { - type_, - items: None, - default: "{}".to_string(), - }, - ); - props + default_property(type_, items.clone(), GetRawTransaction::default())? } + // default + _ => Property { + type_: type_.to_string(), + items: None, + default: "{}".to_string(), + }, }; - Ok(properties) + + props.insert("result".to_string(), default_result); + Ok(props) }