Skip to content

Commit

Permalink
Merge pull request #100 from zacshowa/query_global_state_identifier
Browse files Browse the repository at this point in the history
Query global state identifier
  • Loading branch information
Zach Showalter authored Sep 5, 2023
2 parents 81b3a6e + 54e63fb commit dd9ed54
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ All notable changes to this project will be documented in this file. The format
## Unreleased

### Added
* Add support for crafting unsigned deploys and transfers by providing an account, but not seccret key, to the `make-deploy` and `make-transfer` subcommands.
* Add support for crafting unsigned deploys and transfers by providing an account, but not secret key, to the `make-deploy` and `make-transfer` subcommands.
* Added an optional flag to retrieve finalized approvals for `info_get_deploy`
* Add support for providing an account identifier (public key, or account hash) for the `state_get_account_info` RPC method.

### Changed
* Changed query-global-state to support omitting a global state identifier, if no global state identifier is provided the latest block will be used.



## [2.0.0] - 2023-06-28

Expand Down
3 changes: 1 addition & 2 deletions lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ pub async fn query_global_state(
let rpc_id = parse::rpc_id(maybe_rpc_id);
let verbosity = parse::verbosity(verbosity_level);
let global_state_identifier =
parse::global_state_identifier(maybe_block_id, maybe_state_root_hash)?
.ok_or(CliError::FailedToParseStateIdentifier)?;
parse::global_state_identifier(maybe_block_id, maybe_state_root_hash)?;
let key = parse::key_for_query(key)?;
let path = if path.is_empty() {
vec![]
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub async fn query_global_state(
rpc_id: JsonRpcId,
node_address: &str,
verbosity: Verbosity,
global_state_identifier: GlobalStateIdentifier,
global_state_identifier: Option<GlobalStateIdentifier>,
key: Key,
path: Vec<String>,
) -> Result<SuccessResponse<QueryGlobalStateResult>, Error> {
Expand Down
2 changes: 1 addition & 1 deletion lib/rpcs/v1_4_5/get_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct GetAccountParams {
}

impl GetAccountParams {
//This clippy link should be re-enabled once the client is updated to handle multiple different node versions.
//This clippy lint should be re-enabled once the client is updated to handle multiple different node versions.
#[allow(dead_code)]
pub(crate) fn new(public_key: PublicKey, block_identifier: Option<BlockIdentifier>) -> Self {
GetAccountParams {
Expand Down
6 changes: 5 additions & 1 deletion lib/rpcs/v1_4_5/query_global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ pub(crate) const QUERY_GLOBAL_STATE_METHOD: &str = "query_global_state";
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub(crate) struct QueryGlobalStateParams {
/// The identifier used for the query.
state_identifier: GlobalStateIdentifier,
// `Key` as formatted string.
/// `casper_types::Key` as formatted string.
key: String,
/// The path components starting from the key as base.
path: Vec<String>,
}

impl QueryGlobalStateParams {
//This clippy lint should be re-enabled once the client is updated to handle multiple different node versions.
#[allow(dead_code)]
pub(crate) fn new(
state_identifier: GlobalStateIdentifier,
key: Key,
Expand Down
3 changes: 0 additions & 3 deletions lib/rpcs/v1_5_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,4 @@ pub(crate) mod query_global_state {
pub use crate::rpcs::v1_4_5::query_global_state::{
GlobalStateIdentifier, QueryGlobalStateResult,
};
pub(crate) use crate::rpcs::v1_4_5::query_global_state::{
QueryGlobalStateParams, QUERY_GLOBAL_STATE_METHOD,
};
}
11 changes: 2 additions & 9 deletions lib/rpcs/v1_6_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
pub(crate) mod get_account;

pub(crate) mod query_global_state;

// The following RPCs are all unchanged from v1.5.0, so we just re-export them.

pub(crate) mod get_chainspec {
Expand Down Expand Up @@ -113,12 +115,3 @@ pub(crate) mod put_deploy {
pub use crate::rpcs::v1_5_0::put_deploy::PutDeployResult;
pub(crate) use crate::rpcs::v1_5_0::put_deploy::{PutDeployParams, PUT_DEPLOY_METHOD};
}

pub(crate) mod query_global_state {
pub use crate::rpcs::v1_5_0::query_global_state::{
GlobalStateIdentifier, QueryGlobalStateResult,
};
pub(crate) use crate::rpcs::v1_5_0::query_global_state::{
QueryGlobalStateParams, QUERY_GLOBAL_STATE_METHOD,
};
}
52 changes: 52 additions & 0 deletions lib/rpcs/v1_6_0/query_global_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use serde::{Deserialize, Serialize};

use casper_types::{Key, ProtocolVersion};

pub(crate) use crate::rpcs::v1_4_5::query_global_state::QUERY_GLOBAL_STATE_METHOD;
use crate::{
rpcs::common::GlobalStateIdentifier,
types::{BlockHeader, StoredValue},
};

#[cfg(doc)]
use crate::BlockIdentifier;

#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub(crate) struct QueryGlobalStateParams {
/// The identifier used for the query. If none is passed
/// the tip of the chain will be used.
state_identifier: Option<GlobalStateIdentifier>,
/// `casper_types::Key` as formatted string.
key: String,
/// The path components starting from the key as base.
path: Vec<String>,
}

impl QueryGlobalStateParams {
pub(crate) fn new(
state_identifier: Option<GlobalStateIdentifier>,
key: Key,
path: Vec<String>,
) -> Self {
QueryGlobalStateParams {
state_identifier,
key: key.to_formatted_string(),
path,
}
}
}

/// The `result` field of a successful JSON-RPC response to a `query_global_state` request.
#[derive(Serialize, Deserialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct QueryGlobalStateResult {
/// The JSON-RPC server version.
pub api_version: ProtocolVersion,
/// The block header if the query was made using a block hash.
pub block_header: Option<BlockHeader>,
/// The stored value.
pub stored_value: StoredValue,
/// The merkle proof of the value.
pub merkle_proof: String,
}
2 changes: 1 addition & 1 deletion src/query_global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl ClientCommand for QueryGlobalState {
ArgGroup::new("state-identifier")
.arg(common::block_identifier::ARG_NAME)
.arg(common::state_root_hash::ARG_NAME)
.required(true),
.required(false),
)
.arg(key::arg(DisplayOrder::Key as usize))
.arg(path::arg(DisplayOrder::Path as usize))
Expand Down

0 comments on commit dd9ed54

Please sign in to comment.