Skip to content

Commit bea4045

Browse files
committed
Add trait for operations on the scheduler state
1 parent d28f200 commit bea4045

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

plt-scheduler/src/lib.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use concordium_base::base::AccountIndex;
1+
use concordium_base::base::{AccountIndex, Energy};
2+
use concordium_base::id::types::AccountAddress;
23
use concordium_base::protocol_level_tokens::TokenId;
34
use plt_deployment_unit::TokenRawAmount;
45

@@ -169,6 +170,47 @@ pub trait BlockStateOperations {
169170
fn set_token_state(&mut self, token_index: TokenIndex, mutable_token_state: MutableTokenState);
170171
}
171172

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+
172200
/// The computation resulted in overflow.
173201
#[derive(Debug)]
174202
pub struct OverflowError;
203+
204+
type TransactionRejectReason = ();
205+
type TransactionPayload = Vec<u8>;
206+
type Events = ();
207+
208+
/// Execute a transaction payload modifying `scheduler` and `block_state` accordingly.
209+
/// Returns the events produce if successful otherwise a reject reason.
210+
pub fn execute_transaction(
211+
_scheduler: &mut impl SchedulerOperations,
212+
_block_state: &mut impl BlockStateOperations,
213+
_payload: TransactionPayload,
214+
) -> Result<Events, TransactionRejectReason> {
215+
todo!()
216+
}

0 commit comments

Comments
 (0)