-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block_by_hash RPC endpoint and tests (#1089)
* Add block_by_hash RPC endpoint and tests * rpc-probe part of this * Fix comments * Update .changelog/unreleased/features/832-block-by-hash.md Co-authored-by: Thane Thomson <connect@thanethomson.com> * cargo fmt Co-authored-by: Thane Thomson <connect@thanethomson.com>
- Loading branch information
1 parent
c70f6ee
commit 33a4841
Showing
12 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- `[tendermint-rpc]` Add support for the `/block_by_hash` RPC endpoint. See <https://docs.tendermint.com/master/rpc/#/Info/block_by_hash> for details ([#832](https://github.com/informalsystems/tendermint-rs/issues/832)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! `/block_by_hash` endpoint JSON-RPC wrapper | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use tendermint::block::{self, Block}; | ||
use tendermint::Hash; | ||
|
||
/// Get information about a specific block by its hash | ||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] | ||
pub struct Request { | ||
/// Hash of the block to request. | ||
/// | ||
/// If no hash is provided, it will return no block (as if the hash | ||
/// did not match any block). | ||
pub hash: Option<Hash>, | ||
} | ||
|
||
impl Request { | ||
/// Create a new request for information about a particular block | ||
pub fn new<H: Into<Hash>>(hash: H) -> Self { | ||
Self { | ||
hash: Some(hash.into()), | ||
} | ||
} | ||
} | ||
|
||
impl crate::Request for Request { | ||
type Response = Response; | ||
|
||
fn method(&self) -> crate::Method { | ||
crate::Method::BlockByHash | ||
} | ||
} | ||
|
||
impl crate::SimpleRequest for Request {} | ||
|
||
/// Block responses | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Response { | ||
/// Block ID | ||
pub block_id: block::Id, | ||
|
||
/// Block data | ||
pub block: Option<Block>, | ||
} | ||
|
||
impl crate::Response for Response {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
{ | ||
"id": "988f944f-4d85-486f-ad27-2f3574c2a4a3", | ||
"jsonrpc": "2.0", | ||
"result": { | ||
"block": { | ||
"data": { | ||
"txs": [] | ||
}, | ||
"evidence": { | ||
"evidence": [] | ||
}, | ||
"header": { | ||
"app_hash": "0000000000000000", | ||
"chain_id": "dockerchain", | ||
"consensus_hash": "048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F", | ||
"data_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", | ||
"evidence_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", | ||
"height": "10", | ||
"last_block_id": { | ||
"hash": "03979BC4F521D92D137F8A93B64D7D1A8589560F64C4543784DECCBCEDF1D13F", | ||
"parts": { | ||
"hash": "00DC8C2DE1DE6B66960CB5F15F802286D6423903C06804C35053E0F757B34E47", | ||
"total": 1 | ||
} | ||
}, | ||
"last_commit_hash": "B194E4E363E010ED4F80860FAF452B45D81C77D7C68C753424F44596A229D692", | ||
"last_results_hash": "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", | ||
"next_validators_hash": "D506A39182DDCC44917A3E7827E784B501B354789F99BAC8D56AE50ABE34972B", | ||
"proposer_address": "6B3F66DCF73507BCE7148D6580DAC27074108628", | ||
"time": "2021-11-25T17:04:38.160820316Z", | ||
"validators_hash": "D506A39182DDCC44917A3E7827E784B501B354789F99BAC8D56AE50ABE34972B", | ||
"version": { | ||
"app": "1", | ||
"block": "11" | ||
} | ||
}, | ||
"last_commit": { | ||
"block_id": { | ||
"hash": "03979BC4F521D92D137F8A93B64D7D1A8589560F64C4543784DECCBCEDF1D13F", | ||
"parts": { | ||
"hash": "00DC8C2DE1DE6B66960CB5F15F802286D6423903C06804C35053E0F757B34E47", | ||
"total": 1 | ||
} | ||
}, | ||
"height": "9", | ||
"round": 0, | ||
"signatures": [ | ||
{ | ||
"block_id_flag": 2, | ||
"signature": "5yClL8UlPdvb2tzNguZu3UaTH5X5S8S635u9nBQjZQw3NFhrZklXm6Aw7Mxvhn3y7CL0yKHdRmH0FnPh8cs2Cg==", | ||
"timestamp": "2021-11-25T17:04:38.160820316Z", | ||
"validator_address": "6B3F66DCF73507BCE7148D6580DAC27074108628" | ||
} | ||
] | ||
} | ||
}, | ||
"block_id": { | ||
"hash": "BCF3DB412E80A396D10BF5B5E6D3E63D3B06DEB25AA958BCB8CE18D023838042", | ||
"parts": { | ||
"hash": "7F02924A557B6B6AEB9390183F5458C88EAC02956AFDCCAAFC09B59A80D1EEA8", | ||
"total": 1 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "a37bcc8e-6a32-4157-9200-a26be9981bbd", | ||
"jsonrpc": "2.0", | ||
"method": "block", | ||
"params": { | ||
"hash": "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters