mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-17 00:07:53 +00:00
rpc/types: add from
module
This commit is contained in:
parent
b8656961f3
commit
d1cff90660
7 changed files with 49 additions and 2 deletions
|
@ -15,9 +15,11 @@ epee = ["dep:cuprate-epee-encoding"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cuprate-epee-encoding = { path = "../../net/epee-encoding", optional = true }
|
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-fixed-bytes = { path = "../../net/fixed-bytes" }
|
||||||
cuprate-types = { path = "../../types" }
|
cuprate-types = { path = "../../types" }
|
||||||
|
|
||||||
|
hex = { workspace = true }
|
||||||
paste = { workspace = true }
|
paste = { workspace = true }
|
||||||
serde = { workspace = true, optional = true }
|
serde = { workspace = true, optional = true }
|
||||||
|
|
||||||
|
|
1
rpc/types/src/from/bin.rs
Normal file
1
rpc/types/src/from/bin.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
rpc/types/src/from/json.rs
Normal file
1
rpc/types/src/from/json.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
37
rpc/types/src/from/misc.rs
Normal file
37
rpc/types/src/from/misc.rs
Normal 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!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4
rpc/types/src/from/mod.rs
Normal file
4
rpc/types/src/from/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
mod bin;
|
||||||
|
mod json;
|
||||||
|
mod misc;
|
||||||
|
mod other;
|
1
rpc/types/src/from/other.rs
Normal file
1
rpc/types/src/from/other.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
mod constants;
|
mod constants;
|
||||||
mod defaults;
|
mod defaults;
|
||||||
mod free;
|
mod free;
|
||||||
|
mod from;
|
||||||
mod macros;
|
mod macros;
|
||||||
mod rpc_call;
|
mod rpc_call;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue