1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Module containing the [`Runtime`](Runtime) trait and its example implementations. You can use
//! `drink` with any runtime that implements the `Runtime` trait.

pub mod minimal;
pub mod pallet_contracts_debugging;

pub use frame_metadata::RuntimeMetadataPrefixed;
use frame_support::sp_runtime::{traits::Dispatchable, Storage};
use frame_system::pallet_prelude::BlockNumberFor;
pub use minimal::MinimalRuntime;

/// The type of an account identifier.
pub type AccountIdFor<R> = <R as frame_system::Config>::AccountId;

/// The type of a hash.
pub type HashFor<R> = <R as frame_system::Config>::Hash;

/// Extract the Runtime configuration.
pub type ConfigOf<R> = <R as Runtime>::Config;

/// A runtime to use.
pub trait Runtime {
    /// The runtime configuration.
    type Config: frame_system::Config;

    /// Initialize the storage at the genesis block.
    fn initialize_storage(_storage: &mut Storage) -> Result<(), String> {
        Ok(())
    }

    /// Initialize a new block at particular height.
    fn initialize_block(
        _height: BlockNumberFor<Self::Config>,
        _parent_hash: <Self::Config as frame_system::Config>::Hash,
    ) -> Result<(), String> {
        Ok(())
    }

    /// Finalize a block at particular height.
    fn finalize_block(
        _height: BlockNumberFor<Self::Config>,
    ) -> Result<<Self::Config as frame_system::Config>::Hash, String> {
        Ok(Default::default())
    }

    /// Default actor for the runtime.
    fn default_actor() -> AccountIdFor<Self::Config>;

    /// Metadata of the runtime.
    fn get_metadata() -> RuntimeMetadataPrefixed;

    /// Convert an account to an call origin.
    fn convert_account_to_origin(
        account: AccountIdFor<Self::Config>,
    ) -> <<Self::Config as frame_system::Config>::RuntimeCall as Dispatchable>::RuntimeOrigin;
}