Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary port balance query #274

Merged
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'rafal/track-feat-2.0-spicy-merge' into …
…binary-port-balance-query
  • Loading branch information
jacek-casper committed Apr 8, 2024
commit c434d7282474f0a91eea3f63075086fd151b75e9
13 changes: 4 additions & 9 deletions rpc_sidecar/src/node_client.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use crate::{config::ExponentialBackoffConfig, NodeClientConfig, SUPPORTED_PROTOCOL_VERSION};
use anyhow::Error as AnyhowError;
use async_trait::async_trait;
use casper_binary_port::{
BalanceResponse, BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
ConsensusValidatorChanges, ErrorCode, GetRequest, GetTrieFullResult, GlobalStateQueryResult,
GlobalStateRequest, InformationRequest, NodeStatus, PayloadEntity, PurseIdentifier, RecordId,
SpeculativeExecutionResult, TransactionWithExecutionInfo,
};
use metrics::rpc::{inc_disconnect, observe_reconnect_time};
use serde::de::DeserializeOwned;
use std::{
@@ -18,10 +12,11 @@ use std::{
};

use casper_binary_port::{
BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
BalanceResponse, BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest,
ConsensusValidatorChanges, DictionaryItemIdentifier, DictionaryQueryResult, ErrorCode,
GetRequest, GetTrieFullResult, GlobalStateQueryResult, GlobalStateRequest, InformationRequest,
NodeStatus, PayloadEntity, RecordId, SpeculativeExecutionResult, TransactionWithExecutionInfo,
NodeStatus, PayloadEntity, PurseIdentifier, RecordId, SpeculativeExecutionResult,
TransactionWithExecutionInfo,
};
use casper_types::{
bytesrepr::{self, FromBytes, ToBytes},
@@ -152,7 +147,7 @@ pub trait NodeClient: Send + Sync {
identifier,
};
let resp = self
.send_request(BinaryRequest::Get(GetRequest::State(get)))
.send_request(BinaryRequest::Get(GetRequest::State(Box::new(get))))
.await?;
parse_response::<DictionaryQueryResult>(&resp.into())
}
34 changes: 20 additions & 14 deletions rpc_sidecar/src/rpcs/state.rs
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ use super::{
ApiVersion, Error, NodeClient, RpcError, RpcWithOptionalParams, RpcWithParams,
CURRENT_API_VERSION,
};
use casper_binary_port::DictionaryItemIdentifier;
use casper_binary_port::PurseIdentifier as PortPurseIdentifier;
#[cfg(test)]
use casper_types::testing::TestRng;
@@ -28,8 +29,8 @@ use casper_types::{
AUCTION,
},
AddressableEntity, AddressableEntityHash, AuctionState, BlockHash, BlockHeader, BlockHeaderV2,
BlockIdentifier, BlockV2, CLValue, Digest, GlobalStateIdentifier, Key, KeyTag, PublicKey,
SecretKey, StoredValue, Tagged, Timestamp, URef, U512,
BlockIdentifier, BlockV2, CLValue, Digest, EntityAddr, GlobalStateIdentifier, Key, KeyTag,
PublicKey, SecretKey, StoredValue, Timestamp, URef, U512,
};
#[cfg(test)]
use rand::Rng;
@@ -1155,8 +1156,9 @@ mod tests {

use crate::{rpcs::ErrorCode, ClientError, SUPPORTED_PROTOCOL_VERSION};
use casper_binary_port::{
BalanceResponse, BinaryRequest, BinaryResponse, BinaryResponseAndRequest, GetRequest,
GlobalStateQueryResult, GlobalStateRequest, InformationRequestTag,
BalanceResponse, BinaryRequest, BinaryResponse, BinaryResponseAndRequest,
DictionaryQueryResult, GetRequest, GlobalStateQueryResult, GlobalStateRequest,
InformationRequestTag,
};
use casper_types::{
addressable_entity::{MessageTopics, NamedKeys},
@@ -1940,15 +1942,17 @@ mod tests {
req: BinaryRequest,
) -> Result<BinaryResponseAndRequest, ClientError> {
match req {
BinaryRequest::Get(GetRequest::State(GlobalStateRequest::DictionaryItem {
..
})) => Ok(BinaryResponseAndRequest::new(
BinaryResponse::from_value(
DictionaryQueryResult::new(self.dict_key, self.query_result.clone()),
SUPPORTED_PROTOCOL_VERSION,
),
&[],
)),
BinaryRequest::Get(GetRequest::State(req))
if matches!(&*req, GlobalStateRequest::DictionaryItem { .. }) =>
{
Ok(BinaryResponseAndRequest::new(
BinaryResponse::from_value(
DictionaryQueryResult::new(self.dict_key, self.query_result.clone()),
SUPPORTED_PROTOCOL_VERSION,
),
&[],
))
}
req => unimplemented!("unexpected request: {:?}", req),
}
}
@@ -1963,7 +1967,9 @@ mod tests {
req: BinaryRequest,
) -> Result<BinaryResponseAndRequest, ClientError> {
match req {
BinaryRequest::Get(GetRequest::State(GlobalStateRequest::Item { .. })) => {
BinaryRequest::Get(GetRequest::State(req))
if matches!(&*req, GlobalStateRequest::Item { .. }) =>
{
Ok(BinaryResponseAndRequest::new(
BinaryResponse::from_value(self.0.clone(), SUPPORTED_PROTOCOL_VERSION),
&[],
You are viewing a condensed version of this merge commit. You can view the full changes here.