#![allow(clippy::let_unit_value)]
use pink_extension_macro as pink;
use alloc::string::String;
use scale::{Decode, Encode};
use crate::{AccountId, Balance, Hash};
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum Error {
PermisionDenied,
DriverNotFound,
CodeNotFound,
ConditionNotMet,
}
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum CodeType {
Ink,
Sidevm,
}
impl CodeType {
pub fn is_ink(&self) -> bool {
matches!(self, CodeType::Ink)
}
pub fn is_sidevm(&self) -> bool {
matches!(self, CodeType::Sidevm)
}
}
pub type Result<T, E = Error> = core::result::Result<T, E>;
pub use this_crate::VersionTuple;
#[pink::system]
#[ink::trait_definition(namespace = "pink_system")]
pub trait System {
#[ink(message, selector = 0x87c98a8d)]
fn version(&self) -> VersionTuple;
#[ink(message)]
fn grant_admin(&mut self, contract_id: AccountId) -> Result<()>;
#[ink(message)]
fn is_admin(&self, contract_id: AccountId) -> bool;
#[ink(message)]
fn set_driver(&mut self, name: String, contract_id: AccountId) -> Result<()>;
#[ink(message)]
fn get_driver(&self, name: String) -> Option<AccountId>;
#[ink(message)]
fn deploy_sidevm_to(&self, contract_id: AccountId, code_hash: Hash) -> Result<()>;
#[ink(message)]
fn stop_sidevm_at(&self, contract_id: AccountId) -> Result<()>;
#[ink(message)]
fn set_hook(
&mut self,
hook: crate::HookPoint,
contract_id: AccountId,
selector: u32,
gas_limit: u64,
) -> Result<()>;
#[ink(message)]
fn set_contract_weight(&self, contract_id: AccountId, weight: u32) -> Result<()>;
#[ink(message)]
fn total_balance_of(&self, account: AccountId) -> Balance;
#[ink(message)]
fn free_balance_of(&self, account: AccountId) -> Balance;
#[ink(message)]
fn upgrade_system_contract(&mut self) -> Result<()>;
#[ink(message)]
fn do_upgrade(&self, from_version: VersionTuple) -> Result<()>;
#[ink(message)]
fn upgrade_runtime(&mut self, version: (u32, u32)) -> Result<()>;
#[ink(message)]
fn code_exists(&self, code_hash: Hash, code_type: CodeType) -> bool;
}
#[derive(Debug, PartialEq, Eq, Encode, Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum DriverError {
Other(String),
SystemError(Error),
BadOrigin,
}
impl From<Error> for DriverError {
fn from(value: Error) -> Self {
Self::SystemError(value)
}
}
#[pink::driver]
#[ink::trait_definition]
pub trait SidevmOperation {
#[ink(message)]
fn deploy(&self, code_hash: Hash) -> Result<(), DriverError>;
#[ink(message)]
fn can_deploy(&self, contract_id: AccountId) -> bool;
}
#[pink::driver]
#[ink::trait_definition]
pub trait ContractDeposit {
#[ink(message, selector = 0xa24bcb44)]
fn change_deposit(
&mut self,
contract_id: AccountId,
deposit: Balance,
) -> Result<(), DriverError>;
}