From 1b9573128843e4cb91fcf62db24a3a09ca774d78 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 30 Mar 2022 23:52:04 +0200 Subject: [PATCH 1/6] rpc: getblock fixups Github-Pull: #24718 Rebased-From: 2a4767fff4c6211a662bd173631db3e40636d308 --- src/rpc/blockchain.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index fb22321d90..ea57a4b29c 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -642,16 +642,17 @@ const RPCResult getblock_vin{ } }; + static RPCHelpMan getblock() { return RPCHelpMan{"getblock", - "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" - "If verbosity is 1, returns an Object with information about block .\n" - "If verbosity is 2, returns an Object with information about block and information about each transaction.\n" - "If verbosity is 3, returns an Object with information about block and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n", + "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data about block .\n" + "If verbosity is 1, returns a JSON object with information about block .\n" + "If verbosity is 2, returns a JSON object with information about block and information about each transaction.\n" + "If verbosity is 3, returns a JSON object with information about block and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n", { {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a JSON object, 2 for JSON object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs", + {"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a JSON object, 2 for a JSON object with transaction data, and 3 for a JSON object with transaction data including prevout information for inputs", RPCArgOptions{.skip_type_check = true}}, }, { @@ -662,15 +663,10 @@ static RPCHelpMan getblock() { {RPCResult::Type::STR_HEX, "hash", "the block hash (same as provided)"}, {RPCResult::Type::NUM, "confirmations", "The number of confirmations, or -1 if the block is not on the main chain"}, - {RPCResult::Type::NUM, "size", "The block size"}, - {RPCResult::Type::NUM, "strippedsize", "The block size excluding witness data"}, - {RPCResult::Type::NUM, "weight", "The block weight as defined in BIP 141"}, {RPCResult::Type::NUM, "height", "The block height or index"}, {RPCResult::Type::NUM, "version", "The block version"}, {RPCResult::Type::STR_HEX, "versionHex", "The block version formatted in hexadecimal"}, {RPCResult::Type::STR_HEX, "merkleroot", "The merkle root"}, - {RPCResult::Type::ARR, "tx", "The transaction ids", - {{RPCResult::Type::STR_HEX, "", "The transaction id"}}}, {RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "nonce", "The nonce"}, @@ -680,6 +676,11 @@ static RPCHelpMan getblock() {RPCResult::Type::NUM, "nTx", "The number of transactions in the block"}, {RPCResult::Type::STR_HEX, "previousblockhash", /*optional=*/true, "The hash of the previous block (if available)"}, {RPCResult::Type::STR_HEX, "nextblockhash", /*optional=*/true, "The hash of the next block (if available)"}, + {RPCResult::Type::NUM, "strippedsize", "The block size, excluding witness data"}, + {RPCResult::Type::NUM, "size", "The block size"}, + {RPCResult::Type::NUM, "weight", "The block weight as defined in BIP 141"}, + {RPCResult::Type::ARR, "tx", "The transaction ids", + {{RPCResult::Type::STR_HEX, "", "The transaction id"}}}, }}, RPCResult{"for verbosity = 2", RPCResult::Type::OBJ, "", "", From f6a151ca16ed801ecfb3ad3b716b483f7d0402f3 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Wed, 30 Mar 2022 23:54:17 +0200 Subject: [PATCH 2/6] rpc: getrawtransaction fixups Github-Pull: #24718 Rebased-From: ffe6a9f2d648176c64b7972a117227c427aab25a --- src/rpc/rawtransaction.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 21d49fda9d..951113065b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -54,8 +54,8 @@ using node::PSBTAnalysis; using node::ReadBlockFromDisk; using node::UndoReadFromDisk; -static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, - Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, +static void TxToJSON(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, + const Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS) { CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS); @@ -67,7 +67,7 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, RPCSerializationFlags(), txundo, verbosity); if (!hashBlock.IsNull()) { - LOCK(cs_main); + LOCK(::cs_main); entry.pushKV("blockhash", hashBlock.GetHex()); const CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock); @@ -76,9 +76,9 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry.pushKV("confirmations", 1 + active_chainstate.m_chain.Height() - pindex->nHeight); entry.pushKV("time", pindex->GetBlockTime()); entry.pushKV("blocktime", pindex->GetBlockTime()); - } - else + } else { entry.pushKV("confirmations", 0); + } } } } @@ -202,7 +202,7 @@ static RPCHelpMan getrawtransaction() { {RPCResult::Type::BOOL, "in_active_chain", /*optional=*/true, "Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"}, {RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "the block hash"}, - {RPCResult::Type::NUM, "confirmations", /*optional=*/true, "The confirmations"}, + {RPCResult::Type::NUM, "confirmations", /*optional=*/true, "The number of confirmations"}, {RPCResult::Type::NUM_TIME, "blocktime", /*optional=*/true, "The block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""}, {RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"}, From 742c428ac0c70f0a829784a0ff93be2211fa0068 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 31 Mar 2022 01:38:42 +0200 Subject: [PATCH 3/6] rpc: decodepsbt fixups Github-Pull: #24718 Rebased-From: 758b7cf0fe8927f2a297124aa2e2d683a204228e --- src/rpc/rawtransaction.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 951113065b..93e0d2c4f3 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -745,10 +745,10 @@ const RPCResult decodepsbt_inputs{ {RPCResult::Type::OBJ, "scriptPubKey", "", { {RPCResult::Type::STR, "asm", "Disassembly of the public key script"}, - {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, + {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"}, {RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, }}, }}, {RPCResult::Type::OBJ_DYN, "partial_signatures", /*optional=*/true, "", @@ -760,13 +760,13 @@ const RPCResult decodepsbt_inputs{ { {RPCResult::Type::STR, "asm", "Disassembly of the redeem script"}, {RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, }}, {RPCResult::Type::OBJ, "witness_script", /*optional=*/true, "", { {RPCResult::Type::STR, "asm", "Disassembly of the witness script"}, {RPCResult::Type::STR_HEX, "hex", "The raw witness script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, }}, {RPCResult::Type::ARR, "bip32_derivs", /*optional=*/true, "", { @@ -866,13 +866,13 @@ const RPCResult decodepsbt_outputs{ { {RPCResult::Type::STR, "asm", "Disassembly of the redeem script"}, {RPCResult::Type::STR_HEX, "hex", "The raw redeem script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, }}, {RPCResult::Type::OBJ, "witness_script", /*optional=*/true, "", { {RPCResult::Type::STR, "asm", "Disassembly of the witness script"}, {RPCResult::Type::STR_HEX, "hex", "The raw witness script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, }}, {RPCResult::Type::ARR, "bip32_derivs", /*optional=*/true, "", { From 0949bf4f85703c22a219a8dc42bf70e558122242 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 31 Mar 2022 01:41:30 +0200 Subject: [PATCH 4/6] rpc: decodescript fixups Github-Pull: #24718 Rebased-From: 716c3fa6ea8d65ffde2891a2a0798f6d559683a8 --- src/rpc/rawtransaction.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 93e0d2c4f3..7c5e1b93d5 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -431,10 +431,10 @@ static RPCHelpMan decodescript() "Result of a witness script public key wrapping this redeem script (not returned for types that should not be wrapped)", { {RPCResult::Type::STR, "asm", "String representation of the script public key"}, - {RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"}, - {RPCResult::Type::STR, "type", "The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"}, - {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"}, + {RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"}, + {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, {RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"}, }}, }, From 858f9cb93a40377ddc909baa084e273cf3157cbd Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 31 Mar 2022 01:49:09 +0200 Subject: [PATCH 5/6] rpc: gettxout fixups Github-Pull: #24718 Rebased-From: 68a041dd12b3bfee1f8308cd3586dccd3efefed4 --- src/rpc/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ea57a4b29c..15ee3cfd85 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1039,7 +1039,7 @@ static RPCHelpMan gettxout() {RPCResult::Type::STR, "asm", "Disassembly of the public key script"}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, {RPCResult::Type::STR_HEX, "hex", "The raw public key script bytes, hex-encoded"}, - {RPCResult::Type::STR, "type", "The type, eg pubkeyhash"}, + {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, }}, {RPCResult::Type::BOOL, "coinbase", "Coinbase or not"}, From c16bbb6909acad9cf4e58465bd6dd8bcd4a62ecc Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 14 Apr 2022 00:40:49 +0000 Subject: [PATCH 6/6] Diff-minimise --- src/rpc/blockchain.cpp | 21 ++++++++++----------- src/rpc/rawtransaction.cpp | 16 ++++++++-------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 15ee3cfd85..350cf653eb 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -642,17 +642,16 @@ const RPCResult getblock_vin{ } }; - static RPCHelpMan getblock() { return RPCHelpMan{"getblock", - "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data about block .\n" - "If verbosity is 1, returns a JSON object with information about block .\n" - "If verbosity is 2, returns a JSON object with information about block and information about each transaction.\n" - "If verbosity is 3, returns a JSON object with information about block and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n", + "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" + "If verbosity is 1, returns an Object with information about block .\n" + "If verbosity is 2, returns an Object with information about block and information about each transaction.\n" + "If verbosity is 3, returns an Object with information about block and information about each transaction, including prevout information for inputs (only for unpruned blocks in the current best chain).\n", { {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"}, - {"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a JSON object, 2 for a JSON object with transaction data, and 3 for a JSON object with transaction data including prevout information for inputs", + {"verbosity|verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a JSON object, 2 for JSON object with transaction data, and 3 for JSON object with transaction data including prevout information for inputs", RPCArgOptions{.skip_type_check = true}}, }, { @@ -663,10 +662,15 @@ static RPCHelpMan getblock() { {RPCResult::Type::STR_HEX, "hash", "the block hash (same as provided)"}, {RPCResult::Type::NUM, "confirmations", "The number of confirmations, or -1 if the block is not on the main chain"}, + {RPCResult::Type::NUM, "size", "The block size"}, + {RPCResult::Type::NUM, "strippedsize", "The block size excluding witness data"}, + {RPCResult::Type::NUM, "weight", "The block weight as defined in BIP 141"}, {RPCResult::Type::NUM, "height", "The block height or index"}, {RPCResult::Type::NUM, "version", "The block version"}, {RPCResult::Type::STR_HEX, "versionHex", "The block version formatted in hexadecimal"}, {RPCResult::Type::STR_HEX, "merkleroot", "The merkle root"}, + {RPCResult::Type::ARR, "tx", "The transaction ids", + {{RPCResult::Type::STR_HEX, "", "The transaction id"}}}, {RPCResult::Type::NUM_TIME, "time", "The block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM_TIME, "mediantime", "The median block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "nonce", "The nonce"}, @@ -676,11 +680,6 @@ static RPCHelpMan getblock() {RPCResult::Type::NUM, "nTx", "The number of transactions in the block"}, {RPCResult::Type::STR_HEX, "previousblockhash", /*optional=*/true, "The hash of the previous block (if available)"}, {RPCResult::Type::STR_HEX, "nextblockhash", /*optional=*/true, "The hash of the next block (if available)"}, - {RPCResult::Type::NUM, "strippedsize", "The block size, excluding witness data"}, - {RPCResult::Type::NUM, "size", "The block size"}, - {RPCResult::Type::NUM, "weight", "The block weight as defined in BIP 141"}, - {RPCResult::Type::ARR, "tx", "The transaction ids", - {{RPCResult::Type::STR_HEX, "", "The transaction id"}}}, }}, RPCResult{"for verbosity = 2", RPCResult::Type::OBJ, "", "", diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 7c5e1b93d5..3de8a95136 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -54,8 +54,8 @@ using node::PSBTAnalysis; using node::ReadBlockFromDisk; using node::UndoReadFromDisk; -static void TxToJSON(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, - const Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, +static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, + Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS) { CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS); @@ -67,7 +67,7 @@ static void TxToJSON(const CTransaction& tx, const uint256& hashBlock, UniValue& TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, RPCSerializationFlags(), txundo, verbosity); if (!hashBlock.IsNull()) { - LOCK(::cs_main); + LOCK(cs_main); entry.pushKV("blockhash", hashBlock.GetHex()); const CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock); @@ -76,9 +76,9 @@ static void TxToJSON(const CTransaction& tx, const uint256& hashBlock, UniValue& entry.pushKV("confirmations", 1 + active_chainstate.m_chain.Height() - pindex->nHeight); entry.pushKV("time", pindex->GetBlockTime()); entry.pushKV("blocktime", pindex->GetBlockTime()); - } else { - entry.pushKV("confirmations", 0); } + else + entry.pushKV("confirmations", 0); } } } @@ -202,7 +202,7 @@ static RPCHelpMan getrawtransaction() { {RPCResult::Type::BOOL, "in_active_chain", /*optional=*/true, "Whether specified block is in the active chain or not (only present with explicit \"blockhash\" argument)"}, {RPCResult::Type::STR_HEX, "blockhash", /*optional=*/true, "the block hash"}, - {RPCResult::Type::NUM, "confirmations", /*optional=*/true, "The number of confirmations"}, + {RPCResult::Type::NUM, "confirmations", /*optional=*/true, "The confirmations"}, {RPCResult::Type::NUM_TIME, "blocktime", /*optional=*/true, "The block time expressed in " + UNIX_EPOCH_TIME}, {RPCResult::Type::NUM, "time", /*optional=*/true, "Same as \"blocktime\""}, {RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"}, @@ -431,10 +431,10 @@ static RPCHelpMan decodescript() "Result of a witness script public key wrapping this redeem script (not returned for types that should not be wrapped)", { {RPCResult::Type::STR, "asm", "String representation of the script public key"}, - {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"}, {RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, - {RPCResult::Type::STR, "type", "The type (one of: " + GetAllOutputTypes() + ")"}, + {RPCResult::Type::STR, "desc", "Inferred descriptor for the script"}, + {RPCResult::Type::STR, "type", "The type of the script public key (one of: " + GetAllOutputTypes() + ")"}, {RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"}, }}, },