From 6626f7abaf4834c79e7915913de59bb1fb52f82f Mon Sep 17 00:00:00 2001 From: Mikael Lindlof Date: Tue, 26 May 2020 23:52:23 +0100 Subject: [PATCH] Add type for second getblockfilter param --- btcjson/chainsvrcmds.go | 15 ++++++++++++--- rpcclient/chain.go | 6 +++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/btcjson/chainsvrcmds.go b/btcjson/chainsvrcmds.go index 5619248a5b..26fe5ff63f 100644 --- a/btcjson/chainsvrcmds.go +++ b/btcjson/chainsvrcmds.go @@ -163,10 +163,19 @@ func NewGetBlockCountCmd() *GetBlockCountCmd { return &GetBlockCountCmd{} } +// FilterTypeName defines the type used in the getblockfilter JSON-RPC command for the +// filter type field. +type FilterTypeName string + +const ( + // Basic is the basic filter type defined in BIP0158. + FilterTypeBasic FilterTypeName = "basic" +) + // GetBlockFilterCmd defines the getblockfilter JSON-RPC command. type GetBlockFilterCmd struct { - BlockHash string // The hash of the block - FilterType *string // The type name of the filter, default=basic + BlockHash string // The hash of the block + FilterType *FilterTypeName // The type name of the filter, default=basic } // NewGetBlockFilterCmd returns a new instance which can be used to issue a @@ -174,7 +183,7 @@ type GetBlockFilterCmd struct { // // The parameters which are pointers indicate they are optional. Passing nil // for optional parameters will use the default value. -func NewGetBlockFilterCmd(blockHash string, filterType *string) *GetBlockFilterCmd { +func NewGetBlockFilterCmd(blockHash string, filterType *FilterTypeName) *GetBlockFilterCmd { return &GetBlockFilterCmd{ BlockHash: blockHash, FilterType: filterType, diff --git a/rpcclient/chain.go b/rpcclient/chain.go index 84689e271e..dbcc0621e1 100644 --- a/rpcclient/chain.go +++ b/rpcclient/chain.go @@ -388,15 +388,15 @@ func (r FutureGetBlockFilterResult) Receive() (*btcjson.GetBlockFilterResult, er // returned instance. // // See GetBlockFilter for the blocking version and more details. -func (c *Client) GetBlockFilterAsync(blockHash chainhash.Hash, filterType *string) FutureGetBlockFilterResult { +func (c *Client) GetBlockFilterAsync(blockHash chainhash.Hash, filterType *btcjson.FilterTypeName) FutureGetBlockFilterResult { hash := blockHash.String() cmd := btcjson.NewGetBlockFilterCmd(hash, filterType) return c.sendCmd(cmd) } -// GetBlockFilter retrieves a BIP 157 content filter for a particular block. -func (c *Client) GetBlockFilter(blockHash chainhash.Hash, filterType *string) (*btcjson.GetBlockFilterResult, error) { +// GetBlockFilter retrieves a BIP0157 content filter for a particular block. +func (c *Client) GetBlockFilter(blockHash chainhash.Hash, filterType *btcjson.FilterTypeName) (*btcjson.GetBlockFilterResult, error) { return c.GetBlockFilterAsync(blockHash, filterType).Receive() }