pub use crate::traits::{
access_control::*,
errors::TimelockControllerError,
};
use ink::prelude::vec::Vec;
use openbrush::traits::{
AccountId,
Balance,
Hash,
Timestamp,
ZERO_ADDRESS,
};
pub type OperationId = Hash;
#[derive(Debug, Clone, PartialEq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct Transaction {
pub callee: AccountId,
pub selector: [u8; 4],
pub input: Vec<u8>,
pub transferred_value: Balance,
pub gas_limit: u64,
}
impl Default for Transaction {
fn default() -> Self {
Self {
callee: ZERO_ADDRESS.into(),
selector: Default::default(),
input: Default::default(),
transferred_value: Default::default(),
gas_limit: Default::default(),
}
}
}
#[openbrush::wrapper]
pub type TimelockControllerRef = dyn TimelockController + AccessControl;
#[openbrush::trait_definition]
pub trait TimelockController: AccessControl {
#[ink(message)]
fn is_operation(&self, id: OperationId) -> bool;
#[ink(message)]
fn is_operation_pending(&self, id: OperationId) -> bool;
#[ink(message)]
fn is_operation_ready(&self, id: OperationId) -> bool;
#[ink(message)]
fn is_operation_done(&self, id: OperationId) -> bool;
#[ink(message)]
fn get_timestamp(&self, id: OperationId) -> Timestamp;
#[ink(message)]
fn get_min_delay(&self) -> Timestamp;
#[ink(message)]
fn hash_operation(&self, transaction: Transaction, predecessor: Option<OperationId>, salt: [u8; 32]) -> Hash;
#[ink(message)]
fn hash_operation_batch(
&self,
transactions: Vec<Transaction>,
predecessor: Option<OperationId>,
salt: [u8; 32],
) -> Hash;
#[ink(message)]
fn schedule(
&mut self,
transaction: Transaction,
predecessor: Option<OperationId>,
salt: [u8; 32],
delay: Timestamp,
) -> Result<(), TimelockControllerError>;
#[ink(message)]
fn schedule_batch(
&mut self,
transactions: Vec<Transaction>,
predecessor: Option<OperationId>,
salt: [u8; 32],
delay: Timestamp,
) -> Result<(), TimelockControllerError>;
#[ink(message)]
fn cancel(&mut self, id: OperationId) -> Result<(), TimelockControllerError>;
#[ink(message, payable)]
fn execute(
&mut self,
transaction: Transaction,
predecessor: Option<OperationId>,
salt: [u8; 32],
) -> Result<(), TimelockControllerError>;
#[ink(message, payable)]
fn execute_batch(
&mut self,
transactions: Vec<Transaction>,
predecessor: Option<OperationId>,
salt: [u8; 32],
) -> Result<(), TimelockControllerError>;
#[ink(message)]
fn update_delay(&mut self, new_delay: Timestamp) -> Result<(), TimelockControllerError>;
}