Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ description = "CLI for Casper binary port."
license = "Apache-2.0"

[dependencies]
casper-types = { git = "https://github.com/casper-network/casper-node", features = [
casper-types = { git = "https://github.com/casper-network/casper-node", branch = "dev", features = [
"std-fs-io",
] }
casper-binary-port = { version = "1.0.0", git = "https://github.com/casper-network/casper-node" }
casper-binary-port = { version = "1.0.0", git = "https://github.com/casper-network/casper-node", branch = "dev" }
casper-binary-port-access = { path = "./binary-port-access" }
clap = { version = "4.5.20", features = ["derive", "wrap_help"] }
thiserror = "1.0.64"
Expand Down
4 changes: 2 additions & 2 deletions binary-port-access/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ path = "src/lib.rs"

# Dependencies for all compilation targets
[dependencies]
casper-types = { git = "https://github.com/casper-network/casper-node", default-features = false }
casper-binary-port = { git = "https://github.com/casper-network/casper-node" }
casper-types = { git = "https://github.com/casper-network/casper-node", branch = "dev", default-features = false }
casper-binary-port = { git = "https://github.com/casper-network/casper-node", branch="dev" }
thiserror = "1.0.64"
futures = "0.3.31"

Expand Down
29 changes: 16 additions & 13 deletions binary-port-access/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use casper_binary_port::{
};
use casper_types::{
bytesrepr::ToBytes, AvailableBlockRange, BlockHash, BlockHeader, BlockIdentifier,
BlockSynchronizerStatus, ChainspecRawBytes, Digest, EraId, GlobalStateIdentifier, Key,
NextUpgrade, Peers, ProtocolVersion, PublicKey, SignedBlock, Transaction, TransactionHash,
BlockSynchronizerStatus, BlockWithSignatures, ChainspecRawBytes, Digest, EraId,
GlobalStateIdentifier, Key, NextUpgrade, Peers, ProtocolVersion, PublicKey, Transaction,
TransactionHash,
};
use communication::common::parse_response;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -83,45 +84,47 @@ pub async fn block_header_by_hash(
}

/// Returns the latest block along with signatures.
pub async fn latest_signed_block(node_address: &str) -> Result<Option<SignedBlock>, Error> {
pub async fn latest_block_with_signatures(
node_address: &str,
) -> Result<Option<BlockWithSignatures>, Error> {
let block_id: Option<BlockIdentifier> = None;
let request = make_information_get_request(
InformationRequestTag::SignedBlock,
InformationRequestTag::BlockWithSignatures,
block_id.to_bytes()?.as_slice(),
)?;
let response = send_request(node_address, request).await?;
check_error_code(&response)?;
parse_response::<SignedBlock>(response.response())
parse_response::<BlockWithSignatures>(response.response())
}

/// Returns the block at the given height along with signatures.
pub async fn signed_block_by_height(
pub async fn block_with_signatures_by_height(
node_address: &str,
height: u64,
) -> Result<Option<SignedBlock>, Error> {
) -> Result<Option<BlockWithSignatures>, Error> {
let block_id = Some(BlockIdentifier::Height(height));
let request = make_information_get_request(
InformationRequestTag::SignedBlock,
InformationRequestTag::BlockWithSignatures,
block_id.to_bytes()?.as_slice(),
)?;
let response = send_request(node_address, request).await?;
check_error_code(&response)?;
parse_response::<SignedBlock>(response.response())
parse_response::<BlockWithSignatures>(response.response())
}

/// Returns the block with the given hash along with signatures.
pub async fn signed_block_by_hash(
pub async fn block_with_signatures_by_hash(
node_address: &str,
hash: BlockHash,
) -> Result<Option<SignedBlock>, Error> {
) -> Result<Option<BlockWithSignatures>, Error> {
let block_id = Some(BlockIdentifier::Hash(hash));
let request = make_information_get_request(
InformationRequestTag::SignedBlock,
InformationRequestTag::BlockWithSignatures,
block_id.to_bytes()?.as_slice(),
)?;
let response = send_request(node_address, request).await?;
check_error_code(&response)?;
parse_response::<SignedBlock>(response.response())
parse_response::<BlockWithSignatures>(response.response())
}

/// Returns the transaction with the given hash. If `with_finalized_approvals` is `false`, the
Expand Down
20 changes: 10 additions & 10 deletions src/information.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use casper_binary_port_access::{
available_block_range, block_header_by_hash, block_header_by_height, block_synchronizer_status,
chainspec_raw_bytes, consensus_status, consensus_validator_changes,
delegator_reward_by_block_hash, delegator_reward_by_block_height, delegator_reward_by_era,
last_progress, latest_block_header, latest_signed_block, latest_switch_block_header,
network_name, next_upgrade, node_status, peers, protocol_version, reactor_state,
signed_block_by_hash, signed_block_by_height, transaction_by_hash, uptime,
block_with_signatures_by_hash, block_with_signatures_by_height, chainspec_raw_bytes,
consensus_status, consensus_validator_changes, delegator_reward_by_block_hash,
delegator_reward_by_block_height, delegator_reward_by_era, last_progress, latest_block_header,
latest_block_with_signatures, latest_switch_block_header, network_name, next_upgrade,
node_status, peers, protocol_version, reactor_state, transaction_by_hash, uptime,
validator_reward_by_block_hash, validator_reward_by_block_height, validator_reward_by_era,
};
use casper_types::{AsymmetricType, BlockHash, DeployHash, Digest, PublicKey, TransactionHash};
Expand All @@ -22,7 +22,7 @@ pub(crate) enum Information {
height: Option<u64>,
},
/// Retrieve block with signatures by height or hash.
SignedBlock {
BlockWithSignatures {
#[clap(long, conflicts_with = "height")]
hash: Option<String>,
#[clap(long, conflicts_with = "hash")]
Expand Down Expand Up @@ -111,12 +111,12 @@ pub(super) async fn handle_information_request(
}
(Some(_), Some(_)) => return Err(Error::EitherHashOrHeightRequired),
}),
Information::SignedBlock { hash, height } => Box::new(match (hash, height) {
(None, None) => latest_signed_block(node_address).await?,
(None, Some(height)) => signed_block_by_height(node_address, height).await?,
Information::BlockWithSignatures { hash, height } => Box::new(match (hash, height) {
(None, None) => latest_block_with_signatures(node_address).await?,
(None, Some(height)) => block_with_signatures_by_height(node_address, height).await?,
(Some(hash), None) => {
let digest = casper_types::Digest::from_hex(hash)?;
signed_block_by_hash(node_address, BlockHash::new(digest)).await?
block_with_signatures_by_hash(node_address, BlockHash::new(digest)).await?
}
(Some(_), Some(_)) => return Err(Error::EitherHashOrHeightRequired),
}),
Expand Down
Loading