2014-05-14 13:41:30 +03:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/eth-go"
|
|
|
|
"github.com/ethereum/eth-go/ethminer"
|
2014-05-14 14:32:49 +03:00
|
|
|
"github.com/ethereum/eth-go/ethpub"
|
|
|
|
"github.com/ethereum/eth-go/ethrpc"
|
2014-05-14 13:41:30 +03:00
|
|
|
"github.com/ethereum/eth-go/ethutil"
|
2014-05-14 14:26:15 +03:00
|
|
|
"time"
|
2014-05-14 13:41:30 +03:00
|
|
|
)
|
|
|
|
|
2014-05-14 14:32:49 +03:00
|
|
|
func DoRpc(ethereum *eth.Ethereum, RpcPort int) {
|
|
|
|
var err error
|
|
|
|
ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
|
|
|
|
if err != nil {
|
2014-05-19 13:14:47 +03:00
|
|
|
ethutil.Config.Log.Infoln("Could not start RPC interface:", err)
|
2014-05-14 14:32:49 +03:00
|
|
|
} else {
|
|
|
|
go ethereum.RpcServer.Start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 13:41:30 +03:00
|
|
|
func DoMining(ethereum *eth.Ethereum) {
|
|
|
|
// Set Mining status
|
|
|
|
ethereum.Mining = true
|
|
|
|
|
2014-05-14 15:04:43 +03:00
|
|
|
if ethutil.GetKeyRing().Len() == 0 {
|
2014-05-19 13:14:47 +03:00
|
|
|
ethutil.Config.Log.Infoln("No address found, can't start mining")
|
2014-05-14 14:55:55 +03:00
|
|
|
return
|
|
|
|
}
|
2014-05-14 15:04:43 +03:00
|
|
|
keyPair := ethutil.GetKeyRing().Get(0)
|
|
|
|
addr := keyPair.Address()
|
2014-05-14 14:55:55 +03:00
|
|
|
|
2014-05-14 13:41:30 +03:00
|
|
|
go func() {
|
2014-05-14 14:26:15 +03:00
|
|
|
// Give it some time to connect with peers
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
|
2014-05-17 16:15:46 +03:00
|
|
|
/*
|
|
|
|
for ethereum.IsUpToDate() == false {
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
}
|
|
|
|
*/
|
2014-05-19 13:14:47 +03:00
|
|
|
ethutil.Config.Log.Infoln("Miner started")
|
2014-05-14 14:26:15 +03:00
|
|
|
|
2014-05-14 14:55:08 +03:00
|
|
|
miner := ethminer.NewDefaultMiner(addr, ethereum)
|
2014-05-14 13:41:30 +03:00
|
|
|
miner.Start()
|
|
|
|
}()
|
|
|
|
}
|