Make sure we have a coinbase address to mine with

This commit is contained in:
Maran 2014-05-14 13:55:55 +02:00
parent 9fce273ce9
commit 2c7b625daa

View File

@ -26,6 +26,16 @@ func DoMining(ethereum *eth.Ethereum) {
// Set Mining status // Set Mining status
ethereum.Mining = true ethereum.Mining = true
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
if len(data) == 0 {
log.Println("No address found, can't start mining")
return
}
keyRing := ethutil.NewValueFromBytes(data)
addr := keyRing.Get(0).Bytes()
pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr)))
go func() { go func() {
// Give it some time to connect with peers // Give it some time to connect with peers
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
@ -35,10 +45,6 @@ func DoMining(ethereum *eth.Ethereum) {
} }
log.Println("Miner started") log.Println("Miner started")
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
keyRing := ethutil.NewValueFromBytes(data)
addr := keyRing.Get(0).Bytes()
pair, _ := ethchain.NewKeyPairFromSec(ethutil.FromHex(hex.EncodeToString(addr)))
miner := ethminer.NewDefaultMiner(pair.Address(), ethereum) miner := ethminer.NewDefaultMiner(pair.Address(), ethereum)
miner.Start() miner.Start()
}() }()