-
Notifications
You must be signed in to change notification settings - Fork 20.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored mining into utils and exposed it to ethereal. Partly fixes #…
- Loading branch information
Maran
committed
May 14, 2014
1 parent
0d9c948
commit e8147cf
Showing
3 changed files
with
36 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() | ||
|
||
}() | ||
} |