Skip to content

Commit 51a68b0

Browse files
committed
merge bitcoin#24673: followup of remove -deprecatedrpc=addresses flag
1 parent d4fc4dd commit 51a68b0

File tree

10 files changed

+39
-40
lines changed

10 files changed

+39
-40
lines changed

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
691691
static void OutputTxJSON(const CTransaction& tx)
692692
{
693693
UniValue entry(UniValue::VOBJ);
694-
TxToUniv(tx, uint256(), entry);
694+
TxToUniv(tx, /*block_hash=*/uint256(), entry);
695695

696696
std::string jsonOutput = entry.write(4);
697697
tfm::format(std::cout, "%s\n", jsonOutput);

src/core_io.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ UniValue ValueFromAmount(const CAmount amount);
5454
std::string FormatScript(const CScript& script);
5555
std::string EncodeHexTx(const CTransaction& tx);
5656
std::string SighashToStr(unsigned char sighash_type);
57-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address = true);
58-
void ScriptToUniv(const CScript& script, UniValue& out);
59-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
57+
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false);
58+
void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
6059

6160
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include <evo/specialtx.h>
3030
#include <llmq/commitment.h>
3131

32+
#include <map>
33+
#include <string>
34+
#include <vector>
35+
3236
UniValue ValueFromAmount(const CAmount amount)
3337
{
3438
static_assert(COIN > 1);
@@ -153,31 +157,28 @@ std::string EncodeHexTx(const CTransaction& tx)
153157
return HexStr(ssTx);
154158
}
155159

