koios-sdk 0.1.1

A Rust SDK for the Koios Cardano API
Documentation
use serde::{Deserialize, Serialize};

use super::ProposalType;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Tip {
    pub hash: String,
    pub epoch_no: u64,
    pub abs_slot: u64,
    pub epoch_slot: u64,
    pub block_no: u64,
    pub block_time: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Genesis {
    pub networkmagic: String,
    pub networkid: String,
    pub epochlength: String,
    pub slotlength: String,
    pub maxlovelacesupply: String,
    pub systemstart: u64,
    pub activeslotcoeff: String,
    pub slotsperkesperiod: String,
    pub maxkesrevolutions: String,
    pub securityparam: String,
    pub updatequorum: String,
    pub alonzogenesis: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Totals {
    pub epoch_no: u64,
    pub circulation: String,
    pub treasury: String,
    pub reward: String,
    pub supply: String,
    pub reserves: String,
    pub fees: String,
    pub deposits_stake: String,
    pub deposits_drep: String,
    pub deposits_proposal: String,
}

#[derive(Debug, Clone, Serialize, Copy, Deserialize)]
pub struct CliProtocolParams {
    pub collateral_percentage: u64,
    pub max_block_body_size: u64,
    pub max_block_header_size: u64,
    pub max_collateral_inputs: u64,
    pub max_tx_size: u64,
    pub max_value_size: u64,
    pub min_pool_cost: u64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub min_utxo_value: Option<u64>,
    pub monetary_expansion: f64,
    pub pool_pledge_influence: f64,
    pub pool_retire_max_epoch: u64,
    pub protocol_version: ProtocolVersion,
    pub stake_address_deposit: u64,
    pub stake_pool_deposit: u64,
    pub stake_pool_target_num: u64,
    pub treasury_cut: f64,
    pub tx_fee_fixed: u64,
    pub tx_fee_per_byte: u64,
    pub utxo_cost_per_byte: u64,
}

#[derive(Debug, Clone, Serialize, Copy, Deserialize)]
pub struct ProtocolVersion {
    pub major: u64,
    pub minor: u64,
}

// Implement conversion traits and custom methods
impl Tip {
    pub fn new(
        hash: String,
        epoch_no: u64,
        abs_slot: u64,
        epoch_slot: u64,
        block_no: u64,
        block_time: u64,
    ) -> Self {
        Self {
            hash,
            epoch_no,
            abs_slot,
            epoch_slot,
            block_no,
            block_time,
        }
    }
}

impl Genesis {
    pub fn new(
        networkmagic: String,
        networkid: String,
        epochlength: String,
        slotlength: String,
        maxlovelacesupply: String,
        systemstart: u64,
        activeslotcoeff: String,
        slotsperkesperiod: String,
        maxkesrevolutions: String,
        securityparam: String,
        updatequorum: String,
        alonzogenesis: String,
    ) -> Self {
        Self {
            networkmagic,
            networkid,
            epochlength,
            slotlength,
            maxlovelacesupply,
            systemstart,
            activeslotcoeff,
            slotsperkesperiod,
            maxkesrevolutions,
            securityparam,
            updatequorum,
            alonzogenesis,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReserveWithdrawal {
    pub epoch_no: u64,
    pub epoch_slot: u64,
    pub tx_hash: String,
    pub block_hash: String,
    pub block_height: u64,
    pub amount: String,
    pub stake_address: String,
    pub earned_epoch: u64,
    pub spendable_epoch: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParamUpdate {
    pub tx_hash: String,
    pub block_height: u64,
    pub block_time: u64,
    pub epoch_no: u64,
    pub data: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct OgmiosTip {
    pub jsonrpc: String,
    pub method: String,
    #[serde(default)] // Handle missing result field
    pub result: OgmiosTipResult,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct OgmiosTipResult {
    pub slot: u64,
    pub id: String,
}

impl OgmiosTip {
    pub fn new(slot: u64, id: String) -> Self {
        Self {
            jsonrpc: "2.0".to_string(),
            method: "queryNetwork/tip".to_string(),
            result: OgmiosTipResult { slot, id },
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProposalVotingSummary {
    pub proposal_type: ProposalType,
    pub epoch_no: u64,
    pub drep_yes_votes_cast: u64,
    pub drep_active_yes_vote_power: u64,
    pub drep_yes_vote_power: u64,
    pub drep_yes_pct: f64,
    pub drep_no_votes_cast: u64,
    pub drep_active_no_vote_power: u64,
    pub drep_no_vote_power: u64,
    pub drep_no_pct: f64,
    pub drep_abstain_votes_cast: u64,
    pub drep_active_abstain_vote_power: u64,
    pub drep_always_no_confidence_vote_power: u64,
    pub drep_always_abstain_vote_power: u64,
    pub pool_yes_votes_cast: u64,
    pub pool_active_yes_vote_power: u64,
    pub pool_yes_vote_power: u64,
    pub pool_yes_pct: f64,
    pub pool_no_votes_cast: u64,
    pub pool_active_no_vote_power: u64,
    pub pool_no_vote_power: u64,
    pub pool_no_pct: f64,
    pub pool_abstain_votes_cast: u64,
    pub pool_active_abstain_vote_power: u64,
    pub pool_passive_always_abstain_votes_assigned: u64,
    pub pool_passive_always_abstain_vote_power: u64,
    pub pool_passive_always_no_confidence_votes_assigned: u64,
    pub pool_passive_always_no_confidence_vote_power: u64,
    pub committee_yes_votes_cast: u64,
    pub committee_yes_pct: f64,
    pub committee_no_votes_cast: u64,
    pub committee_no_pct: f64,
    pub committee_abstain_votes_cast: u64,
}