mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
Merge bitcoin/bitcoin#22650: Remove -deprecatedrpc=addresses flag and corresponding code/logic
43cd6b8af9
doc: add release notes for removal of the -deprecatedrpc=addresses flag (Michael Dietz)2b1fdc2c6c
refactor: minor styling, prefer snake case and same line if (Michael Dietz)d64deac7b8
refactor: share logic between ScriptPubKeyToUniv and ScriptToUniv (Michael Dietz)8721638daa
rpc: remove deprecated addresses and reqSigs from rpc outputs (Michael Dietz) Pull request description: Resolves #21797 now that we've branched-off to v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed. `-deprecatedrpc=addresses` was initially added in this PR #20286 (which resolved the original issue #20102). Some chunks of code and logic are no longer used/necessary with the removal of this, and therefore some minor refactoring is done in this PR as well (separated commits) ACKs for top commit: MarcoFalke: re-ACK43cd6b8af9
🐉 meshcollider: Code review ACK43cd6b8af9
jonatack: ACK43cd6b8af9
per `git range-diffa9d0cec
92dc5e9 43cd6b8`, also rebased to latest master, debug built + quick re-review of each commit to bring back context, and ran tests locally at the final commit Tree-SHA512: fba83495e396d3c06f0dcf49292f14f4aa6b68fa758f0503941fade1a6e7271cda8378e2734af1faea550d1b43c85a36c52ebcc9dec0732936f9233b4b97901c
This commit is contained in:
commit
d6492d4ed0
15 changed files with 53 additions and 316 deletions
|
@ -64,6 +64,12 @@ P2P and network changes
|
|||
Updated RPCs
|
||||
------------
|
||||
|
||||
- The `-deprecatedrpc=addresses` configuration option has been removed. RPCs
|
||||
`gettxout`, `getrawtransaction`, `decoderawtransaction`, `decodescript`,
|
||||
`gettransaction verbose=true` and REST endpoints `/rest/tx`, `/rest/getutxos`,
|
||||
`/rest/block` no longer return the `addresses` and `reqSigs` fields, which
|
||||
were previously deprecated in 22.0. (#22650)
|
||||
|
||||
New RPCs
|
||||
--------
|
||||
|
||||
|
|
|
@ -727,7 +727,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
|
|||
static void OutputTxJSON(const CTransaction& tx)
|
||||
{
|
||||
UniValue entry(UniValue::VOBJ);
|
||||
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
|
||||
TxToUniv(tx, uint256(), entry);
|
||||
|
||||
std::string jsonOutput = entry.write(4);
|
||||
tfm::format(std::cout, "%s\n", jsonOutput);
|
||||
|
|
|
@ -44,8 +44,8 @@ UniValue ValueFromAmount(const CAmount amount);
|
|||
std::string FormatScript(const CScript& script);
|
||||
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
|
||||
std::string SighashToStr(unsigned char sighash_type);
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
|
||||
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
|
||||
void ScriptToUniv(const CScript& script, UniValue& out);
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
|
||||
|
||||
#endif // BITCOIN_CORE_IO_H
|
||||
|
|
|
@ -141,56 +141,28 @@ std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags)
|
|||
return HexStr(ssTx);
|
||||
}
|
||||
|
||||
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
|
||||
void ScriptToUniv(const CScript& script, UniValue& out)
|
||||
{
|
||||
out.pushKV("asm", ScriptToAsmStr(script));
|
||||
out.pushKV("hex", HexStr(script));
|
||||
|
||||
std::vector<std::vector<unsigned char>> solns;
|
||||
TxoutType type = Solver(script, solns);
|
||||
out.pushKV("type", GetTxnOutputType(type));
|
||||
|
||||
CTxDestination address;
|
||||
if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
|
||||
out.pushKV("address", EncodeDestination(address));
|
||||
}
|
||||
ScriptPubKeyToUniv(script, out, /* include_hex */ true, /* include_address */ false);
|
||||
}
|
||||
|
||||
// TODO: from v23 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option
|
||||
// this method can also be combined with `ScriptToUniv` as they will overlap
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
|
||||
UniValue& out, bool fIncludeHex, bool include_addresses)
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address)
|
||||
{
|
||||
TxoutType type;
|
||||
CTxDestination address;
|
||||
std::vector<CTxDestination> addresses;
|
||||
int nRequired;
|
||||
|
||||
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
|
||||
if (fIncludeHex)
|
||||
out.pushKV("hex", HexStr(scriptPubKey));
|
||||
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
|
||||
|
||||
if (!ExtractDestinations(scriptPubKey, type, addresses, nRequired) || type == TxoutType::PUBKEY) {
|
||||
out.pushKV("type", GetTxnOutputType(type));
|
||||
return;
|
||||
}
|
||||
std::vector<std::vector<unsigned char>> solns;
|
||||
const TxoutType type{Solver(scriptPubKey, solns)};
|
||||
|
||||
if (ExtractDestination(scriptPubKey, address)) {
|
||||
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
|
||||
out.pushKV("address", EncodeDestination(address));
|
||||
}
|
||||
out.pushKV("type", GetTxnOutputType(type));
|
||||
|
||||
if (include_addresses) {
|
||||
UniValue a(UniValue::VARR);
|
||||
for (const CTxDestination& addr : addresses) {
|
||||
a.push_back(EncodeDestination(addr));
|
||||
}
|
||||
out.pushKV("addresses", a);
|
||||
out.pushKV("reqSigs", nRequired);
|
||||
}
|
||||
}
|
||||
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
|
||||
{
|
||||
entry.pushKV("txid", tx.GetHash().GetHex());
|
||||
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
|
||||
|
@ -249,7 +221,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_add
|
|||
out.pushKV("n", (int64_t)i);
|
||||
|
||||
UniValue o(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
|
||||
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
|
||||
out.pushKV("scriptPubKey", o);
|
||||
vout.push_back(out);
|
||||
|
||||
|
|
|
@ -1256,11 +1256,8 @@ static RPCHelpMan gettxout()
|
|||
{RPCResult::Type::OBJ, "scriptPubKey", "", {
|
||||
{RPCResult::Type::STR, "asm", ""},
|
||||
{RPCResult::Type::STR_HEX, "hex", ""},
|
||||
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
|
||||
{RPCResult::Type::STR, "type", "The type, eg pubkeyhash"},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
|
||||
{{RPCResult::Type::STR, "address", "bitcoin address"}}},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
}},
|
||||
{RPCResult::Type::BOOL, "coinbase", "Coinbase or not"},
|
||||
}},
|
||||
|
@ -1933,16 +1930,6 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
|
|||
}
|
||||
}
|
||||
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex)
|
||||
{
|
||||
ScriptPubKeyToUniv(scriptPubKey, out, fIncludeHex, IsDeprecatedRPCEnabled("addresses"));
|
||||
}
|
||||
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo)
|
||||
{
|
||||
TxToUniv(tx, hashBlock, IsDeprecatedRPCEnabled("addresses"), entry, include_hex, serialize_flags, txundo);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static inline bool SetHasKeys(const std::set<T>& set) {return false;}
|
||||
template<typename T, typename Tk, typename... Args>
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#define BITCOIN_RPC_BLOCKCHAIN_H
|
||||
|
||||
#include <amount.h>
|
||||
#include <core_io.h>
|
||||
#include <streams.h>
|
||||
#include <sync.h>
|
||||
|
||||
|
@ -53,9 +52,6 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
|
|||
/** Used by getblockstats to get feerates at different percentiles by weight */
|
||||
void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_weight);
|
||||
|
||||
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
|
||||
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
|
||||
|
||||
NodeContext& EnsureAnyNodeContext(const std::any& context);
|
||||
CTxMemPool& EnsureMemPool(const NodeContext& node);
|
||||
CTxMemPool& EnsureAnyMemPool(const std::any& context);
|
||||
|
|
|
@ -131,13 +131,8 @@ static RPCHelpMan getrawtransaction()
|
|||
{
|
||||
{RPCResult::Type::STR, "asm", "the asm"},
|
||||
{RPCResult::Type::STR, "hex", "the hex"},
|
||||
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
|
||||
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
|
||||
{
|
||||
{RPCResult::Type::STR, "address", "bitcoin address"},
|
||||
}},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
|
@ -495,13 +490,8 @@ static RPCHelpMan decoderawtransaction()
|
|||
{
|
||||
{RPCResult::Type::STR, "asm", "the asm"},
|
||||
{RPCResult::Type::STR_HEX, "hex", "the hex"},
|
||||
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
|
||||
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
|
||||
{
|
||||
{RPCResult::Type::STR, "address", "bitcoin address"},
|
||||
}},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
}},
|
||||
}},
|
||||
}},
|
||||
|
@ -554,24 +544,14 @@ static RPCHelpMan decodescript()
|
|||
{
|
||||
{RPCResult::Type::STR, "asm", "Script public key"},
|
||||
{RPCResult::Type::STR, "type", "The output type (e.g. "+GetAllOutputTypes()+")"},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
|
||||
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
|
||||
{
|
||||
{RPCResult::Type::STR, "address", "bitcoin address"},
|
||||
}},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::STR, "p2sh", /* optional */ true, "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
|
||||
{RPCResult::Type::OBJ, "segwit", /* optional */ true, "Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness)",
|
||||
{
|
||||
{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, "bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
|
||||
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of bitcoin addresses",
|
||||
{
|
||||
{RPCResult::Type::STR, "address", "segwit address"},
|
||||
}},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
{RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"},
|
||||
}},
|
||||
}
|
||||
|
@ -592,7 +572,7 @@ static RPCHelpMan decodescript()
|
|||
} else {
|
||||
// Empty scripts are valid
|
||||
}
|
||||
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
|
||||
ScriptPubKeyToUniv(script, r, /* include_hex */ false);
|
||||
|
||||
UniValue type;
|
||||
type = find_value(r, "type");
|
||||
|
@ -626,7 +606,7 @@ static RPCHelpMan decodescript()
|
|||
// Newer segwit program versions should be considered when then become available.
|
||||
segwitScr = GetScriptForDestination(WitnessV0ScriptHash(script));
|
||||
}
|
||||
ScriptPubKeyToUniv(segwitScr, sr, /* fIncludeHex */ true);
|
||||
ScriptPubKeyToUniv(segwitScr, sr, /* include_hex */ true);
|
||||
sr.pushKV("p2sh-segwit", EncodeDestination(ScriptHash(segwitScr)));
|
||||
r.pushKV("segwit", sr);
|
||||
}
|
||||
|
@ -1061,7 +1041,7 @@ static RPCHelpMan decodepsbt()
|
|||
{RPCResult::Type::STR, "asm", "The asm"},
|
||||
{RPCResult::Type::STR_HEX, "hex", "The hex"},
|
||||
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
|
||||
{RPCResult::Type::STR, "address", /*optional=*/true, "Bitcoin address if there is one"},
|
||||
{RPCResult::Type::STR, "address", /* optional */ true, "The Bitcoin address (only if a well-defined address exists)"},
|
||||
}},
|
||||
}},
|
||||
{RPCResult::Type::OBJ_DYN, "partial_signatures", /* optional */ true, "",
|
||||
|
@ -1181,7 +1161,7 @@ static RPCHelpMan decodepsbt()
|
|||
txout = input.witness_utxo;
|
||||
|
||||
UniValue o(UniValue::VOBJ);
|
||||
ScriptToUniv(txout.scriptPubKey, o, true);
|
||||
ScriptPubKeyToUniv(txout.scriptPubKey, o, /* include_hex */ true);
|
||||
|
||||
UniValue out(UniValue::VOBJ);
|
||||
out.pushKV("amount", ValueFromAmount(txout.nValue));
|
||||
|
@ -1228,12 +1208,12 @@ static RPCHelpMan decodepsbt()
|
|||
// Redeem script and witness script
|
||||
if (!input.redeem_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(input.redeem_script, r, false);
|
||||
ScriptToUniv(input.redeem_script, r);
|
||||
in.pushKV("redeem_script", r);
|
||||
}
|
||||
if (!input.witness_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(input.witness_script, r, false);
|
||||
ScriptToUniv(input.witness_script, r);
|
||||
in.pushKV("witness_script", r);
|
||||
}
|
||||
|
||||
|
@ -1288,12 +1268,12 @@ static RPCHelpMan decodepsbt()
|
|||
// Redeem script and witness script
|
||||
if (!output.redeem_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(output.redeem_script, r, false);
|
||||
ScriptToUniv(output.redeem_script, r);
|
||||
out.pushKV("redeem_script", r);
|
||||
}
|
||||
if (!output.witness_script.empty()) {
|
||||
UniValue r(UniValue::VOBJ);
|
||||
ScriptToUniv(output.witness_script, r, false);
|
||||
ScriptToUniv(output.witness_script, r);
|
||||
out.pushKV("witness_script", r);
|
||||
}
|
||||
|
||||
|
|
|
@ -266,47 +266,6 @@ bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
// TODO: from v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
|
||||
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet)
|
||||
{
|
||||
addressRet.clear();
|
||||
std::vector<valtype> vSolutions;
|
||||
typeRet = Solver(scriptPubKey, vSolutions);
|
||||
if (typeRet == TxoutType::NONSTANDARD) {
|
||||
return false;
|
||||
} else if (typeRet == TxoutType::NULL_DATA) {
|
||||
// This is data, not addresses
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeRet == TxoutType::MULTISIG)
|
||||
{
|
||||
nRequiredRet = vSolutions.front()[0];
|
||||
for (unsigned int i = 1; i < vSolutions.size()-1; i++)
|
||||
{
|
||||
CPubKey pubKey(vSolutions[i]);
|
||||
if (!pubKey.IsValid())
|
||||
continue;
|
||||
|
||||
CTxDestination address = PKHash(pubKey);
|
||||
addressRet.push_back(address);
|
||||
}
|
||||
|
||||
if (addressRet.empty())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nRequiredRet = 1;
|
||||
CTxDestination address;
|
||||
if (!ExtractDestination(scriptPubKey, address))
|
||||
return false;
|
||||
addressRet.push_back(address);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
class CScriptVisitor
|
||||
{
|
||||
|
|
|
@ -176,27 +176,11 @@ TxoutType Solver(const CScript& scriptPubKey, std::vector<std::vector<unsigned c
|
|||
|
||||
/**
|
||||
* Parse a standard scriptPubKey for the destination address. Assigns result to
|
||||
* the addressRet parameter and returns true if successful. For multisig
|
||||
* scripts, instead use ExtractDestinations. Currently only works for P2PK,
|
||||
* the addressRet parameter and returns true if successful. Currently only works for P2PK,
|
||||
* P2PKH, P2SH, P2WPKH, and P2WSH scripts.
|
||||
*/
|
||||
bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet);
|
||||
|
||||
/**
|
||||
* Parse a standard scriptPubKey with one or more destination addresses. For
|
||||
* multisig scripts, this populates the addressRet vector with the pubkey IDs
|
||||
* and nRequiredRet with the n required to spend. For other destinations,
|
||||
* addressRet is populated with a single value and nRequiredRet is set to 1.
|
||||
* Returns true if successful.
|
||||
*
|
||||
* Note: this function confuses destinations (a subset of CScripts that are
|
||||
* encodable as an address) with key identifiers (of keys involved in a
|
||||
* CScript), and its use should be phased out.
|
||||
*
|
||||
* TODO: from v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed
|
||||
*/
|
||||
bool ExtractDestinations(const CScript& scriptPubKey, TxoutType& typeRet, std::vector<CTxDestination>& addressRet, int& nRequiredRet);
|
||||
|
||||
/**
|
||||
* Generate a Bitcoin scriptPubKey for the given CTxDestination. Returns a P2PKH
|
||||
* script for a CKeyID destination, a P2SH script for a CScriptID, and an empty
|
||||
|
|
|
@ -56,46 +56,8 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||
assert(script == decompressed_script);
|
||||
}
|
||||
|
||||
CTxDestination address;
|
||||
TxoutType type_ret;
|
||||
std::vector<CTxDestination> addresses;
|
||||
int required_ret;
|
||||
bool extract_destinations_ret = ExtractDestinations(script, type_ret, addresses, required_ret);
|
||||
bool extract_destination_ret = ExtractDestination(script, address);
|
||||
if (!extract_destinations_ret) {
|
||||
assert(!extract_destination_ret);
|
||||
if (type_ret == TxoutType::MULTISIG) {
|
||||
assert(addresses.empty() && required_ret == 0);
|
||||
} else {
|
||||
assert(type_ret == TxoutType::PUBKEY ||
|
||||
type_ret == TxoutType::NONSTANDARD ||
|
||||
type_ret == TxoutType::NULL_DATA);
|
||||
}
|
||||
} else {
|
||||
assert(required_ret >= 1 && required_ret <= 16);
|
||||
assert((unsigned long)required_ret == addresses.size());
|
||||
assert(type_ret == TxoutType::MULTISIG || required_ret == 1);
|
||||
}
|
||||
if (type_ret == TxoutType::NONSTANDARD || type_ret == TxoutType::NULL_DATA) {
|
||||
assert(!extract_destinations_ret);
|
||||
}
|
||||
if (!extract_destination_ret) {
|
||||
assert(type_ret == TxoutType::PUBKEY ||
|
||||
type_ret == TxoutType::NONSTANDARD ||
|
||||
type_ret == TxoutType::NULL_DATA ||
|
||||
type_ret == TxoutType::MULTISIG);
|
||||
} else {
|
||||
assert(address == addresses[0]);
|
||||
}
|
||||
if (type_ret == TxoutType::NONSTANDARD ||
|
||||
type_ret == TxoutType::NULL_DATA ||
|
||||
type_ret == TxoutType::MULTISIG) {
|
||||
assert(!extract_destination_ret);
|
||||
}
|
||||
|
||||
TxoutType which_type;
|
||||
bool is_standard_ret = IsStandard(script, which_type);
|
||||
assert(type_ret == which_type);
|
||||
if (!is_standard_ret) {
|
||||
assert(which_type == TxoutType::NONSTANDARD ||
|
||||
which_type == TxoutType::NULL_DATA ||
|
||||
|
@ -112,6 +74,20 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||
which_type == TxoutType::NONSTANDARD);
|
||||
}
|
||||
|
||||
CTxDestination address;
|
||||
bool extract_destination_ret = ExtractDestination(script, address);
|
||||
if (!extract_destination_ret) {
|
||||
assert(which_type == TxoutType::PUBKEY ||
|
||||
which_type == TxoutType::NONSTANDARD ||
|
||||
which_type == TxoutType::NULL_DATA ||
|
||||
which_type == TxoutType::MULTISIG);
|
||||
}
|
||||
if (which_type == TxoutType::NONSTANDARD ||
|
||||
which_type == TxoutType::NULL_DATA ||
|
||||
which_type == TxoutType::MULTISIG) {
|
||||
assert(!extract_destination_ret);
|
||||
}
|
||||
|
||||
const FlatSigningProvider signing_provider;
|
||||
(void)InferDescriptor(script, signing_provider);
|
||||
(void)IsSegWitOutput(signing_provider, script);
|
||||
|
@ -133,15 +109,11 @@ FUZZ_TARGET_INIT(script, initialize_script)
|
|||
(void)ScriptToAsmStr(script, true);
|
||||
|
||||
UniValue o1(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(script, o1, true, true);
|
||||
ScriptPubKeyToUniv(script, o1, true, false);
|
||||
ScriptPubKeyToUniv(script, o1, true);
|
||||
UniValue o2(UniValue::VOBJ);
|
||||
ScriptPubKeyToUniv(script, o2, false, true);
|
||||
ScriptPubKeyToUniv(script, o2, false, false);
|
||||
ScriptPubKeyToUniv(script, o2, false);
|
||||
UniValue o3(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o3, true);
|
||||
UniValue o4(UniValue::VOBJ);
|
||||
ScriptToUniv(script, o4, false);
|
||||
ScriptToUniv(script, o3);
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
|
|
|
@ -103,6 +103,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
|
|||
(void)IsWitnessStandard(tx, coins_view_cache);
|
||||
|
||||
UniValue u(UniValue::VOBJ);
|
||||
TxToUniv(tx, /* hashBlock */ uint256::ZERO, /* include_addresses */ true, u);
|
||||
TxToUniv(tx, /* hashBlock */ uint256::ONE, /* include_addresses */ false, u);
|
||||
TxToUniv(tx, /* hashBlock */ uint256::ZERO, u);
|
||||
TxToUniv(tx, /* hashBlock */ uint256::ONE, u);
|
||||
}
|
||||
|
|
|
@ -252,67 +252,6 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
|
|||
BOOST_CHECK(std::get<WitnessUnknown>(address) == unk);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
|
||||
{
|
||||
CKey keys[3];
|
||||
CPubKey pubkeys[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
keys[i].MakeNewKey(true);
|
||||
pubkeys[i] = keys[i].GetPubKey();
|
||||
}
|
||||
|
||||
CScript s;
|
||||
TxoutType whichType;
|
||||
std::vector<CTxDestination> addresses;
|
||||
int nRequired;
|
||||
|
||||
// TxoutType::PUBKEY
|
||||
s.clear();
|
||||
s << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TxoutType::PUBKEYHASH
|
||||
s.clear();
|
||||
s << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
|
||||
// TxoutType::SCRIPTHASH
|
||||
CScript redeemScript(s); // initialize with leftover P2PKH script
|
||||
s.clear();
|
||||
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 1U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 1);
|
||||
BOOST_CHECK(std::get<ScriptHash>(addresses[0]) == ScriptHash(redeemScript));
|
||||
|
||||
// TxoutType::MULTISIG
|
||||
s.clear();
|
||||
s << OP_2 <<
|
||||
ToByteVector(pubkeys[0]) <<
|
||||
ToByteVector(pubkeys[1]) <<
|
||||
OP_2 << OP_CHECKMULTISIG;
|
||||
BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
|
||||
BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
|
||||
BOOST_CHECK_EQUAL(addresses.size(), 2U);
|
||||
BOOST_CHECK_EQUAL(nRequired, 2);
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
|
||||
BOOST_CHECK(std::get<PKHash>(addresses[1]) == PKHash(pubkeys[1]));
|
||||
|
||||
// TxoutType::NULL_DATA
|
||||
s.clear();
|
||||
s << OP_RETURN << std::vector<unsigned char>({75});
|
||||
BOOST_CHECK(!ExtractDestinations(s, whichType, addresses, nRequired));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
||||
{
|
||||
CKey keys[3];
|
||||
|
|
|
@ -1762,7 +1762,7 @@ static RPCHelpMan gettransaction()
|
|||
|
||||
if (verbose) {
|
||||
UniValue decoded(UniValue::VOBJ);
|
||||
TxToUniv(*wtx.tx, uint256(), pwallet->chain().rpcEnableDeprecated("addresses"), decoded, false);
|
||||
TxToUniv(*wtx.tx, uint256(), decoded, false);
|
||||
entry.pushKV("decoded", decoded);
|
||||
}
|
||||
|
||||
|
@ -3799,7 +3799,6 @@ public:
|
|||
obj.pushKV("embedded", std::move(subobj));
|
||||
} else if (which_type == TxoutType::MULTISIG) {
|
||||
// Also report some information on multisig scripts (which do not have a corresponding address).
|
||||
// TODO: abstract out the common functionality between this logic and ExtractDestinations.
|
||||
obj.pushKV("sigsrequired", solutions_data[0][0]);
|
||||
UniValue pubkeys(UniValue::VARR);
|
||||
for (size_t i = 1; i < solutions_data.size() - 1; ++i) {
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2020 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
"""Test deprecation of reqSigs and addresses RPC fields."""
|
||||
|
||||
from test_framework.messages import (
|
||||
tx_from_hex,
|
||||
)
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
)
|
||||
|
||||
|
||||
class AddressesDeprecationTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [[], ["-deprecatedrpc=addresses"]]
|
||||
|
||||
def skip_test_if_missing_module(self):
|
||||
self.skip_if_no_wallet()
|
||||
|
||||
def run_test(self):
|
||||
self.test_addresses_deprecation()
|
||||
|
||||
def test_addresses_deprecation(self):
|
||||
node = self.nodes[0]
|
||||
coin = node.listunspent().pop()
|
||||
|
||||
inputs = [{'txid': coin['txid'], 'vout': coin['vout']}]
|
||||
outputs = {node.getnewaddress(): 0.99}
|
||||
raw = node.createrawtransaction(inputs, outputs)
|
||||
signed = node.signrawtransactionwithwallet(raw)['hex']
|
||||
|
||||
# This transaction is derived from test/util/data/txcreatemultisig1.json
|
||||
tx = tx_from_hex(signed)
|
||||
tx.vout[0].scriptPubKey = bytes.fromhex("522102a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff39721021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d2102df2089105c77f266fa11a9d33f05c735234075f2e8780824c6b709415f9fb48553ae")
|
||||
tx_signed = node.signrawtransactionwithwallet(tx.serialize().hex())['hex']
|
||||
txid = node.sendrawtransaction(hexstring=tx_signed, maxfeerate=0)
|
||||
|
||||
self.log.info("Test RPCResult scriptPubKey no longer returns the fields addresses or reqSigs by default")
|
||||
hash = self.generateblock(node, output=node.getnewaddress(), transactions=[txid])['hash']
|
||||
# Ensure both nodes have the newly generated block on disk.
|
||||
self.sync_blocks()
|
||||
script_pub_key = node.getblock(blockhash=hash, verbose=2)['tx'][-1]['vout'][0]['scriptPubKey']
|
||||
assert 'addresses' not in script_pub_key and 'reqSigs' not in script_pub_key
|
||||
|
||||
self.log.info("Test RPCResult scriptPubKey returns the addresses field with -deprecatedrpc=addresses")
|
||||
script_pub_key = self.nodes[1].getblock(blockhash=hash, verbose=2)['tx'][-1]['vout'][0]['scriptPubKey']
|
||||
assert_equal(script_pub_key['addresses'], ['mvKDK6D54HU8wQumJBLHY95eq5iHFqXSBz', 'mv3rHCQSwKp2BLSuMHD8uCS32LW5xiNAA5', 'mirrsyhAQYzo5CwVhcaYJKwUJu1WJRCRJe'])
|
||||
assert_equal(script_pub_key['reqSigs'], 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
AddressesDeprecationTest().main()
|
|
@ -304,7 +304,6 @@ BASE_SCRIPTS = [
|
|||
'feature_presegwit_node_upgrade.py',
|
||||
'feature_settings.py',
|
||||
'rpc_getdescriptorinfo.py',
|
||||
'rpc_addresses_deprecation.py',
|
||||
'rpc_help.py',
|
||||
'feature_help.py',
|
||||
'feature_shutdown.py',
|
||||
|
|
Loading…
Add table
Reference in a new issue