156-
void ScriptToUniv(const CScript& script, UniValue& out)
157-
{
158-
ScriptPubKeyToUniv(script, out, /* include_hex */ true, /* include_address */ false);
159-
}
160-
161-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include_hex, bool include_address)
160+
void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool include_address)
162161
{
163162
CTxDestination address;
164163

165-
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
164+
out.pushKV("asm", ScriptToAsmStr(script));
166165
if (include_address) {
167-
out.pushKV("desc", InferDescriptor(scriptPubKey, DUMMY_SIGNING_PROVIDER)->ToString());
166+
out.pushKV("desc", InferDescriptor(script, DUMMY_SIGNING_PROVIDER)->ToString());
167+
}
168+
if (include_hex) {
169+
out.pushKV("hex", HexStr(script));
168170
}
169-
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
170171

171172
std::vector<std::vector<unsigned char>> solns;
172-
const TxoutType type{Solver(scriptPubKey, solns)};
173+
const TxoutType type{Solver(script, solns)};
173174

174-
if (include_address && ExtractDestination(scriptPubKey, address) && type != TxoutType::PUBKEY) {
175+
if (include_address && ExtractDestination(script, address) && type != TxoutType::PUBKEY) {
175176
out.pushKV("address", EncodeDestination(address));
176177
}
177178
out.pushKV("type", GetTxnOutputType(type));
178179
}
179180

180-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, TxVerbosity verbosity, const CSpentIndexTxInfo* ptxSpentInfo)
181+
void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, int serialize_flags, const CTxUndo* txundo, TxVerbosity verbosity, const CSpentIndexTxInfo* ptxSpentInfo)
181182
{
182183
uint256 txid = tx.GetHash();
183184
entry.pushKV("txid", txid.GetHex());
@@ -233,7 +234,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
233234

234235
if (verbosity == TxVerbosity::SHOW_DETAILS_AND_PREVOUT) {
235236
UniValue o_script_pub_key(UniValue::VOBJ);
236-
ScriptPubKeyToUniv(prev_txout.scriptPubKey, o_script_pub_key, /*include_hex=*/ true, /*include_address=*/true);
237+
ScriptToUniv(prev_txout.scriptPubKey, /*out=*/o_script_pub_key, /*include_hex=*/true, /*include_address=*/true);
237238

238239
UniValue p(UniValue::VOBJ);
239240
p.pushKV("generated", bool(prev_coin.fCoinBase));
@@ -259,7 +260,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
259260
out.pushKV("n", (int64_t)i);
260261

261262
UniValue o(UniValue::VOBJ);
262-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
263+
ScriptToUniv(txout.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
263264
out.pushKV("scriptPubKey", o);
264265

265266
// Add spent information if spentindex is enabled
@@ -335,8 +336,9 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
335336
entry.pushKV("fee", ValueFromAmount(fee));
336337
}
337338

338-
if (!hashBlock.IsNull())
339-
entry.pushKV("blockhash", hashBlock.GetHex());
339+
if (!block_hash.IsNull()) {
340+
entry.pushKV("blockhash", block_hash.GetHex());
341+
}
340342

341343
if (include_hex) {
342344
entry.pushKV("hex", EncodeHexTx(tx)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction".

src/evo/core_write.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
out.pushKV("value", ValueFromAmount(credit_output.nValue));
2121
out.pushKV("valueSat", credit_output.nValue);
2222
UniValue spk(UniValue::VOBJ);
23-
ScriptPubKeyToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false);
23+
ScriptToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false);
2424
out.pushKV("scriptPubKey", spk);
2525
outputs.push_back(out);
2626
}

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static bool rest_tx(const CoreContext& context, HTTPRequest* req, const std::str
694694

695695
case RetFormat::JSON: {
696696
UniValue objTx(UniValue::VOBJ);
697-
TxToUniv(*tx, hashBlock, objTx);
697+
TxToUniv(*tx, /*block_hash=*/hashBlock, /*entry=*/objTx);
698698
std::string strJSON = objTx.write() + "\n";
699699
req->WriteHeader("Content-Type", "application/json");
700700
req->WriteReply(HTTP_OK, strJSON);
@@ -879,7 +879,7 @@ static bool rest_getutxos(const CoreContext& context, HTTPRequest* req, const st
879879

880880
// include the script in a json output
881881
UniValue o(UniValue::VOBJ);
882-
ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true);
882+
ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
883883
utxo.pushKV("scriptPubKey", o);
884884
utxos.push_back(utxo);
885885
}

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
177177
// coinbase transaction (i.e. i == 0) doesn't have undo data
178178
const CTxUndo* txundo = (have_undo && i > 0) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
179179
UniValue objTx(UniValue::VOBJ);
180-
TxToUniv(*tx, uint256(), objTx, true, 0, txundo, verbosity);
180+
TxToUniv(*tx, /*block_hash=*/uint256(), /*entry=*/objTx, /*include_hex=*/true, /*serialize_flags=*/0, txundo, verbosity);
181181
bool fLocked = isman.IsLocked(tx->GetHash());
182182
objTx.pushKV("instantlock", fLocked || result["chainlock"].get_bool());
183183
objTx.pushKV("instantlock_internal", fLocked);
@@ -1310,7 +1310,7 @@ static RPCHelpMan gettxout()
13101310
}
13111311
ret.pushKV("value", ValueFromAmount(coin.out.nValue));
13121312
UniValue o(UniValue::VOBJ);
1313-
ScriptPubKeyToUniv(coin.out.scriptPubKey, o, true);
1313+
ScriptToUniv(coin.out.scriptPubKey, /*out=*/o, /*include_hex=*/true, /*include_address=*/true);
13141314
ret.pushKV("scriptPubKey", o);
13151315
ret.pushKV("coinbase", (bool)coin.fCoinBase);
13161316

src/rpc/rawtransaction.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool
9696
txSpentInfoPtr = &txSpentInfo;
9797
}
9898

99-
TxToUniv(tx, uint256(), entry, true, 0, /* txundo = */ nullptr, TxVerbosity::SHOW_DETAILS, txSpentInfoPtr);
99+
TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, /*serialize_flags=*/0, /*txundo=*/nullptr, TxVerbosity::SHOW_DETAILS, txSpentInfoPtr);
100100

101101
bool chainLock = false;
102102
if (!hashBlock.IsNull()) {
@@ -790,7 +790,7 @@ static RPCHelpMan decoderawtransaction()
790790
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
791791

792792
UniValue result(UniValue::VOBJ);
793-
TxToUniv(CTransaction(std::move(mtx)), uint256(), result, false);
793+
TxToUniv(CTransaction(std::move(mtx)), /*block_hash=*/uint256(), /*entry=*/result, /*include_hex=*/false);
794794

795795
return result;
796796
},
@@ -830,7 +830,7 @@ static RPCHelpMan decodescript()
830830
} else {
831831
// Empty scripts are valid
832832
}
833-
ScriptPubKeyToUniv(script, r, /* include_hex */ false);
833+
ScriptToUniv(script, /*out=*/r, /*include_hex=*/false, /*include_address=*/true);
834834

