Improve ConfirmProof and print it out in main()

This commit is contained in:
Ivan Kuznetsov 2017-08-22 11:41:15 +07:00
parent 35449eb8a6
commit f94bbb4451
2 changed files with 8 additions and 3 deletions

View File

@ -1,6 +1,9 @@
package main
import "fmt"
import (
"fmt"
"strconv"
)
func main() {
bc := NewBlockchain()
@ -12,6 +15,8 @@ func main() {
fmt.Printf("Prev. hash: %x\n", block.PrevBlockHash)
fmt.Printf("Data: %s\n", block.Data)
fmt.Printf("Hash: %x\n", block.Hash)
pow := NewProofOfWork(block)
fmt.Printf("PoF: %s\n", strconv.FormatBool(pow.ConfirmProof()))
fmt.Println()
}
}

View File

@ -75,10 +75,10 @@ func (pow *ProofOfWork) Run() (int, []byte) {
}
// ConfirmProof confirms that the proof is correct
func (pow *ProofOfWork) ConfirmProof(nonce int) bool {
func (pow *ProofOfWork) ConfirmProof() bool {
var hashInt big.Int
data := pow.prepareData(nonce)
data := pow.prepareData(pow.block.Nonce)
hash := sha256.Sum256(data)
hashInt.SetBytes(hash[:])