@@ -146,7 +146,7 @@ static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateMan
146
146
}
147
147
}
148
148
149
- UniValue blockheaderToJSON (const CBlockIndex& tip, const CBlockIndex& blockindex)
149
+ UniValue blockheaderToJSON (const CBlockIndex& tip, const CBlockIndex& blockindex, const uint256 pow_limit )
150
150
{
151
151
// Serialize passed information without accessing chain state of the active chain!
152
152
AssertLockNotHeld (cs_main); // For performance reasons
@@ -164,6 +164,7 @@ UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex
164
164
result.pushKV (" mediantime" , blockindex.GetMedianTimePast ());
165
165
result.pushKV (" nonce" , blockindex.nNonce );
166
166
result.pushKV (" bits" , strprintf (" %08x" , blockindex.nBits ));
167
+ result.pushKV (" target" , GetTarget (tip, pow_limit).GetHex ());
167
168
result.pushKV (" difficulty" , GetDifficulty (blockindex));
168
169
result.pushKV (" chainwork" , blockindex.nChainWork .GetHex ());
169
170
result.pushKV (" nTx" , blockindex.nTx );
@@ -175,9 +176,9 @@ UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex
175
176
return result;
176
177
}
177
178
178
- UniValue blockToJSON (BlockManager& blockman, const CBlock& block, const CBlockIndex& tip, const CBlockIndex& blockindex, TxVerbosity verbosity)
179
+ UniValue blockToJSON (BlockManager& blockman, const CBlock& block, const CBlockIndex& tip, const CBlockIndex& blockindex, TxVerbosity verbosity, const uint256 pow_limit )
179
180
{
180
- UniValue result = blockheaderToJSON (tip, blockindex);
181
+ UniValue result = blockheaderToJSON (tip, blockindex, pow_limit );
181
182
182
183
result.pushKV (" strippedsize" , (int )::GetSerializeSize (TX_NO_WITNESS (block)));
183
184
result.pushKV (" size" , (int )::GetSerializeSize (TX_WITH_WITNESS (block)));
@@ -554,6 +555,7 @@ static RPCHelpMan getblockheader()
554
555
{RPCResult::Type::NUM_TIME, " mediantime" , " The median block time expressed in " + UNIX_EPOCH_TIME},
555
556
{RPCResult::Type::NUM, " nonce" , " The nonce" },
556
557
{RPCResult::Type::STR_HEX, " bits" , " nBits: compact representation of the block difficulty target" },
558
+ {RPCResult::Type::STR_HEX, " target" , " The difficulty target" },
557
559
{RPCResult::Type::NUM, " difficulty" , " The difficulty" },
558
560
{RPCResult::Type::STR_HEX, " chainwork" , " Expected number of hashes required to produce the current chain" },
559
561
{RPCResult::Type::NUM, " nTx" , " The number of transactions in the block" },
@@ -577,8 +579,8 @@ static RPCHelpMan getblockheader()
577
579
578
580
const CBlockIndex* pblockindex;
579
581
const CBlockIndex* tip;
582
+ ChainstateManager& chainman = EnsureAnyChainman (request.context );
580
583
{
581
- ChainstateManager& chainman = EnsureAnyChainman (request.context );
582
584
LOCK (cs_main);
583
585
pblockindex = chainman.m_blockman .LookupBlockIndex (hash);
584
586
tip = chainman.ActiveChain ().Tip ();
@@ -596,7 +598,7 @@ static RPCHelpMan getblockheader()
596
598
return strHex;
597
599
}
598
600
599
- return blockheaderToJSON (*tip, *pblockindex);
601
+ return blockheaderToJSON (*tip, *pblockindex, chainman. GetConsensus (). powLimit );
600
602
},
601
603
};
602
604
}
@@ -728,6 +730,7 @@ static RPCHelpMan getblock()
728
730
{RPCResult::Type::NUM_TIME, " mediantime" , " The median block time expressed in " + UNIX_EPOCH_TIME},
729
731
{RPCResult::Type::NUM, " nonce" , " The nonce" },
730
732
{RPCResult::Type::STR_HEX, " bits" , " nBits: compact representation of the block difficulty target" },
733
+ {RPCResult::Type::STR_HEX, " target" , " The difficulty target" },
731
734
{RPCResult::Type::NUM, " difficulty" , " The difficulty" },
732
735
{RPCResult::Type::STR_HEX, " chainwork" , " Expected number of hashes required to produce the chain up to this block (in hex)" },
733
736
{RPCResult::Type::NUM, " nTx" , " The number of transactions in the block" },
@@ -802,7 +805,7 @@ static RPCHelpMan getblock()
802
805
tx_verbosity = TxVerbosity::SHOW_DETAILS_AND_PREVOUT;
803
806
}
804
807
805
- return blockToJSON (chainman.m_blockman , block, *tip, *pblockindex, tx_verbosity);
808
+ return blockToJSON (chainman.m_blockman , block, *tip, *pblockindex, tx_verbosity, chainman. GetConsensus (). powLimit );
806
809
},
807
810
};
808
811
}
0 commit comments