aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2023-09-07 19:16:57 +1000
committerAnthony Towns <aj@erisian.com.au>2023-11-14 08:45:30 +1000
commit6e9e4e6130797b721c8df1eabaf46ec25ebb6abe (patch)
tree6444c337cd23d1e6aabedf229a9efb1583fb7351 /src/rpc
parent5800c558eb5efb4839ed00d6967e43306d68e1c3 (diff)
downloadbitcoin-6e9e4e6130797b721c8df1eabaf46ec25ebb6abe.tar.xz
Use ParamsWrapper for witness serialization
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp10
-rw-r--r--src/rpc/mining.cpp4
-rw-r--r--src/rpc/rawtransaction.cpp10
-rw-r--r--src/rpc/server.cpp7
-rw-r--r--src/rpc/server.h11
5 files changed, 23 insertions, 19 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index 7b84747a3f..9a29b73bee 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -166,8 +166,8 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
{
UniValue result = blockheaderToJSON(tip, blockindex);
- result.pushKV("strippedsize", (int)::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS));
- result.pushKV("size", (int)::GetSerializeSize(block, PROTOCOL_VERSION));
+ result.pushKV("strippedsize", (int)::GetSerializeSize(TX_NO_WITNESS(block)));
+ result.pushKV("size", (int)::GetSerializeSize(TX_WITH_WITNESS(block)));
result.pushKV("weight", (int)::GetBlockWeight(block));
UniValue txs(UniValue::VARR);
@@ -189,7 +189,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn
// coinbase transaction (i.e. i == 0) doesn't have undo data
const CTxUndo* txundo = (have_undo && i > 0) ? &blockUndo.vtxundo.at(i - 1) : nullptr;
UniValue objTx(UniValue::VOBJ);
- TxToUniv(*tx, /*block_hash=*/uint256(), /*entry=*/objTx, /*include_hex=*/true, RPCSerializationFlags(), txundo, verbosity);
+ TxToUniv(*tx, /*block_hash=*/uint256(), /*entry=*/objTx, /*include_hex=*/true, /*without_witness=*/RPCSerializationWithoutWitness(), txundo, verbosity);
txs.push_back(objTx);
}
break;
@@ -740,8 +740,8 @@ static RPCHelpMan getblock()
if (verbosity <= 0)
{
- CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags());
- ssBlock << block;
+ DataStream ssBlock;
+ ssBlock << RPCTxSerParams(block);
std::string strHex = HexStr(ssBlock);
return strHex;
}
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 76170c3201..1bdc1e1029 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -390,8 +390,8 @@ static RPCHelpMan generateblock()
UniValue obj(UniValue::VOBJ);
obj.pushKV("hash", block_out->GetHash().GetHex());
if (!process_new_block) {
- CDataStream block_ser{SER_NETWORK, PROTOCOL_VERSION | RPCSerializationFlags()};
- block_ser << *block_out;
+ DataStream block_ser;
+ block_ser << RPCTxSerParams(*block_out);
obj.pushKV("hex", HexStr(block_ser));
}
return obj;
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 16705b3ce2..397ece08c0 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -62,7 +62,7 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
// Blockchain contextual information (confirmations and blocktime) is not
// available to code in bitcoin-common, so we query them here and push the
// data into the returned UniValue.
- TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, RPCSerializationFlags(), txundo, verbosity);
+ TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, RPCSerializationWithoutWitness(), txundo, verbosity);
if (!hashBlock.IsNull()) {
LOCK(cs_main);
@@ -383,7 +383,7 @@ static RPCHelpMan getrawtransaction()
}
if (verbosity <= 0) {
- return EncodeHexTx(*tx, RPCSerializationFlags());
+ return EncodeHexTx(*tx, /*without_witness=*/RPCSerializationWithoutWitness());
}
UniValue result(UniValue::VOBJ);
@@ -1541,7 +1541,7 @@ static RPCHelpMan finalizepsbt()
std::string result_str;
if (complete && extract) {
- ssTx << mtx;
+ ssTx << TX_WITH_WITNESS(mtx);
result_str = HexStr(ssTx);
result.pushKV("hex", result_str);
} else {
@@ -1994,8 +1994,8 @@ RPCHelpMan descriptorprocesspsbt()
CMutableTransaction mtx;
PartiallySignedTransaction psbtx_copy = psbtx;
CHECK_NONFATAL(FinalizeAndExtractPSBT(psbtx_copy, mtx));
- CDataStream ssTx_final(SER_NETWORK, PROTOCOL_VERSION);
- ssTx_final << mtx;
+ DataStream ssTx_final;
+ ssTx_final << TX_WITH_WITNESS(mtx);
result.pushKV("hex", HexStr(ssTx_final));
}
return result;
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index d3c5a19326..5de05e2e67 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -595,12 +595,9 @@ void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nS
deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000)));
}
-int RPCSerializationFlags()
+bool RPCSerializationWithoutWitness()
{
- int flag = 0;
- if (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0)
- flag |= SERIALIZE_TRANSACTION_NO_WITNESS;
- return flag;
+ return (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0);
}
CRPCTable tableRPC;
diff --git a/src/rpc/server.h b/src/rpc/server.h
index 24658ddb8b..9a49d82570 100644
--- a/src/rpc/server.h
+++ b/src/rpc/server.h
@@ -183,7 +183,14 @@ void InterruptRPC();
void StopRPC();
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
-// Retrieves any serialization flags requested in command line argument
-int RPCSerializationFlags();
+// Drop witness when serializing for RPC?
+bool RPCSerializationWithoutWitness();
+
+template<typename T>
+auto RPCTxSerParams(T&& t)
+{
+ if (RPCSerializationWithoutWitness()) return TX_NO_WITNESS(t);
+ return TX_WITH_WITNESS(t);
+}
#endif // BITCOIN_RPC_SERVER_H