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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#[cfg(feature = "std")]
use std::error as stderror;
use alloc::vec::Vec;
use core::hash;
pub trait Block: Clone {
type Identifier: Clone + Eq + hash::Hash;
fn id(&self) -> Self::Identifier;
fn parent_id(&self) -> Option<Self::Identifier>;
}
pub trait Auxiliary<B: Block>: Clone {
type Key: Clone + Eq + hash::Hash;
fn key(&self) -> Self::Key;
fn associated(&self) -> Vec<B::Identifier> {
Vec::new()
}
}
impl<B: Block> Auxiliary<B> for () {
type Key = ();
fn key(&self) -> () { () }
}
pub trait AsExternalities<E: ?Sized> {
fn as_externalities(&mut self) -> &mut E;
}
pub trait NullExternalities { }
impl NullExternalities for () { }
impl AsExternalities<dyn NullExternalities> for () {
fn as_externalities(&mut self) -> &mut (dyn NullExternalities + 'static) {
self
}
}
pub trait StorageExternalities<Error> {
fn read_storage(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Error>;
fn write_storage(&mut self, key: Vec<u8>, value: Vec<u8>);
fn remove_storage(&mut self, key: &[u8]);
}
pub trait BlockExecutor {
#[cfg(feature = "std")]
type Error: stderror::Error + 'static;
#[cfg(not(feature = "std"))]
type Error: 'static;
type Block: Block;
type Externalities: ?Sized;
fn execute_block(
&self,
block: &Self::Block,
state: &mut Self::Externalities
) -> Result<(), Self::Error>;
}
pub trait SimpleBuilderExecutor: BlockExecutor {
type BuildBlock;
type Inherent;
type Extrinsic;
fn initialize_block(
&self,
parent_block: &Self::Block,
state: &mut Self::Externalities,
inherent: Self::Inherent,
) -> Result<Self::BuildBlock, Self::Error>;
fn apply_extrinsic(
&self,
block: &mut Self::BuildBlock,
extrinsic: Self::Extrinsic,
state: &mut Self::Externalities,
) -> Result<(), Self::Error>;
fn finalize_block(
&self,
block: &mut Self::BuildBlock,
state: &mut Self::Externalities,
) -> Result<(), Self::Error>;
}