Refactored mining into utils and exposed it to ethereal. Partly fixes #43
This commit is contained in:
parent
0d9c948b9b
commit
e8147cf7c6
@ -99,6 +99,10 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if StartMining {
|
||||||
|
utils.DoMining(ethereum)
|
||||||
|
}
|
||||||
|
|
||||||
if StartRpc {
|
if StartRpc {
|
||||||
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
|
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethminer"
|
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
"github.com/ethereum/eth-go/ethrpc"
|
"github.com/ethereum/eth-go/ethrpc"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
@ -127,28 +125,7 @@ func main() {
|
|||||||
ethereum.Mining = StartMining
|
ethereum.Mining = StartMining
|
||||||
|
|
||||||
if StartMining {
|
if StartMining {
|
||||||
logger.Infoln("Miner started")
|
utils.DoMining(ethereum)
|
||||||
|
|
||||||
// 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()
|
|
||||||
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if StartConsole {
|
if StartConsole {
|
||||||
|
31
utils/cmd.go
Normal file
31
utils/cmd.go
Normal file
@ -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()
|
||||||
|
|
||||||
|
}()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user