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