-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainblock.go
More file actions
34 lines (31 loc) · 726 Bytes
/
mainblock.go
File metadata and controls
34 lines (31 loc) · 726 Bytes
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
package main
import (
"fmt"
bc "./blockchain"
)
const (
DBNAME = "blockchain.db"
)
func main() {
miner := bc.NewUser()
bc.NewChain(DBNAME, miner.Address())
chain := bc.LoadChain(DBNAME)
for i := 0; i < 3; i++ {
block := bc.NewBlock(miner.Address(), chain.LastHash())
block.AddTransaction(chain,
bc.NewTransaction(miner, chain.LastHash(), "aaa", 5))
block.AddTransaction(chain,
bc.NewTransaction(miner, chain.LastHash(), "bbb", 3))
block.Accept(chain, miner, make(chan bool))
chain.AddBlock(block)
}
var sblock string
rows, error := chain.DB.Query("SELECT Block FROM BlockChain")
if error != nil {
panic("error: Query to db")
}
for rows.Next() {
rows.Scan(&sblock)
fmt.Println(sblock)
}
}