diff options
author | Felix Lange <fjl@twurst.com> | 2016-08-16 02:14:05 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-08-17 23:39:04 +0800 |
commit | 3c09c5f12d21258865677cf565bb9d53a8098d3a (patch) | |
tree | 768b7f6f9df8fa7a572d80a04d94e5d31fe3580a /miner/miner.go | |
parent | 1a9e66915b415cb1ca2bc2680f8fb4ff1883787c (diff) | |
download | dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar.gz dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar.bz2 dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar.lz dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar.xz dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.tar.zst dexon-3c09c5f12d21258865677cf565bb9d53a8098d3a.zip |
core, miner: move Backend to miner
This ensures that package core doesn't depend on package accounts and
resolves an age-old TODO.
Diffstat (limited to 'miner/miner.go')
-rw-r--r-- | miner/miner.go | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/miner/miner.go b/miner/miner.go index 7cc25cdf7..c16cbe6ae 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -22,11 +22,13 @@ import ( "math/big" "sync/atomic" + "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/downloader" + "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" @@ -34,6 +36,15 @@ import ( "github.com/ethereum/go-ethereum/pow" ) +// Backend wraps all methods required for mining. +type Backend interface { + AccountManager() *accounts.Manager + BlockChain() *core.BlockChain + TxPool() *core.TxPool + ChainDb() ethdb.Database +} + +// Miner creates blocks and searches for proof-of-work values. type Miner struct { mux *event.TypeMux @@ -44,15 +55,21 @@ type Miner struct { threads int coinbase common.Address mining int32 - eth core.Backend + eth Backend pow pow.PoW canStart int32 // can start indicates whether we can start the mining operation shouldStart int32 // should start indicates whether we should start after sync } -func New(eth core.Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner { - miner := &Miner{eth: eth, mux: mux, pow: pow, worker: newWorker(config, common.Address{}, eth), canStart: 1} +func New(eth Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner { + miner := &Miner{ + eth: eth, + mux: mux, + pow: pow, + worker: newWorker(config, common.Address{}, eth, mux), + canStart: 1, + } go miner.update() return miner |