Skip to content

Commit

Permalink
Leverage new dictionary request (#267)
Browse files Browse the repository at this point in the history
* Leverage dictionary request in the node

* Fix compilation errors

* Update git ref

* Fix lint
  • Loading branch information
jacek-casper authored Apr 4, 2024
1 parent b24b905 commit 3cf155e
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions resources/test/rpc_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6348,6 +6348,38 @@
},
"additionalProperties": false
},
{
"description": "Lookup a dictionary item via an entities named keys.",
"type": "object",
"required": [
"EntityNamedKey"
],
"properties": {
"EntityNamedKey": {
"type": "object",
"required": [
"dictionary_item_key",
"dictionary_name",
"key"
],
"properties": {
"key": {
"description": "The entity address formatted as a string.",
"type": "string"
},
"dictionary_name": {
"description": "The named key under which the dictionary seed URef is stored.",
"type": "string"
},
"dictionary_item_key": {
"description": "The dictionary item key formatted as a string.",
"type": "string"
}
}
}
},
"additionalProperties": false
},
{
"description": "Lookup a dictionary item via its seed URef.",
"type": "object",
Expand Down
22 changes: 19 additions & 3 deletions rpc_sidecar/src/node_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ use async_trait::async_trait;
use casper_types::{
binary_port::{
BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
ConsensusValidatorChanges, ErrorCode as BinaryPortError, GetRequest, GetTrieFullResult,
GlobalStateQueryResult, GlobalStateRequest, InformationRequest, NodeStatus, PayloadEntity,
RecordId, SpeculativeExecutionResult, TransactionWithExecutionInfo,
ConsensusValidatorChanges, DictionaryItemIdentifier, DictionaryQueryResult,
ErrorCode as BinaryPortError, GetRequest, GetTrieFullResult, GlobalStateQueryResult,
GlobalStateRequest, InformationRequest, NodeStatus, PayloadEntity, RecordId,
SpeculativeExecutionResult, TransactionWithExecutionInfo,
},
bytesrepr::{self, FromBytes, ToBytes},
AvailableBlockRange, BlockHash, BlockHeader, BlockIdentifier, ChainspecRawBytes, Digest,
Expand Down Expand Up @@ -100,6 +101,21 @@ pub trait NodeClient: Send + Sync {
Ok(res.into_inner().map(<Vec<u8>>::from))
}

async fn query_dictionary_item(
&self,
state_identifier: Option<GlobalStateIdentifier>,
identifier: DictionaryItemIdentifier,
) -> Result<Option<DictionaryQueryResult>, Error> {
let get = GlobalStateRequest::DictionaryItem {
state_identifier,
identifier,
};
let resp = self
.send_request(BinaryRequest::Get(GetRequest::State(get)))
.await?;
parse_response::<DictionaryQueryResult>(&resp.into())
}

async fn try_accept_transaction(&self, transaction: Transaction) -> Result<(), Error> {
let request = BinaryRequest::TryAcceptTransaction { transaction };
let response = self.send_request(request).await?;
Expand Down
6 changes: 3 additions & 3 deletions rpc_sidecar/src/rpcs/error.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::node_client::Error as NodeClientError;
use casper_json_rpc::{Error as RpcError, ReservedErrorCode};
use casper_types::{
bytesrepr, AvailableBlockRange, BlockIdentifier, DeployHash, KeyFromStrError, KeyTag,
TransactionHash, URefFromStrError,
bytesrepr, AvailableBlockRange, BlockIdentifier, DeployHash, KeyTag, TransactionHash,
URefFromStrError,
};

use super::{ErrorCode, ErrorData};
Expand All @@ -24,7 +24,7 @@ pub enum Error {
#[error("the requested purse URef was invalid: {0}")]
InvalidPurseURef(URefFromStrError),
#[error("the provided dictionary key was invalid: {0}")]
InvalidDictionaryKey(KeyFromStrError),
InvalidDictionaryKey(String),
#[error("the provided dictionary key points at an unexpected type: {0}")]
InvalidTypeUnderDictionaryKey(String),
#[error("the provided dictionary key doesn't exist")]
Expand Down
Loading

0 comments on commit 3cf155e

Please sign in to comment.