|
1 | | -use concordium_base::base::AccountIndex; |
| 1 | +use concordium_base::base::{AccountIndex, Energy}; |
| 2 | +use concordium_base::id::types::AccountAddress; |
2 | 3 | use concordium_base::protocol_level_tokens::TokenId; |
3 | 4 | use plt_deployment_unit::TokenRawAmount; |
4 | 5 |
|
@@ -169,6 +170,49 @@ pub trait BlockStateOperations { |
169 | 170 | fn set_token_state(&mut self, token_index: TokenIndex, mutable_token_state: MutableTokenState); |
170 | 171 | } |
171 | 172 |
|
| 173 | +/// Operations on the scheduler state. |
| 174 | +pub trait SchedulerOperations { |
| 175 | + /// The account initiating the transaction. |
| 176 | + fn sender_account(&self) -> AccountIndex; |
| 177 | + |
| 178 | + /// The address of the account initiating the transaction. |
| 179 | + fn sender_account_address(&self) -> AccountAddress; |
| 180 | + |
| 181 | + /// Get the amount of energy remaining for the execution. |
| 182 | + fn get_energy(&self) -> Energy; |
| 183 | + |
| 184 | + /// Reduce the available energy for the execution. |
| 185 | + /// |
| 186 | + /// # Arguments |
| 187 | + /// |
| 188 | + /// - `energy` The amount of energy to charge. |
| 189 | + /// |
| 190 | + /// # Errors |
| 191 | + /// |
| 192 | + /// - [`OutOfEnergyError`] If the available energy is smaller than the ticked amount. |
| 193 | + fn tick_energy(&mut self, energy: Energy) -> Result<(), OutOfEnergyError>; |
| 194 | +} |
| 195 | + |
| 196 | +/// Transaction execution ran out of energy. |
| 197 | +#[derive(Debug)] |
| 198 | +pub struct OutOfEnergyError; |
| 199 | + |
172 | 200 | /// The computation resulted in overflow. |
173 | 201 | #[derive(Debug)] |
174 | 202 | pub struct OverflowError; |
| 203 | + |
| 204 | +#[derive(Debug)] |
| 205 | +pub enum TransactionRejectReason {} |
| 206 | + |
| 207 | +pub type TransactionPayload = Vec<u8>; |
| 208 | +pub type Events = (); |
| 209 | + |
| 210 | +/// Execute a transaction payload modifying `scheduler` and `block_state` accordingly. |
| 211 | +/// Returns the events produce if successful otherwise a reject reason. |
| 212 | +pub fn execute_transaction( |
| 213 | + _scheduler: &mut impl SchedulerOperations, |
| 214 | + _block_state: &mut impl BlockStateOperations, |
| 215 | + _payload: TransactionPayload, |
| 216 | +) -> Result<Events, TransactionRejectReason> { |
| 217 | + todo!() |
| 218 | +} |
0 commit comments