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

Change getblock default verbosity to 1 #1560

Merged
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
2 changes: 1 addition & 1 deletion btcjson/chainsvrcmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func NewGetBestBlockHashCmd() *GetBestBlockHashCmd {
// GetBlockCmd defines the getblock JSON-RPC command.
type GetBlockCmd struct {
Hash string
Verbosity *int `jsonrpcdefault:"0"`
Verbosity *int `jsonrpcdefault:"1"`
}

// NewGetBlockCmd returns a new instance which can be used to issue a getblock
Expand Down
14 changes: 14 additions & 0 deletions btcjson/chainsvrcmds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ func TestChainSvrCmds(t *testing.T) {
Verbosity: btcjson.Int(0),
},
},
{
name: "getblock default verbosity",
newCmd: func() (interface{}, error) {
return btcjson.NewCmd("getblock", "123")
},
staticCmd: func() interface{} {
return btcjson.NewGetBlockCmd("123", nil)
},
marshalled: `{"jsonrpc":"1.0","method":"getblock","params":["123"],"id":1}`,
unmarshalled: &btcjson.GetBlockCmd{
Hash: "123",
Verbosity: btcjson.Int(1),
},
},
{
name: "getblock required optional1",
newCmd: func() (interface{}, error) {
Expand Down
2 changes: 1 addition & 1 deletion btcjson/cmdinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestMethodUsageText(t *testing.T) {
{
name: "getblock",
method: "getblock",
expected: `getblock "hash" (verbosity=0)`,
expected: `getblock "hash" (verbosity=1)`,
},
}

Expand Down
2 changes: 1 addition & 1 deletion rpcclient/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *Client) GetBlockAsync(blockHash *chainhash.Hash) FutureGetBlockResult {
hash = blockHash.String()
}

cmd := btcjson.NewGetBlockCmd(hash, nil)
cmd := btcjson.NewGetBlockCmd(hash, btcjson.Int(0))
return c.sendCmd(cmd)
}

Expand Down
6 changes: 2 additions & 4 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,14 +1081,12 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
Message: "Block not found",
}
}

// When the verbose flag isn't set, simply return the serialized block
// as a hex-encoded string.
// If verbosity is 0, return the serialized block as a hex encoded string.
if c.Verbosity != nil && *c.Verbosity == 0 {
return hex.EncodeToString(blkBytes), nil
}

// The verbose flag is set, so generate the JSON object and return it.
// Otherwise, generate the JSON object and return it.

// Deserialize the block.
blk, err := btcutil.NewBlockFromBytes(blkBytes)
Expand Down
4 changes: 2 additions & 2 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ var helpDescsEnUS = map[string]string{
"getblockverboseresult-version": "The block version",
"getblockverboseresult-versionHex": "The block version in hexadecimal",
"getblockverboseresult-merkleroot": "Root hash of the merkle tree",
"getblockverboseresult-tx": "The transaction hashes (only when verbosetx=false)",
"getblockverboseresult-rawtx": "The transactions as JSON objects (only when verbosetx=true)",
"getblockverboseresult-tx": "The transaction hashes (only when verbosity=1)",
"getblockverboseresult-rawtx": "The transactions as JSON objects (only when verbosity=2)",
wpaulino marked this conversation as resolved.
Show resolved Hide resolved
"getblockverboseresult-time": "The block time in seconds since 1 Jan 1970 GMT",
"getblockverboseresult-nonce": "The block nonce",
"getblockverboseresult-bits": "The bits which represent the block difficulty",
Expand Down