aboutsummaryrefslogtreecommitdiffstats
path: root/utils/cmd.go
blob: a99fd9eed1618d87bdd800ad09a276831dd3f6b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()

    }()
}