gitlab.com/flarenetwork/coreth@v0.1.1/miner/miner.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. 2 // 3 // This file is a derived work, based on the go-ethereum library whose original 4 // notices appear below. 5 // 6 // It is distributed under a license compatible with the licensing terms of the 7 // original code from which it is derived. 8 // 9 // Much love to the original authors for their work. 10 // ********** 11 // Copyright 2014 The go-ethereum Authors 12 // This file is part of the go-ethereum library. 13 // 14 // The go-ethereum library is free software: you can redistribute it and/or modify 15 // it under the terms of the GNU Lesser General Public License as published by 16 // the Free Software Foundation, either version 3 of the License, or 17 // (at your option) any later version. 18 // 19 // The go-ethereum library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 // GNU Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public License 25 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 26 27 // Package miner implements Ethereum block creation and mining. 28 package miner 29 30 import ( 31 "github.com/ethereum/go-ethereum/common" 32 "github.com/ethereum/go-ethereum/event" 33 "gitlab.com/flarenetwork/coreth/consensus" 34 "gitlab.com/flarenetwork/coreth/core" 35 "gitlab.com/flarenetwork/coreth/core/types" 36 "gitlab.com/flarenetwork/coreth/params" 37 ) 38 39 // Backend wraps all methods required for mining. 40 type Backend interface { 41 BlockChain() *core.BlockChain 42 TxPool() *core.TxPool 43 } 44 45 // Config is the configuration parameters of mining. 46 type Config struct { 47 Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account) 48 } 49 50 type Miner struct { 51 worker *worker 52 } 53 54 func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine) *Miner { 55 return &Miner{ 56 worker: newWorker(config, chainConfig, engine, eth, mux), 57 } 58 } 59 60 func (miner *Miner) SetEtherbase(addr common.Address) { 61 miner.worker.setEtherbase(addr) 62 } 63 64 func (miner *Miner) GenerateBlock() (*types.Block, error) { 65 return miner.worker.commitNewWork() 66 } 67 68 // SubscribePendingLogs starts delivering logs from pending transactions 69 // to the given channel. 70 func (miner *Miner) SubscribePendingLogs(ch chan<- []*types.Log) event.Subscription { 71 return miner.worker.pendingLogsFeed.Subscribe(ch) 72 }