use chia_protocol::{Bytes32, CoinSpend};
use crate::lineage::SingletonLineage;
use crate::provider::ProviderInfo;
use crate::record::CoinRecord;
pub trait ChainSource {
type Error: core::fmt::Display;
fn coin_record(&self, coin_id: Bytes32) -> Result<Option<CoinRecord>, Self::Error>;
fn coin_records_by_puzzle_hash(
&self,
puzzle_hash: Bytes32,
include_spent: bool,
) -> Result<Vec<CoinRecord>, Self::Error>;
fn coin_records_by_parent(
&self,
parent_coin_id: Bytes32,
) -> Result<Vec<CoinRecord>, Self::Error>;
fn coin_spend(&self, coin_id: Bytes32) -> Result<Option<CoinSpend>, Self::Error>;
fn parent_spend(&self, coin_id: Bytes32) -> Result<Option<CoinSpend>, Self::Error> {
let Some(record) = self.coin_record(coin_id)? else {
return Ok(None);
};
self.coin_spend(record.coin.parent_coin_info)
}
fn resolve_singleton_lineage(
&self,
launcher_id: Bytes32,
) -> Result<Option<SingletonLineage>, Self::Error>;
fn peak_height(&self) -> Result<Option<u32>, Self::Error>;
fn block_timestamp(&self, height: u32) -> Result<Option<u64>, Self::Error>;
}
pub trait ChainSourceProvider: ChainSource {
fn provider_info(&self) -> ProviderInfo;
}