From 6c7b5be94e295362d181eab9435c0307966583d1 Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Fri, 6 Sep 2024 20:59:04 -0400 Subject: [PATCH] cuprated: use `From` when mapping types --- Cargo.lock | 2 ++ binaries/cuprated/src/rpc/json.rs | 34 +++++++------------------------ 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bb4612a..c941dc12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -827,8 +827,10 @@ version = "0.0.0" dependencies = [ "cuprate-epee-encoding", "cuprate-fixed-bytes", + "cuprate-helper", "cuprate-test-utils", "cuprate-types", + "hex", "paste", "serde", "serde_json", diff --git a/binaries/cuprated/src/rpc/json.rs b/binaries/cuprated/src/rpc/json.rs index 07a381ea..c331cd25 100644 --- a/binaries/cuprated/src/rpc/json.rs +++ b/binaries/cuprated/src/rpc/json.rs @@ -5,7 +5,10 @@ use futures::StreamExt; use tower::{Service, ServiceExt}; use cuprate_consensus::BlockchainResponse; -use cuprate_helper::cast::{u64_to_usize, usize_to_u64}; +use cuprate_helper::{ + cast::{u64_to_usize, usize_to_u64}, + map::split_u128_into_low_high_bits, +}; use cuprate_rpc_types::{ base::{AccessResponseBase, ResponseBase}, json::{ @@ -180,38 +183,15 @@ async fn get_block_header_by_hash( let ready = state.blockchain.ready().await.expect("TODO"); - let BlockchainResponse::BlockExtendedHeaderByHash(header) = ready - .call(BlockchainReadRequest::BlockExtendedHeaderByHash(hash)) + let BlockchainResponse::BlockByHash(block) = ready + .call(BlockchainReadRequest::BlockByHash(hash)) .await .expect("TODO") else { unreachable!(); }; - let block_header = BlockHeader { - block_size: todo!(), - block_weight: todo!(), - cumulative_difficulty_top64: todo!(), - cumulative_difficulty: todo!(), - depth: todo!(), - difficulty_top64: todo!(), - difficulty: todo!(), - hash: todo!(), - height: todo!(), - long_term_weight: todo!(), - major_version: todo!(), - miner_tx_hash: todo!(), - minor_version: todo!(), - nonce: todo!(), - num_txes: todo!(), - orphan_status: todo!(), - pow_hash: todo!(), - prev_hash: todo!(), - reward: todo!(), - timestamp: todo!(), - wide_cumulative_difficulty: todo!(), - wide_difficulty: todo!(), - }; + let block_header = BlockHeader::from(&block); Ok(block_header) }