-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
106 lines (90 loc) · 2.47 KB
/
main.rs
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
mod balances;
mod proof_of_existence;
mod support;
mod system;
use support::Dispatch;
mod types {
use crate::support;
pub type AccountID = String;
pub type Balance = u128;
pub type BlockNumber = u32;
pub type Nonce = u32;
pub type Extrinsic = support::Extrinsic<AccountID, crate::RuntimeCall>;
pub type Header = support::Header<BlockNumber>;
pub type Block = support::Block<Header, Extrinsic>;
pub type Content = &'static str;
}
// This is our main Runtime.
// It accumulates all of the different pallets we want to use.
#[derive(Debug)]
#[macros::runtime]
pub struct Runtime {
system: system::Pallet<Self>,
balances: balances::Pallet<Self>,
proof_of_existence: proof_of_existence::Pallet<Self>,
}
impl system::Config for Runtime {
type AccountID = types::AccountID;
type BlockNumber = types::BlockNumber;
type Nonce = types::Nonce;
}
impl balances::Config for Runtime {
type Balance = types::Balance;
}
impl proof_of_existence::Config for Runtime {
type Content = types::Content;
}
fn main() {
// instantiate the runtime
let mut runtime = Runtime::new();
// set alice's balance to 100 tokens
let alice = String::from("alice");
let bob = String::from("bob");
let charlie: String = String::from("charlie");
runtime.balances.set_balance(&alice, 100);
let block_1 = types::Block {
header: types::Header { block_number: 1 },
extrinsics: vec![
types::Extrinsic {
caller: alice.clone(),
call: RuntimeCall::balances(balances::Call::transfer {
to: bob.clone(),
amount: 50,
}),
},
types::Extrinsic {
caller: alice.clone(),
call: RuntimeCall::balances(balances::Call::transfer {
to: charlie.clone(),
amount: 20,
}),
},
],
};
let block_2 = types::Block {
header: types::Header { block_number: 2 },
extrinsics: vec![
types::Extrinsic {
caller: charlie.clone(),
call: RuntimeCall::proof_of_existence(proof_of_existence::Call::create_claim {
claim: "0xContent claim",
}),
},
types::Extrinsic {
caller: bob.clone(),
call: RuntimeCall::proof_of_existence(proof_of_existence::Call::create_claim {
claim: "0xContent claim",
}),
},
],
};
runtime.execute_block(block_1).expect("Invalid block");
runtime.execute_block(block_2).expect("Invalid block");
// uncomment lines to cause panic.
// let block_3 = types::Block {
// header: types::Header{block_number: 2},
// extrinsics: vec!{},
// };
// runtime.execute_block(block_3).expect("Invalid block");
println!("{:#?}", runtime);
}