WIP to expose hashrate to gui

This commit is contained in:
Maran 2014-07-18 12:01:08 +02:00
parent 28a146d438
commit db8170def3
2 changed files with 13 additions and 2 deletions

View File

@ -16,10 +16,16 @@ var powlogger = ethlog.NewLogger("POW")
type PoW interface { type PoW interface {
Search(block *Block, reactChan chan ethutil.React) []byte Search(block *Block, reactChan chan ethutil.React) []byte
Verify(hash []byte, diff *big.Int, nonce []byte) bool Verify(hash []byte, diff *big.Int, nonce []byte) bool
GetHashrate() int64
} }
type EasyPow struct { type EasyPow struct {
hash *big.Int hash *big.Int
HashRate int64
}
func (pow *EasyPow) GetHashrate() int64 {
return pow.HashRate
} }
func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte { func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
@ -39,7 +45,8 @@ func (pow *EasyPow) Search(block *Block, reactChan chan ethutil.React) []byte {
if i%1234567 == 0 { if i%1234567 == 0 {
elapsed := time.Now().UnixNano() - start elapsed := time.Now().UnixNano() - start
hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000 hashes := ((float64(1e9) / float64(elapsed)) * float64(i)) / 1000
powlogger.Infoln("Hashing @", int64(hashes), "khash") pow.HashRate = int64(hashes)
powlogger.Infoln("Hashing @", int64(pow.HashRate), "khash")
} }
sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes()) sha := ethcrypto.Sha3Bin(big.NewInt(r.Int63()).Bytes())

View File

@ -24,6 +24,10 @@ type Miner struct {
quitChan chan bool quitChan chan bool
} }
func (self Miner) GetPow() *ethchain.PoW {
return &self.pow
}
func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner { func NewDefaultMiner(coinbase []byte, ethereum ethchain.EthManager) Miner {
reactChan := make(chan ethutil.React, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in reactChan := make(chan ethutil.React, 1) // This is the channel that receives 'updates' when ever a new transaction or block comes in
powChan := make(chan []byte, 1) // This is the channel that receives valid sha hases for a given block powChan := make(chan []byte, 1) // This is the channel that receives valid sha hases for a given block