-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
55 lines (44 loc) · 1.02 KB
/
main.go
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
package main
import (
"fmt"
"github.com/gunjan5/blockchain-from-scratch/block"
)
func main() {
// Initialize the blockchain with the Genesis block.
bc := block.NewBlockchain()
lastSuccessfulBlock := block.GenesisBlock
lastSuccessfulBlock, _ = addBlock(&bc, block.Transactions{
block.Transaction{
Owes: "Gunjan",
To: "Bob",
Amount: 4.20,
},
block.Transaction{
Owes: "Elon",
To: "Gunjan",
Amount: 3.14,
},
block.Transaction{
Owes: "Lannister",
To: "No-one",
Amount: 1000.0,
},
}, lastSuccessfulBlock)
lastSuccessfulBlock, _ = addBlock(&bc, block.Transactions{
block.Transaction{
Owes: "Happy",
To: "Lemon",
Amount: 4.5,
},
}, lastSuccessfulBlock)
fmt.Println("-----------------\nBlockchain:\n-----------------")
bc.PrettyPrint()
}
func addBlock(bc *block.Blockchain, txns block.Transactions, lsb block.Block) (block.Block, bool) {
b := block.New(lsb.Index+1, lsb.Hash, txns)
if bc.Append(b) {
lsb = b
return lsb, true
}
return lsb, false
}