diff --git a/doc/release-notes-6229.md b/doc/release-notes-6229.md new file mode 100644 index 0000000000..9400e96606 --- /dev/null +++ b/doc/release-notes-6229.md @@ -0,0 +1,4 @@ +RPC changes +----------- + +- `creditOutputs` entries in various RPCs that output transaction JSON are shown as objects now instead of being shown as strings. diff --git a/src/evo/assetlocktx.h b/src/evo/assetlocktx.h index ff4853fb35..b55902fea4 100644 --- a/src/evo/assetlocktx.h +++ b/src/evo/assetlocktx.h @@ -22,6 +22,10 @@ namespace llmq { class CQuorumManager; } // namespace llmq +// Forward declaration from core_io to get rid of circular dependency +UniValue ValueFromAmount(const CAmount amount); +void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses); + class CAssetLockPayload { public: @@ -51,14 +55,18 @@ public: [[nodiscard]] UniValue ToJson() const { - UniValue obj; - obj.setObject(); - obj.pushKV("version", int(nVersion)); - UniValue outputs; - outputs.setArray(); - for (const CTxOut& out : creditOutputs) { - outputs.push_back(out.ToString()); + UniValue outputs(UniValue::VARR); + for (const CTxOut& credit_output : creditOutputs) { + UniValue out(UniValue::VOBJ); + out.pushKV("value", ValueFromAmount(credit_output.nValue)); + out.pushKV("valueSat", credit_output.nValue); + UniValue spk(UniValue::VOBJ); + ScriptPubKeyToUniv(credit_output.scriptPubKey, spk, /* fIncludeHex = */ true, /* include_addresses = */ false); + out.pushKV("scriptPubKey", spk); + outputs.push_back(out); } + UniValue obj(UniValue::VOBJ); + obj.pushKV("version", int(nVersion)); obj.pushKV("creditOutputs", outputs); return obj; } diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index f83aa6e2e3..8dd11ecb12 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -30,12 +30,9 @@ from test_framework.messages import ( from test_framework.script import ( CScript, OP_CHECKSIG, - OP_DUP, - OP_EQUALVERIFY, - OP_HASH160, OP_RETURN, - hash160, ) +from test_framework.script_util import key_to_p2pkh_script from test_framework.test_framework import DashTestFramework from test_framework.util import ( assert_equal, @@ -65,8 +62,8 @@ class AssetLocksTest(DashTestFramework): tmp_amount = amount if tmp_amount > COIN: tmp_amount -= COIN - credit_outputs.append(CTxOut(COIN, CScript([OP_DUP, OP_HASH160, hash160(pubkey), OP_EQUALVERIFY, OP_CHECKSIG]))) - credit_outputs.append(CTxOut(tmp_amount, CScript([OP_DUP, OP_HASH160, hash160(pubkey), OP_EQUALVERIFY, OP_CHECKSIG]))) + credit_outputs.append(CTxOut(COIN, key_to_p2pkh_script(pubkey))) + credit_outputs.append(CTxOut(tmp_amount, key_to_p2pkh_script(pubkey))) lockTx_payload = CAssetLockTx(1, credit_outputs) @@ -282,7 +279,11 @@ class AssetLocksTest(DashTestFramework): self.check_mempool_result(tx=asset_lock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}}) self.validate_credit_pool_balance(0) txid_in_block = self.send_tx(asset_lock_tx) - assert "assetLockTx" in node.getrawtransaction(txid_in_block, 1) + rpc_tx = node.getrawtransaction(txid_in_block, 1) + assert_equal(len(rpc_tx["assetLockTx"]["creditOutputs"]), 2) + assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][0]["valueSat"] + rpc_tx["assetLockTx"]["creditOutputs"][1]["valueSat"], locked_1) + assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][0]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex()) + assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][1]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex()) self.validate_credit_pool_balance(0) node.generate(1) assert_equal(self.get_credit_pool_balance(node=node), locked_1)