835835
std::vector<std::vector<unsigned char>> solutions_data;
836836
const TxoutType which_type{Solver(script, solutions_data)};
@@ -1395,7 +1395,7 @@ static RPCHelpMan decodepsbt()
13951395

13961396
// Add the decoded tx
13971397
UniValue tx_univ(UniValue::VOBJ);
1398-
TxToUniv(CTransaction(*psbtx.tx), uint256(), tx_univ, false);
1398+
TxToUniv(CTransaction(*psbtx.tx), /*block_hash=*/uint256(), /*entry=*/tx_univ, /*include_hex=*/false);
13991399
result.pushKV("tx", tx_univ);
14001400

14011401
// Add the global xpubs
@@ -1451,7 +1451,7 @@ static RPCHelpMan decodepsbt()
14511451
txout = input.non_witness_utxo->vout[psbtx.tx->vin[i].prevout.n];
14521452

14531453
UniValue non_wit(UniValue::VOBJ);
1454-
TxToUniv(*input.non_witness_utxo, uint256(), non_wit, false);
1454+
TxToUniv(*input.non_witness_utxo, /*block_hash=*/uint256(), /*entry=*/non_wit, /*include_hex=*/false);
14551455
in.pushKV("non_witness_utxo", non_wit);
14561456

14571457
have_a_utxo = true;
@@ -1484,7 +1484,7 @@ static RPCHelpMan decodepsbt()
14841484
// Redeem script
14851485
if (!input.redeem_script.empty()) {
14861486
UniValue r(UniValue::VOBJ);
1487-
ScriptToUniv(input.redeem_script, r);
1487+
ScriptToUniv(input.redeem_script, /*out=*/r);
14881488
in.pushKV("redeem_script", r);
14891489
}
14901490

@@ -1582,7 +1582,7 @@ static RPCHelpMan decodepsbt()
15821582
// Redeem script
15831583
if (!output.redeem_script.empty()) {
15841584
UniValue r(UniValue::VOBJ);
1585-
ScriptToUniv(output.redeem_script, r);
1585+
ScriptToUniv(output.redeem_script, /*out=*/r);
15861586
out.pushKV("redeem_script", r);
15871587
}
15881588

src/test/fuzz/script_format.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,5 @@ FUZZ_TARGET(script_format, .init = initialize_script_format)
2424
(void)ScriptToAsmStr(script, /*fAttemptSighashDecode=*/fuzzed_data_provider.ConsumeBool());
2525

2626
UniValue o1(UniValue::VOBJ);
27-
ScriptPubKeyToUniv(script, o1, /*include_hex=*/fuzzed_data_provider.ConsumeBool());
28-
UniValue o3(UniValue::VOBJ);
29-
ScriptToUniv(script, o3);
27+
ScriptToUniv(script, /*out=*/o1, /*include_hex=*/fuzzed_data_provider.ConsumeBool(), /*include_address=*/fuzzed_data_provider.ConsumeBool());
3028
}

src/test/fuzz/transaction.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ FUZZ_TARGET(transaction, .init = initialize_transaction)
9494
(void)AreInputsStandard(tx, coins_view_cache);
9595

9696
UniValue u(UniValue::VOBJ);
97-
TxToUniv(tx, /*hashBlock=*/uint256::ZERO, u);
98-
TxToUniv(tx, /*hashBlock=*/uint256::ONE, u);
97+
TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*entry=*/u);
98+
TxToUniv(tx, /*block_hash=*/uint256::ONE, /*entry=*/u);
9999

100-
// TxToUniv(tx, /*hashBlock=*/uint256::ZERO, /*include_addresses=*/true, u);
101-
// TxToUniv(tx, /*hashBlock=*/uint256::ONE, /*include_addresses=*/false, u);
100+
// TxToUniv(tx, /*block_hash=*/uint256::ZERO, /*include_addresses=*/true, u);
101+
// TxToUniv(tx, /*block_hash=*/uint256::ONE, /*include_addresses=*/false, u);
102102
}

src/wallet/rpc/transactions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ RPCHelpMan gettransaction()
791791

792792
if (verbose) {
793793
UniValue decoded(UniValue::VOBJ);
794-
TxToUniv(*wtx.tx, uint256(), decoded, false);
794+
TxToUniv(*wtx.tx, /*block_hash=*/uint256(), /*entry=*/decoded, /*include_hex=*/false);
795795
entry.pushKV("decoded", decoded);
796796
}
797797

0 commit comments

Comments
 (0)