2023-05-29 04:09:34 -05:00
|
|
|
// Copyright 2023 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package eth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MinerAPI provides an API to control the miner.
|
|
|
|
type MinerAPI struct {
|
|
|
|
e *Ethereum
|
|
|
|
}
|
|
|
|
|
2024-02-20 05:42:48 -06:00
|
|
|
// NewMinerAPI creates a new MinerAPI instance.
|
2023-05-29 04:09:34 -05:00
|
|
|
func NewMinerAPI(e *Ethereum) *MinerAPI {
|
|
|
|
return &MinerAPI{e}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetExtra sets the extra data string that is included when this miner mines a block.
|
|
|
|
func (api *MinerAPI) SetExtra(extra string) (bool, error) {
|
|
|
|
if err := api.e.Miner().SetExtra([]byte(extra)); err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGasPrice sets the minimum accepted gas price for the miner.
|
|
|
|
func (api *MinerAPI) SetGasPrice(gasPrice hexutil.Big) bool {
|
|
|
|
api.e.lock.Lock()
|
|
|
|
api.e.gasPrice = (*big.Int)(&gasPrice)
|
|
|
|
api.e.lock.Unlock()
|
|
|
|
|
2023-06-06 04:53:29 -05:00
|
|
|
api.e.txPool.SetGasTip((*big.Int)(&gasPrice))
|
2024-02-06 02:59:24 -06:00
|
|
|
api.e.Miner().SetGasTip((*big.Int)(&gasPrice))
|
2023-05-29 04:09:34 -05:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetGasLimit sets the gaslimit to target towards during mining.
|
|
|
|
func (api *MinerAPI) SetGasLimit(gasLimit hexutil.Uint64) bool {
|
|
|
|
api.e.Miner().SetGasCeil(uint64(gasLimit))
|
|
|
|
return true
|
|
|
|
}
|