From fae0154c78bf1be5be2fb978ce17f05073e98c62 Mon Sep 17 00:00:00 2001 From: sleepy ramen Date: Fri, 5 Apr 2024 20:34:50 +0200 Subject: [PATCH] fix: make block/last with a num param a proper json response (#192) --- src/server/endpoints/block.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/server/endpoints/block.rs b/src/server/endpoints/block.rs index 639310b..f6d91d0 100644 --- a/src/server/endpoints/block.rs +++ b/src/server/endpoints/block.rs @@ -16,7 +16,12 @@ use crate::{ #[serde(untagged)] pub enum LatestBlock { LastBlock(Box), - LatestBlocks(Vec), + LatestBlocks(LatestBlocks), +} + +#[derive(Debug, Serialize, Deserialize, PartialEq)] +pub struct LatestBlocks { + pub blocks: Vec, } async fn get_tx_hashes( @@ -88,7 +93,7 @@ pub async fn get_last_block( if let Some(n) = num { let rows = state.db.get_lastest_blocks(n, offset).await?; - let mut blocks: Vec = vec![]; + let mut blocks: LatestBlocks = LatestBlocks { blocks: vec![] }; for row in rows { let mut block = BlockInfo::try_from(&row)?; @@ -96,7 +101,7 @@ pub async fn get_last_block( let block_id: Vec = row.try_get("block_id")?; get_tx_hashes(&state, &mut block, &block_id).await?; - blocks.push(block); + blocks.blocks.push(block); } Ok(Json(LatestBlock::LatestBlocks(blocks)))