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 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from tendermint/tendermint-rs/abci_query
tendermint-rs: /abci_query RPC endpoint (closes #287)
- Loading branch information
Showing
11 changed files
with
229 additions
and
6 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,26 @@ | ||
//! Paths to ABCI data | ||
|
||
use crate::error::Error; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
fmt::{self, Display}, | ||
str::FromStr, | ||
}; | ||
|
||
/// Path to ABCI data | ||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] | ||
pub struct Path(String); | ||
|
||
impl Display for Path { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", &self.0) | ||
} | ||
} | ||
|
||
impl FromStr for Path { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Error> { | ||
Ok(Path(s.to_owned())) | ||
} | ||
} |
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,51 @@ | ||
//! ABCI Merkle proofs | ||
|
||
use crate::error::Error; | ||
use serde::{de::Error as _, Deserialize, Deserializer, Serialize, Serializer}; | ||
use std::{ | ||
fmt::{self, Display}, | ||
str::FromStr, | ||
}; | ||
use subtle_encoding::{Encoding, Hex}; | ||
|
||
/// ABCI Merkle proofs | ||
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
pub struct Proof(Vec<u8>); | ||
|
||
impl AsRef<[u8]> for Proof { | ||
fn as_ref(&self) -> &[u8] { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl Display for Proof { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
&Hex::upper_case().encode_to_string(&self.0).unwrap() | ||
) | ||
} | ||
} | ||
|
||
impl FromStr for Proof { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Error> { | ||
let bytes = Hex::upper_case().decode(s)?; | ||
Ok(Proof(bytes)) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for Proof { | ||
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { | ||
let hex = String::deserialize(deserializer)?; | ||
Ok(Self::from_str(&hex).map_err(|e| D::Error::custom(format!("{}", e)))?) | ||
} | ||
} | ||
|
||
impl Serialize for Proof { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { | ||
self.to_string().serialize(serializer) | ||
} | ||
} |
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,95 @@ | ||
//! `/abci_query` endpoint JSONRPC wrapper | ||
|
||
use crate::{ | ||
abci::{Code, Log, Path, Proof}, | ||
block, rpc, serializers, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Query the ABCI application for information | ||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] | ||
pub struct Request { | ||
/// Path to the data | ||
path: Option<Path>, | ||
|
||
/// Data to query | ||
data: Vec<u8>, | ||
|
||
/// Block height | ||
height: Option<block::Height>, | ||
|
||
/// Include proof in response | ||
prove: bool, | ||
} | ||
|
||
impl Request { | ||
/// Create a new ABCI query request | ||
pub fn new<D>(path: Option<Path>, data: D, height: Option<block::Height>, prove: bool) -> Self | ||
where | ||
D: Into<Vec<u8>>, | ||
{ | ||
Self { | ||
path, | ||
data: data.into(), | ||
height, | ||
prove, | ||
} | ||
} | ||
} | ||
|
||
impl rpc::Request for Request { | ||
type Response = Response; | ||
|
||
fn method(&self) -> rpc::Method { | ||
rpc::Method::AbciInfo | ||
} | ||
} | ||
|
||
/// ABCI query response wrapper | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Response { | ||
/// ABCI query results | ||
pub response: AbciQuery, | ||
} | ||
|
||
impl rpc::Response for Response {} | ||
|
||
/// ABCI query results | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct AbciQuery { | ||
/// Response code | ||
pub code: Code, | ||
|
||
/// Log value | ||
pub log: Log, | ||
|
||
/// Info value | ||
pub info: Option<String>, | ||
|
||
/// Index | ||
#[cfg_attr( | ||
feature = "serde", | ||
serde( | ||
serialize_with = "serializers::serialize_i64", | ||
deserialize_with = "serializers::parse_i64" | ||
) | ||
)] | ||
pub index: i64, | ||
|
||
/// Key | ||
// TODO(tarcieri): parse to Vec<u8>? | ||
pub key: String, | ||
|
||
/// Value | ||
// TODO(tarcieri): parse to Vec<u8>? | ||
pub value: String, | ||
|
||
/// Proof (if requested) | ||
pub proof: Option<Proof>, | ||
|
||
/// Block height | ||
pub height: block::Height, | ||
|
||
/// Codespace | ||
pub codespace: Option<String>, | ||
} |
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,15 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": "", | ||
"result": { | ||
"response": { | ||
"log": "exists", | ||
"height": "1", | ||
"proof": "010114FED0DAD959F36091AD761C922ABA3CBF1D8349990101020103011406AA2262E2F448242DF2C2607C3CDC705313EE3B0001149D16177BC71E445476174622EA559715C293740C", | ||
"value": "61626364", | ||
"key": "61626364", | ||
"index": "-1", | ||
"code": "0" | ||
} | ||
} | ||
} |