diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:21 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-15 03:34:21 +0800 |
commit | 942f552c620471602326c1ded54095c1cf41ed76 (patch) | |
tree | cbc1f21a967bb522afad6c891afb4c4628f16ab4 /utils/cmd.go | |
parent | 809b4ae0f68da7a6904208662dc316cd669184fe (diff) | |
parent | a73ae8727d38391c6975a9fa149043e6c69a2f30 (diff) | |
download | dexon-942f552c620471602326c1ded54095c1cf41ed76.tar dexon-942f552c620471602326c1ded54095c1cf41ed76.tar.gz dexon-942f552c620471602326c1ded54095c1cf41ed76.tar.bz2 dexon-942f552c620471602326c1ded54095c1cf41ed76.tar.lz dexon-942f552c620471602326c1ded54095c1cf41ed76.tar.xz dexon-942f552c620471602326c1ded54095c1cf41ed76.tar.zst dexon-942f552c620471602326c1ded54095c1cf41ed76.zip |
Merge branch 'release/poc5-rc6'
Diffstat (limited to 'utils/cmd.go')
-rw-r--r-- | utils/cmd.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/utils/cmd.go b/utils/cmd.go new file mode 100644 index 000000000..8395ac8fc --- /dev/null +++ b/utils/cmd.go @@ -0,0 +1,46 @@ +package utils + +import ( + "github.com/ethereum/eth-go" + "github.com/ethereum/eth-go/ethminer" + "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 + + if ethutil.GetKeyRing().Len() == 0 { + log.Println("No address found, can't start mining") + return + } + keyPair := ethutil.GetKeyRing().Get(0) + addr := keyPair.Address() + + go func() { + // 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() + }() +} |