Skip to content
Closed
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
80 changes: 40 additions & 40 deletions Cargo.lock

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

24 changes: 8 additions & 16 deletions binary-port-access/src/communication/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ use crate::Error;
#[cfg(not(target_arch = "wasm32"))]
use casper_binary_port::BinaryMessage;
use casper_binary_port::{
BinaryRequest, BinaryRequestHeader, BinaryResponse, BinaryResponseAndRequest, PayloadEntity,
};
use casper_types::{
bytesrepr::{self, FromBytes, ToBytes},
ProtocolVersion,
BinaryResponse, BinaryResponseAndRequest, Command, CommandHeader, PayloadEntity,
};
use casper_types::bytesrepr::{self, FromBytes, ToBytes};
use std::sync::atomic::AtomicU16;
use std::sync::atomic::Ordering;
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -19,8 +16,6 @@ use tokio::{
time::timeout,
};

// TODO[RC]: Do not hardcode this.
pub(crate) const SUPPORTED_PROTOCOL_VERSION: ProtocolVersion = ProtocolVersion::from_parts(2, 0, 0);
pub(crate) const LENGTH_FIELD_SIZE: usize = 4;
#[cfg(not(target_arch = "wasm32"))]
const TIMEOUT_DURATION: Duration = Duration::from_secs(5);
Expand Down Expand Up @@ -175,7 +170,7 @@ async fn read_response(client: &mut TcpStream) -> Result<Vec<u8>, Error> {
///
/// - `node_address`: A string slice that holds the address of the node to connect to,
/// typically in the format "hostname:28101".
/// - `request`: An instance of `BinaryRequest` representing the request data to be sent.
/// - `request`: An instance of `Command` representing the request data to be sent.
///
/// # Returns
///
Expand All @@ -202,7 +197,7 @@ async fn read_response(client: &mut TcpStream) -> Result<Vec<u8>, Error> {
#[cfg(not(target_arch = "wasm32"))]
pub(crate) async fn send_request(
node_address: &str,
request: BinaryRequest,
request: Command,
) -> Result<BinaryResponseAndRequest, Error> {
let request_id = COUNTER.fetch_add(1, Ordering::SeqCst); // Atomically increment the counter

Expand Down Expand Up @@ -232,13 +227,13 @@ pub(crate) async fn send_raw(

/// Encodes a binary request into a byte vector for transmission.
///
/// This function serializes a `BinaryRequest` along with a specified request ID (if provided)
/// This function serializes a `Command` along with a specified request ID (if provided)
/// into a byte vector. The encoded data includes a header containing the protocol version,
/// request tag, and the request ID. This byte vector can then be sent over a network connection.
///
/// # Parameters
///
/// - `req`: A reference to a `BinaryRequest` instance representing the request to be serialized.
/// - `req`: A reference to a `Command` instance representing the request to be serialized.
/// - `request_id`: An optional `u16` representing the unique identifier for the request. If not provided,
/// a default value of `0` is used.
///
Expand All @@ -258,11 +253,8 @@ pub(crate) async fn send_raw(
///
/// The request ID helps in tracking requests and their corresponding responses, allowing for easier
/// identification in asynchronous communication.
pub(crate) fn encode_request(
req: &BinaryRequest,
request_id: u16,
) -> Result<Vec<u8>, bytesrepr::Error> {
let header = BinaryRequestHeader::new(SUPPORTED_PROTOCOL_VERSION, req.tag(), request_id);
pub(crate) fn encode_request(req: &Command, request_id: u16) -> Result<Vec<u8>, bytesrepr::Error> {
let header = CommandHeader::new(req.tag(), request_id);
let mut bytes = Vec::with_capacity(header.serialized_length() + req.serialized_length());
header.write_bytes(&mut bytes)?;
req.write_bytes(&mut bytes)?;
Expand Down
6 changes: 3 additions & 3 deletions binary-port-access/src/communication/wasm32/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::communication::common::{encode_request, process_response, COUNTER, LENGTH_FIELD_SIZE};
use crate::Error;
use casper_binary_port::{BinaryRequest, BinaryResponseAndRequest};
use casper_binary_port::{BinaryResponseAndRequest, Command};
use gloo_utils::format::JsValueSerdeExt;
use js_sys::{JsString, Promise, Reflect};
use node_tcp_helper::generate_tcp_script;
Expand Down Expand Up @@ -561,7 +561,7 @@ async fn read_response(response_bytes: Vec<u8>) -> Result<Vec<u8>, Error> {
/// - `node_address`: A `&str` representing the address of the node to which
/// the request will be sent. This should include the host and port (e.g.,
/// "localhost:28101").
/// - `request`: A `BinaryRequest` instance containing the data to be sent.
/// - `request`: A `Command` instance containing the data to be sent.
///
/// # Returns
///
Expand All @@ -582,7 +582,7 @@ async fn read_response(response_bytes: Vec<u8>) -> Result<Vec<u8>, Error> {
/// for WebAssembly applications where communication with a node server is required.
pub(crate) async fn send_request(
node_address: &str,
request: BinaryRequest,
request: Command,
) -> Result<BinaryResponseAndRequest, Error> {
let request_id = COUNTER.fetch_add(1, Ordering::SeqCst); // Atomically increment the counter

Expand Down
Loading
Loading