use anyhow::Result;
use rs_zephyr_common::{Account, ContractDataEntry};
use soroban_env_host::xdr::{AccountEntry, ScAddress, ScVal};
use crate::{ZephyrMock, ZephyrStandard};
pub trait LedgerStateRead {
fn read_contract_data_entry_by_contract_id_and_key(
&self,
contract: ScAddress,
key: ScVal,
) -> Option<ContractDataEntry>;
fn read_contract_data_entries_by_contract_id(
&self,
contract: ScAddress,
) -> Vec<ContractDataEntry>;
fn read_account(&self, account: String) -> Option<Account>;
}
#[derive(Clone)]
pub struct LedgerImpl<L: LedgerStateRead> {
pub ledger: Box<L>,
}
#[derive(Clone)]
pub struct Ledger<L: LedgerStateRead>(pub(crate) LedgerImpl<L>);
impl<L: LedgerStateRead + ZephyrStandard> ZephyrStandard for LedgerImpl<L> {
fn zephyr_standard() -> Result<Self>
where
Self: Sized,
{
Ok(Self {
ledger: Box::new(L::zephyr_standard()?),
})
}
}
impl<L: LedgerStateRead + ZephyrStandard> ZephyrStandard for Ledger<L> {
fn zephyr_standard() -> Result<Self>
where
Self: Sized,
{
Ok(Self(LedgerImpl::zephyr_standard()?))
}
}
impl<L: LedgerStateRead + ZephyrMock> ZephyrMock for LedgerImpl<L> {
fn mocked() -> Result<Self>
where
Self: Sized,
{
Ok(Self {
ledger: Box::new(L::mocked()?),
})
}
}
impl<L: LedgerStateRead + ZephyrMock> ZephyrMock for Ledger<L> {
fn mocked() -> Result<Self>
where
Self: Sized,
{
Ok(Self(LedgerImpl::mocked()?))
}
}