|
| 1 | +// Copyright (c) 2018-2025 The Dash Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <core_io.h> |
| 6 | +#include <evo/assetlocktx.h> |
| 7 | +#include <evo/cbtx.h> |
| 8 | +#include <evo/mnhftx.h> |
| 9 | +#include <evo/providertx.h> |
| 10 | +#include <llmq/commitment.h> |
| 11 | + |
| 12 | +#include <univalue.h> |
| 13 | + |
| 14 | +[[nodiscard]] UniValue CAssetLockPayload::ToJson() const |
| 15 | +{ |
| 16 | + UniValue outputs(UniValue::VARR); |
| 17 | + for (const CTxOut& credit_output : creditOutputs) { |
| 18 | + UniValue out(UniValue::VOBJ); |
| 19 | + out.pushKV("value", ValueFromAmount(credit_output.nValue)); |
| 20 | + out.pushKV("valueSat", credit_output.nValue); |
| 21 | + UniValue spk(UniValue::VOBJ); |
| 22 | + ScriptPubKeyToUniv(credit_output.scriptPubKey, spk, /*include_hex=*/true, /*include_address=*/false); |
| 23 | + out.pushKV("scriptPubKey", spk); |
| 24 | + outputs.push_back(out); |
| 25 | + } |
| 26 | + |
| 27 | + UniValue ret(UniValue::VOBJ); |
| 28 | + ret.pushKV("version", int(nVersion)); |
| 29 | + ret.pushKV("creditOutputs", outputs); |
| 30 | + return ret; |
| 31 | +} |
| 32 | + |
| 33 | +[[nodiscard]] UniValue CAssetUnlockPayload::ToJson() const |
| 34 | +{ |
| 35 | + UniValue ret(UniValue::VOBJ); |
| 36 | + ret.pushKV("version", int(nVersion)); |
| 37 | + ret.pushKV("index", int(index)); |
| 38 | + ret.pushKV("fee", int(fee)); |
| 39 | + ret.pushKV("requestedHeight", int(requestedHeight)); |
| 40 | + ret.pushKV("quorumHash", quorumHash.ToString()); |
| 41 | + ret.pushKV("quorumSig", quorumSig.ToString()); |
| 42 | + return ret; |
| 43 | +} |
| 44 | + |
| 45 | +[[nodiscard]] UniValue CCbTx::ToJson() const |
| 46 | +{ |
| 47 | + UniValue ret(UniValue::VOBJ); |
| 48 | + ret.pushKV("version", (int)nVersion); |
| 49 | + ret.pushKV("height", nHeight); |
| 50 | + ret.pushKV("merkleRootMNList", merkleRootMNList.ToString()); |
| 51 | + if (nVersion >= CCbTx::Version::MERKLE_ROOT_QUORUMS) { |
| 52 | + ret.pushKV("merkleRootQuorums", merkleRootQuorums.ToString()); |
| 53 | + if (nVersion >= CCbTx::Version::CLSIG_AND_BALANCE) { |
| 54 | + ret.pushKV("bestCLHeightDiff", static_cast<int>(bestCLHeightDiff)); |
| 55 | + ret.pushKV("bestCLSignature", bestCLSignature.ToString()); |
| 56 | + ret.pushKV("creditPoolBalance", ValueFromAmount(creditPoolBalance)); |
| 57 | + } |
| 58 | + } |
| 59 | + return ret; |
| 60 | +} |
| 61 | + |
| 62 | +[[nodiscard]] UniValue CProRegTx::ToJson() const |
| 63 | +{ |
| 64 | + UniValue ret(UniValue::VOBJ); |
| 65 | + ret.pushKV("version", nVersion); |
| 66 | + ret.pushKV("type", ToUnderlying(nType)); |
| 67 | + ret.pushKV("collateralHash", collateralOutpoint.hash.ToString()); |
| 68 | + ret.pushKV("collateralIndex", (int)collateralOutpoint.n); |
| 69 | + ret.pushKV("service", addr.ToStringAddrPort()); |
| 70 | + ret.pushKV("ownerAddress", EncodeDestination(PKHash(keyIDOwner))); |
| 71 | + ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting))); |
| 72 | + if (CTxDestination dest; ExtractDestination(scriptPayout, dest)) { |
| 73 | + ret.pushKV("payoutAddress", EncodeDestination(dest)); |
| 74 | + } |
| 75 | + ret.pushKV("pubKeyOperator", pubKeyOperator.ToString()); |
| 76 | + ret.pushKV("operatorReward", (double)nOperatorReward / 100); |
| 77 | + if (nType == MnType::Evo) { |
| 78 | + ret.pushKV("platformNodeID", platformNodeID.ToString()); |
| 79 | + ret.pushKV("platformP2PPort", platformP2PPort); |
| 80 | + ret.pushKV("platformHTTPPort", platformHTTPPort); |
| 81 | + } |
| 82 | + ret.pushKV("inputsHash", inputsHash.ToString()); |
| 83 | + return ret; |
| 84 | +} |
| 85 | + |
| 86 | +[[nodiscard]] UniValue CProUpRegTx::ToJson() const |
| 87 | +{ |
| 88 | + UniValue ret(UniValue::VOBJ); |
| 89 | + ret.pushKV("version", nVersion); |
| 90 | + ret.pushKV("proTxHash", proTxHash.ToString()); |
| 91 | + ret.pushKV("votingAddress", EncodeDestination(PKHash(keyIDVoting))); |
| 92 | + if (CTxDestination dest; ExtractDestination(scriptPayout, dest)) { |
| 93 | + ret.pushKV("payoutAddress", EncodeDestination(dest)); |
| 94 | + } |
| 95 | + ret.pushKV("pubKeyOperator", pubKeyOperator.ToString()); |
| 96 | + ret.pushKV("inputsHash", inputsHash.ToString()); |
| 97 | + return ret; |
| 98 | +} |
| 99 | + |
| 100 | +[[nodiscard]] UniValue CProUpRevTx::ToJson() const |
| 101 | +{ |
| 102 | + UniValue ret(UniValue::VOBJ); |
| 103 | + ret.pushKV("version", nVersion); |
| 104 | + ret.pushKV("proTxHash", proTxHash.ToString()); |
| 105 | + ret.pushKV("reason", (int)nReason); |
| 106 | + ret.pushKV("inputsHash", inputsHash.ToString()); |
| 107 | + return ret; |
| 108 | +} |
| 109 | + |
| 110 | +[[nodiscard]] UniValue CProUpServTx::ToJson() const |
| 111 | +{ |
| 112 | + UniValue ret(UniValue::VOBJ); |
| 113 | + ret.pushKV("version", nVersion); |
| 114 | + ret.pushKV("type", ToUnderlying(nType)); |
| 115 | + ret.pushKV("proTxHash", proTxHash.ToString()); |
| 116 | + ret.pushKV("service", addr.ToStringAddrPort()); |
| 117 | + if (CTxDestination dest; ExtractDestination(scriptOperatorPayout, dest)) { |
| 118 | + ret.pushKV("operatorPayoutAddress", EncodeDestination(dest)); |
| 119 | + } |
| 120 | + if (nType == MnType::Evo) { |
| 121 | + ret.pushKV("platformNodeID", platformNodeID.ToString()); |
| 122 | + ret.pushKV("platformP2PPort", platformP2PPort); |
| 123 | + ret.pushKV("platformHTTPPort", platformHTTPPort); |
| 124 | + } |
| 125 | + ret.pushKV("inputsHash", inputsHash.ToString()); |
| 126 | + return ret; |
| 127 | +} |
| 128 | + |
| 129 | +[[nodiscard]] UniValue MNHFTxPayload::ToJson() const |
| 130 | +{ |
| 131 | + UniValue ret(UniValue::VOBJ); |
| 132 | + ret.pushKV("version", (int)nVersion); |
| 133 | + ret.pushKV("signal", signal.ToJson()); |
| 134 | + return ret; |
| 135 | +} |
| 136 | + |
| 137 | +[[nodiscard]] UniValue llmq::CFinalCommitmentTxPayload::ToJson() const |
| 138 | +{ |
| 139 | + UniValue ret(UniValue::VOBJ); |
| 140 | + ret.pushKV("version", int{nVersion}); |
| 141 | + ret.pushKV("height", int(nHeight)); |
| 142 | + ret.pushKV("commitment", commitment.ToJson()); |
| 143 | + return ret; |
| 144 | +} |
0 commit comments