Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,11 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry
}

if (tx.nType == TRANSACTION_PROVIDER_REGISTER) {
if (const auto opt_proTx = GetTxPayload<CProRegTx>(tx)) {
if (const auto opt_proTx = GetTxPayload<CProRegTx>(tx); opt_proTx && opt_proTx->netInfo) {
entry.pushKV("proRegTx", opt_proTx->ToJson());
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) {
if (const auto opt_proTx = GetTxPayload<CProUpServTx>(tx)) {
if (const auto opt_proTx = GetTxPayload<CProUpServTx>(tx); opt_proTx && opt_proTx->netInfo) {
entry.pushKV("proUpServTx", opt_proTx->ToJson());
Comment thread
PastaPastaPasta marked this conversation as resolved.
Resolved
}
} else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) {
Expand Down
45 changes: 45 additions & 0 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
import urllib.parse


from test_framework.blocktools import create_block, create_coinbase
from test_framework.messages import (
BLOCK_HEADER_SIZE,
COIN,
COutPoint,
CTransaction,
CTxIn,
CTxOut,
)
from test_framework.script import CScript, OP_TRUE
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
Expand Down Expand Up @@ -451,5 +457,44 @@ def run_test(self):
self.sync_all()
assert_equal(self.test_rest_request(f"/deploymentinfo/{header_only_hash}"), self.nodes[0].getdeploymentinfo(header_only_hash))

self.log.info("Test rendering stored ProTx payloads with unsupported versions")
node = self.nodes[0]
tip = node.getbestblockhash()
protxes = []
for tx_type in (1, 2):
for version in (0, 65535):
tx = CTransaction()
tx.nVersion = 3
tx.nType = tx_type
tx.vin = [CTxIn(COutPoint(0x1234, len(protxes)))]
tx.vout = [CTxOut(1000, CScript([OP_TRUE]))]
tx.vExtraPayload = version.to_bytes(2, "little")
tx.calc_sha256()
protxes.append(tx)
block = create_block(
tmpl=node.getblocktemplate(),
coinbase=create_coinbase(node.getblockcount() + 1, dip4_activated=True, v20_activated=True),
txlist=protxes,
)
block.solve()
assert_equal(node.submitblock(block.serialize().hex()), "bad-protx-version")
assert_equal(node.getblock(block.hash, 0), block.serialize().hex())

for deprecated_service in (False, True):
if deprecated_service:
self.restart_node(0, extra_args=self.extra_args[0] + ["-deprecatedrpc=service"])
self.test_rest_request(f"/block/notxdetails/{block.hash}")
block_json = self.test_rest_request(f"/block/{block.hash}")
assert_equal(block_json, node.getblock(block.hash, 2))
assert_equal(len(block_json["tx"]), len(block.vtx))
for tx, tx_json in zip(protxes, block_json["tx"][1:]):
field = "proRegTx" if tx.nType == 1 else "proUpServTx"
for decoded in (tx_json, node.decoderawtransaction(tx.serialize().hex()),
node.getrawtransaction(tx.hash, True, block.hash)):
assert field not in decoded
assert_equal(decoded["extraPayload"], tx.vExtraPayload.hex())
assert_equal(node.getbestblockhash(), tip)
assert_equal(self.test_rest_request("/chaininfo")["bestblockhash"], tip)

if __name__ == '__main__':
RESTTest().main()
10 changes: 6 additions & 4 deletions test/functional/rpc_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ def test_malformed_deprecated_service_rawtransactions(self):
self.log.info("Test malformed provider payloads do not crash -deprecatedrpc=service")
node = self.nodes[2]
block_count = node.getblockcount()
for tx_hex in [
"03000100000000000000020000", # ProRegTx with only nVersion=0 payload
"03000200000000000000020000", # ProUpServTx with only nVersion=0 payload
for tx_hex, payload_field in [
("03000100000000000000020000", "proRegTx"), # ProRegTx with only nVersion=0 payload
("03000200000000000000020000", "proUpServTx"), # ProUpServTx with only nVersion=0 payload
]:
assert_raises_rpc_error(-1, "Internal bug detected: obj.netInfo", node.decoderawtransaction, tx_hex)
decoded = node.decoderawtransaction(tx_hex)
assert payload_field not in decoded
assert_equal(decoded["extraPayload"], "0000")
assert_equal(node.getblockcount(), block_count)

if __name__ == '__main__':
Expand Down
Loading