Skip to content

Commit

Permalink
Refactored mining into utils and exposed it to ethereal. Partly fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
Maran committed May 14, 2014
1 parent 0d9c948 commit e8147cf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
4 changes: 4 additions & 0 deletions ethereal/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func main() {
os.Exit(0)
}

if StartMining {
utils.DoMining(ethereum)
}

if StartRpc {
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
if err != nil {
Expand Down
25 changes: 1 addition & 24 deletions ethereum/ethereum.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"encoding/hex"
"fmt"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethminer"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil"
Expand Down Expand Up @@ -127,28 +125,7 @@ func main() {
ethereum.Mining = StartMining

if StartMining {
logger.Infoln("Miner started")

// Fake block mining. It broadcasts a new block every 5 seconds
go func() {

if StartMining {
logger.Infoln("Miner started")

go func() {
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.Start()

}()
}
}()

utils.DoMining(ethereum)
}

if StartConsole {
Expand Down
31 changes: 31 additions & 0 deletions utils/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package utils

import (
"encoding/hex"
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethminer"
_ "github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil"
"log"
)

func DoMining(ethereum *eth.Ethereum) {
// Set Mining status
ethereum.Mining = true

log.Println("Miner started")

// Fake block mining. It broadcasts a new block every 5 seconds
go func() {
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.Start()

}()
}

0 comments on commit e8147cf

Please sign in to comment.