@@ -181,13 +181,35 @@ UniValue blockheaderToJSON(const CBlockIndex& tip, const CBlockIndex& blockindex
181181 return result;
182182}
183183
184+ /* * Serialize coinbase transaction metadata */
185+ UniValue coinbaseTxToJSON (const CTransaction& coinbase_tx)
186+ {
187+ CHECK_NONFATAL (!coinbase_tx.vin .empty ());
188+ const CTxIn& vin_0{coinbase_tx.vin [0 ]};
189+ UniValue coinbase_tx_obj (UniValue::VOBJ);
190+ coinbase_tx_obj.pushKV (" version" , coinbase_tx.version );
191+ coinbase_tx_obj.pushKV (" locktime" , coinbase_tx.nLockTime );
192+ coinbase_tx_obj.pushKV (" sequence" , vin_0.nSequence );
193+ coinbase_tx_obj.pushKV (" coinbase" , HexStr (vin_0.scriptSig ));
194+ const auto & witness_stack{vin_0.scriptWitness .stack };
195+ if (!witness_stack.empty ()) {
196+ CHECK_NONFATAL (witness_stack.size () == 1 );
197+ coinbase_tx_obj.pushKV (" witness" , HexStr (witness_stack[0 ]));
198+ }
199+ return coinbase_tx_obj;
200+ }
201+
184202UniValue blockToJSON (BlockManager& blockman, const CBlock& block, const CBlockIndex& tip, const CBlockIndex& blockindex, TxVerbosity verbosity, const uint256 pow_limit)
185203{
186204 UniValue result = blockheaderToJSON (tip, blockindex, pow_limit);
187205
188206 result.pushKV (" strippedsize" , ::GetSerializeSize (TX_NO_WITNESS (block)));
189207 result.pushKV (" size" , ::GetSerializeSize (TX_WITH_WITNESS (block)));
190208 result.pushKV (" weight" , ::GetBlockWeight (block));
209+
210+ CHECK_NONFATAL (!block.vtx .empty ());
211+ result.pushKV (" coinbase_tx" , coinbaseTxToJSON (*block.vtx [0 ]));
212+
191213 UniValue txs (UniValue::VARR);
192214 txs.reserve (block.vtx .size ());
193215
@@ -760,6 +782,14 @@ static RPCHelpMan getblock()
760782 {RPCResult::Type::NUM, " size" , " The block size" },
761783 {RPCResult::Type::NUM, " strippedsize" , " The block size excluding witness data" },
762784 {RPCResult::Type::NUM, " weight" , " The block weight as defined in BIP 141" },
785+ {RPCResult::Type::OBJ, " coinbase_tx" , " Coinbase transaction metadata" ,
786+ {
787+ {RPCResult::Type::NUM, " version" , " The coinbase transaction version" },
788+ {RPCResult::Type::NUM, " locktime" , " The coinbase transaction's locktime (nLockTime)" },
789+ {RPCResult::Type::NUM, " sequence" , " The coinbase input's sequence number (nSequence)" },
790+ {RPCResult::Type::STR_HEX, " coinbase" , " The coinbase input's scriptSig" },
791+ {RPCResult::Type::STR_HEX, " witness" , /* optional=*/ true , " The coinbase input's first (and only) witness stack element, if present" },
792+ }},
763793 {RPCResult::Type::NUM, " height" , " The block height or index" },
764794 {RPCResult::Type::NUM, " version" , " The block version" },
765795 {RPCResult::Type::STR_HEX, " versionHex" , " The block version formatted in hexadecimal" },
0 commit comments