aboutsummaryrefslogtreecommitdiffstats
path: root/dagger.go
diff options
context:
space:
mode:
Diffstat (limited to 'dagger.go')
-rw-r--r--dagger.go46
1 files changed, 14 insertions, 32 deletions
diff --git a/dagger.go b/dagger.go
index 9fef78a36..8509232a2 100644
--- a/dagger.go
+++ b/dagger.go
@@ -2,7 +2,6 @@ package main
import (
"math/big"
- "fmt"
"math/rand"
"time"
"github.com/obscuren/sha3"
@@ -26,8 +25,6 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
resChan <- rnd
// Notify other threads we've found a valid nonce
Found = true
- } else {
- fmt.Printf(".")
}
// Break out if found
@@ -37,17 +34,15 @@ func (dag *Dagger) Find(obj *big.Int, resChan chan int64) {
resChan <- 0
}
-func (dag *Dagger) Search(diff *big.Int) *big.Int {
+func (dag *Dagger) Search(hash, diff *big.Int) *big.Int {
// TODO fix multi threading. Somehow it results in the wrong nonce
amountOfRoutines := 1
- dag.hash = big.NewInt(0)
+ dag.hash = hash
obj := BigPow(2, 256)
obj = obj.Div(obj, diff)
- fmt.Println("diff", diff, "< objective", obj)
-
Found = false
resChan := make(chan int64, 3)
var res int64
@@ -64,8 +59,6 @@ func (dag *Dagger) Search(diff *big.Int) *big.Int {
}
}
- fmt.Println("\n")
-
return big.NewInt(res)
}
@@ -128,32 +121,21 @@ func (dag *Dagger) Eval(N *big.Int) *big.Int {
sha.Reset()
ret := new(big.Int)
- //doneChan := make(chan bool, 3)
-
for k := 0; k < 4; k++ {
- //go func(_k int) {
- _k := k
- d := sha3.NewKeccak224()
- b := new(big.Int)
-
- d.Reset()
- d.Write(dag.hash.Bytes())
- d.Write(dag.xn.Bytes())
- d.Write(N.Bytes())
- d.Write(big.NewInt(int64(_k)).Bytes())
-
- b.SetBytes(Sum(d))
- pk := (b.Uint64() & 0x1ffffff)
-
- sha.Write(dag.Node(9, pk).Bytes())
- //doneChan <- true
- //}(k)
- }
+ d := sha3.NewKeccak224()
+ b := new(big.Int)
- //for k := 0; k < 4; k++ {
- // <- doneChan
- //}
+ d.Reset()
+ d.Write(dag.hash.Bytes())
+ d.Write(dag.xn.Bytes())
+ d.Write(N.Bytes())
+ d.Write(big.NewInt(int64(k)).Bytes())
+ b.SetBytes(Sum(d))
+ pk := (b.Uint64() & 0x1ffffff)
+
+ sha.Write(dag.Node(9, pk).Bytes())
+ }
return ret.SetBytes(Sum(sha))
}