use std::ops::{Deref, DerefMut};
use pchain_world_state::{
keys::AppKey,
network::{constants::NETWORK_ADDRESS, network_account::NetworkAccountStorage},
storage::WorldStateStorage,
};
use crate::{transition::TransitionContext, types::BaseTx, BlockchainParams};
pub(crate) struct ExecutionState<S>
where
S: WorldStateStorage + Send + Sync + Clone + 'static,
{
pub tx: BaseTx,
pub tx_size: usize,
pub commands_len: usize,
pub bd: BlockchainParams,
pub ctx: TransitionContext<S>,
}
impl<S> Deref for ExecutionState<S>
where
S: WorldStateStorage + Send + Sync + Clone,
{
type Target = TransitionContext<S>;
fn deref(&self) -> &Self::Target {
&self.ctx
}
}
impl<S> DerefMut for ExecutionState<S>
where
S: WorldStateStorage + Send + Sync + Clone,
{
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.ctx
}
}
impl<S> NetworkAccountStorage for ExecutionState<S>
where
S: WorldStateStorage + Send + Sync + Clone,
{
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
self.app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec())).0
}
fn contains(&self, key: &[u8]) -> bool {
self.contains_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()))
}
fn set(&mut self, key: &[u8], value: Vec<u8>) {
self.set_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()), value);
}
fn delete(&mut self, key: &[u8]) {
self.set_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()), Vec::new());
}
}