pub trait ManualBalanceModel<T>: Clone + Debugwhere
T: LazyBalanceMarker,{
type User: Sortable + Hash + Copy;
type Error: Debug + Clone + 'static;
// Required methods
fn new() -> Self;
fn deposit(
&mut self,
user: Self::User,
amount: T::Asset,
lazy_result: &(T::Asset, T::Receipt),
) -> Result<(), Self::Error>;
fn withdraw(
&mut self,
user: Self::User,
lazy_result: &T::Asset,
) -> Result<T::Asset, Self::Error>;
fn mint(
&mut self,
amount: T::Asset,
lazy_result: &T::Asset,
) -> Result<(), Self::Error>;
fn reap(
&mut self,
amount: T::Asset,
lazy_result: &T::Asset,
) -> Result<(), Self::Error>;
fn drain(&mut self) -> Result<(), Self::Error>;
fn total(&self) -> T::Asset;
}Expand description
A user-indexed eager balance model over a LazyBalance system,
primarily intended for testing and validation.
This model consumes the resolved outputs of lazy balance operations
(lazy_result) and maintains a concrete, user-facing state without
any deferred semantics (no receipts, no lazy evaluation).
Unlike LazyBalance, implementations are free to use the simplest
possible accounting logic (e.g., a single global state machine or
direct user balances), as correctness is derived from the provided
results rather than internal computation.
It is not a source of truth and must remain consistent with the
underlying LazyBalance execution.
This makes it suitable as a reference model for:
- validating lazy execution behavior
- testing invariants and edge cases
- comparing expected vs actual outcomes
Required Associated Types§
Required Methods§
Sourcefn deposit(
&mut self,
user: Self::User,
amount: T::Asset,
lazy_result: &(T::Asset, T::Receipt),
) -> Result<(), Self::Error>
fn deposit( &mut self, user: Self::User, amount: T::Asset, lazy_result: &(T::Asset, T::Receipt), ) -> Result<(), Self::Error>
Applies a deposit for user.
amount is the requested input. The lazy model is assumed to have been
executed with the same inputs, and lazy_result contains its resolved output:
- actual deposited value
- corresponding receipt
This method consumes that result to update the manual balance state.
Sourcefn withdraw(
&mut self,
user: Self::User,
lazy_result: &T::Asset,
) -> Result<T::Asset, Self::Error>
fn withdraw( &mut self, user: Self::User, lazy_result: &T::Asset, ) -> Result<T::Asset, Self::Error>
Applies a withdrawal for user.
The lazy model is assumed to have been executed with the same inputs,
and lazy_result contains the resolved asset produced by that withdrawal.
This method consumes that result to update the manual balance state.
Returns the withdrawn amount.
Sourcefn mint(
&mut self,
amount: T::Asset,
lazy_result: &T::Asset,
) -> Result<(), Self::Error>
fn mint( &mut self, amount: T::Asset, lazy_result: &T::Asset, ) -> Result<(), Self::Error>
Applies a mint operation.
The lazy model is assumed to have been executed with the same input,
and lazy_result contains the resolved asset produced by that mint.
This method consumes that result to update the manual balance state.
Sourcefn reap(
&mut self,
amount: T::Asset,
lazy_result: &T::Asset,
) -> Result<(), Self::Error>
fn reap( &mut self, amount: T::Asset, lazy_result: &T::Asset, ) -> Result<(), Self::Error>
Applies a reap operation.
The lazy model is assumed to have been executed with the same input,
and lazy_result contains the resolved asset produced by that reap.
This method consumes that result to update the manual balance state.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.