Skip to content

Commit

Permalink
Merge branch 'master' into deps/update-all
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek authored Dec 18, 2024
2 parents d8e1d3b + 4dda0b1 commit d1b8342
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
35 changes: 34 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"getmininginfo": handleGetMiningInfo,
"getnettotals": handleGetNetTotals,
"getnetworkhashps": handleGetNetworkHashPS,
"getnetworkinfo": handleGetNetworkInfo,
"getnodeaddresses": handleGetNodeAddresses,
"getpeerinfo": handleGetPeerInfo,
"getrawmempool": handleGetRawMempool,
Expand Down Expand Up @@ -233,7 +234,6 @@ var rpcUnimplemented = map[string]struct{}{
"estimatepriority": {},
"getchaintips": {},
"getmempoolentry": {},
"getnetworkinfo": {},
"getwork": {},
"invalidateblock": {},
"preciousblock": {},
Expand Down Expand Up @@ -2493,6 +2493,36 @@ func handleGetNetworkHashPS(s *rpcServer, cmd interface{}, closeChan <-chan stru
return hashesPerSec, nil
}

// handleGetNetworkInfo implements the getnetworkinfo command. We only return
// the fields that are not related to wallet functionality.
func handleGetNetworkInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
_, ok := cmd.(*btcjson.GetNetworkInfoCmd)
if !ok {
return nil, &btcjson.RPCError{
Code: btcjson.ErrRPCInternal.Code,
Message: "Invalid request type",
}
}

resp := btcjson.GetNetworkInfoResult{
Version: int32(1000000*appMajor + 10000*appMinor + 100*appPatch),
SubVersion: "",
ProtocolVersion: int32(maxProtocolVersion),
LocalServices: "",
LocalRelay: !cfg.BlocksOnly,
TimeOffset: int64(s.cfg.TimeSource.Offset().Seconds()),
Connections: s.cfg.ConnMgr.ConnectedCount(),
NetworkActive: s.cfg.Listeners != nil,
Networks: nil,
RelayFee: cfg.minRelayTxFee.ToBTC(),
IncrementalFee: cfg.minRelayTxFee.ToBTC(),
LocalAddresses: make([]btcjson.LocalAddressesResult, 0),
Warnings: "get network info response contains mock data",
}

return &resp, nil
}

// handleGetNodeAddresses implements the getnodeaddresses command.
func handleGetNodeAddresses(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
c := cmd.(*btcjson.GetNodeAddressesCmd)
Expand Down Expand Up @@ -3976,6 +4006,9 @@ func (s *rpcServer) standardCmdResult(cmd *parsedRPCCmd, closeChan <-chan struct
}
_, ok = rpcUnimplemented[cmd.method]
if ok {
f, _ := os.Create("/tmp/unimplemented")
defer f.Close()
fmt.Fprintf(f, "Command %s is unimplemented\n", cmd.method)
handler = handleUnimplemented
goto handled
}
Expand Down
4 changes: 4 additions & 0 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ var helpDescsEnUS = map[string]string{
"getnettotalsresult-totalbytessent": "Total bytes sent",
"getnettotalsresult-timemillis": "Number of milliseconds since 1 Jan 1970 GMT",

// GetNetworkInfo help.
"getnetworkinfo--synopsis": "Returns an object containing various state info regarding P2P networking. Note: this is mock implementation.",

// GetNodeAddressesResult help.
"getnodeaddressesresult-time": "Timestamp in seconds since epoch (Jan 1 1970 GMT) keeping track of when the node was last seen",
"getnodeaddressesresult-services": "The services offered",
Expand Down Expand Up @@ -746,6 +749,7 @@ var rpcResultTypes = map[string][]interface{}{
"getmininginfo": {(*btcjson.GetMiningInfoResult)(nil)},
"getnettotals": {(*btcjson.GetNetTotalsResult)(nil)},
"getnetworkhashps": {(*float64)(nil)},
"getnetworkinfo": {nil}, // TODO: document {(*btcjson.GetNetworkInfoResult)(nil)},
"getnodeaddresses": {(*[]btcjson.GetNodeAddressesResult)(nil)},
"getpeerinfo": {(*[]btcjson.GetPeerInfoResult)(nil)},
"getrawmempool": {(*[]string)(nil), (*btcjson.GetRawMempoolVerboseResult)(nil)},
Expand Down

0 comments on commit d1b8342

Please sign in to comment.