From ba0e64505b7bc97f9e5da3e457f89db77040e97f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Fri, 23 Aug 2024 23:39:44 +0300 Subject: [PATCH 1/5] fix: `creditOutputs` in AssetLock tx json output should be an array of objects, not debug strings --- src/evo/assetlocktx.h | 19 ++++++++++++------- test/lint/lint-circular-dependencies.sh | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/evo/assetlocktx.h b/src/evo/assetlocktx.h index ff4853fb35..e724c6faa3 100644 --- a/src/evo/assetlocktx.h +++ b/src/evo/assetlocktx.h @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -51,14 +52,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/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index 340c97e452..88285178f5 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -102,6 +102,7 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "llmq/chainlocks -> net_processing -> llmq/context -> llmq/chainlocks" "coinjoin/client -> coinjoin/coinjoin -> llmq/chainlocks -> net_processing -> coinjoin/client" "rpc/blockchain -> rpc/server -> rpc/blockchain" + "core_io -> evo/assetlocktx -> core_io" ) EXIT_CODE=0 From 3ed62468898eb45c124ac02ce35fac315606fb40 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 24 Aug 2024 00:51:14 +0300 Subject: [PATCH 2/5] test: check `creditOutputs` format --- test/functional/feature_asset_locks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index 7c3593cf20..af0c0e89ff 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -36,6 +36,7 @@ from test_framework.script import ( 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, @@ -283,7 +284,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) From e54fe42ce85b0ace8291699f3ecce2e52e638d27 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sat, 24 Aug 2024 00:51:21 +0300 Subject: [PATCH 3/5] refactor: use `key_to_p2pkh_script` in more places --- test/functional/feature_asset_locks.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/functional/feature_asset_locks.py b/test/functional/feature_asset_locks.py index af0c0e89ff..a4d9761522 100755 --- a/test/functional/feature_asset_locks.py +++ b/test/functional/feature_asset_locks.py @@ -30,11 +30,7 @@ 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 @@ -67,8 +63,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) From b330318db788129eab69ed91c755b31cafa03c8f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 26 Aug 2024 11:45:24 +0300 Subject: [PATCH 4/5] refactor: drop circular dependency --- src/evo/assetlocktx.h | 5 ++++- test/lint/lint-circular-dependencies.sh | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/evo/assetlocktx.h b/src/evo/assetlocktx.h index e724c6faa3..b55902fea4 100644 --- a/src/evo/assetlocktx.h +++ b/src/evo/assetlocktx.h @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -23,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: diff --git a/test/lint/lint-circular-dependencies.sh b/test/lint/lint-circular-dependencies.sh index 88285178f5..340c97e452 100755 --- a/test/lint/lint-circular-dependencies.sh +++ b/test/lint/lint-circular-dependencies.sh @@ -102,7 +102,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES=( "llmq/chainlocks -> net_processing -> llmq/context -> llmq/chainlocks" "coinjoin/client -> coinjoin/coinjoin -> llmq/chainlocks -> net_processing -> coinjoin/client" "rpc/blockchain -> rpc/server -> rpc/blockchain" - "core_io -> evo/assetlocktx -> core_io" ) EXIT_CODE=0 From 9876c2d78b0df7eee802cf3b90529fdcacdf1c2c Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 4 Sep 2024 22:33:34 +0300 Subject: [PATCH 5/5] docs: add partial release notes --- doc/release-notes-6229.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 doc/release-notes-6229.md 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.