-
Notifications
You must be signed in to change notification settings - Fork 90
[WIP][RPC] RingCT output overhaul #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mimirmim
wants to merge
9
commits into
Veil-Project:master
Choose a base branch
from
mimirmim:rpc-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0eac106
Add key_image value(s) to gettransaction rpc output
codeofalltrades 88a6f40
Remove unneeded debug information from `gettransaction`
mimirmim d8bfadc
Overload method for Core functionality TxtoUniv
mimirmim f281df7
GetTxringCtInputs takes in an actual reference
mimirmim 480aa78
KeyImage code added to TxToUniv
mimirmim 3abedee
Copyright and cleanup
mimirmim 1e699d7
Change key images from array sequence map to array.
mimirmim 9cd1242
Correct naming for array and ephemeral public key
mimirmim f6ea7a1
RingCT inputs organized with related data
mimirmim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // Copyright (c) 2009-2019 The Bitcoin Core developers | ||
| // Copyright (c) 2019 The Veil developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
|
|
@@ -189,11 +190,11 @@ void OutputToJSON(uint256 &txid, int i, | |
| { | ||
| CTxOutCT *s = (CTxOutCT*) baseOut; | ||
| entry.pushKV("type", "blind"); | ||
| entry.pushKV("valueCommitment", HexStr(&s->commitment.data[0], &s->commitment.data[0]+33)); | ||
| entry.pushKV("ephemeral_pubkey", HexStr(s->vData.begin(), s->vData.end())); | ||
| UniValue o(UniValue::VOBJ); | ||
| ScriptPubKeyToUniv(s->scriptPubKey, o, true); | ||
| entry.pushKV("scriptPubKey", o); | ||
| entry.pushKV("data_hex", HexStr(s->vData.begin(), s->vData.end())); | ||
| entry.pushKV("valueCommitment", HexStr(&s->commitment.data[0], &s->commitment.data[0]+33)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will want to make 33 at const as some point?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a const for 33 is added as part of #696 |
||
|
|
||
| AddRangeproof(s->vRangeproof, entry); | ||
| } | ||
|
|
@@ -202,9 +203,9 @@ void OutputToJSON(uint256 &txid, int i, | |
| { | ||
| CTxOutRingCT *s = (CTxOutRingCT*) baseOut; | ||
| entry.pushKV("type", "ringct"); | ||
| entry.pushKV("ephemeral_pubkey", HexStr(s->vData.begin(), s->vData.end())); | ||
| entry.pushKV("pubkey", HexStr(s->pk.begin(), s->pk.end())); | ||
| entry.pushKV("valueCommitment", HexStr(&s->commitment.data[0], &s->commitment.data[0]+33)); | ||
| entry.pushKV("data_hex", HexStr(s->vData.begin(), s->vData.end())); | ||
|
|
||
| AddRangeproof(s->vRangeproof, entry); | ||
| } | ||
|
|
@@ -257,7 +258,9 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, | |
| out.pushKV("addresses", a); | ||
mimirmim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void TxToUniv(const CTransaction& tx, const uint256& hashBlock, const std::vector<std::vector<COutPoint>>& vTxRingCtInputs, UniValue& entry, bool include_hex, int serialize_flags) | ||
| // TODO: Fix duplicate code. This was done as such to prevent veil-tx and some tests from failing to build. | ||
| // One requires core lib, the other doesn't. | ||
| void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, int serialize_flags) | ||
| { | ||
| entry.pushKV("txid", tx.GetHash().GetHex()); | ||
| entry.pushKV("hash", tx.GetWitnessHash().GetHex()); | ||
|
|
@@ -275,19 +278,117 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, const std::vecto | |
| in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||
| if (txin.IsAnonInput()) { | ||
| in.pushKV("type", "anon"); | ||
| uint32_t nSigInputs, nSigRingSize; | ||
| txin.GetAnonInfo(nSigInputs, nSigRingSize); | ||
| in.pushKV("num_inputs", (int) nSigInputs); | ||
| in.pushKV("ring_size", (int) nSigRingSize); | ||
| in.pushKV("ringct_inputs", "To see the RingCT inputs, you must run the core library!"); | ||
|
|
||
| const std::vector<uint8_t> vKeyImages = txin.scriptData.stack[0]; | ||
| UniValue arrKeyImage(UniValue::VARR); | ||
| for (unsigned int k = 0; k < nSigInputs; k++) { | ||
| arrKeyImage.push_back(HexStr(&vKeyImages[k*33], &vKeyImages[(k*33)+33])); | ||
| } | ||
| in.pushKV("key_images", arrKeyImage); | ||
| } else { | ||
| in.pushKV("txid", txin.prevout.hash.GetHex()); | ||
| if (txin.IsZerocoinSpend()) { | ||
| in.pushKV("type", "zerocoinspend"); | ||
| in.pushKV("denomination", FormatMoney(txin.GetZerocoinSpent())); | ||
| std::vector<char, zero_after_free_allocator<char> > dataTxIn; | ||
| dataTxIn.insert(dataTxIn.end(), txin.scriptSig.begin() + 4, txin.scriptSig.end()); | ||
| CDataStream serializedCoinSpend(dataTxIn, SER_NETWORK, PROTOCOL_VERSION); | ||
| libzerocoin::CoinSpend spend(Params().Zerocoin_Params(), serializedCoinSpend); | ||
| in.pushKV("serial", spend.getCoinSerialNumber().GetHex()); | ||
| if (spend.getVersion() >= 4) { | ||
| in.pushKV("pubcoin", spend.getPubcoinValue().GetHex()); | ||
| } | ||
| } | ||
| in.pushKV("vout", (int64_t)txin.prevout.n); | ||
| UniValue o(UniValue::VOBJ); | ||
| o.pushKV("asm", ScriptToAsmStr(txin.scriptSig, true)); | ||
| o.pushKV("hex", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||
| in.pushKV("scriptSig", o); | ||
| if (!tx.vin[i].scriptWitness.IsNull()) { | ||
| UniValue txinwitness(UniValue::VARR); | ||
| for (const auto& item : tx.vin[i].scriptWitness.stack) { | ||
| txinwitness.push_back(HexStr(item.begin(), item.end())); | ||
| } | ||
| in.pushKV("txinwitness", txinwitness); | ||
| } | ||
| } | ||
| in.pushKV("sequence", (int64_t)txin.nSequence); | ||
| vin.push_back(in); | ||
| } | ||
| entry.pushKV("vin", vin); | ||
|
|
||
| UniValue vout(UniValue::VARR); | ||
| auto txid = tx.GetHash(); | ||
| for (unsigned int i = 0; i < tx.vpout.size(); i++) { | ||
| const auto& pout = tx.vpout[i]; | ||
| UniValue out(UniValue::VOBJ); | ||
| OutputToJSON(txid, i, pout.get(), out, tx.IsCoinBase()); | ||
| vout.push_back(out); | ||
| } | ||
|
|
||
| entry.pushKV("vout", vout); | ||
|
|
||
| if (!hashBlock.IsNull()) | ||
| entry.pushKV("blockhash", hashBlock.GetHex()); | ||
|
|
||
| if (include_hex) { | ||
| entry.pushKV("hex", EncodeHexTx(tx, serialize_flags)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction". | ||
| } | ||
| } | ||
|
|
||
| void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, const std::vector<std::vector<std::pair<int64_t, COutPoint>>>& vTxRingCTInputs, bool include_hex, int serialize_flags) { | ||
| entry.pushKV("txid", tx.GetHash().GetHex()); | ||
| entry.pushKV("hash", tx.GetWitnessHash().GetHex()); | ||
| entry.pushKV("version", tx.nVersion); | ||
| entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)); | ||
| entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR); | ||
| entry.pushKV("weight", GetTransactionWeight(tx)); | ||
| entry.pushKV("locktime", (int64_t)tx.nLockTime); | ||
|
|
||
| // For tracking position in RingCT transactions. Its possible to have more than 1 RingCT inputs in a tx. | ||
| unsigned int j = 0; | ||
| unsigned int k = 0; | ||
| UniValue vin(UniValue::VARR); | ||
| for (unsigned int i = 0; i < tx.vin.size(); i++) { | ||
| const CTxIn& txin = tx.vin[i]; | ||
| UniValue in(UniValue::VOBJ); | ||
| if (tx.IsCoinBase()) | ||
| in.pushKV("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end())); | ||
| if (txin.IsAnonInput()) { | ||
| in.pushKV("type", "ringct"); // FIXME: Should match the type from enum? | ||
|
|
||
| uint32_t nSigInputs, nSigRingSize; | ||
| txin.GetAnonInfo(nSigInputs, nSigRingSize); | ||
| in.pushKV("num_inputs", (int) nSigInputs); | ||
| in.pushKV("ring_size", (int) nSigRingSize); | ||
|
|
||
| //Add ring ct inputs | ||
| if (vTxRingCtInputs.size() > i) { | ||
| std::vector<COutPoint> vRingCtInputs = vTxRingCtInputs[i]; | ||
| const std::vector<uint8_t> vCommitments = txin.scriptWitness.stack[1]; | ||
| in.pushKV("commitment_sig", HexStr(&vCommitments[j], &vCommitments[j + 32])); | ||
|
|
||
| if (vTxRingCTInputs.size() > i) { | ||
| UniValue arrRing(UniValue::VARR); | ||
| for (const COutPoint& outpoint : vRingCtInputs) { | ||
| const std::vector<uint8_t> vKeyImages = txin.scriptData.stack[0]; | ||
| for (k; k < nSigInputs; k++) { | ||
| UniValue obj(UniValue::VOBJ); | ||
| obj.pushKV("txid", outpoint.hash.GetHex()); | ||
| obj.pushKV("vout.n", (uint64_t) outpoint.n); | ||
| obj.pushKV("key_image", HexStr(&vKeyImages[k*33], &vKeyImages[(k*33)+33])); | ||
|
|
||
| std::vector<std::pair<int64_t, COutPoint>> vRingCtInputs = vTxRingCTInputs[i]; | ||
| obj.pushKV("txid", vRingCtInputs[k].second.hash.GetHex()); | ||
| obj.pushKV("vout.n", (uint64_t) vRingCtInputs[k].second.n); | ||
| obj.pushKV("index", vRingCtInputs[k].first); | ||
|
|
||
| UniValue arrCommitment(UniValue::VARR); | ||
| for (unsigned int m = 0; m < (nSigRingSize); m++) { | ||
| j += 1; | ||
| arrCommitment.push_back(HexStr(&vCommitments[j*32], &vCommitments[(j*32)+32])); | ||
| } | ||
| obj.pushKV("commitments", arrCommitment); | ||
|
|
||
| arrRing.push_back(obj); | ||
| } | ||
| in.pushKV("ringct_inputs", arrRing); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.