Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
fix: make block/last with a num param a proper json response (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
rllola authored Apr 5, 2024
1 parent a2c7c59 commit fae0154
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/server/endpoints/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ use crate::{
#[serde(untagged)]
pub enum LatestBlock {
LastBlock(Box<BlockInfo>),
LatestBlocks(Vec<BlockInfo>),
LatestBlocks(LatestBlocks),
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct LatestBlocks {
pub blocks: Vec<BlockInfo>,
}

async fn get_tx_hashes(
Expand Down Expand Up @@ -88,15 +93,15 @@ 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<BlockInfo> = vec![];
let mut blocks: LatestBlocks = LatestBlocks { blocks: vec![] };

for row in rows {
let mut block = BlockInfo::try_from(&row)?;

let block_id: Vec<u8> = 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)))
Expand Down

0 comments on commit fae0154

Please sign in to comment.