-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 1.03 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
package main
import (
"fmt"
"time"
"github.com/juankohler/web3-blockchain-go/domain/blockchains"
"github.com/juankohler/web3-blockchain-go/domain/blocks"
)
func main() {
/** Create blockchain */
blockchain := blockchains.CreateBlockchain()
/** Add Block */
block1 := blocks.CreateBlock(
time.Date(2009, 1, 3, 0, 0, 0, 0, time.UTC).Unix(),
blocks.CreateBlockData("Juancho", "Messi", 10),
blockchain.GetLastestBlock().Hash,
)
blockchain.AddBlock(block1)
/** Add Block */
block2 := blocks.CreateBlock(
time.Date(2009, 1, 3, 0, 0, 0, 0, time.UTC).Unix(),
blocks.CreateBlockData("Messi", "Juancho", 10),
blockchain.GetLastestBlock().Hash,
)
blockchain.AddBlock(block2)
/** Print blockchain */
blockchain.Print()
/** Validate chains */
fmt.Printf("Is blockchain valid? %t \n\n", blockchain.ValidateChain())
/** Invalidate chain */
aux := blockchain.Chains[1]
aux.PreviousHash = "fake_hash"
blockchain.Chains[1] = aux
/** Validate chains */
fmt.Printf("Is blockchain valid? %t \n\n", blockchain.ValidateChain())
}