2017-08-15 02:05:02 -05:00
|
|
|
package main
|
|
|
|
|
2017-08-21 23:41:15 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
)
|
2017-08-15 02:20:34 -05:00
|
|
|
|
2017-08-15 02:05:02 -05:00
|
|
|
func main() {
|
2017-08-15 02:28:18 -05:00
|
|
|
bc := NewBlockchain()
|
2017-08-15 02:20:34 -05:00
|
|
|
|
2017-08-28 01:57:27 -05:00
|
|
|
// bc.AddBlock("Send 1 BTC to Ivan")
|
|
|
|
// bc.AddBlock("Send 2 more BTC to Ivan")
|
|
|
|
|
|
|
|
bci := bc.Iterator()
|
|
|
|
|
|
|
|
for {
|
|
|
|
block := bci.Next()
|
2017-08-15 02:28:18 -05:00
|
|
|
|
2017-08-17 01:04:56 -05:00
|
|
|
fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
|
2017-08-16 02:20:18 -05:00
|
|
|
fmt.Printf("Data: %s\n", block.Data)
|
|
|
|
fmt.Printf("Hash: %x\n", block.Hash)
|
2017-08-21 23:41:15 -05:00
|
|
|
pow := NewProofOfWork(block)
|
2017-08-23 22:35:14 -05:00
|
|
|
fmt.Printf("PoW: %s\n", strconv.FormatBool(pow.Validate()))
|
2017-08-16 02:20:18 -05:00
|
|
|
fmt.Println()
|
2017-08-28 01:57:27 -05:00
|
|
|
|
|
|
|
if len(block.PrevBlockHash) == 0 {
|
|
|
|
break
|
|
|
|
}
|
2017-08-15 02:28:18 -05:00
|
|
|
}
|
2017-08-15 02:05:02 -05:00
|
|
|
}
|