Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ListSinceBlockMinConfWatchOnly method. #1451

Merged
merged 1 commit into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions btcjson/walletsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,21 @@ func TestWalletSvrCmds(t *testing.T) {
IncludeWatchOnly: btcjson.Bool(true),
},
},
{
name: "listsinceblock pad null",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("listsinceblock", "null", 1, false)
},
staticCmd: func() interface{} {
return btcjson.NewListSinceBlockCmd(nil, btcjson.Int(1), btcjson.Bool(false))
},
marshalled: `{"jsonrpc":"1.0","method":"listsinceblock","params":[null,1,false],"id":1}`,
unmarshalled: &btcjson.ListSinceBlockCmd{
BlockHash: nil,
TargetConfirmations: btcjson.Int(1),
IncludeWatchOnly: btcjson.Bool(false),
},
},
{
name: "listtransactions",
newCmd: func() (interface{}, error) {
Expand Down
25 changes: 25 additions & 0 deletions rpcclient/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func (c *Client) ListSinceBlockAsync(blockHash *chainhash.Hash) FutureListSinceB
// minimum confirmations as a filter.
//
// See ListSinceBlockMinConf to override the minimum number of confirmations.
// See ListSinceBlockMinConfWatchOnly to override the minimum number of confirmations and watch only parameter.
func (c *Client) ListSinceBlock(blockHash *chainhash.Hash) (*btcjson.ListSinceBlockResult, error) {
return c.ListSinceBlockAsync(blockHash).Receive()
}
Expand Down Expand Up @@ -354,6 +355,30 @@ func (c *Client) ListSinceBlockMinConf(blockHash *chainhash.Hash, minConfirms in
return c.ListSinceBlockMinConfAsync(blockHash, minConfirms).Receive()
}

// ListSinceBlockMinConfWatchOnlyAsync returns an instance of a type that can be used to
// get the result of the RPC at some future time by invoking the Receive
// function on the returned instance.
//
// See ListSinceBlockMinConfWatchOnly for the blocking version and more details.
func (c *Client) ListSinceBlockMinConfWatchOnlyAsync(blockHash *chainhash.Hash, minConfirms int, watchOnly bool) FutureListSinceBlockResult {
var hash *string
if blockHash != nil {
hash = btcjson.String(blockHash.String())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably won't work if you want to do something like list all watch-only transactions with the following call:

ListSinceBlockMinConfWatchOnlyAsync(nil, 1, true)

Here's a workaround, although I'm not sure if it's the best solution.

Suggested change
}
} else {
hash = btcjson.String("")
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to #1594, we may not need to do this. Could you please verify this on your side?


cmd := btcjson.NewListSinceBlockCmd(hash, &minConfirms, &watchOnly)
return c.sendCmd(cmd)
}

// ListSinceBlockMinConfWatchOnly returns all transactions added in blocks since the
// specified block hash, or all transactions if it is nil, using the specified
// number of minimum confirmations as a filter.
//
// See ListSinceBlock to use the default minimum number of confirmations and default watch only paremeter.
func (c *Client) ListSinceBlockMinConfWatchOnly(blockHash *chainhash.Hash, minConfirms int, watchOnly bool) (*btcjson.ListSinceBlockResult, error) {
return c.ListSinceBlockMinConfWatchOnlyAsync(blockHash, minConfirms, watchOnly).Receive()
}

// **************************
// Transaction Send Functions
// **************************
Expand Down