Improve ConfirmProof and print it out in main()
This commit is contained in:
parent
35449eb8a6
commit
f94bbb4451
7
main.go
7
main.go
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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[:])
|
||||
|
||||
|
|
Loading…
Reference in New Issue