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.
tendermint-rs: /abci_query RPC endpoint (closes #287)
Adds support for invoking the ABCIQuery endpoint: https://tendermint.com/rpc/#abciquery
- Loading branch information
1 parent
fcc52e5
commit 7491c6f
Showing
10 changed files
with
182 additions
and
5 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 @@ | ||
|
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,80 @@ | ||
//! `/abci_query` endpoint JSONRPC wrapper | ||
|
||
use crate::{ | ||
abci::{Code, Log, 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<String>, | ||
|
||
/// Data to query | ||
data: Vec<u8>, | ||
|
||
/// Block height | ||
height: Option<block::Height>, | ||
|
||
/// Include proof in response | ||
prove: bool, | ||
} | ||
|
||
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
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" | ||
} | ||
} | ||
} |