add GetNodeConfig() function to backend API (#2216)

This commit is contained in:
RichΛrd 2021-04-29 15:22:10 -04:00 committed by GitHub
parent 6037570901
commit 244686e3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 0 deletions

View File

@ -22,6 +22,7 @@ type StatusBackend interface {
StopNode() error
// RestartNode() error // NOTE: Only used in tests
GetNodeConfig() (*params.NodeConfig, error)
UpdateRootDataDir(datadir string)
// SelectAccount(loginParams account.LoginParams) error

View File

@ -68,6 +68,8 @@ var (
// ErrRPCClientUnavailable is returned if an RPC client can't be retrieved.
// This is a normal situation when a node is stopped.
ErrRPCClientUnavailable = errors.New("JSON-RPC client is unavailable")
// ErrDBNotAvailable is returned if a method is called before the DB is available for usage
ErrDBNotAvailable = errors.New("DB is unavailable")
)
var _ StatusBackend = (*GethStatusBackend)(nil)
@ -538,6 +540,13 @@ func (b *GethStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
return &conf, nil
}
func (b *GethStatusBackend) GetNodeConfig() (*params.NodeConfig, error) {
if b.appDB == nil {
return nil, ErrDBNotAvailable
}
return b.loadNodeConfig()
}
func (b *GethStatusBackend) rpcFiltersService() gethnode.ServiceConstructor {
return func(*gethnode.ServiceContext) (gethnode.Service, error) {
return rpcfilters.New(b.statusNode), nil

View File

@ -51,6 +51,8 @@ var (
// ErrRPCClientUnavailable is returned if an RPC client can't be retrieved.
// This is a normal situation when a node is stopped.
ErrRPCClientUnavailable = errors.New("JSON-RPC client is unavailable")
// ErrDBNotAvailable is returned if a method is called before the DB is available for usage
ErrDBNotAvailable = errors.New("DB is unavailable")
)
var _ StatusBackend = (*nimbusStatusBackend)(nil)
@ -380,6 +382,13 @@ func (b *nimbusStatusBackend) loadNodeConfig() (*params.NodeConfig, error) {
return &conf, nil
}
func (b *GethStatusBackend) GetNodeConfig() (*params.NodeConfig, error) {
if b.appDB == nil {
return nil, ErrDBNotAvailable
}
return b.loadNodeConfig()
}
func (b *nimbusStatusBackend) rpcFiltersService() nimbussvc.ServiceConstructor {
return func(*nimbussvc.ServiceContext) (nimbussvc.Service, error) {
return rpcfilters.New(b.statusNode), nil

View File

@ -87,6 +87,22 @@ func SignGroupMembership(content string) string {
return string(data)
}
// GetNodeConfig returns the current config of the Status node
func GetNodeConfig() string {
conf, err := statusBackend.GetNodeConfig()
if err != nil {
return makeJSONResponse(err)
}
respJSON, err := json.Marshal(conf)
if err != nil {
return makeJSONResponse(err)
}
return string(respJSON)
}
// ValidateNodeConfig validates config for the Status node.
func ValidateNodeConfig(configJSON string) string {
var resp APIDetailedResponse