diff options
author | Maran <maran.hidskes@gmail.com> | 2014-03-17 17:37:37 +0800 |
---|---|---|
committer | Maran <maran.hidskes@gmail.com> | 2014-03-17 17:37:37 +0800 |
commit | 8ea7e21f64842380833cce7aafa52b909cb8426b (patch) | |
tree | 08b138c3ef94da8fb1ff0a11c7c47aba5e59e616 /ethchain/dagger.go | |
parent | 3274e0a2496e622a847b213bb5ba0272650ef06c (diff) | |
download | dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar.gz dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar.bz2 dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar.lz dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar.xz dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.tar.zst dexon-8ea7e21f64842380833cce7aafa52b909cb8426b.zip |
Merge
Diffstat (limited to 'ethchain/dagger.go')
-rw-r--r-- | ethchain/dagger.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ethchain/dagger.go b/ethchain/dagger.go index c33b3c14e..4d2034e20 100644 --- a/ethchain/dagger.go +++ b/ethchain/dagger.go @@ -11,7 +11,7 @@ import ( ) type PoW interface { - Search(block *Block, breakChan chan bool) []byte + Search(block *Block, minerChan chan ethutil.React) []byte Verify(hash []byte, diff *big.Int, nonce []byte) bool } @@ -19,19 +19,32 @@ type EasyPow struct { hash *big.Int } -func (pow *EasyPow) Search(block *Block, breakChan chan bool) []byte { +func (pow *EasyPow) Search(block *Block, minerChan chan ethutil.React) []byte { r := rand.New(rand.NewSource(time.Now().UnixNano())) hash := block.HashNoNonce() diff := block.Difficulty + i := int64(0) + start := time.Now().UnixNano() for { select { - case shouldbreak := <-breakChan: - if shouldbreak { - log.Println("Got signal: Breaking out mining.") + case chanMessage := <-minerChan: + if _, ok := chanMessage.Resource.(*Block); ok { + log.Println("BREAKING OUT: BLOCK") + return nil + } + if _, ok := chanMessage.Resource.(*Transaction); ok { + log.Println("BREAKING OUT: TX") return nil } default: + i++ + if i%1234567 == 0 { + elapsed := time.Now().UnixNano() - start + hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000 + log.Println("Hashing @", int64(hashes), "khash") + } + sha := ethutil.Sha3Bin(big.NewInt(r.Int63()).Bytes()) if pow.Verify(hash, diff, sha) { return sha |