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
use sov_state::WorkingSet;
use crate::{CallResponse, Context, Error, Module, Spec};
/// Methods from this trait should be called only once during the rollup deployment.
pub trait Genesis {
type Context: Context;
/// Initial configuration for the module.
type Config;
/// Initializes the state of the rollup.
fn genesis(
&self,
config: &Self::Config,
working_set: &mut WorkingSet<<<Self as Genesis>::Context as Spec>::Storage>,
) -> Result<(), Error>;
}
/// A trait that needs to be implemented for any call message.
pub trait DispatchCall {
type Context: Context;
type Decodable;
/// Decodes serialized call message
fn decode_call(serialized_message: &[u8]) -> Result<Self::Decodable, std::io::Error>;
/// Dispatches a call message to the appropriate module.
fn dispatch_call(
&self,
message: Self::Decodable,
working_set: &mut WorkingSet<<<Self as DispatchCall>::Context as Spec>::Storage>,
context: &Self::Context,
) -> Result<CallResponse, Error>;
/// Returns an address of the dispatched module.
fn module_address(&self, message: &Self::Decodable) -> &<Self::Context as Spec>::Address;
}
/// A trait that specifies how a runtime should encode the data for each module
pub trait EncodeCall<M: Module> {
/// The encoding function
fn encode_call(data: M::CallMessage) -> Vec<u8>;
}
/// A trait that needs to be implemented for a *runtime* to be used with the CLI wallet
#[cfg(feature = "native")]
pub trait CliWallet: DispatchCall {
/// The type that is used to represent this type in the CLI. Typically,
/// this type implements the clap::Subcommand trait. This type is generic to
/// allow for different representations of the same type in the interface; a
/// typical end-usage will impl traits only in the case where `CliStringRepr<T>: Into::RuntimeCall`
type CliStringRepr<T>;
}