github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/eth/api_miner.go (about) 1 // Copyright 2023 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package eth 18 19 import ( 20 "math/big" 21 22 "github.com/ethereum/go-ethereum/common/hexutil" 23 ) 24 25 // MinerAPI provides an API to control the miner. 26 type MinerAPI struct { 27 e *Ethereum 28 } 29 30 // NewMinerAPI creates a new MinerAPI instance. 31 func NewMinerAPI(e *Ethereum) *MinerAPI { 32 return &MinerAPI{e} 33 } 34 35 // SetExtra sets the extra data string that is included when this miner mines a block. 36 func (api *MinerAPI) SetExtra(extra string) (bool, error) { 37 if err := api.e.Miner().SetExtra([]byte(extra)); err != nil { 38 return false, err 39 } 40 return true, nil 41 } 42 43 // SetGasPrice sets the minimum accepted gas price for the miner. 44 func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool { 45 api.e.lock.Lock() 46 api.e.gasPrice = (*big.Int)(&gasPrice) 47 api.e.lock.Unlock() 48 49 api.e.txPool.SetGasTip((*big.Int)(&gasPrice)) 50 api.e.Miner().SetGasTip((*big.Int)(&gasPrice)) 51 return true 52 } 53 54 // SetGasLimit sets the gaslimit to target towards during mining. 55 func (api *MinerAPI) SetGasLimit(gasLimit hexutil.Uint64) bool { 56 api.e.Miner().SetGasCeil(uint64(gasLimit)) 57 return true 58 }