Skip to content

Commit

Permalink
rpcclient: Use dcrjson/v3.
Browse files Browse the repository at this point in the history
This updates the rpcclient module to use v3 of the dcrjson module and v1
of the newly introduced rpc/jsonrpc/types module which now provides the
chain types separately in the same way the wallet types are separate.
  • Loading branch information
davecgh committed Jul 22, 2019
1 parent ac5a935 commit fd3e180
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 259 deletions.
109 changes: 55 additions & 54 deletions rpcclient/chain.go

Large diffs are not rendered by default.

169 changes: 85 additions & 84 deletions rpcclient/extensions.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion rpcclient/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/dchest/siphash v1.2.1 // indirect
github.com/decred/dcrd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/dcrjson/v2 v2.2.0
github.com/decred/dcrd/dcrjson/v3 v3.0.0
github.com/decred/dcrd/dcrutil v1.4.0
github.com/decred/dcrd/gcs v1.0.2
github.com/decred/dcrd/hdkeychain/v2 v2.0.0
github.com/decred/dcrd/rpc/jsonrpc/types v1.0.0
github.com/decred/dcrd/wire v1.2.0
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.1.0
github.com/decred/go-socks v1.0.0
Expand Down
2 changes: 0 additions & 2 deletions rpcclient/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ github.com/decred/dcrd/dcrec/secp256k1 v1.0.1 h1:EFWVd1p0t0Y5tnsm/dJujgV0ORogRJ6
github.com/decred/dcrd/dcrec/secp256k1 v1.0.1/go.mod h1:lhu4eZFSfTJWUnR3CFRcpD+Vta0KUAqnhTsTksHXgy0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2 h1:awk7sYJ4pGWmtkiGHFfctztJjHMKGLV8jctGQhAbKe0=
github.com/decred/dcrd/dcrec/secp256k1 v1.0.2/go.mod h1:CHTUIVfmDDd0KFVFpNX1pFVCBUegxW387nN0IGwNKR0=
github.com/decred/dcrd/dcrjson/v2 v2.2.0 h1:u0ON3IZ8/fqoA624HPNBsWYjIgBtC82DGMtq35bthhI=
github.com/decred/dcrd/dcrjson/v2 v2.2.0/go.mod h1:/vbjikqJR0MVih59iOMtPjRyN5lVRDzJHHfqzHAln2Y=
github.com/decred/dcrd/dcrjson/v3 v3.0.0 h1:yDrNFvyn2l/557iZHB236jTqQjAmhZnVaFgMb2vm0UM=
github.com/decred/dcrd/dcrjson/v3 v3.0.0/go.mod h1:pWYlHJ3VFidPwqD5HHiJXjfGaplif8uspAL2qFdifkY=
github.com/decred/dcrd/dcrutil v1.1.1 h1:zOkGiumN/JkobhAgpG/zfFgUoolGKVGYT5na1hbYUoE=
Expand Down
15 changes: 8 additions & 7 deletions rpcclient/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (

"github.com/gorilla/websocket"

"github.com/decred/dcrd/dcrjson/v2"
"github.com/decred/dcrd/dcrjson/v3"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
"github.com/decred/go-socks/socks"
)

