Skip to content

Commit

Permalink
Update dcrd JSON-RPC types module
Browse files Browse the repository at this point in the history
This also includes help descriptions for the new powhash fields for the
verbose getblock and getblockhash response objects, and populates the powhash
fields in the RPC handlers.

Backport of 30218b1 and
4abcbee.
  • Loading branch information
jrick committed Sep 27, 2023
1 parent bc7f095 commit a02926a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/decred/dcrd/dcrutil/v4 v4.0.1
github.com/decred/dcrd/gcs/v4 v4.0.0
github.com/decred/dcrd/hdkeychain/v3 v3.1.1
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0
github.com/decred/dcrd/rpcclient/v8 v8.0.0
github.com/decred/dcrd/txscript/v4 v4.1.0
github.com/decred/dcrd/wire v1.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ github.com/decred/dcrd/hdkeychain/v3 v3.1.1 h1:4WhyHNBy7ec6qBUC7Fq7JFVGSd7bpuR5H
github.com/decred/dcrd/hdkeychain/v3 v3.1.1/go.mod h1:HaabrLc27lnny5/Ph9+6I3szp0op5MCb7smEwlzfD60=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0 h1:4YUKsWKrKlkhVMYGRB6G0XI6QfwUnwEH18eoEbM1/+M=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0/go.mod h1:dDHO7ivrPAhZjFD3LoOJN/kdq5gi0sxie6zCsWHAiUo=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0 h1:kQFK7FMTmMDX9amyhh8IR0vwwI8dH0KCBm42C64bWVs=
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0/go.mod h1:dDHO7ivrPAhZjFD3LoOJN/kdq5gi0sxie6zCsWHAiUo=
github.com/decred/dcrd/rpcclient/v8 v8.0.0 h1:O4B5d+8e2OjbeFW+c1XcZNQzyp++04ArWhXgYrsURus=
github.com/decred/dcrd/rpcclient/v8 v8.0.0/go.mod h1:gx4+DI5apuOEeLwPBJFlMoj3GFWq1I7/X8XCQmMTi8Q=
github.com/decred/dcrd/txscript/v4 v4.0.0/go.mod h1:OJtxNc5RqwQyfrRnG2gG8uMeNPo8IAJp+TD1UKXkqk8=
Expand Down
20 changes: 20 additions & 0 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,8 +1278,18 @@ func (s *Server) getBlockHeader(ctx context.Context, icmd interface{}) (interfac
})
medianTime := timestamps[len(timestamps)/2]

// Determine the PoW hash. When the v1 PoW hash differs from the
// block hash, this is assumed to be v2 (DCP0011). More advanced
// selection logic will be necessary if the PoW hash changes again in
// the future.
powHash := blockHeader.PowHashV1()
if powHash != *blockHash {
powHash = blockHeader.PowHashV2()
}

return &dcrdtypes.GetBlockHeaderVerboseResult{
Hash: blockHash.String(),
PowHash: powHash.String(),
Confirmations: confirmations,
Version: blockHeader.Version,
MerkleRoot: blockHeader.MerkleRoot.String(),
Expand Down Expand Up @@ -1394,9 +1404,19 @@ func (s *Server) getBlock(ctx context.Context, icmd interface{}) (interface{}, e
})
medianTime := timestamps[len(timestamps)/2]

// Determine the PoW hash. When the v1 PoW hash differs from the
// block hash, this is assumed to be v2 (DCP0011). More advanced
// selection logic will be necessary if the PoW hash changes again in
// the future.
powHash := blockHeader.PowHashV1()
if powHash != *blockHash {
powHash = blockHeader.PowHashV2()
}

sbitsFloat := float64(blockHeader.SBits) / dcrutil.AtomsPerCoin
blockReply := dcrdtypes.GetBlockVerboseResult{
Hash: cmd.Hash,
PoWHash: powHash.String(),
Version: blockHeader.Version,
MerkleRoot: blockHeader.MerkleRoot.String(),
StakeRoot: blockHeader.StakeRoot.String(),
Expand Down
4 changes: 2 additions & 2 deletions internal/rpc/jsonrpc/rpcserverhelp.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions internal/rpchelp/helpdescs_en_US.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ var helpDescsEnUS = map[string]string{

// GetBlockHeaderVerboseResult help.
"getblockheaderverboseresult-hash": "The hash of the block (same as provided)",
"getblockheaderverboseresult-powhash": "The Proof-of-Work hash of the block (same as hash prior to DCP0011 activation)",
"getblockheaderverboseresult-confirmations": "The number of confirmations",
"getblockheaderverboseresult-height": "The height of the block in the block chain",
"getblockheaderverboseresult-version": "The block version",
Expand Down Expand Up @@ -231,6 +232,7 @@ var helpDescsEnUS = map[string]string{

// GetBlockVerboseResult help.
"getblockverboseresult-hash": "The hash of the block (same as provided)",
"getblockverboseresult-powhash": "The Proof-of-Work hash of the block (same as hash prior to DCP0011 activation)",
"getblockverboseresult-confirmations": "The number of confirmations",
"getblockverboseresult-size": "The size of the block",
"getblockverboseresult-height": "The height of the block in the block chain",
Expand Down

0 comments on commit a02926a

Please sign in to comment.