mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-23 17:47:24 +00:00
New RPC command to display the uptime of the server
Version 0.15.0 of Bitcoin Core will include a new RPC command that will allow us to obtain the amount of time (in seconds) that the server has been running.
This commit is contained in:
parent
6487ba1047
commit
948d80b198
5 changed files with 36 additions and 0 deletions
|
@ -671,6 +671,14 @@ func NewSubmitBlockCmd(hexBlock string, options *SubmitBlockOptions) *SubmitBloc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UptimeCmd defines the uptime JSON-RPC command.
|
||||||
|
type UptimeCmd struct{}
|
||||||
|
|
||||||
|
// NewUptimeCmd returns a new instance which can be used to issue an uptime JSON-RPC command.
|
||||||
|
func NewUptimeCmd() *UptimeCmd {
|
||||||
|
return &UptimeCmd{}
|
||||||
|
}
|
||||||
|
|
||||||
// ValidateAddressCmd defines the validateaddress JSON-RPC command.
|
// ValidateAddressCmd defines the validateaddress JSON-RPC command.
|
||||||
type ValidateAddressCmd struct {
|
type ValidateAddressCmd struct {
|
||||||
Address string
|
Address string
|
||||||
|
@ -777,6 +785,7 @@ func init() {
|
||||||
MustRegisterCmd("setgenerate", (*SetGenerateCmd)(nil), flags)
|
MustRegisterCmd("setgenerate", (*SetGenerateCmd)(nil), flags)
|
||||||
MustRegisterCmd("stop", (*StopCmd)(nil), flags)
|
MustRegisterCmd("stop", (*StopCmd)(nil), flags)
|
||||||
MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags)
|
MustRegisterCmd("submitblock", (*SubmitBlockCmd)(nil), flags)
|
||||||
|
MustRegisterCmd("uptime", (*UptimeCmd)(nil), flags)
|
||||||
MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
|
MustRegisterCmd("validateaddress", (*ValidateAddressCmd)(nil), flags)
|
||||||
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
|
MustRegisterCmd("verifychain", (*VerifyChainCmd)(nil), flags)
|
||||||
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
|
MustRegisterCmd("verifymessage", (*VerifyMessageCmd)(nil), flags)
|
||||||
|
|
|
@ -959,6 +959,17 @@ func TestChainSvrCmds(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "uptime",
|
||||||
|
newCmd: func() (interface{}, error) {
|
||||||
|
return btcjson.NewCmd("uptime")
|
||||||
|
},
|
||||||
|
staticCmd: func() interface{} {
|
||||||
|
return btcjson.NewUptimeCmd()
|
||||||
|
},
|
||||||
|
marshalled: `{"jsonrpc":"1.0","method":"uptime","params":[],"id":1}`,
|
||||||
|
unmarshalled: &btcjson.UptimeCmd{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "validateaddress",
|
name: "validateaddress",
|
||||||
newCmd: func() (interface{}, error) {
|
newCmd: func() (interface{}, error) {
|
||||||
|
|
|
@ -163,6 +163,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
|
||||||
"setgenerate": handleSetGenerate,
|
"setgenerate": handleSetGenerate,
|
||||||
"stop": handleStop,
|
"stop": handleStop,
|
||||||
"submitblock": handleSubmitBlock,
|
"submitblock": handleSubmitBlock,
|
||||||
|
"uptime": handleUptime,
|
||||||
"validateaddress": handleValidateAddress,
|
"validateaddress": handleValidateAddress,
|
||||||
"verifychain": handleVerifyChain,
|
"verifychain": handleVerifyChain,
|
||||||
"verifymessage": handleVerifyMessage,
|
"verifymessage": handleVerifyMessage,
|
||||||
|
@ -267,6 +268,7 @@ var rpcLimited = map[string]struct{}{
|
||||||
"searchrawtransactions": {},
|
"searchrawtransactions": {},
|
||||||
"sendrawtransaction": {},
|
"sendrawtransaction": {},
|
||||||
"submitblock": {},
|
"submitblock": {},
|
||||||
|
"uptime": {},
|
||||||
"validateaddress": {},
|
"validateaddress": {},
|
||||||
"verifymessage": {},
|
"verifymessage": {},
|
||||||
"version": {},
|
"version": {},
|
||||||
|
@ -3313,6 +3315,11 @@ func handleSubmitBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleUptime implements the uptime command.
|
||||||
|
func handleUptime(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||||
|
return time.Now().Unix() - s.server.startupTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
// handleValidateAddress implements the validateaddress command.
|
// handleValidateAddress implements the validateaddress command.
|
||||||
func handleValidateAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
func handleValidateAddress(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
|
||||||
c := cmd.(*btcjson.ValidateAddressCmd)
|
c := cmd.(*btcjson.ValidateAddressCmd)
|
||||||
|
|
|
@ -615,6 +615,10 @@ var helpDescsEnUS = map[string]string{
|
||||||
"rescannedblock-hash": "Hash of the matching block.",
|
"rescannedblock-hash": "Hash of the matching block.",
|
||||||
"rescannedblock-transactions": "List of matching transactions, serialized and hex-encoded.",
|
"rescannedblock-transactions": "List of matching transactions, serialized and hex-encoded.",
|
||||||
|
|
||||||
|
// Uptime help.
|
||||||
|
"uptime--synopsis": "Returns the total uptime of the server.",
|
||||||
|
"uptime--result0": "The number of seconds that the server has been running",
|
||||||
|
|
||||||
// Version help.
|
// Version help.
|
||||||
"version--synopsis": "Returns the JSON-RPC API version (semver)",
|
"version--synopsis": "Returns the JSON-RPC API version (semver)",
|
||||||
"version--result0--desc": "Version objects keyed by the program or API name",
|
"version--result0--desc": "Version objects keyed by the program or API name",
|
||||||
|
@ -672,6 +676,7 @@ var rpcResultTypes = map[string][]interface{}{
|
||||||
"setgenerate": nil,
|
"setgenerate": nil,
|
||||||
"stop": {(*string)(nil)},
|
"stop": {(*string)(nil)},
|
||||||
"submitblock": {nil, (*string)(nil)},
|
"submitblock": {nil, (*string)(nil)},
|
||||||
|
"uptime": {(*int64)(nil)},
|
||||||
"validateaddress": {(*btcjson.ValidateAddressChainResult)(nil)},
|
"validateaddress": {(*btcjson.ValidateAddressChainResult)(nil)},
|
||||||
"verifychain": {(*bool)(nil)},
|
"verifychain": {(*bool)(nil)},
|
||||||
"verifymessage": {(*bool)(nil)},
|
"verifymessage": {(*bool)(nil)},
|
||||||
|
|
|
@ -167,6 +167,7 @@ type server struct {
|
||||||
started int32
|
started int32
|
||||||
shutdown int32
|
shutdown int32
|
||||||
shutdownSched int32
|
shutdownSched int32
|
||||||
|
startupTime int64
|
||||||
|
|
||||||
chainParams *chaincfg.Params
|
chainParams *chaincfg.Params
|
||||||
addrManager *addrmgr.AddrManager
|
addrManager *addrmgr.AddrManager
|
||||||
|
@ -2003,6 +2004,9 @@ func (s *server) Start() {
|
||||||
|
|
||||||
srvrLog.Trace("Starting server")
|
srvrLog.Trace("Starting server")
|
||||||
|
|
||||||
|
// Server startup time. Used for the uptime command for uptime calculation.
|
||||||
|
s.startupTime = time.Now().Unix()
|
||||||
|
|
||||||
// Start the peer handler which in turn starts the address and block
|
// Start the peer handler which in turn starts the address and block
|
||||||
// managers.
|
// managers.
|
||||||
s.wg.Add(1)
|
s.wg.Add(1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue