koios-sdk 0.1.1

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

use super::AssetItem;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressInfo {
    pub address: String,
    pub balance: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stake_address: Option<String>,
    pub script_address: bool,
    pub utxo_set: Vec<AddressUtxo>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressUtxo {
    pub tx_hash: String,
    pub tx_index: u64,
    pub block_height: u64,
    pub block_time: u64,
    pub value: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datum_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inline_datum: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reference_script: Option<serde_json::Value>,
    pub asset_list: Vec<AssetItem>,
}

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AddressAsset {
    pub address: String,
    pub policy_id: String,
    pub asset_name: String,
    pub fingerprint: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub decimals: Option<u64>,
    pub quantity: String,
}

// Implementation blocks for constructors and utility methods
impl AddressInfo {
    pub fn new(
        address: String,
        balance: String,
        stake_address: Option<String>,
        script_address: bool,
    ) -> Self {
        Self {
            address,
            balance,
            stake_address,
            script_address,
            utxo_set: Vec::new(),
        }
    }
}

impl AddressUtxo {
    pub fn new(
        tx_hash: String,
        tx_index: u64,
        block_height: u64,
        block_time: u64,
        value: String,
    ) -> Self {
        Self {
            tx_hash,
            tx_index,
            block_height,
            block_time,
            value,
            datum_hash: None,
            inline_datum: None,
            reference_script: None,
            asset_list: Vec::new(),
        }
    }
}

impl AssetItem {
    pub fn new(
        policy_id: String,
        asset_name: String,
        fingerprint: String,
        quantity: String,
    ) -> Self {
        Self {
            policy_id,
            asset_name,
            fingerprint,
            decimals: None,
            quantity,
        }
    }
}

impl AddressTransaction {
    pub fn new(tx_hash: String, epoch_no: u64, block_height: u64, block_time: u64) -> Self {
        Self {
            tx_hash,
            epoch_no,
            block_height,
            block_time,
        }
    }
}