chore: redefine namespace constants for better code structure

This commit is contained in:
arcane4096 2024-09-28 20:06:44 +08:00
parent 283be23817
commit 18c91c647c
17 changed files with 55 additions and 38 deletions

View file

@ -727,7 +727,7 @@ func signer(c *cli.Context) error {
)
rpcAPI := []rpc.API{
{
Namespace: "account",
Namespace: rpc.NamespaceAccount,
Service: api,
},
}

View file

@ -328,13 +328,6 @@ func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
}
func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir string) error {
scryptN := keystore.StandardScryptN
scryptP := keystore.StandardScryptP
if conf.UseLightweightKDF {
scryptN = keystore.LightScryptN
scryptP = keystore.LightScryptP
}
// Assemble the supported backends
if len(conf.ExternalSigner) > 0 {
log.Info("Using external signer", "url", conf.ExternalSigner)
@ -346,6 +339,13 @@ func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir s
}
}
scryptN := keystore.StandardScryptN
scryptP := keystore.StandardScryptP
if conf.UseLightweightKDF {
scryptN = keystore.LightScryptN
scryptP = keystore.LightScryptP
}
// For now, we're using EITHER external signer OR local signers.
// If/when we implement some form of lockfile for USB and keystore wallets,
// we can have both, but it's very confusing for the user to see the same

View file

@ -1955,7 +1955,7 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
LogCacheSize: ethcfg.FilterLogCacheSize,
})
stack.RegisterAPIs([]rpc.API{{
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: filters.NewFilterAPI(filterSystem),
}})
return filterSystem

View file

@ -716,7 +716,7 @@ func (c *Clique) Close() error {
// controlling the signer voting.
func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
return []rpc.API{{
Namespace: "clique",
Namespace: rpc.NamespaceClique,
Service: &API{chain: chain, clique: c},
}}
}

View file

@ -302,19 +302,19 @@ func (s *Ethereum) APIs() []rpc.API {
// Append all the local APIs and return
return append(apis, []rpc.API{
{
Namespace: "miner",
Namespace: rpc.NamespaceMiner,
Service: NewMinerAPI(s),
}, {
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: downloader.NewDownloaderAPI(s.handler.downloader, s.blockchain, s.eventMux),
}, {
Namespace: "admin",
Namespace: rpc.NamespaceAdmin,
Service: NewAdminAPI(s),
}, {
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
Service: NewDebugAPI(s),
}, {
Namespace: "net",
Namespace: rpc.NamespaceNet,
Service: s.netRPCService,
},
}...)

View file

@ -48,7 +48,7 @@ func Register(stack *node.Node, backend *eth.Ethereum) error {
log.Warn("Engine API enabled", "protocol", "eth")
stack.RegisterAPIs([]rpc.API{
{
Namespace: "engine",
Namespace: rpc.NamespaceEngine,
Service: NewConsensusAPI(backend),
Authenticated: true,
},

View file

@ -328,7 +328,7 @@ func RegisterSimulatedBeaconAPIs(stack *node.Node, sim *SimulatedBeacon) {
api := newSimulatedBeaconAPI(sim)
stack.RegisterAPIs([]rpc.API{
{
Namespace: "dev",
Namespace: rpc.NamespaceDev,
Service: api,
Version: "1.0",
},

View file

@ -19,7 +19,7 @@ package downloader
import "fmt"
// SyncMode represents the synchronisation mode of the downloader.
// It is a uint32 as it is used with atomic operations.
// It is an uint32 as it is used with atomic operations.
type SyncMode uint32
const (

View file

@ -1049,7 +1049,7 @@ func APIs(backend Backend) []rpc.API {
// Append all the local APIs and return
return []rpc.API{
{
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
Service: NewAPI(backend),
},
}

View file

@ -64,7 +64,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
}
filterSystem := filters.NewFilterSystem(ethservice.APIBackend, filters.Config{})
n.RegisterAPIs([]rpc.API{{
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: filters.NewFilterAPI(filterSystem),
}})

View file

@ -113,7 +113,7 @@ func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backe
// Register the filter system
filterSystem := filters.NewFilterSystem(backend.APIBackend, filters.Config{})
stack.RegisterAPIs([]rpc.API{{
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: filters.NewFilterAPI(filterSystem),
}})
// Start the node

View file

@ -103,25 +103,25 @@ func GetAPIs(apiBackend Backend) []rpc.API {
nonceLock := new(AddrLocker)
return []rpc.API{
{
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: NewEthereumAPI(apiBackend),
}, {
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: NewBlockChainAPI(apiBackend),
}, {
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: NewTransactionAPI(apiBackend, nonceLock),
}, {
Namespace: "txpool",
Namespace: rpc.NamespaceTxpool,
Service: NewTxPoolAPI(apiBackend),
}, {
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
Service: NewDebugAPI(apiBackend),
}, {
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
}, {
Namespace: "personal",
Namespace: rpc.NamespacePersonal,
Service: NewPersonalAccountAPI(apiBackend, nonceLock),
},
}

View file

@ -35,16 +35,16 @@ import (
func (n *Node) apis() []rpc.API {
return []rpc.API{
{
Namespace: "admin",
Namespace: rpc.NamespaceAdmin,
Service: &adminAPI{n},
}, {
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
Service: debug.Handler,
}, {
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
Service: &p2pDebugAPI{n},
}, {
Namespace: "web3",
Namespace: rpc.NamespaceWeb3,
Service: &web3API{n},
},
}

View file

@ -378,7 +378,7 @@ func (n *Node) startRPC() error {
// Filter out personal api
var apis []rpc.API
for _, api := range n.rpcAPIs {
if api.Namespace == "personal" {
if api.Namespace == rpc.NamespacePersonal {
if n.config.EnablePersonal {
log.Warn("Deprecated personal namespace activated")
} else {

View file

@ -122,14 +122,14 @@ func TestAuthEndpoints(t *testing.T) {
// register dummy apis so we can test the modules are available and reachable with authentication
node.RegisterAPIs([]rpc.API{
{
Namespace: "engine",
Namespace: rpc.NamespaceEngine,
Version: "1.0",
Service: helloRPC("hello engine"),
Public: true,
Authenticated: true,
},
{
Namespace: "eth",
Namespace: rpc.NamespaceEth,
Version: "1.0",
Service: helloRPC("hello eth"),
Public: true,

View file

@ -94,13 +94,13 @@ func (f *FullService) Protocols() []p2p.Protocol {
func (f *FullService) APIs() []rpc.API {
return []rpc.API{
{
Namespace: "admin",
Namespace: rpc.NamespaceAdmin,
},
{
Namespace: "debug",
Namespace: rpc.NamespaceDebug,
},
{
Namespace: "net",
Namespace: rpc.NamespaceNet,
},
}
}

View file

@ -28,6 +28,23 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)
// These constants define the namespaces for the JSON-RPC APIs provided by Geth.
// They categorize the RPC methods into logical groups for easier access and management.
const (
NamespaceAdmin = "admin"
NamespaceEth = "eth"
NamespaceWeb3 = "web3"
NamespaceAccount = "account"
NamespaceClique = "clique"
NamespaceTxpool = "txpool"
NamespaceMiner = "miner"
NamespaceDebug = "debug"
NamespaceDev = "dev"
NamespaceNet = "net"
NamespacePersonal = "personal"
NamespaceEngine = "engine"
)
// API describes the set of methods offered over the RPC interface
type API struct {
Namespace string // namespace under which the rpc methods of Service are exposed