aboutsummaryrefslogtreecommitdiffstats
path: root/utils/cmd.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/cmd.go')
-rw-r--r--utils/cmd.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/utils/cmd.go b/utils/cmd.go
index 654014169..8395ac8fc 100644
--- a/utils/cmd.go
+++ b/utils/cmd.go
@@ -3,24 +3,44 @@ package utils
import (
"github.com/ethereum/eth-go"
"github.com/ethereum/eth-go/ethminer"
- _ "github.com/ethereum/eth-go/ethrpc"
+ "github.com/ethereum/eth-go/ethpub"
+ "github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethutil"
"log"
+ "time"
)
+func DoRpc(ethereum *eth.Ethereum, RpcPort int) {
+ var err error
+ ethereum.RpcServer, err = ethrpc.NewJsonRpcServer(ethpub.NewPEthereum(ethereum), RpcPort)
+ if err != nil {
+ log.Println("Could not start RPC interface:", err)
+ } else {
+ go ethereum.RpcServer.Start()
+ }
+}
+
func DoMining(ethereum *eth.Ethereum) {
// Set Mining status
ethereum.Mining = true
- log.Println("Miner started")
+ if ethutil.GetKeyRing().Len() == 0 {
+ log.Println("No address found, can't start mining")
+ return
+ }
+ keyPair := ethutil.GetKeyRing().Get(0)
+ addr := keyPair.Address()
- // Fake block mining. It broadcasts a new block every 5 seconds
go func() {
- keyPair := ethutil.GetKeyRing().Get(0)
- addr := keyPair.Address()
+ // Give it some time to connect with peers
+ time.Sleep(3 * time.Second)
+
+ for ethereum.IsUpToDate() == false {
+ time.Sleep(5 * time.Second)
+ }
+ log.Println("Miner started")
miner := ethminer.NewDefaultMiner(addr, ethereum)
miner.Start()
-
}()
}