koios-sdk 0.1.1

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptInfo {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub script_hash: Option<String>,
    pub creation_tx_hash: String,
    #[serde(rename = "type")]
    pub script_type: ScriptType,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bytes: Option<String>,
    pub size: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ScriptType {
    PlutusV1,
    PlutusV2,
    Timelock,
    Multisig,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptRedeemer {
    pub script_hash: String,
    pub redeemers: Vec<RedeemerData>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedeemerData {
    pub tx_hash: String,
    pub tx_index: u64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unit_mem: Option<RedeemerUnitValue>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unit_steps: Option<RedeemerUnitValue>,
    pub fee: String,
    pub purpose: RedeemerPurpose,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datum_hash: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub datum_value: Option<serde_json::Value>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RedeemerUnitValue {
    String(String),
    Number(u64),
}

#[derive(Debug, Clone, Serialize, Deserialize, Copy, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum RedeemerPurpose {
    Spend,
    Mint,
    Cert,
    Reward,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DatumInfo {
    pub datum_hash: String,
    pub creation_tx_hash: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub value: Option<serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub bytes: Option<String>,
}

// Implementation blocks for key types
impl ScriptInfo {
    pub fn new(creation_tx_hash: String, script_type: ScriptType, size: u64) -> Self {
        Self {
            script_hash: None,
            creation_tx_hash,
            script_type,
            value: None,
            bytes: None,
            size,
        }
    }
}

impl ScriptRedeemer {
    pub fn new(script_hash: String) -> Self {
        Self {
            script_hash,
            redeemers: Vec::new(),
        }
    }
}

impl RedeemerData {
    pub fn new(tx_hash: String, tx_index: u64, fee: String, purpose: RedeemerPurpose) -> Self {
        Self {
            tx_hash,
            tx_index,
            unit_mem: None,
            unit_steps: None,
            fee,
            purpose,
            datum_hash: None,
            datum_value: None,
        }
    }
}

impl DatumInfo {
    pub fn new(datum_hash: String, creation_tx_hash: String) -> Self {
        Self {
            datum_hash,
            creation_tx_hash,
            value: None,
            bytes: None,
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptList {
    pub script_hash: String,
    pub creation_tx_hash: String,
    #[serde(rename = "type")]
    pub script_type: ScriptType,
    pub size: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TxUtxos {
    pub tx_hash: String,
    pub inputs: Vec<UtxoDetail>,
    pub outputs: Vec<UtxoDetail>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UtxoDetail {
    pub payment_addr: PaymentAddr,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub stake_addr: Option<String>,
    pub tx_hash: String,
    pub tx_index: u64,
    pub value: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentAddr {
    pub bech32: String,
    pub cred: String,
}

// Implementation blocks
impl ScriptList {
    pub fn new(
        script_hash: String,
        creation_tx_hash: String,
        script_type: ScriptType,
        size: u64,
    ) -> Self {
        Self {
            script_hash,
            creation_tx_hash,
            script_type,
            size,
        }
    }
}

impl TxUtxos {
    pub fn new(tx_hash: String) -> Self {
        Self {
            tx_hash,
            inputs: Vec::new(),
            outputs: Vec::new(),
        }
    }
}