Skip to content

Commit a02926a

Browse files
committed
Update dcrd JSON-RPC types module
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.
1 parent bc7f095 commit a02926a

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/decred/dcrd/dcrutil/v4 v4.0.1
2121
github.com/decred/dcrd/gcs/v4 v4.0.0
2222
github.com/decred/dcrd/hdkeychain/v3 v3.1.1
23-
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0
23+
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0
2424
github.com/decred/dcrd/rpcclient/v8 v8.0.0
2525
github.com/decred/dcrd/txscript/v4 v4.1.0
2626
github.com/decred/dcrd/wire v1.6.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ github.com/decred/dcrd/hdkeychain/v3 v3.1.1 h1:4WhyHNBy7ec6qBUC7Fq7JFVGSd7bpuR5H
7272
github.com/decred/dcrd/hdkeychain/v3 v3.1.1/go.mod h1:HaabrLc27lnny5/Ph9+6I3szp0op5MCb7smEwlzfD60=
7373
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0 h1:4YUKsWKrKlkhVMYGRB6G0XI6QfwUnwEH18eoEbM1/+M=
7474
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.0.0/go.mod h1:dDHO7ivrPAhZjFD3LoOJN/kdq5gi0sxie6zCsWHAiUo=
75+
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0 h1:kQFK7FMTmMDX9amyhh8IR0vwwI8dH0KCBm42C64bWVs=
76+
github.com/decred/dcrd/rpc/jsonrpc/types/v4 v4.1.0/go.mod h1:dDHO7ivrPAhZjFD3LoOJN/kdq5gi0sxie6zCsWHAiUo=
7577
github.com/decred/dcrd/rpcclient/v8 v8.0.0 h1:O4B5d+8e2OjbeFW+c1XcZNQzyp++04ArWhXgYrsURus=
7678
github.com/decred/dcrd/rpcclient/v8 v8.0.0/go.mod h1:gx4+DI5apuOEeLwPBJFlMoj3GFWq1I7/X8XCQmMTi8Q=
7779
github.com/decred/dcrd/txscript/v4 v4.0.0/go.mod h1:OJtxNc5RqwQyfrRnG2gG8uMeNPo8IAJp+TD1UKXkqk8=

internal/rpc/jsonrpc/methods.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,18 @@ func (s *Server) getBlockHeader(ctx context.Context, icmd interface{}) (interfac
12781278
})
12791279
medianTime := timestamps[len(timestamps)/2]
12801280

1281+
// Determine the PoW hash. When the v1 PoW hash differs from the
1282+
// block hash, this is assumed to be v2 (DCP0011). More advanced
1283+
// selection logic will be necessary if the PoW hash changes again in
1284+
// the future.
1285+
powHash := blockHeader.PowHashV1()
1286+
if powHash != *blockHash {
1287+
powHash = blockHeader.PowHashV2()
1288+
}
1289+
12811290
return &dcrdtypes.GetBlockHeaderVerboseResult{
12821291
Hash: blockHash.String(),
1292+
PowHash: powHash.String(),
12831293
Confirmations: confirmations,
12841294
Version: blockHeader.Version,
12851295
MerkleRoot: blockHeader.MerkleRoot.String(),
@@ -1394,9 +1404,19 @@ func (s *Server) getBlock(ctx context.Context, icmd interface{}) (interface{}, e
13941404
})
13951405
medianTime := timestamps[len(timestamps)/2]
13961406

1407+
// Determine the PoW hash. When the v1 PoW hash differs from the
1408+
// block hash, this is assumed to be v2 (DCP0011). More advanced
1409+
// selection logic will be necessary if the PoW hash changes again in
1410+
// the future.
1411+
powHash := blockHeader.PowHashV1()
1412+
if powHash != *blockHash {
1413+
powHash = blockHeader.PowHashV2()
1414+
}
1415+
13971416
sbitsFloat := float64(blockHeader.SBits) / dcrutil.AtomsPerCoin
13981417
blockReply := dcrdtypes.GetBlockVerboseResult{
13991418
Hash: cmd.Hash,
1419+
PoWHash: powHash.String(),
14001420
Version: blockHeader.Version,
14011421
MerkleRoot: blockHeader.MerkleRoot.String(),
14021422
StakeRoot: blockHeader.StakeRoot.String(),

internal/rpc/jsonrpc/rpcserverhelp.go

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

internal/rpchelp/helpdescs_en_US.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ var helpDescsEnUS = map[string]string{
196196

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

232233
// GetBlockVerboseResult help.
233234
"getblockverboseresult-hash": "The hash of the block (same as provided)",
235+
"getblockverboseresult-powhash": "The Proof-of-Work hash of the block (same as hash prior to DCP0011 activation)",
234236
"getblockverboseresult-confirmations": "The number of confirmations",
235237
"getblockverboseresult-size": "The size of the block",
236238
"getblockverboseresult-height": "The height of the block in the block chain",

0 commit comments

Comments
 (0)