Rename ConfirmProof function to Validate
This commit is contained in:
parent
d379fdeae2
commit
2a9385dd5b
2
main.go
2
main.go
|
@ -16,7 +16,7 @@ func main() {
|
||||||
fmt.Printf("Data: %s\n", block.Data)
|
fmt.Printf("Data: %s\n", block.Data)
|
||||||
fmt.Printf("Hash: %x\n", block.Hash)
|
fmt.Printf("Hash: %x\n", block.Hash)
|
||||||
pow := NewProofOfWork(block)
|
pow := NewProofOfWork(block)
|
||||||
fmt.Printf("PoF: %s\n", strconv.FormatBool(pow.ConfirmProof()))
|
fmt.Printf("PoW: %s\n", strconv.FormatBool(pow.Validate()))
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,15 +70,15 @@ func (pow *ProofOfWork) Run() (int, []byte) {
|
||||||
return nonce, hash[:]
|
return nonce, hash[:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfirmProof confirms that the proof is correct
|
// Validate validates block's PoW
|
||||||
func (pow *ProofOfWork) ConfirmProof() bool {
|
func (pow *ProofOfWork) Validate() bool {
|
||||||
var hashInt big.Int
|
var hashInt big.Int
|
||||||
|
|
||||||
data := pow.prepareData(pow.block.Nonce)
|
data := pow.prepareData(pow.block.Nonce)
|
||||||
hash := sha256.Sum256(data)
|
hash := sha256.Sum256(data)
|
||||||
hashInt.SetBytes(hash[:])
|
hashInt.SetBytes(hash[:])
|
||||||
|
|
||||||
confirmation := hashInt.Cmp(pow.target) == -1
|
isValid := hashInt.Cmp(pow.target) == -1
|
||||||
|
|
||||||
return confirmation
|
return isValid
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue