Line data Source code
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 : 6 : #include "sapling/sapling_core_write.h" 7 : #include "utilstrencodings.h" 8 : #include "utilmoneystr.h" 9 : 10 19 : static UniValue TxShieldedSpendsToJSON(const CTransaction& tx) { 11 19 : UniValue vdesc(UniValue::VARR); 12 19 : if (tx.sapData) { 13 43 : for (const SpendDescription& spendDesc : tx.sapData->vShieldedSpend) { 14 48 : UniValue obj(UniValue::VOBJ); 15 48 : obj.pushKV("cv", spendDesc.cv.GetHex()); 16 48 : obj.pushKV("anchor", spendDesc.anchor.GetHex()); 17 48 : obj.pushKV("nullifier", spendDesc.nullifier.GetHex()); 18 48 : obj.pushKV("rk", spendDesc.rk.GetHex()); 19 48 : obj.pushKV("proof", HexStr(spendDesc.zkproof)); 20 48 : obj.pushKV("spendAuthSig", HexStr(spendDesc.spendAuthSig)); 21 24 : vdesc.push_back(obj); 22 : } 23 : } 24 19 : return vdesc; 25 : } 26 : 27 19 : static UniValue TxShieldedOutputsToJSON(const CTransaction& tx) { 28 19 : UniValue vdesc(UniValue::VARR); 29 19 : if (tx.sapData) { 30 39 : for (const OutputDescription& outputDesc : tx.sapData->vShieldedOutput) { 31 40 : UniValue obj(UniValue::VOBJ); 32 40 : obj.pushKV("cv", outputDesc.cv.GetHex()); 33 40 : obj.pushKV("cmu", outputDesc.cmu.GetHex()); 34 40 : obj.pushKV("ephemeralKey", outputDesc.ephemeralKey.GetHex()); 35 40 : obj.pushKV("encCiphertext", HexStr(outputDesc.encCiphertext)); 36 40 : obj.pushKV("outCiphertext", HexStr(outputDesc.outCiphertext)); 37 40 : obj.pushKV("proof", HexStr(outputDesc.zkproof)); 38 20 : vdesc.push_back(obj); 39 : } 40 : } 41 19 : return vdesc; 42 : } 43 : 44 1070 : void TxSaplingToJSON(const CTransaction& tx, UniValue& entry) { 45 1070 : if (tx.IsShieldedTx()) { 46 38 : entry.pushKV("valueBalance", FormatMoney(tx.sapData->valueBalance)); 47 19 : entry.pushKV("valueBalanceSat", tx.sapData->valueBalance); 48 38 : UniValue vspenddesc = TxShieldedSpendsToJSON(tx); 49 19 : entry.pushKV("vShieldSpend", vspenddesc); 50 38 : UniValue voutputdesc = TxShieldedOutputsToJSON(tx); 51 19 : entry.pushKV("vShieldOutput", voutputdesc); 52 19 : if (tx.sapData->hasBindingSig()) { 53 57 : entry.pushKV("bindingSig", HexStr(tx.sapData->bindingSig)); 54 : } 55 : } 56 1070 : }