add GetNodeConfig() function to backend API (#2216)
This commit is contained in:
parent
6037570901
commit
244686e3a8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue