implement the getinfo rpc command.
This contains some wallet inforamtion, but bitcoind if wallet is disabled returns just the non wallet information. we do the same.
This commit is contained in:
parent
042d9206a1
commit
82fca37eae
2 changed files with 35 additions and 1 deletions
30
rpcserver.go
30
rpcserver.go
|
@ -63,6 +63,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
|
|||
"getdifficulty": handleGetDifficulty,
|
||||
"getgenerate": handleGetGenerate,
|
||||
"gethashespersec": handleGetHashesPerSec,
|
||||
"getinfo": handleGetInfo,
|
||||
"getpeerinfo": handleGetPeerInfo,
|
||||
"getrawmempool": handleGetRawMempool,
|
||||
"getrawtransaction": handleGetRawTransaction,
|
||||
|
@ -94,7 +95,6 @@ var rpcAskWallet = map[string]bool{
|
|||
"getaddressesbyaccount": true,
|
||||
"getbalance": true,
|
||||
"getblocktemplate": true,
|
||||
"getinfo": true,
|
||||
"getnewaddress": true,
|
||||
"getrawchangeaddress": true,
|
||||
"getreceivedbyaccount": true,
|
||||
|
@ -950,6 +950,34 @@ func handleGetHashesPerSec(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
// handleGetInfo implements the getinfo command. We only return the fields
|
||||
// that are not related to wallet functionality.
|
||||
func handleGetInfo(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
|
||||
// We require the current block height and sha.
|
||||
sha, height, err := s.server.db.NewestSha()
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Error getting sha: %v", err)
|
||||
return nil, btcjson.ErrBlockCount
|
||||
}
|
||||
blkHeader, err := s.server.db.FetchBlockHeaderBySha(sha)
|
||||
if err != nil {
|
||||
rpcsLog.Errorf("Error getting block: %v", err)
|
||||
return nil, btcjson.ErrDifficulty
|
||||
}
|
||||
|
||||
ret := map[string]interface{}{
|
||||
"version": 1000000*appMajor + 10000*appMinor + 100*appPatch,
|
||||
"protocolversion": btcwire.ProtocolVersion,
|
||||
"blocks": height,
|
||||
"timeoffset": 0,
|
||||
"proxy": cfg.Proxy,
|
||||
"difficulty": getDifficultyRatio(blkHeader.Bits),
|
||||
"testnet": cfg.TestNet3,
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// handleGetPeerInfo implements the getpeerinfo command.
|
||||
func handleGetPeerInfo(s *rpcServer, cmd btcjson.Cmd) (interface{}, error) {
|
||||
return s.server.PeerInfo(), nil
|
||||
|
|
|
@ -65,6 +65,7 @@ var commandHandlers = map[string]*handlerData{
|
|||
"getdifficulty": &handlerData{0, 0, displayFloat64, nil, makeGetDifficulty, ""},
|
||||
"getgenerate": &handlerData{0, 0, displayGeneric, nil, makeGetGenerate, ""},
|
||||
"gethashespersec": &handlerData{0, 0, displayGeneric, nil, makeGetHashesPerSec, ""},
|
||||
"getinfo": &handlerData{0, 0, displayJSONDump, nil, makeGetInfo, ""},
|
||||
"getnewaddress": &handlerData{0, 1, displayGeneric, nil, makeGetNewAddress, "[account]"},
|
||||
"getpeerinfo": &handlerData{0, 0, displayJSONDump, nil, makeGetPeerInfo, ""},
|
||||
"getrawmempool": &handlerData{0, 1, displayJSONDump, []conversionHandler{toBool}, makeGetRawMempool, "[verbose=false]"},
|
||||
|
@ -355,6 +356,11 @@ func makeGetHashesPerSec(args []interface{}) (btcjson.Cmd, error) {
|
|||
return btcjson.NewGetHashesPerSecCmd("btcctl")
|
||||
}
|
||||
|
||||
// makeGetInfo generates the cmd structure for getinfo commands.
|
||||
func makeGetInfo(args []interface{}) (btcjson.Cmd, error) {
|
||||
return btcjson.NewGetInfoCmd("btcctl")
|
||||
}
|
||||
|
||||
// makeGetNewAddress generates the cmd structure for getnewaddress commands.
|
||||
func makeGetNewAddress(args []interface{}) (btcjson.Cmd, error) {
|
||||
var account string
|
||||
|
|
Loading…
Reference in a new issue