Skip to content

Commit b38c4d3

Browse files
Merge #6229: fix: creditOutputs in AssetLock tx json output should be an array of objects, not debug strings
9876c2d docs: add partial release notes (UdjinM6) b330318 refactor: drop circular dependency (UdjinM6) e54fe42 refactor: use `key_to_p2pkh_script` in more places (UdjinM6) 3ed6246 test: check `creditOutputs` format (UdjinM6) ba0e645 fix: `creditOutputs` in AssetLock tx json output should be an array of objects, not debug strings (UdjinM6) Pull request description: ## Issue being fixed or feature implemented Txout-s in `creditOutputs` for AssetLock txes should be shown the way txout-s are shown in other places. We should not be using debug strings there. Example: `getrawtransaction 50757f651f335e22c5a810bd05c1e5aac0d95b132f6454e2a72683f88e3983f3 1` develop: ``` "assetLockTx": { "version": 1, "creditOutputs": [ "CTxOut(nValue=0.01000000, scriptPubKey=76a914cdfca4ae1cf2333056659a2c)" ] }, ``` This PR: ``` "assetLockTx": { "version": 1, "creditOutputs": [ { "value": 0.01000000, "valueSat": 1000000, "scriptPubKey": { "asm": "OP_DUP OP_HASH160 cdfca4ae1cf2333056659a2c8dc656f36d228402 OP_EQUALVERIFY OP_CHECKSIG", "hex": "76a914cdfca4ae1cf2333056659a2c8dc656f36d22840288ac", "address": "yf6c2VSpWGXUgmjQSHRpfEcTPsbqN4oL4c", "type": "pubkeyhash" } } ] }, ``` kudos to @coolaj86 for finding the issue ## What was done? Change `CAssetLockPayload::ToJson()` output to be closer to [`TxToUniv()`](https://github.com/dashpay/dash/blob/develop/src/core_write.cpp#L262-L272) NOTE: `refactor: use key_to_p2pkh_script in more places` commit is a bit unrelated but I decided to add it anyway to make it easier to follow assetlock creation vs getrawtransaction rpc check. ## How Has This Been Tested? Try example above, run tests ## Breaking Changes RPC output is different for AssetLock txes ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone ACKs for top commit: PastaPastaPasta: utACK 9876c2d Tree-SHA512: 158c98ac9e4979bb29c4f54cb1b71806f22aaec92218d92cd2b2e9b9f74df721563e7a6c5f517ea358ac74659fa79f51d1b683002a1cdceb1b8ee80f8fd79375
2 parents 18625ae + 9876c2d commit b38c4d3

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

doc/release-notes-6229.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RPC changes
2+
-----------
3+
4+
- `creditOutputs` entries in various RPCs that output transaction JSON are shown as objects now instead of being shown as strings.

src/evo/assetlocktx.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ namespace llmq {
2222
class CQuorumManager;
2323
} // namespace llmq
2424

25+
// Forward declaration from core_io to get rid of circular dependency
26+
UniValue ValueFromAmount(const CAmount amount);
27+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
28+
2529
class CAssetLockPayload
2630
{
2731
public:
@@ -51,14 +55,18 @@ class CAssetLockPayload
5155

5256
[[nodiscard]] UniValue ToJson() const
5357
{
54-
UniValue obj;
55-
obj.setObject();
56-
obj.pushKV("version", int(nVersion));
57-
UniValue outputs;
58-
outputs.setArray();
59-
for (const CTxOut& out : creditOutputs) {
60-
outputs.push_back(out.ToString());
58+
UniValue outputs(UniValue::VARR);
59+
for (const CTxOut& credit_output : creditOutputs) {
60+
UniValue out(UniValue::VOBJ);
61+
out.pushKV("value", ValueFromAmount(credit_output.nValue));
62+
out.pushKV("valueSat", credit_output.nValue);
63+
UniValue spk(UniValue::VOBJ);
64+
ScriptPubKeyToUniv(credit_output.scriptPubKey, spk, /* fIncludeHex = */ true, /* include_addresses = */ false);
65+
out.pushKV("scriptPubKey", spk);
66+
outputs.push_back(out);
6167
}
68+
UniValue obj(UniValue::VOBJ);
69+
obj.pushKV("version", int(nVersion));
6270
obj.pushKV("creditOutputs", outputs);
6371
return obj;
6472
}

test/functional/feature_asset_locks.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@
3030
from test_framework.script import (
3131
CScript,
3232
OP_CHECKSIG,
33-
OP_DUP,
34-
OP_EQUALVERIFY,
35-
OP_HASH160,
3633
OP_RETURN,
37-
hash160,
3834
)
35+
from test_framework.script_util import key_to_p2pkh_script
3936
from test_framework.test_framework import DashTestFramework
4037
from test_framework.util import (
4138
assert_equal,
@@ -65,8 +62,8 @@ def create_assetlock(self, coin, amount, pubkey):
6562
tmp_amount = amount
6663
if tmp_amount > COIN:
6764
tmp_amount -= COIN
68-
credit_outputs.append(CTxOut(COIN, CScript([OP_DUP, OP_HASH160, hash160(pubkey), OP_EQUALVERIFY, OP_CHECKSIG])))
69-
credit_outputs.append(CTxOut(tmp_amount, CScript([OP_DUP, OP_HASH160, hash160(pubkey), OP_EQUALVERIFY, OP_CHECKSIG])))
65+
credit_outputs.append(CTxOut(COIN, key_to_p2pkh_script(pubkey)))
66+
credit_outputs.append(CTxOut(tmp_amount, key_to_p2pkh_script(pubkey)))
7067

7168
lockTx_payload = CAssetLockTx(1, credit_outputs)
7269

@@ -282,7 +279,11 @@ def test_asset_locks(self, node_wallet, node, pubkey):
282279
self.check_mempool_result(tx=asset_lock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
283280
self.validate_credit_pool_balance(0)
284281
txid_in_block = self.send_tx(asset_lock_tx)
285-
assert "assetLockTx" in node.getrawtransaction(txid_in_block, 1)
282+
rpc_tx = node.getrawtransaction(txid_in_block, 1)
283+
assert_equal(len(rpc_tx["assetLockTx"]["creditOutputs"]), 2)
284+
assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][0]["valueSat"] + rpc_tx["assetLockTx"]["creditOutputs"][1]["valueSat"], locked_1)
285+
assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][0]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex())
286+
assert_equal(rpc_tx["assetLockTx"]["creditOutputs"][1]["scriptPubKey"]["hex"], key_to_p2pkh_script(pubkey).hex())
286287
self.validate_credit_pool_balance(0)
287288
node.generate(1)
288289
assert_equal(self.get_credit_pool_balance(node=node), locked_1)

0 commit comments

Comments
 (0)