rpc/types: add from module

This commit is contained in:
hinto.janai 2024-09-06 20:58:50 -04:00
parent b8656961f3
commit d1cff90660
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
7 changed files with 49 additions and 2 deletions

View file

@ -15,11 +15,13 @@ epee = ["dep:cuprate-epee-encoding"]
[dependencies]
cuprate-epee-encoding = { path = "../../net/epee-encoding", optional = true }
cuprate-helper = { path = "../../helper", default-features = false, features = ["cast", "map"] }
cuprate-fixed-bytes = { path = "../../net/fixed-bytes" }
cuprate-types = { path = "../../types" }
paste = { workspace = true }
serde = { workspace = true, optional = true }
hex = { workspace = true }
paste = { workspace = true }
serde = { workspace = true, optional = true }
[dev-dependencies]
cuprate-test-utils = { path = "../../test-utils" }

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@

View file

@ -0,0 +1,37 @@
use cuprate_types::VerifiedBlockInformation;
use cuprate_helper::{cast::usize_to_u64, map::split_u128_into_low_high_bits};
use crate::misc::BlockHeader;
impl From<&VerifiedBlockInformation> for BlockHeader {
fn from(b: &VerifiedBlockInformation) -> Self {
let (cumulative_difficulty_top64, cumulative_difficulty) =
split_u128_into_low_high_bits(b.cumulative_difficulty);
Self {
block_size: usize_to_u64(b.block_blob.len()),
block_weight: usize_to_u64(b.weight),
cumulative_difficulty_top64,
cumulative_difficulty,
depth: todo!(),
difficulty_top64: todo!(),
difficulty: todo!(),
hash: hex::encode(b.block_hash),
height: usize_to_u64(b.height),
long_term_weight: usize_to_u64(b.long_term_weight),
major_version: b.block.header.hardfork_version,
miner_tx_hash: hex::encode(b.block.miner_transaction.hash()),
minor_version: b.block.header.hardfork_signal,
nonce: b.block.header.nonce,
num_txes: usize_to_u64(b.txs.len()),
orphan_status: todo!(),
pow_hash: hex::encode(b.pow_hash),
prev_hash: hex::encode(b.block.header.previous),
reward: todo!(),
timestamp: b.block.header.timestamp,
wide_cumulative_difficulty: todo!(),
wide_difficulty: todo!(),
}
}
}

View file

@ -0,0 +1,4 @@
mod bin;
mod json;
mod misc;
mod other;

View file

@ -0,0 +1 @@

View file

@ -4,6 +4,7 @@
mod constants;
mod defaults;
mod free;
mod from;
mod macros;
mod rpc_call;