forked from GeekLaunch/blockchain-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
66 lines (54 loc) · 1.74 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
use blockchainlib::*;
fn main () {
let difficulty = 0x000fffffffffffffffffffffffffffff;
let mut genesis_block = Block::new(0, now(), vec![0; 32], vec![
Transaction {
inputs: vec![ ],
outputs: vec![
transaction::Output {
to_addr: "Alice".to_owned(),
value: 50,
},
transaction::Output {
to_addr: "Bob".to_owned(),
value: 7,
},
],
},
], difficulty);
genesis_block.mine();
println!("Mined genesis block {:?}", &genesis_block);
let mut last_hash = genesis_block.hash.clone();
let mut blockchain = Blockchain::new();
blockchain.update_with_block(genesis_block).expect("Failed to add genesis block");
let mut block = Block::new(1, now(), last_hash, vec![
Transaction {
inputs: vec![ ],
outputs: vec![
transaction::Output {
to_addr: "Chris".to_owned(),
value: 536,
},
],
},
Transaction {
inputs: vec![
blockchain.blocks[0].transactions[0].outputs[0].clone(),
],
outputs: vec![
transaction::Output {
to_addr: "Alice".to_owned(),
value: 360,
},
transaction::Output {
to_addr: "Bob".to_owned(),
value: 12,
},
],
},
], difficulty);
block.mine();
println!("Mined block {:?}", &block);
last_hash = block.hash.clone();
blockchain.update_with_block(block).expect("Failed to add block");
}