Expand Down Expand Up @@ -260,22 +261,22 @@ func (c *Client) trackRegisteredNtfns(cmd interface{}) {
defer c.ntfnStateLock.Unlock()

switch bcmd := cmd.(type) {
case *dcrjson.NotifyWinningTicketsCmd:
case *chainjson.NotifyWinningTicketsCmd:
c.ntfnState.notifyWinningTickets = true

case *dcrjson.NotifySpentAndMissedTicketsCmd:
case *chainjson.NotifySpentAndMissedTicketsCmd:
c.ntfnState.notifySpentAndMissedTickets = true

case *dcrjson.NotifyNewTicketsCmd:
case *chainjson.NotifyNewTicketsCmd:
c.ntfnState.notifyNewTickets = true

case *dcrjson.NotifyStakeDifficultyCmd:
case *chainjson.NotifyStakeDifficultyCmd:
c.ntfnState.notifyStakeDifficulty = true

case *dcrjson.NotifyBlocksCmd:
case *chainjson.NotifyBlocksCmd:
c.ntfnState.notifyBlocks = true

case *dcrjson.NotifyNewTransactionsCmd:
case *chainjson.NotifyNewTransactionsCmd:
if bcmd.Verbose != nil && *bcmd.Verbose {
c.ntfnState.notifyNewTxVerbose = true
} else {
Expand Down
50 changes: 25 additions & 25 deletions rpcclient/mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"errors"

"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrjson/v2"
"github.com/decred/dcrd/dcrutil"
chainjson "github.com/decred/dcrd/rpc/jsonrpc/types"
)

// FutureGenerateResult is a future promise to deliver the result of a
Expand Down Expand Up @@ -53,7 +53,7 @@ func (r FutureGenerateResult) Receive() ([]*chainhash.Hash, error) {
//
// See Generate for the blocking version and more details.
func (c *Client) GenerateAsync(numBlocks uint32) FutureGenerateResult {
cmd := dcrjson.NewGenerateCmd(numBlocks)
cmd := chainjson.NewGenerateCmd(numBlocks)
return c.sendCmd(cmd)
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func (r FutureGetGenerateResult) Receive() (bool, error) {
//
// See GetGenerate for the blocking version and more details.
func (c *Client) GetGenerateAsync() FutureGetGenerateResult {
cmd := dcrjson.NewGetGenerateCmd()
cmd := chainjson.NewGetGenerateCmd()
return c.sendCmd(cmd)
}

Expand All @@ -116,7 +116,7 @@ func (r FutureSetGenerateResult) Receive() error {
//
// See SetGenerate for the blocking version and more details.
func (c *Client) SetGenerateAsync(enable bool, numCPUs int) FutureSetGenerateResult {
cmd := dcrjson.NewSetGenerateCmd(enable, &numCPUs)
cmd := chainjson.NewSetGenerateCmd(enable, &numCPUs)
return c.sendCmd(cmd)
}

Expand Down Expand Up @@ -154,7 +154,7 @@ func (r FutureGetHashesPerSecResult) Receive() (int64, error) {
//
// See GetHashesPerSec for the blocking version and more details.
func (c *Client) GetHashesPerSecAsync() FutureGetHashesPerSecResult {
cmd := dcrjson.NewGetHashesPerSecCmd()
cmd := chainjson.NewGetHashesPerSecCmd()
return c.sendCmd(cmd)
}

Expand All @@ -171,14 +171,14 @@ type FutureGetMiningInfoResult chan *response

// Receive waits for the response promised by the future and returns the mining
// information.
func (r FutureGetMiningInfoResult) Receive() (*dcrjson.GetMiningInfoResult, error) {
func (r FutureGetMiningInfoResult) Receive() (*chainjson.GetMiningInfoResult, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}

// Unmarshal result as a getmininginfo result object.
var infoResult dcrjson.GetMiningInfoResult
var infoResult chainjson.GetMiningInfoResult
err = json.Unmarshal(res, &infoResult)
if err != nil {
return nil, err
Expand All @@ -193,12 +193,12 @@ func (r FutureGetMiningInfoResult) Receive() (*dcrjson.GetMiningInfoResult, erro
//
// See GetMiningInfo for the blocking version and more details.
func (c *Client) GetMiningInfoAsync() FutureGetMiningInfoResult {
cmd := dcrjson.NewGetMiningInfoCmd()
cmd := chainjson.NewGetMiningInfoCmd()
return c.sendCmd(cmd)
}

// GetMiningInfo returns mining information.
func (c *Client) GetMiningInfo() (*dcrjson.GetMiningInfoResult, error) {
func (c *Client) GetMiningInfo() (*chainjson.GetMiningInfoResult, error) {
return c.GetMiningInfoAsync().Receive()
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (r FutureGetNetworkHashPS) Receive() (int64, error) {
//
// See GetNetworkHashPS for the blocking version and more details.
func (c *Client) GetNetworkHashPSAsync() FutureGetNetworkHashPS {
cmd := dcrjson.NewGetNetworkHashPSCmd(nil, nil)
cmd := chainjson.NewGetNetworkHashPSCmd(nil, nil)
return c.sendCmd(cmd)
}

Expand All @@ -250,7 +250,7 @@ func (c *Client) GetNetworkHashPS() (int64, error) {
//
// See GetNetworkHashPS2 for the blocking version and more details.
func (c *Client) GetNetworkHashPS2Async(blocks int) FutureGetNetworkHashPS {
cmd := dcrjson.NewGetNetworkHashPSCmd(&blocks, nil)
cmd := chainjson.NewGetNetworkHashPSCmd(&blocks, nil)
return c.sendCmd(cmd)
}

Expand All @@ -271,7 +271,7 @@ func (c *Client) GetNetworkHashPS2(blocks int) (int64, error) {
//
// See GetNetworkHashPS3 for the blocking version and more details.
func (c *Client) GetNetworkHashPS3Async(blocks, height int) FutureGetNetworkHashPS {
cmd := dcrjson.NewGetNetworkHashPSCmd(&blocks, &height)
cmd := chainjson.NewGetNetworkHashPSCmd(&blocks, &height)
return c.sendCmd(cmd)
}

Expand All @@ -291,14 +291,14 @@ type FutureGetWork chan *response

// Receive waits for the response promised by the future and returns the hash
// data to work on.
func (r FutureGetWork) Receive() (*dcrjson.GetWorkResult, error) {
func (r FutureGetWork) Receive() (*chainjson.GetWorkResult, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}

// Unmarshal result as a getwork result object.
var result dcrjson.GetWorkResult
var result chainjson.GetWorkResult
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
Expand All @@ -313,14 +313,14 @@ func (r FutureGetWork) Receive() (*dcrjson.GetWorkResult, error) {
//
// See GetWork for the blocking version and more details.
func (c *Client) GetWorkAsync() FutureGetWork {
cmd := dcrjson.NewGetWorkCmd(nil)
cmd := chainjson.NewGetWorkCmd(nil)
return c.sendCmd(cmd)
}

// GetWork returns hash data to work on.
//
// See GetWorkSubmit to submit the found solution.
func (c *Client) GetWork() (*dcrjson.GetWorkResult, error) {
func (c *Client) GetWork() (*chainjson.GetWorkResult, error) {
return c.GetWorkAsync().Receive()
}

Expand Down Expand Up @@ -352,7 +352,7 @@ func (r FutureGetWorkSubmit) Receive() (bool, error) {
//
// See GetWorkSubmit for the blocking version and more details.
func (c *Client) GetWorkSubmitAsync(data string) FutureGetWorkSubmit {
cmd := dcrjson.NewGetWorkCmd(&data)
cmd := chainjson.NewGetWorkCmd(&data)
return c.sendCmd(cmd)
}

Expand All @@ -370,14 +370,14 @@ type FutureGetBlockTemplate chan *response

// Receive waits for the response promised by the future and returns an error if
// any occurred while generating the block template.
func (r FutureGetBlockTemplate) Receive() (*dcrjson.GetBlockTemplateResult, error) {
func (r FutureGetBlockTemplate) Receive() (*chainjson.GetBlockTemplateResult, error) {
res, err := receiveFuture(r)
if err != nil {
return nil, err
}

// Unmarshal result.
var gbt dcrjson.GetBlockTemplateResult
var gbt chainjson.GetBlockTemplateResult
err = json.Unmarshal(res, &gbt)
if err != nil {
return nil, err
Expand All @@ -391,15 +391,15 @@ func (r FutureGetBlockTemplate) Receive() (*dcrjson.GetBlockTemplateResult, erro
// on the returned instance.
//
// See GetBlockTemplate for the blocking version and more details.
func (c *Client) GetBlockTemplateAsync(req *dcrjson.TemplateRequest) FutureGetBlockTemplate {
cmd := dcrjson.NewGetBlockTemplateCmd(req)
func (c *Client) GetBlockTemplateAsync(req *chainjson.TemplateRequest) FutureGetBlockTemplate {
cmd := chainjson.NewGetBlockTemplateCmd(req)
return c.sendCmd(cmd)
}

// GetBlockTemplate returns a block template to work on.
//
// See SubmitBlock to submit the found solution.
func (c *Client) GetBlockTemplate(req *dcrjson.TemplateRequest) (*dcrjson.GetBlockTemplateResult, error) {
func (c *Client) GetBlockTemplate(req *chainjson.TemplateRequest) (*chainjson.GetBlockTemplateResult, error) {
return c.GetBlockTemplateAsync(req).Receive()
}

Expand Down Expand Up @@ -434,7 +434,7 @@ func (r FutureSubmitBlockResult) Receive() error {
// returned instance.
//
// See SubmitBlock for the blocking version and more details.
func (c *Client) SubmitBlockAsync(block *dcrutil.Block, options *dcrjson.SubmitBlockOptions) FutureSubmitBlockResult {
func (c *Client) SubmitBlockAsync(block *dcrutil.Block, options *chainjson.SubmitBlockOptions) FutureSubmitBlockResult {
blockHex := ""
if block != nil {
blockBytes, err := block.Bytes()
Expand All @@ -445,11 +445,11 @@ func (c *Client) SubmitBlockAsync(block *dcrutil.Block, options *dcrjson.SubmitB
blockHex = hex.EncodeToString(blockBytes)
}

cmd := dcrjson.NewSubmitBlockCmd(blockHex, options)
cmd := chainjson.NewSubmitBlockCmd(blockHex, options)
return c.sendCmd(cmd)
}

// SubmitBlock attempts to submit a new block into the Decred network.
func (c *Client) SubmitBlock(block *dcrutil.Block, options *dcrjson.SubmitBlockOptions) error {
func (c *Client) SubmitBlock(block *dcrutil.Block, options *chainjson.SubmitBlockOptions) error {
return c.SubmitBlockAsync(block, options).Receive()
}
Loading

0 comments on commit fd3e180

Please sign in to comment.