diff --git a/src/server/blocks.rs b/src/server/blocks.rs index 8c27d3b..78b274b 100644 --- a/src/server/blocks.rs +++ b/src/server/blocks.rs @@ -82,14 +82,19 @@ impl LastCommitInfo { } } +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +#[repr(transparent)] +pub struct HashID( + #[serde(serialize_with = "serialize_hex", deserialize_with = "from_hex")] pub Vec, +); + /// Relevant information regarding blocks #[derive(Debug, Serialize, Deserialize, PartialEq)] pub struct BlockInfo { - #[serde(serialize_with = "serialize_hex", deserialize_with = "from_hex")] - pub block_id: Vec, + pub block_id: HashID, pub header: Header, pub last_commit: Option, - pub tx_hashes: Vec>, + pub tx_hashes: Vec, } impl From for Header { @@ -236,7 +241,7 @@ impl TryFrom<&Row> for BlockInfo { }; Ok(BlockInfo { - block_id, + block_id: HashID(block_id), header, last_commit, tx_hashes: vec![], diff --git a/src/server/mod.rs b/src/server/mod.rs index 7c13eb4..7701f59 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -43,9 +43,9 @@ async fn get_tx_hashes( ) -> Result<(), Error> { let rows = state.db.get_tx_hashes_block(hash).await?; - let mut tx_hashes: Vec> = vec![]; + let mut tx_hashes: Vec = vec![]; for row in rows.iter() { - let hash: Vec = row.try_get("hash")?; + let hash = blocks::HashID(row.try_get("hash")?); tx_hashes.push(hash); } diff --git a/tests/block_tests.rs b/tests/block_tests.rs index 08092bd..de31012 100644 --- a/tests/block_tests.rs +++ b/tests/block_tests.rs @@ -33,7 +33,7 @@ mod block_tests { let header = response.json_body_as::().unwrap(); - let hash_str = hex::encode(&header.block_id); + let hash_str = hex::encode(&header.block_id.0); // now retrieve same block but by hash: let new_header = hc