From 9ff3879e2061a933d00991bf7397cf70c724abaf Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 13 Dec 2016 14:26:16 +0300 Subject: [PATCH] added curl examples for RPCs --- rpc/src/v1/traits/blockchain.rs | 6 ++++++ rpc/src/v1/traits/miner.rs | 1 + rpc/src/v1/traits/raw.rs | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/rpc/src/v1/traits/blockchain.rs b/rpc/src/v1/traits/blockchain.rs index 2b75ddd0..85330fd3 100644 --- a/rpc/src/v1/traits/blockchain.rs +++ b/rpc/src/v1/traits/blockchain.rs @@ -11,21 +11,27 @@ build_rpc_trait! { /// Parity-bitcoin blockchain data interface. pub trait BlockChain { /// Get hash of best block. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getbestblockhash", "params": [], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getbestblockhash")] fn best_block_hash(&self) -> Result; /// Get hash of block at given height. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getblockhash", "params": [0], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getblockhash")] fn block_hash(&self, u32) -> Result; /// Get proof-of-work difficulty as a multiple of the minimum difficulty + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getdifficulty", "params": [], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getdifficulty")] fn difficulty(&self) -> Result; /// Get information on given block. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getblock", "params": ["000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getblock")] fn block(&self, H256, Trailing) -> Result; /// Get details about an unspent transaction output. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "gettxout", "params": ["4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b", 0], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "gettxout")] fn transaction_out(&self, H256, u32, Trailing) -> Result; /// Get statistics about the unspent transaction output set. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "gettxoutsetinfo", "params": [], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "gettxoutsetinfo")] fn transaction_out_set_info(&self) -> Result; } diff --git a/rpc/src/v1/traits/miner.rs b/rpc/src/v1/traits/miner.rs index c3c47194..1c67114f 100644 --- a/rpc/src/v1/traits/miner.rs +++ b/rpc/src/v1/traits/miner.rs @@ -6,6 +6,7 @@ build_rpc_trait! { /// Partiy-bitcoin miner data interface. pub trait Miner { /// Get block template for mining. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getblocktemplate", "params": [{"capabilities": ["coinbasetxn", "workid", "coinbase/append"]}], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getblocktemplate")] fn get_block_template(&self, BlockTemplateRequest) -> Result; } diff --git a/rpc/src/v1/traits/raw.rs b/rpc/src/v1/traits/raw.rs index 55a7ce50..4a093c30 100644 --- a/rpc/src/v1/traits/raw.rs +++ b/rpc/src/v1/traits/raw.rs @@ -12,15 +12,19 @@ build_rpc_trait! { /// Partiy-bitcoin raw data interface. pub trait Raw { /// Adds transaction to the memory pool && relays it to the peers. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "sendrawtransaction", "params": ["01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "sendrawtransaction")] fn send_raw_transaction(&self, RawTransaction) -> Result; /// Create a transaction spending the given inputs and creating new outputs. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "createrawtransaction", "params": [[{"txid":"4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b","vout":0}],{"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa":0.01}], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "createrawtransaction")] fn create_raw_transaction(&self, Vec, Vec, Trailing) -> Result; /// Return an object representing the serialized, hex-encoded transaction. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "decoderawtransaction", "params": ["01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000"], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "decoderawtransaction")] fn decode_raw_transaction(&self, RawTransaction) -> Result; /// Return the raw transaction data. + /// @curl-example: curl --data-binary '{"jsonrpc": "2.0", "method": "getrawtransaction", "params": ["4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"], "id":1 }' -H 'content-type: application/json;' http://127.0.0.1:8332/ #[rpc(name = "getrawtransaction")] fn get_raw_transaction(&self, H256, Trailing) -> Result; }