From 0ecee0d5e2a44348d3894d212d7101a6751c32f0 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Thu, 9 Nov 2017 13:35:27 -0800 Subject: [PATCH] Adds hashrate --- test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test.go b/test.go index d19bad6..28177f6 100644 --- a/test.go +++ b/test.go @@ -1,11 +1,13 @@ package main import ( - "os" "bytes" - "encoding/binary" "crypto/sha256" + "encoding/binary" "math/big" + "os" + "time" + "fmt" ) func main() { @@ -15,21 +17,27 @@ func main() { buffer := make([]byte, total+8) copy(buffer, bytes) - threshold := new(big.Int) - threshold.SetString("00000099999999999999999999999999999999999999999999999999999999999999999999999", 10) + var maxUint256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0)) + threshold := new(big.Int).Div(maxUint256, big.NewInt(1000000000)) + start := time.Now() + found := int64(0) for i := int64(0); i < 1<<63-1; i++ { binary.PutVarint(buffer[total:], i) sum := sha256.Sum256(buffer) - value := new(big.Int) - value.SetBytes(sum[:]) + value := new(big.Int).SetBytes(sum[:]) if value.Cmp(threshold) < 0 { println("Found match", value.String()) + found = i break } } + + hashesPerSecond := found / int64(time.Since(start).Seconds()) + + fmt.Printf("Found a match with hashrate of %.2f MH/s\n", float32(hashesPerSecond)/float32(1000000)) } func argToBytes() []byte {