chia-sdk-driver 0.33.0

Driver code for interacting with standard puzzles on the Chia blockchain.
Documentation
use std::ops::Add;

use chia_protocol::Bytes32;
use indexmap::IndexMap;

#[derive(Debug, Default, Clone)]
pub struct Arbitrage {
    pub offered: ArbitrageSide,
    pub requested: ArbitrageSide,
}

impl Arbitrage {
    pub fn new() -> Self {
        Self::default()
    }
}

#[derive(Debug, Default, Clone)]
pub struct ArbitrageSide {
    pub xch: u64,
    pub cats: IndexMap<Bytes32, u64>,
    pub nfts: Vec<Bytes32>,
    pub options: Vec<Bytes32>,
}

impl ArbitrageSide {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn amounts(&self) -> OfferAmounts {
        OfferAmounts {
            xch: self.xch,
            cats: self.cats.clone(),
        }
    }
}

#[derive(Debug, Default, Clone)]
pub struct OfferAmounts {
    pub xch: u64,
    pub cats: IndexMap<Bytes32, u64>,
}

impl OfferAmounts {
    pub fn new() -> Self {
        Self::default()
    }
}

impl Add for &OfferAmounts {
    type Output = OfferAmounts;

    fn add(self, other: Self) -> Self::Output {
        let mut cats = self.cats.clone();

        for (&asset_id, amount) in &other.cats {
            *cats.entry(asset_id).or_insert(0) += amount;
        }

        Self::Output {
            xch: self.xch + other.xch,
            cats,
        }
    }
}