Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/utils/cmd.go

32 lines
734 B

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()
}()
}