From 84a95ee79458e3a37dabbd4bdeec50191f656c84 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 5 Mar 2024 16:36:01 +0100 Subject: [PATCH] eth: get rid of most miner api --- cmd/geth/consolecmd_test.go | 2 -- console/console.go | 2 +- eth/api.go | 46 ------------------------------------- eth/api_miner.go | 5 ++++ eth/backend.go | 4 ---- miner/miner.go | 8 +++++++ 6 files changed, 14 insertions(+), 53 deletions(-) delete mode 100644 eth/api.go diff --git a/cmd/geth/consolecmd_test.go b/cmd/geth/consolecmd_test.go index ef6ef5f288..62136df8c9 100644 --- a/cmd/geth/consolecmd_test.go +++ b/cmd/geth/consolecmd_test.go @@ -131,7 +131,6 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) { attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH }) attach.SetTemplateFunc("gover", runtime.Version) attach.SetTemplateFunc("gethver", func() string { return params.VersionWithCommit("", "") }) - attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase }) attach.SetTemplateFunc("niltime", func() string { return time.Unix(1548854791, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)") }) @@ -144,7 +143,6 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) { Welcome to the Geth JavaScript console! instance: Geth/v{{gethver}}/{{goos}}-{{goarch}}/{{gover}} -coinbase: {{etherbase}} at block: 0 ({{niltime}}){{if ipc}} datadir: {{datadir}}{{end}} modules: {{apis}} diff --git a/console/console.go b/console/console.go index cdee53684e..b3ceffbb7e 100644 --- a/console/console.go +++ b/console/console.go @@ -326,7 +326,7 @@ func (c *Console) Welcome() { if res, err := c.jsre.Run(` var message = "instance: " + web3.version.node + "\n"; try { - message += "coinbase: " + eth.coinbase + "\n"; + message += "coinbase: " + miner.etherbase() + "\n"; } catch (err) {} message += "at block: " + eth.blockNumber + " (" + new Date(1000 * eth.getBlock(eth.blockNumber).timestamp) + ")\n"; try { diff --git a/eth/api.go b/eth/api.go deleted file mode 100644 index 6fa2be73f8..0000000000 --- a/eth/api.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015 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 . - -package eth - -import ( - "github.com/ethereum/go-ethereum/common" -) - -// EthereumAPI provides an API to access Ethereum full node-related information. -type EthereumAPI struct { - e *Ethereum -} - -// NewEthereumAPI creates a new Ethereum protocol API for full nodes. -func NewEthereumAPI(e *Ethereum) *EthereumAPI { - return &EthereumAPI{e} -} - -// Etherbase is the address that mining rewards will be sent to. -func (api *EthereumAPI) Etherbase() (common.Address, error) { - return api.e.Etherbase() -} - -// Coinbase is the address that mining rewards will be sent to (alias for Etherbase). -func (api *EthereumAPI) Coinbase() (common.Address, error) { - return api.Etherbase() -} - -// Mining returns an indication if this node is currently mining. -func (api *EthereumAPI) Mining() bool { - return api.e.IsMining() -} diff --git a/eth/api_miner.go b/eth/api_miner.go index 63aadb092c..c7f98eaf2a 100644 --- a/eth/api_miner.go +++ b/eth/api_miner.go @@ -63,3 +63,8 @@ func (api *MinerAPI) SetEtherbase(etherbase common.Address) bool { api.e.SetEtherbase(etherbase) return true } + +// Etherbase is the address that mining rewards will be sent to. +func (api *MinerAPI) Etherbase() common.Address { + return api.e.Miner().Etherbase() +} diff --git a/eth/backend.go b/eth/backend.go index bf668ba895..05a70f9f32 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -315,9 +315,6 @@ func (s *Ethereum) APIs() []rpc.API { // Append all the local APIs and return return append(apis, []rpc.API{ { - Namespace: "eth", - Service: NewEthereumAPI(s), - }, { Namespace: "miner", Service: NewMinerAPI(s), }, { @@ -414,7 +411,6 @@ func (s *Ethereum) SetEtherbase(etherbase common.Address) { s.miner.SetEtherbase(etherbase) } -func (s *Ethereum) IsMining() bool { return true } func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } diff --git a/miner/miner.go b/miner/miner.go index 1ad8f7ec6a..346fbc254f 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -107,6 +107,14 @@ func (miner *Miner) SetExtra(extra []byte) error { return nil } +// Etherbase returns the address of fee recipient. +func (miner *Miner) Etherbase() common.Address { + miner.confMu.RLock() + addr := miner.config.Etherbase + miner.confMu.RUnlock() + return addr +} + // SetEtherbase sets the address of fee recipient. func (miner *Miner) SetEtherbase(addr common.Address) { miner.confMu.Lock()