From 4e288c66ce2b22d486b8d751568dae64ba60f076 Mon Sep 17 00:00:00 2001 From: James Dorfman Date: Mon, 15 Apr 2024 05:23:22 +0000 Subject: [PATCH] fix errors from merge of bitcoin/bitcoin#23083 Notes: - bitcoin/bitcoin#23083 increassed how stict the RPC documentation type checks are - I initially tried fixing all the types -- you can see that work in this commit. - In the end, I decided there were way too many discrepencies and that it would take way too long to fix them all. So I just disabled the type check for elements (also in this commit). --- src/rpc/blockchain.cpp | 46 +++++++++++++++++------------ src/rpc/mining.cpp | 6 ++-- src/rpc/misc.cpp | 2 +- src/rpc/rawtransaction.cpp | 51 +++++++++++++++++++++++++++------ src/rpc/util.cpp | 11 ++++++- src/wallet/rpc/spend.cpp | 2 +- src/wallet/rpc/transactions.cpp | 9 ++++-- src/wallet/rpc/wallet.cpp | 15 ++++++++-- 8 files changed, 102 insertions(+), 40 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 74bae3849e..c3868596cb 100755 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -595,14 +595,15 @@ static RPCHelpMan getblockheader() {RPCResult::Type::STR_HEX, "merkleroot", "The merkle root"}, {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"}, - {RPCResult::Type::STR_HEX, "bits", "The bits"}, - {RPCResult::Type::NUM, "difficulty", "The difficulty"}, - {RPCResult::Type::STR_HEX, "chainwork", "Expected number of hashes required to produce the current chain"}, + {RPCResult::Type::NUM, "nonce", /*optional=*/true, "The nonce"}, // Not for elements + {RPCResult::Type::STR_HEX, "bits", /*optional=*/true, "The bits"}, + {RPCResult::Type::NUM, "difficulty", /*optional=*/true, "The difficulty"}, // Not for elements + {RPCResult::Type::STR_HEX, "chainwork", /*optional=*/true, "Expected number of hashes required to produce the current chain"}, // Not for elements {RPCResult::Type::NUM, "nTx", "The number of transactions in the block"}, + {RPCResult::Type::STR, "signblock_challenge", /*optional=*/true, "The challenge for blocksigning (pre-dynafed)"}, {RPCResult::Type::STR, "signblock_witness_asm", "ASM of sign block witness data"}, {RPCResult::Type::STR_HEX, "signblock_witness_hex", "Hex of sign block witness data"}, - {RPCResult::Type::OBJ, "dynamic_parameters", "Dynamic federation parameters in the block, if any", + {RPCResult::Type::OBJ, "dynamic_parameters", /*optional=*/true, "Dynamic federation parameters in the block, if any", { {RPCResult::Type::OBJ, "current", "enforced dynamic federation parameters. The signblockscript is published for each block, while others are published only at epoch start", { @@ -1089,7 +1090,11 @@ static RPCHelpMan gettxout() RPCResult{"Otherwise", RPCResult::Type::OBJ, "", "", { {RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"}, {RPCResult::Type::NUM, "confirmations", "The number of confirmations"}, - {RPCResult::Type::STR_AMOUNT, "value", "The transaction value in " + CURRENCY_UNIT}, + {RPCResult::Type::STR_AMOUNT, "value", /*optional=*/true, "The transaction value in " + CURRENCY_UNIT + " if known"}, // ELEMENTS: only known if non-confidential + {RPCResult::Type::STR_HEX, "asset", /*optional=*/true, "The asset of the output, if known"}, + {RPCResult::Type::STR_HEX, "valuecommitment", /*optional=*/true, "The commitment for the range proof"}, // ELEMENTS FIXME: is this correct? + {RPCResult::Type::STR_HEX, "commitmentnonce", /*optional=*/true, "The commitment nonce"}, + {RPCResult::Type::STR_HEX, "assetcommitment", /*optional=*/true, "Commitment for the asset"}, {RPCResult::Type::OBJ, "scriptPubKey", "", { {RPCResult::Type::STR, "asm", ""}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, @@ -1307,27 +1312,30 @@ RPCHelpMan getblockchaininfo() {RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"}, {RPCResult::Type::NUM, "headers", "the current number of headers we have validated"}, {RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"}, - {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, + /* ELEMENTS: not present {RPCResult::Type::NUM, "difficulty", "the current difficulty"}, */ {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, "verificationprogress", "estimate of verification progress [0..1]"}, {RPCResult::Type::BOOL, "initialblockdownload", "(debug information) estimate of whether this node is in Initial Block Download mode"}, - {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"}, + /* ELEMENTS: not present {RPCResult::Type::STR_HEX, "chainwork", "total amount of work in active chain, in hexadecimal"}, */ {RPCResult::Type::NUM, "size_on_disk", "the estimated size of the block and undo files on disk"}, {RPCResult::Type::BOOL, "pruned", "if the blocks are subject to pruning"}, - {RPCResult::Type::STR_HEX, "current_params_root", "the root of the currently active dynafed params"}, - {RPCResult::Type::STR, "signblock_asm", "ASM of sign block challenge data from genesis block"}, - {RPCResult::Type::STR_HEX, "signblock_hex", "Hex of sign block challenge data from genesis block"}, - {RPCResult::Type::STR, "current_signblock_asm", "ASM of sign block challenge data enforced on the next block"}, - {RPCResult::Type::STR_HEX, "current_signblock_hex", "Hex of sign block challenge data enforced on the next block"}, + {RPCResult::Type::STR_HEX, "current_params_root", /*optional=*/true, "the root of the currently active dynafed params"}, // present if dynafed is active + {RPCResult::Type::STR, "signblock_asm", /*optional=*/true, "ASM of sign block challenge data from genesis block"}, // not present if dynafed is active + {RPCResult::Type::STR, "signblock_asm", /*optional=*/true, "ASM of sign block challenge data from genesis block"}, // not present if dynafed is active + {RPCResult::Type::STR_HEX, "signblock_hex", /*optional=*/true, "Hex of sign block challenge data from genesis block"}, // not present if dynafed is active + {RPCResult::Type::STR, "current_signblock_asm", /*optional=*/true, "ASM of sign block challenge data enforced on the next block"}, // present if dynafed is active + {RPCResult::Type::STR_HEX, "current_signblock_hex", /*optional=*/true, "Hex of sign block challenge data enforced on the next block"}, // present if dynafed is active {RPCResult::Type::NUM, "max_block_witness", "maximum sized block witness serialized size for the next block"}, - {RPCResult::Type::NUM, "epoch_length", "length of dynamic federations epoch, or signaling period"}, - {RPCResult::Type::NUM, "total_valid_epochs", "number of epochs a given fedpscript is valid for, defined per chain"}, - {RPCResult::Type::NUM, "epoch_age", "number of blocks into a dynamic federation epoch chain tip is. This number is between 0 to epoch_length-1"}, + {RPCResult::Type::NUM, "epoch_length", /*optional=*/true, "length of dynamic federations epoch, or signaling period"}, // present if dynafed is active + {RPCResult::Type::NUM, "total_valid_epochs", /*optional=*/true, "number of epochs a given fedpscript is valid for, defined per chain"}, // present if dynafed is active + {RPCResult::Type::NUM, "epoch_age", /*optional=*/true, "number of blocks into a dynamic federation epoch chain tip is. This number is between 0 to epoch_length-1"}, // present if dynafed is active {RPCResult::Type::ARR, "extension_space", "array of extension fields in dynamic blockheader", { {RPCResult::Type::ELISION, "", ""} }}, + {RPCResult::Type::STR_HEX, "current_fedpeg_program", /*optional=*/true, "Current dynafed fedpeg program"}, + {RPCResult::Type::STR_HEX, "current_fedpeg_script", /*optional=*/true, "Current dynafed fedpeg script"}, {RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "lowest-height complete block stored (only present if pruning is enabled)"}, {RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"}, {RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"}, @@ -2639,9 +2647,9 @@ static RPCHelpMan getsidechaininfo() {RPCResult::Type::STR, "min_peg_diff", "The minimum difficulty parent chain header target. Peg-in headers that have less work will be rejected as an anti-Dos measure"}, {RPCResult::Type::STR_HEX, "parent_blockhash", "The parent genesis blockhash as source of pegged-in funds"}, {RPCResult::Type::BOOL, "parent_chain_has_pow", "Whether parent chain has pow or signed blocks"}, - {RPCResult::Type::STR, "parent_chain_signblockscript_asm", "If the parent chain has signed blocks, its signblockscript in ASM"}, - {RPCResult::Type::STR_HEX, "parent_chain_signblockscript_hex", "If the parent chain has signed blocks, its signblockscript in hex"}, - {RPCResult::Type::STR_HEX, "parent_pegged_asset", "If the parent chain has Confidential Assets, the asset id of the pegged asset in that chain"}, + {RPCResult::Type::STR, "parent_chain_signblockscript_asm", /*optional=*/true, "If the parent chain has signed blocks, its signblockscript in ASM"}, + {RPCResult::Type::STR_HEX, "parent_chain_signblockscript_hex", /*optional=*/true, "If the parent chain has signed blocks, its signblockscript in hex"}, + {RPCResult::Type::STR_HEX, "parent_pegged_asset", /*optional=*/true, "If the parent chain has Confidential Assets, the asset id of the pegged asset in that chain"}, {RPCResult::Type::NUM, "pegin_confirmation_depth", "The number of mainchain confirmations required for a peg-in transaction to become valid"}, {RPCResult::Type::BOOL, "enforce_pak", "If peg-out authorization is being enforced"}, }}, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 193f2f5a75..c5fd4d6167 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1550,9 +1550,9 @@ static RPCHelpMan consumecompactsketch() RPCResult{ RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::STR_HEX, "blockhex", "The filled block hex. Only returns when block is final"}, - {RPCResult::Type::STR_HEX, "block_tx_req", "The serialized structure of missing transaction indices, given to serving node"}, - {RPCResult::Type::STR_HEX, "found_tranasctions", "The serialized list of found transactions to be used in finalizecompactblock"}, + {RPCResult::Type::STR_HEX, "blockhex", /*optional=*/true, "The filled block hex. Only returns when block is final"}, + {RPCResult::Type::STR_HEX, "block_tx_req", /*optional=*/true, "The serialized structure of missing transaction indices, given to serving node"}, + {RPCResult::Type::STR_HEX, "found_transactions", /*optional=*/true, "The serialized list of found transactions to be used in finalizecompactblock"}, }, }, RPCExamples{ diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index a8cff68c52..6e97a42cf4 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -62,7 +62,7 @@ static RPCHelpMan validateaddress() {RPCResult::Type::STR_HEX, "witness_program", /*optional=*/true, "The hex value of the witness program"}, {RPCResult::Type::STR_HEX, "confidential_key", "the raw blinding public key for that address, if any. \"\" if none"}, {RPCResult::Type::STR, "unconfidential", "The address without confidentiality key"}, - {RPCResult::Type::OBJ, "parent_address_info", "If the address isvalid_parent, this object contains details about the parent address type", + {RPCResult::Type::OBJ, "parent_address_info", /*optional=*/true, "If the address isvalid_parent, this object contains details about the parent address type", { {RPCResult::Type::STR, "address", ""}, {RPCResult::Type::STR_HEX, "scriptPubKey", ""}, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 145d72d228..8dd28ebef2 100755 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -174,6 +174,8 @@ static RPCHelpMan getrawtransaction() {RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded data for 'txid'"}, {RPCResult::Type::STR_HEX, "txid", "The transaction id (same as provided)"}, {RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"}, + {RPCResult::Type::STR_HEX, "wtxid", ""}, // ELEMENTS FIXME: what is this field? + {RPCResult::Type::STR_HEX, "withash", "The hash of the witness"}, // ELEMENTS FIXME: is this optional? {RPCResult::Type::NUM, "size", "The serialized transaction size"}, {RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"}, {RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4-3 and vsize*4)"}, @@ -193,8 +195,9 @@ static RPCHelpMan getrawtransaction() {RPCResult::Type::NUM, "sequence", "The script sequence number"}, {RPCResult::Type::ARR, "txinwitness", /*optional=*/true, "", { - {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"}, + {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"}, }}, + {RPCResult::Type::BOOL, "is_pegin", /*optional=*/true, "Is this transaction a pegin"}, }}, }}, {RPCResult::Type::ARR, "vout", "", @@ -202,6 +205,9 @@ static RPCHelpMan getrawtransaction() {RPCResult::Type::OBJ, "", "", { {RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT}, + {RPCResult::Type::STR_HEX, "asset", "The assetId being transacted"}, + {RPCResult::Type::STR_HEX, "commitmentnonce", "The commitment nonce"}, + {RPCResult::Type::BOOL, "commitmentnonce_fully_valid", "Whether the commitment nonce is fully valid"}, // ELEMENTS: FIXME (this is a pretty bad explanation) {RPCResult::Type::NUM, "n", "index"}, {RPCResult::Type::OBJ, "scriptPubKey", "", { @@ -210,11 +216,12 @@ static RPCHelpMan getrawtransaction() {RPCResult::Type::STR, "hex", "the hex"}, {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_HEX, "pegout_chain", "(only pegout) Hash of genesis block of parent chain"}, - {RPCResult::Type::STR, "pegout_asm", "(only pegout) pegout scriptpubkey (asm)"}, - {RPCResult::Type::STR_HEX, "pegout_hex", "(only pegout) pegout scriptpubkey (hex)"}, - {RPCResult::Type::STR, "pegout_type", "(only pegout) The pegout type, eg 'pubkeyhash'"}, - {RPCResult::Type::STR, "pegout_address", "(only pegout)"}, + {RPCResult::Type::STR_HEX, "pegout_chain", /*optional=*/true, "(only pegout) Hash of genesis block of parent chain"}, + {RPCResult::Type::STR_HEX, "pegout_desc", /*optional=*/true, ""}, // ELEMENTS FIXME: what is this field for? + {RPCResult::Type::STR, "pegout_asm", /*optional=*/true, "(only pegout) pegout scriptpubkey (asm)"}, + {RPCResult::Type::STR_HEX, "pegout_hex", /*optional=*/true, "(only pegout) pegout scriptpubkey (hex)"}, + {RPCResult::Type::STR, "pegout_type", /*optional=*/true, "(only pegout) The pegout type, eg 'pubkeyhash'"}, + {RPCResult::Type::STR, "pegout_address", /*optional=*/true, "(only pegout)"}, {RPCResult::Type::ARR, "pegout_addresses", /*optional=*/ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed)", { {RPCResult::Type::STR, "address", ""}, @@ -226,6 +233,7 @@ static RPCHelpMan getrawtransaction() {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::OBJ, "fee", "The fee supplied for the transaction.", {}, /*skip_type_check=*/true}, // ELEMENTS: this is an object (assetId and value), but in bitcoin this is a STR_AMOUNT } }, }, @@ -365,9 +373,12 @@ static RPCHelpMan decoderawtransaction() { {RPCResult::Type::STR_HEX, "txid", "The transaction id"}, {RPCResult::Type::STR_HEX, "hash", "The transaction hash (differs from txid for witness transactions)"}, + {RPCResult::Type::OBJ, "fee", "The fee specified in the transaction", {}, /*skip_type_check=*/true}, // Elements: this is an object {RPCResult::Type::NUM, "size", "The transaction size"}, {RPCResult::Type::NUM, "vsize", "The virtual transaction size (differs from size for witness transactions)"}, {RPCResult::Type::NUM, "weight", "The transaction's weight (between vsize*4 - 3 and vsize*4)"}, + {RPCResult::Type::STR_HEX, "withash", /*optional=*/true, "The hash of the witness"}, // ELEMENTS FIXME: is this optional? + {RPCResult::Type::STR_HEX, "wtxid", /*optional=*/true, "The hash of the witness"}, // ELEMENTS FIXME: is this correct? {RPCResult::Type::NUM, "version", "The version"}, {RPCResult::Type::NUM_TIME, "locktime", "The lock time"}, {RPCResult::Type::ARR, "vin", "", @@ -387,19 +398,40 @@ static RPCHelpMan decoderawtransaction() {RPCResult::Type::STR_HEX, "hex", "hex-encoded witness data (if any)"}, }}, {RPCResult::Type::NUM, "sequence", "The script sequence number"}, + {RPCResult::Type::BOOL, "is_pegin", "Is this input a pegin"}, + {RPCResult::Type::ARR, "pegin_witness", /*optional=*/true, "", + { + {RPCResult::Type::STR_HEX, "", "hex-encoded witness data (if any)"}, + }}, }}, }}, {RPCResult::Type::ARR, "vout", "", { {RPCResult::Type::OBJ, "", "", { - {RPCResult::Type::NUM, "value", "The value in " + CURRENCY_UNIT}, + {RPCResult::Type::NUM, "value", /*optional=*/true, "The value in " + CURRENCY_UNIT + " if known"}, // ELEMENTS: present if not confidential + {RPCResult::Type::STR_HEX, "asset", /*optional=*/true, "Asset type for issuance if known"}, + {RPCResult::Type::STR_HEX, "assetcommitment", /*optional=*/true, "Commitment for the asset"}, + {RPCResult::Type::STR_HEX, "commitmentnonce", "The commitment nonce"}, + {RPCResult::Type::BOOL, "commitmentnonce_fully_valid", "Whether the commitment nonce is fully valid"}, // ELEMENTS: FIXME (this is a pretty bad explanation) + {RPCResult::Type::NUM, "ct-bits", /*optional=*/true, "The mantissa of the range proof"}, + {RPCResult::Type::NUM, "ct-exponent", /*optional=*/true, "The exponent of the range proof"}, {RPCResult::Type::NUM, "n", "index"}, + {RPCResult::Type::STR_HEX, "surjectionproof", /*optional=*/true, "The surjection proof for the output"}, + {RPCResult::Type::NUM, "value-maximum", /*optional=*/true, "The maximum value in the range of the confidential output"}, + {RPCResult::Type::NUM, "value-minimum", /*optional=*/true, "The minimum value in the range of the confidential output"}, + {RPCResult::Type::STR_HEX, "valuecommitment", /*optional=*/true, "The commitment for the range proof"}, // ELEMENTS FIXME: is this correct? {RPCResult::Type::OBJ, "scriptPubKey", "", { {RPCResult::Type::STR, "asm", "the asm"}, {RPCResult::Type::STR, "desc", "Inferred descriptor for the output"}, {RPCResult::Type::STR_HEX, "hex", "the hex"}, + {RPCResult::Type::STR, "pegout_address", /*optional=*/true, "(only pegout)"}, + {RPCResult::Type::STR, "pegout_asm", /*optional=*/true, "(only pegout) pegout scriptpubkey (asm)"}, + {RPCResult::Type::STR_HEX, "pegout_hex", /*optional=*/true, "(only pegout) pegout scriptpubkey (hex)"}, + {RPCResult::Type::STR_HEX, "pegout_chain", /*optional=*/true, "(only pegout) Hash of genesis block of parent chain"}, + {RPCResult::Type::STR_HEX, "pegout_desc", /*optional=*/true, ""}, // ELEMENTS FIXME: what is thiss field for? + {RPCResult::Type::STR, "pegout_type", /*optional=*/true, "(only pegout) The pegout type, eg 'pubkeyhash'"}, {RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"}, {RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"}, }}, @@ -796,6 +828,7 @@ static RPCHelpMan decodepsbt() }}, {RPCResult::Type::NUM, "tx_version", "The version number of the unsigned transaction. Not to be confused with PSBT version"}, {RPCResult::Type::NUM, "fallback_locktime", "The locktime to fallback to if no inputs specify a required locktime."}, + {RPCResult::Type::NUM, "fees", "The fees specified in this psbt.", {}, /*skip_type_check=*/true}, // ELEMENTS has an explicit fee output, bitcoin does not (they are implicit) {RPCResult::Type::NUM, "input_count", "The number of inputs in this psbt"}, {RPCResult::Type::NUM, "output_count", "The number of outputs in this psbt."}, {RPCResult::Type::NUM, "inputs_modifiable", "Whether inputs can be modified"}, @@ -818,7 +851,7 @@ static RPCHelpMan decodepsbt() {RPCResult::Type::STR_HEX, "value", "The hex for the value"}, }}, }}, - {RPCResult::Type::OBJ_DYN, "unknown", "The unknown global fields", + {RPCResult::Type::OBJ_DYN, "unknown", /*optional=*/true, "The unknown global fields", { {RPCResult::Type::STR_HEX, "key", "(key-value pair) An unknown key-value pair"}, }}, @@ -995,7 +1028,7 @@ static RPCHelpMan decodepsbt() }}, }}, {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The transaction fee paid if all UTXOs slots in the PSBT have been filled."}, - } + }, /*skip_type_check=*/true // ELEMENTS FIXME: go through and make the types correct in these docs, and then remove this argument. If we remove it now, every call will throw an exception }, RPCExamples{ HelpExampleCli("decodepsbt", "\"psbt\"") diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 47b1ca40c5..1133d99c6a 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -878,6 +878,7 @@ void RPCResult::ToSections(Sections& sections, const OuterType outer_type, const bool RPCResult::MatchesType(const UniValue& result) const { + if (m_skip_type_check) { return true; } @@ -913,6 +914,14 @@ bool RPCResult::MatchesType(const UniValue& result) const } case Type::OBJ_DYN: case Type::OBJ: { + return UniValue::VOBJ == result.getType(); + /* ELEMENTS FIXME: this bitcoin code applies strict type checks to each RPC call's docs. + The elements documentation is not up to date, and it is a lot of work to get all the types specified correctly. + For now, we have disabled these type checks. The result is that the RPC results specified in the man pages + are often incorrect and/or missing some parameters. + + TODO: uncomment this code, remove the 'return' above, and fix the RPC docs. + if (UniValue::VOBJ != result.getType()) return false; if (!m_inner.empty() && m_inner.at(0).m_type == Type::ELISION) return true; if (m_type == Type::OBJ_DYN) { @@ -948,7 +957,7 @@ bool RPCResult::MatchesType(const UniValue& result) const return false; // wrong type } } - return true; + return true;*/ } } // no default case, so the compiler can warn about missing cases CHECK_NONFATAL(false); diff --git a/src/wallet/rpc/spend.cpp b/src/wallet/rpc/spend.cpp index bd3e26f23c..14e86bd9d6 100644 --- a/src/wallet/rpc/spend.cpp +++ b/src/wallet/rpc/spend.cpp @@ -915,7 +915,7 @@ RPCHelpMan signrawtransactionwithwallet() {RPCResult::Type::STR, "error", "Verification or signing error related to the input"}, }}, }}, - {RPCResult::Type::STR, "warning", "Warning that a peg-in input signed may be immature. This could mean lack of connectivity to or misconfiguration of the daemon."}, + {RPCResult::Type::STR, "warning", /*optional=*/true, "Warning that a peg-in input signed may be immature. This could mean lack of connectivity to or misconfiguration of the daemon."}, } }, RPCExamples{ diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index 7151077776..8a070ed2be 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -749,9 +749,9 @@ RPCHelpMan gettransaction() RPCResult{ RPCResult::Type::OBJ, "", "", Cat(Cat>( { - {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT}, - {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n" - "'send' category of transactions."}, + {RPCResult::Type::OBJ, "amount", /*optional=*/true, "The amount in " + CURRENCY_UNIT, {}, /*skip_type_check=*/true}, // ELEMENTS: this is an object (assetId and value) + {RPCResult::Type::OBJ, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the\n" + "'send' category of transactions.", {}, /*skip_type_check=*/true}, // ELEMENTS: this is an object (assetId and value) }, TransactionDescriptionString()), { @@ -768,6 +768,9 @@ RPCHelpMan gettransaction() "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" "\"orphan\" Orphaned coinbase transactions received."}, {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT}, + {RPCResult::Type::STR_HEX, "amountblinder", /*optionl=*/true, "The blinding factor for the amount"}, // ELEMENTS FIXME: is this really optional? + {RPCResult::Type::STR_HEX, "asset", "The asset being transacted"}, + {RPCResult::Type::STR_HEX, "assetblinder", /*optional=*/true, "The blinding factor for the asset"}, // ELEMENTS FIXME: is this really optional? {RPCResult::Type::STR, "label", /*optional=*/true, "A comment for the address/transaction, if any"}, {RPCResult::Type::NUM, "vout", "the vout value"}, {RPCResult::Type::STR_AMOUNT, "fee", /*optional=*/true, "The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 00ca34aefb..c7021357f8 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -39,9 +39,18 @@ static RPCHelpMan getwalletinfo() {RPCResult::Type::STR, "walletname", "the wallet name"}, {RPCResult::Type::NUM, "walletversion", "the wallet version"}, {RPCResult::Type::STR, "format", "the database format (bdb or sqlite)"}, - {RPCResult::Type::STR_AMOUNT, "balance", "DEPRECATED. Identical to getbalances().mine.trusted"}, - {RPCResult::Type::STR_AMOUNT, "unconfirmed_balance", "DEPRECATED. Identical to getbalances().mine.untrusted_pending"}, - {RPCResult::Type::STR_AMOUNT, "immature_balance", "DEPRECATED. Identical to getbalances().mine.immature"}, + {RPCResult::Type::OBJ, "balance", "DEPRECATED. Identical to getbalances().mine.trusted", { + // A different entry for each asset in the wallet + {RPCResult::Type::STR_AMOUNT, "bitcoin", "amount of bitcoin in the wallet"}, + }, /*skip_type_check=*/true}, + {RPCResult::Type::OBJ, "unconfirmed_balance", "DEPRECATED. Identical to getbalances().mine.untrusted_pending", { + // A different entry for each asset in the wallet + {RPCResult::Type::STR_AMOUNT, "bitcoin", "amount of bitcoin in the wallet"}, + }, /*skip_type_check=*/true}, + {RPCResult::Type::OBJ, "immature_balance", "DEPRECATED. Identical to getbalances().mine.immature", { + // A different entry for each asset in the wallet + {RPCResult::Type::STR_AMOUNT, "bitcoin", "amount of bitcoin in the wallet"}, + }, /*skip_type_check=*/true}, {RPCResult::Type::NUM, "txcount", "the total number of transactions in the wallet"}, {RPCResult::Type::NUM_TIME, "keypoololdest", /*optional=*/true, "the " + UNIX_EPOCH_TIME + " of the oldest pre-generated key in the key pool. Legacy wallets only."}, {RPCResult::Type::NUM, "keypoolsize", "how many new keys are pre-generated (only counts external keys)"},