mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 02:33:24 -03:00
Dump transaction version as an unsigned integer in RPC/TxToUniv
Consensus-wise we already treat it as an unsigned integer (the only rules around it are in CSV/locktime handling), but changing the underlying data type means touching consensus code for a simple cleanup change, which isn't really worth it. See-also, https://github.com/rust-bitcoin/rust-bitcoin/pull/299
This commit is contained in:
parent
e653eeff76
commit
970de70bdd
3 changed files with 12 additions and 2 deletions
7
doc/release-notes-16525.md
Normal file
7
doc/release-notes-16525.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
RPC changes
|
||||
-----------
|
||||
|
||||
Exposed transaction version numbers are now treated as unsigned 32-bit integers
|
||||
instead of signed 32-bit integers. This matches their treatment in consensus
|
||||
logic. Versions greater than 2 continue to be non-standard (matching previous
|
||||
behavior of smaller than 1 or greater than 2 being non-standard).
|
|
@ -179,7 +179,9 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
|
|||
{
|
||||
entry.pushKV("txid", tx.GetHash().GetHex());
|
||||
entry.pushKV("hash", tx.GetWitnessHash().GetHex());
|
||||
entry.pushKV("version", tx.nVersion);
|
||||
// Transaction version is actually unsigned in consensus checks, just signed in memory,
|
||||
// so cast to unsigned before giving it to the user.
|
||||
entry.pushKV("version", static_cast<int64_t>(static_cast<uint32_t>(tx.nVersion)));
|
||||
entry.pushKV("size", (int)::GetSerializeSize(tx, PROTOCOL_VERSION));
|
||||
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
|
||||
entry.pushKV("weight", GetTransactionWeight(tx));
|
||||
|
|
|
@ -417,11 +417,12 @@ class RawTransactionsTest(BitcoinTestFramework):
|
|||
####################################
|
||||
|
||||
# Test the minimum transaction version number that fits in a signed 32-bit integer.
|
||||
# As transaction version is unsigned, this should convert to its unsigned equivalent.
|
||||
tx = CTransaction()
|
||||
tx.nVersion = -0x80000000
|
||||
rawtx = ToHex(tx)
|
||||
decrawtx = self.nodes[0].decoderawtransaction(rawtx)
|
||||
assert_equal(decrawtx['version'], -0x80000000)
|
||||
assert_equal(decrawtx['version'], 0x80000000)
|
||||
|
||||
# Test the maximum transaction version number that fits in a signed 32-bit integer.
|
||||
tx = CTransaction()
|
||||
|
|
Loading…
Add table
Reference in a new issue