MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / main

Function main

code/chapter09/blockchain/blockchain7/main/src/main.rs:5–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3use core::transaction::Transaction;
4
5fn main() {
6 let mut user1 = Account::new("0xabcd".to_string(), "Kim".to_string());
7 let mut user2 = Account::new("0xabce".to_string(), "Tom".to_string());
8 let mut user3 = Account::new("0xabcf".to_string(), "Jim".to_string());
9
10 println!("-------------------------Mine Info----------------------------");
11 let mut mine = Mine::new();
12
13 let mut txs: Vec<Transaction> = Vec::new();
14 let res = user1.transfer_to(&mut user2, 9, 1);
15 match res {
16 Ok(tx) => txs.push(tx),
17 Err(e) => panic!("{}", e),
18 }
19 let res = user1.transfer_to(&mut user2, 5, 1);
20 match res {
21 Ok(tx) => txs.push(tx),
22 Err(e) => panic!("{}", e),
23 }
24 mine.mining(&mut txs);
25
26 let mut txs: Vec<Transaction> = Vec::new();
27 let res = user2.transfer_to(&mut user3, 6, 1);
28 match res {
29 Ok(tx) => txs.push(tx),
30 Err(e) => panic!("{}", e),
31 }
32 let res = user2.transfer_to(&mut user3, 3, 1);
33 match res {
34 Ok(tx) => txs.push(tx),
35 Err(e) => panic!("{}", e),
36 }
37 mine.mining(&mut txs);
38
39 println!("-------------------------Miner Info------------------------------");
40 mine.miner.miner_info();
41
42 println!("-------------------------Account Info----------------------------");
43 let users = vec![&user1, &user2, &user3];
44 for u in users {
45 u.account_info();
46 }
47
48 println!("-------------------------Block Info------------------------------");
49 mine.blockchain.block_info();
50}

Callers

nothing calls this directly

Calls 7

to_stringMethod · 0.45
transfer_toMethod · 0.45
pushMethod · 0.45
miningMethod · 0.45
miner_infoMethod · 0.45
account_infoMethod · 0.45
block_infoMethod · 0.45

Tested by

no test coverage detected