pchain_runtime/execution/
state.rs1use std::ops::{Deref, DerefMut};
12
13use pchain_world_state::{
14 keys::AppKey,
15 network::{constants::NETWORK_ADDRESS, network_account::NetworkAccountStorage},
16 storage::WorldStateStorage,
17};
18
19use crate::{transition::TransitionContext, types::BaseTx, BlockchainParams};
20
21pub(crate) struct ExecutionState<S>
25where
26 S: WorldStateStorage + Send + Sync + Clone + 'static,
27{
28 pub tx: BaseTx,
31 pub tx_size: usize,
33 pub commands_len: usize,
35
36 pub bd: BlockchainParams,
39
40 pub ctx: TransitionContext<S>,
43}
44
45impl<S> Deref for ExecutionState<S>
46where
47 S: WorldStateStorage + Send + Sync + Clone,
48{
49 type Target = TransitionContext<S>;
50
51 fn deref(&self) -> &Self::Target {
52 &self.ctx
53 }
54}
55
56impl<S> DerefMut for ExecutionState<S>
57where
58 S: WorldStateStorage + Send + Sync + Clone,
59{
60 fn deref_mut(&mut self) -> &mut Self::Target {
61 &mut self.ctx
62 }
63}
64
65impl<S> NetworkAccountStorage for ExecutionState<S>
69where
70 S: WorldStateStorage + Send + Sync + Clone,
71{
72 fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
73 self.app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec())).0
74 }
75
76 fn contains(&self, key: &[u8]) -> bool {
77 self.contains_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()))
78 }
79
80 fn set(&mut self, key: &[u8], value: Vec<u8>) {
81 self.set_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()), value);
82 }
83
84 fn delete(&mut self, key: &[u8]) {
85 self.set_app_data(NETWORK_ADDRESS, AppKey::new(key.to_vec()), Vec::new());
86 }
87}