This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tendermint-rs: /blockchain RPC endpoint
- Loading branch information
1 parent
37f487f
commit 726b3d9
Showing
5 changed files
with
450 additions
and
8 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
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,56 @@ | ||
//! `/block` endpoint JSONRPC wrapper | ||
use crate::{block, rpc}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::ops::Range; | ||
|
||
/// Get information about a specific block | ||
pub struct Request { | ||
/// First block in the sequence to request info about | ||
min: block::Height, | ||
|
||
/// Last block in the sequence to request info about | ||
max: block::Height, | ||
} | ||
|
||
impl Request { | ||
/// Request information about a sequence of blocks | ||
pub fn new(start: block::Height, end: block::Height) -> Self { | ||
let (min, max) = if start <= end { | ||
(start, end) | ||
} else { | ||
(end, start) | ||
}; | ||
|
||
Self { min, max } | ||
} | ||
} | ||
|
||
impl From<Range<block::Height>> for Request { | ||
fn from(range: Range<block::Height>) -> Request { | ||
Request::new(range.start, range.end) | ||
} | ||
} | ||
|
||
impl rpc::Request for Request { | ||
type Response = Response; | ||
|
||
fn path(&self) -> rpc::request::Path { | ||
// TODO(tarcieri): use a `uri` crate to construct this? | ||
format!("/block?minHeight={}&maxHeight={}", self.min, self.max) | ||
.parse() | ||
.unwrap() | ||
} | ||
} | ||
|
||
/// Block responses | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Response { | ||
/// Last block height for this particular chain | ||
pub last_height: block::Height, | ||
|
||
/// Block metadata | ||
pub block_metas: Vec<block::Meta>, | ||
} | ||
|
||
impl rpc::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
Oops, something went wrong.