PIVX Core  5.6.99
P2P Digital Currency
sapling_core_write.cpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2020 The Zcash developers
2 // Copyright (c) 2020-2021 The PIVX Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
5 
7 #include "utilstrencodings.h"
8 #include "utilmoneystr.h"
9 
10 static UniValue TxShieldedSpendsToJSON(const CTransaction& tx) {
11  UniValue vdesc(UniValue::VARR);
12  if (tx.sapData) {
13  for (const SpendDescription& spendDesc : tx.sapData->vShieldedSpend) {
15  obj.pushKV("cv", spendDesc.cv.GetHex());
16  obj.pushKV("anchor", spendDesc.anchor.GetHex());
17  obj.pushKV("nullifier", spendDesc.nullifier.GetHex());
18  obj.pushKV("rk", spendDesc.rk.GetHex());
19  obj.pushKV("proof", HexStr(spendDesc.zkproof));
20  obj.pushKV("spendAuthSig", HexStr(spendDesc.spendAuthSig));
21  vdesc.push_back(obj);
22  }
23  }
24  return vdesc;
25 }
26 
27 static UniValue TxShieldedOutputsToJSON(const CTransaction& tx) {
28  UniValue vdesc(UniValue::VARR);
29  if (tx.sapData) {
30  for (const OutputDescription& outputDesc : tx.sapData->vShieldedOutput) {
32  obj.pushKV("cv", outputDesc.cv.GetHex());
33  obj.pushKV("cmu", outputDesc.cmu.GetHex());
34  obj.pushKV("ephemeralKey", outputDesc.ephemeralKey.GetHex());
35  obj.pushKV("encCiphertext", HexStr(outputDesc.encCiphertext));
36  obj.pushKV("outCiphertext", HexStr(outputDesc.outCiphertext));
37  obj.pushKV("proof", HexStr(outputDesc.zkproof));
38  vdesc.push_back(obj);
39  }
40  }
41  return vdesc;
42 }
43 
44 void TxSaplingToJSON(const CTransaction& tx, UniValue& entry) {
45  if (tx.IsShieldedTx()) {
46  entry.pushKV("valueBalance", FormatMoney(tx.sapData->valueBalance));
47  entry.pushKV("valueBalanceSat", tx.sapData->valueBalance);
48  UniValue vspenddesc = TxShieldedSpendsToJSON(tx);
49  entry.pushKV("vShieldSpend", vspenddesc);
50  UniValue voutputdesc = TxShieldedOutputsToJSON(tx);
51  entry.pushKV("vShieldOutput", voutputdesc);
52  if (tx.sapData->hasBindingSig()) {
53  entry.pushKV("bindingSig", HexStr(tx.sapData->bindingSig));
54  }
55  }
56 }
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:244
bool IsShieldedTx() const
Definition: transaction.h:319
Optional< SaplingTxData > sapData
Definition: transaction.h:275
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
libzcash::SaplingOutCiphertext outCiphertext
A ciphertext component for the encrypted output note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the output circuit.
libzcash::SaplingEncCiphertext encCiphertext
A ciphertext component for the encrypted output note.
uint256 cv
A value commitment to the value of the output note.
uint256 ephemeralKey
A Jubjub public key.
A shielded input to a transaction.
spend_auth_sig_t spendAuthSig
A signature authorizing this spend.
uint256 cv
A value commitment to the value of the input note.
libzcash::GrothProof zkproof
A zero-knowledge proof using the spend circuit.
uint256 anchor
A Merkle root of the Sapling note commitment tree at some block height in the past.
uint256 rk
The randomized public key for spendAuthSig.
uint256 nullifier
The nullifier of the input note.
@ VOBJ
Definition: univalue.h:21
@ VARR
Definition: univalue.h:21
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
std::string GetHex() const
Definition: uint256.cpp:21
void TxSaplingToJSON(const CTransaction &tx, UniValue &entry)
std::string FormatMoney(const CAmount &n, bool fPlus)
Money parsing/formatting utilities.
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.