mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
chore: redefine namespace constants for better code structure
This commit is contained in:
parent
283be23817
commit
18c91c647c
17 changed files with 55 additions and 38 deletions
|
|
@ -727,7 +727,7 @@ func signer(c *cli.Context) error {
|
||||||
)
|
)
|
||||||
rpcAPI := []rpc.API{
|
rpcAPI := []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "account",
|
Namespace: rpc.NamespaceAccount,
|
||||||
Service: api,
|
Service: api,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -328,13 +328,6 @@ func applyMetricConfig(ctx *cli.Context, cfg *gethConfig) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setAccountManagerBackends(conf *node.Config, am *accounts.Manager, keydir string) error {
|
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
|
// Assemble the supported backends
|
||||||
if len(conf.ExternalSigner) > 0 {
|
if len(conf.ExternalSigner) > 0 {
|
||||||
log.Info("Using external signer", "url", conf.ExternalSigner)
|
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.
|
// For now, we're using EITHER external signer OR local signers.
|
||||||
// If/when we implement some form of lockfile for USB and keystore wallets,
|
// 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
|
// we can have both, but it's very confusing for the user to see the same
|
||||||
|
|
|
||||||
|
|
@ -1955,7 +1955,7 @@ func RegisterFilterAPI(stack *node.Node, backend ethapi.Backend, ethcfg *ethconf
|
||||||
LogCacheSize: ethcfg.FilterLogCacheSize,
|
LogCacheSize: ethcfg.FilterLogCacheSize,
|
||||||
})
|
})
|
||||||
stack.RegisterAPIs([]rpc.API{{
|
stack.RegisterAPIs([]rpc.API{{
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: filters.NewFilterAPI(filterSystem),
|
Service: filters.NewFilterAPI(filterSystem),
|
||||||
}})
|
}})
|
||||||
return filterSystem
|
return filterSystem
|
||||||
|
|
|
||||||
|
|
@ -716,7 +716,7 @@ func (c *Clique) Close() error {
|
||||||
// controlling the signer voting.
|
// controlling the signer voting.
|
||||||
func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
|
func (c *Clique) APIs(chain consensus.ChainHeaderReader) []rpc.API {
|
||||||
return []rpc.API{{
|
return []rpc.API{{
|
||||||
Namespace: "clique",
|
Namespace: rpc.NamespaceClique,
|
||||||
Service: &API{chain: chain, clique: c},
|
Service: &API{chain: chain, clique: c},
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -302,19 +302,19 @@ func (s *Ethereum) APIs() []rpc.API {
|
||||||
// Append all the local APIs and return
|
// Append all the local APIs and return
|
||||||
return append(apis, []rpc.API{
|
return append(apis, []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "miner",
|
Namespace: rpc.NamespaceMiner,
|
||||||
Service: NewMinerAPI(s),
|
Service: NewMinerAPI(s),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: downloader.NewDownloaderAPI(s.handler.downloader, s.blockchain, s.eventMux),
|
Service: downloader.NewDownloaderAPI(s.handler.downloader, s.blockchain, s.eventMux),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "admin",
|
Namespace: rpc.NamespaceAdmin,
|
||||||
Service: NewAdminAPI(s),
|
Service: NewAdminAPI(s),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
Service: NewDebugAPI(s),
|
Service: NewDebugAPI(s),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "net",
|
Namespace: rpc.NamespaceNet,
|
||||||
Service: s.netRPCService,
|
Service: s.netRPCService,
|
||||||
},
|
},
|
||||||
}...)
|
}...)
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func Register(stack *node.Node, backend *eth.Ethereum) error {
|
||||||
log.Warn("Engine API enabled", "protocol", "eth")
|
log.Warn("Engine API enabled", "protocol", "eth")
|
||||||
stack.RegisterAPIs([]rpc.API{
|
stack.RegisterAPIs([]rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "engine",
|
Namespace: rpc.NamespaceEngine,
|
||||||
Service: NewConsensusAPI(backend),
|
Service: NewConsensusAPI(backend),
|
||||||
Authenticated: true,
|
Authenticated: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,7 @@ func RegisterSimulatedBeaconAPIs(stack *node.Node, sim *SimulatedBeacon) {
|
||||||
api := newSimulatedBeaconAPI(sim)
|
api := newSimulatedBeaconAPI(sim)
|
||||||
stack.RegisterAPIs([]rpc.API{
|
stack.RegisterAPIs([]rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "dev",
|
Namespace: rpc.NamespaceDev,
|
||||||
Service: api,
|
Service: api,
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ package downloader
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// SyncMode represents the synchronisation mode of the downloader.
|
// 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
|
type SyncMode uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -1049,7 +1049,7 @@ func APIs(backend Backend) []rpc.API {
|
||||||
// Append all the local APIs and return
|
// Append all the local APIs and return
|
||||||
return []rpc.API{
|
return []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
Service: NewAPI(backend),
|
Service: NewAPI(backend),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
|
||||||
}
|
}
|
||||||
filterSystem := filters.NewFilterSystem(ethservice.APIBackend, filters.Config{})
|
filterSystem := filters.NewFilterSystem(ethservice.APIBackend, filters.Config{})
|
||||||
n.RegisterAPIs([]rpc.API{{
|
n.RegisterAPIs([]rpc.API{{
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: filters.NewFilterAPI(filterSystem),
|
Service: filters.NewFilterAPI(filterSystem),
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func newWithNode(stack *node.Node, conf *eth.Config, blockPeriod uint64) (*Backe
|
||||||
// Register the filter system
|
// Register the filter system
|
||||||
filterSystem := filters.NewFilterSystem(backend.APIBackend, filters.Config{})
|
filterSystem := filters.NewFilterSystem(backend.APIBackend, filters.Config{})
|
||||||
stack.RegisterAPIs([]rpc.API{{
|
stack.RegisterAPIs([]rpc.API{{
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: filters.NewFilterAPI(filterSystem),
|
Service: filters.NewFilterAPI(filterSystem),
|
||||||
}})
|
}})
|
||||||
// Start the node
|
// Start the node
|
||||||
|
|
|
||||||
|
|
@ -103,25 +103,25 @@ func GetAPIs(apiBackend Backend) []rpc.API {
|
||||||
nonceLock := new(AddrLocker)
|
nonceLock := new(AddrLocker)
|
||||||
return []rpc.API{
|
return []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: NewEthereumAPI(apiBackend),
|
Service: NewEthereumAPI(apiBackend),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: NewBlockChainAPI(apiBackend),
|
Service: NewBlockChainAPI(apiBackend),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: NewTransactionAPI(apiBackend, nonceLock),
|
Service: NewTransactionAPI(apiBackend, nonceLock),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "txpool",
|
Namespace: rpc.NamespaceTxpool,
|
||||||
Service: NewTxPoolAPI(apiBackend),
|
Service: NewTxPoolAPI(apiBackend),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
Service: NewDebugAPI(apiBackend),
|
Service: NewDebugAPI(apiBackend),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
|
Service: NewEthereumAccountAPI(apiBackend.AccountManager()),
|
||||||
}, {
|
}, {
|
||||||
Namespace: "personal",
|
Namespace: rpc.NamespacePersonal,
|
||||||
Service: NewPersonalAccountAPI(apiBackend, nonceLock),
|
Service: NewPersonalAccountAPI(apiBackend, nonceLock),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,16 +35,16 @@ import (
|
||||||
func (n *Node) apis() []rpc.API {
|
func (n *Node) apis() []rpc.API {
|
||||||
return []rpc.API{
|
return []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "admin",
|
Namespace: rpc.NamespaceAdmin,
|
||||||
Service: &adminAPI{n},
|
Service: &adminAPI{n},
|
||||||
}, {
|
}, {
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
Service: debug.Handler,
|
Service: debug.Handler,
|
||||||
}, {
|
}, {
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
Service: &p2pDebugAPI{n},
|
Service: &p2pDebugAPI{n},
|
||||||
}, {
|
}, {
|
||||||
Namespace: "web3",
|
Namespace: rpc.NamespaceWeb3,
|
||||||
Service: &web3API{n},
|
Service: &web3API{n},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ func (n *Node) startRPC() error {
|
||||||
// Filter out personal api
|
// Filter out personal api
|
||||||
var apis []rpc.API
|
var apis []rpc.API
|
||||||
for _, api := range n.rpcAPIs {
|
for _, api := range n.rpcAPIs {
|
||||||
if api.Namespace == "personal" {
|
if api.Namespace == rpc.NamespacePersonal {
|
||||||
if n.config.EnablePersonal {
|
if n.config.EnablePersonal {
|
||||||
log.Warn("Deprecated personal namespace activated")
|
log.Warn("Deprecated personal namespace activated")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -122,14 +122,14 @@ func TestAuthEndpoints(t *testing.T) {
|
||||||
// register dummy apis so we can test the modules are available and reachable with authentication
|
// register dummy apis so we can test the modules are available and reachable with authentication
|
||||||
node.RegisterAPIs([]rpc.API{
|
node.RegisterAPIs([]rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "engine",
|
Namespace: rpc.NamespaceEngine,
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
Service: helloRPC("hello engine"),
|
Service: helloRPC("hello engine"),
|
||||||
Public: true,
|
Public: true,
|
||||||
Authenticated: true,
|
Authenticated: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Namespace: "eth",
|
Namespace: rpc.NamespaceEth,
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
Service: helloRPC("hello eth"),
|
Service: helloRPC("hello eth"),
|
||||||
Public: true,
|
Public: true,
|
||||||
|
|
|
||||||
|
|
@ -94,13 +94,13 @@ func (f *FullService) Protocols() []p2p.Protocol {
|
||||||
func (f *FullService) APIs() []rpc.API {
|
func (f *FullService) APIs() []rpc.API {
|
||||||
return []rpc.API{
|
return []rpc.API{
|
||||||
{
|
{
|
||||||
Namespace: "admin",
|
Namespace: rpc.NamespaceAdmin,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Namespace: "debug",
|
Namespace: rpc.NamespaceDebug,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Namespace: "net",
|
Namespace: rpc.NamespaceNet,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
rpc/types.go
17
rpc/types.go
|
|
@ -28,6 +28,23 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"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
|
// API describes the set of methods offered over the RPC interface
|
||||||
type API struct {
|
type API struct {
|
||||||
Namespace string // namespace under which the rpc methods of Service are exposed
|
Namespace string // namespace under which the rpc methods of Service are exposed
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue