use serde::{Deserialize, Serialize};
pub use chia_protocol::{Bytes32, Coin};
pub type Uint32 = u32;
pub type Uint64 = u64;
pub type Uint128 = u128;
pub type SerializedProgram = Vec<u8>;
pub type BlockHeight = Uint32;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParsedBlock {
pub height: u32,
pub weight: String,
pub header_hash: String,
pub timestamp: Option<u32>,
pub coin_additions: Vec<CoinInfo>,
pub coin_removals: Vec<CoinInfo>,
pub coin_spends: Vec<CoinSpendInfo>,
pub coin_creations: Vec<CoinInfo>,
pub has_transactions_generator: bool,
pub generator_size: Option<u32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoinInfo {
pub parent_coin_info: String,
pub puzzle_hash: String,
pub amount: Uint64,
}
impl CoinInfo {
pub fn new(parent_coin_info: Bytes32, puzzle_hash: Bytes32, amount: Uint64) -> Self {
Self {
parent_coin_info: hex::encode(parent_coin_info),
puzzle_hash: hex::encode(puzzle_hash),
amount,
}
}
pub fn from_bytes(parent_coin_info: &[u8], puzzle_hash: &[u8], amount: Uint64) -> Self {
Self {
parent_coin_info: hex::encode(parent_coin_info),
puzzle_hash: hex::encode(puzzle_hash),
amount,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CoinSpendInfo {
pub coin: CoinInfo,
pub puzzle_reveal: String,
pub solution: String,
pub real_data: bool,
pub parsing_method: String,
pub offset: Uint32,
pub created_coins: Vec<CoinInfo>,
}
impl CoinSpendInfo {
pub fn new(
coin: CoinInfo,
puzzle_reveal: String,
solution: String,
real_data: bool,
parsing_method: String,
offset: Uint32,
created_coins: Vec<CoinInfo>,
) -> Self {
Self {
coin,
puzzle_reveal,
solution,
real_data,
parsing_method,
offset,
created_coins,
}
}
}
#[derive(Debug, Clone)]
pub struct GeneratorBlockInfo {
pub prev_header_hash: Bytes32,
pub transactions_generator: Option<SerializedProgram>,
pub transactions_generator_ref_list: Vec<BlockHeight>,
}
impl GeneratorBlockInfo {
pub fn new(
prev_header_hash: Bytes32,
transactions_generator: Option<SerializedProgram>,
transactions_generator_ref_list: Vec<BlockHeight>,
) -> Self {
Self {
prev_header_hash,
transactions_generator,
transactions_generator_ref_list,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BlockHeightInfo {
pub height: Uint32,
pub is_transaction_block: bool,
}
#[derive(Debug, Clone)]
pub struct GeneratorAnalysis {
pub size_bytes: usize,
pub is_empty: bool,
pub contains_clvm_patterns: bool,
pub contains_coin_patterns: bool,
pub entropy: f64,
}
#[derive(Debug, Clone)]
pub struct ParsedGenerator {
pub block_info: GeneratorBlockInfo,
pub generator_hex: Option<String>,
pub analysis: GeneratorAnalysis,
}
impl BlockHeightInfo {
pub fn new(height: Uint32, is_transaction_block: bool) -> Self {
Self {
height,
is_transaction_block,
}
}
}