whisky_provider/blockfrost/utils/
block_utils.rs

1use whisky_common::{models::BlockInfo, WError};
2
3use crate::blockfrost::models::BlockContent;
4
5pub fn block_content_to_block_info(block_content: BlockContent) -> Result<BlockInfo, WError> {
6    let block_info = BlockInfo {
7        time: block_content.time as u64,
8        hash: block_content.hash,
9        slot: match block_content.slot {
10            Some(s) => s.to_string(),
11            None => "".to_string(),
12        },
13        epoch: block_content
14            .epoch
15            .ok_or_else(WError::from_opt("block_content_to_block_info", "epoch"))?
16            as u32,
17        epoch_slot: match block_content.epoch_slot {
18            Some(s) => s.to_string(),
19            None => "".to_string(),
20        },
21        slot_leader: block_content.slot_leader,
22        size: block_content.size as usize,
23        tx_count: block_content.tx_count as usize,
24        output: block_content.output.unwrap_or("".to_string()),
25        fees: block_content.fees.unwrap_or("".to_string()),
26        previous_block: block_content.previous_block.unwrap_or("".to_string()),
27        next_block: block_content.next_block.unwrap_or("".to_string()),
28        confirmations: block_content.confirmations as usize,
29        operational_certificate: block_content.op_cert.unwrap_or("".to_string()),
30        vrf_key: block_content.block_vrf.unwrap_or("".to_string()),
31    };
32    Ok(block_info)
33}