Output mining progress

This commit is contained in:
Ivan Kuznetsov 2017-08-21 20:51:17 +07:00
parent 0f23d64aa0
commit 94f3654c8b
1 changed files with 4 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/sha256"
"encoding/binary"
"fmt"
"log"
"math"
"math/big"
@ -55,10 +56,12 @@ func Prove(block *Block) (int, []byte) {
var hash [32]byte
nonce := 0
fmt.Printf("Mining the block containing \"%s\"\n", block.Data)
for nonce < maxNonce {
data := prepareData(block, nonce)
hash = sha256.Sum256(data)
fmt.Printf("\r%x", hash)
hashInt.SetBytes(hash[:])
if hashInt.Cmp(&target) == -1 {
@ -67,6 +70,7 @@ func Prove(block *Block) (int, []byte) {
nonce++
}
}
fmt.Print("\n\n")
return nonce, hash[:]
}