Skip to content

Commit

Permalink
Add a GetCBFilter RPC command
Browse files Browse the repository at this point in the history
  • Loading branch information
martelletto authored and Roasbeef committed May 23, 2018
1 parent 43bf8db commit 76378e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions btcjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ func NewGetBlockTemplateCmd(request *TemplateRequest) *GetBlockTemplateCmd {
Request: request,
}
}
// GetCBFilterCmd defines the getcbfilter JSON-RPC command.
type GetCBFilterCmd struct {
Hash string
}

// NewGetCBFilterCmd returns a new instance which can be used to issue a
// getcbfilter JSON-RPC command.
func NewGetCBFilterCmd(hash string) *GetCBFilterCmd {
return &GetCBFilterCmd{
Hash: hash,
}
}

// GetChainTipsCmd defines the getchaintips JSON-RPC command.
type GetChainTipsCmd struct{}
Expand Down Expand Up @@ -756,6 +768,7 @@ func init() {
MustRegisterCmd("getblockhash", (*GetBlockHashCmd)(nil), flags)
MustRegisterCmd("getblockheader", (*GetBlockHeaderCmd)(nil), flags)
MustRegisterCmd("getblocktemplate", (*GetBlockTemplateCmd)(nil), flags)
MustRegisterCmd("getcbfilter", (*GetCBFilterCmd)(nil), flags)
MustRegisterCmd("getchaintips", (*GetChainTipsCmd)(nil), flags)
MustRegisterCmd("getconnectioncount", (*GetConnectionCountCmd)(nil), flags)
MustRegisterCmd("getdifficulty", (*GetDifficultyCmd)(nil), flags)
Expand Down
13 changes: 13 additions & 0 deletions btcjson/chainsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ func TestChainSvrCmds(t *testing.T) {
},
},
},
{
name: "getcbfilter",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getcbfilter", "123")
},
staticCmd: func() interface{} {
return btcjson.NewGetCBFilterCmd("123")
},
marshalled: `{"jsonrpc":"1.0","method":"getcbfilter","params":["123"],"id":1}`,
unmarshalled: &btcjson.GetCBFilterCmd{
Hash: "123",
},
},
{
name: "getchaintips",
newCmd: func() (interface{}, error) {
Expand Down
7 changes: 7 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ var rpcHandlersBeforeInit = map[string]commandHandler{
"getblockhash": handleGetBlockHash,
"getblockheader": handleGetBlockHeader,
"getblocktemplate": handleGetBlockTemplate,
"getcbfilter": handleGetCBFilter,
"getconnectioncount": handleGetConnectionCount,
"getcurrentnet": handleGetCurrentNet,
"getdifficulty": handleGetDifficulty,
Expand Down Expand Up @@ -258,6 +259,7 @@ var rpcLimited = map[string]struct{}{
"getblockcount": {},
"getblockhash": {},
"getblockheader": {},
"getcbfilter": {},
"getcurrentnet": {},
"getdifficulty": {},
"getheaders": {},
Expand Down Expand Up @@ -2144,6 +2146,11 @@ func handleGetBlockTemplate(s *rpcServer, cmd interface{}, closeChan <-chan stru
}
}

// handleGetCBFilter implements the getcbfilter command.
func handleGetCBFilter(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
return nil, nil
}

// handleGetConnectionCount implements the getconnectioncount command.
func handleGetConnectionCount(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) {
return s.cfg.ConnMgr.ConnectedCount(), nil
Expand Down
6 changes: 6 additions & 0 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ var helpDescsEnUS = map[string]string{
"getblocktemplate--condition2": "mode=proposal, accepted",
"getblocktemplate--result1": "An error string which represents why the proposal was rejected or nothing if accepted",

// GetCBFilterCmd help.
"getcbfilter--synopsis": "Returns a block's committed bloom filter given its hash.",
"getcbfilter-hash": "The hash of the block",
"getcbfilter--result0": "The block's committed bloom filter",

// GetConnectionCountCmd help.
"getconnectioncount--synopsis": "Returns the number of active connections to other peers.",
"getconnectioncount--result0": "The number of connections",
Expand Down Expand Up @@ -668,6 +673,7 @@ var rpcResultTypes = map[string][]interface{}{
"getblockheader": {(*string)(nil), (*btcjson.GetBlockHeaderVerboseResult)(nil)},
"getblocktemplate": {(*btcjson.GetBlockTemplateResult)(nil), (*string)(nil), nil},
"getblockchaininfo": {(*btcjson.GetBlockChainInfoResult)(nil)},
"getcbfilter": {(*[]byte)(nil)},
"getconnectioncount": {(*int32)(nil)},
"getcurrentnet": {(*uint32)(nil)},
"getdifficulty": {(*float64)(nil)},
Expand Down

0 comments on commit 76378e7

Please sign in to comment.