use arch_program::rune::{RuneAmount, RuneId};
use bitcoin::Amount;
use satellite_bitcoin::generic::fixed_set::FixedCapacitySet;
use satellite_bitcoin::utxo_info::UtxoInfoTrait;
#[repr(C, align(8))]
#[derive(Clone, Debug)]
pub struct AccountUtxos<U, RU> {
pub btc_utxos: U,
pub rune_utxo: RU,
}
pub trait StateShard<
U: UtxoInfoTrait<RuneSet>,
RuneSet: FixedCapacitySet<Item = RuneAmount> + Default,
>
{
fn btc_utxos(&self) -> &[U];
fn btc_utxos_mut(&mut self) -> &mut [U];
fn btc_utxos_retain(&mut self, f: &mut dyn FnMut(&U) -> bool);
fn add_btc_utxo(&mut self, utxo: U) -> Option<usize>;
fn btc_utxos_len(&self) -> usize;
fn btc_utxos_max_len(&self) -> usize;
fn rune_utxo(&self) -> Option<&U>;
fn rune_utxo_mut(&mut self) -> Option<&mut U>;
fn clear_rune_utxo(&mut self);
fn set_rune_utxo(&mut self, utxo: U);
fn total_btc(&self) -> Amount {
let sat = self
.btc_utxos()
.iter()
.map(|utxo_info| utxo_info.value())
.sum();
Amount::from_sat(sat)
}
fn total_rune(&self, rune_id: RuneId) -> u128 {
#[cfg(feature = "runes")]
{
if let Some(utxo_info) = self.rune_utxo() {
utxo_info
.runes()
.iter()
.find(|rune_amount| rune_amount.id == rune_id)
.map_or(0, |rune_amount| rune_amount.amount)
} else {
0
}
}
#[cfg(not(feature = "runes"))]
{
0
}
}
}