Browse Source

Refactoring: rename NotePlaintext --> SproutNotePlaintext

Also renames:
CNotePlaintextEntry --> CSproutNotePlaintextEntry
CUnspentNotePlaintextEntry --> CUnspentSproutNotePlaintextEntry
metaverse
Simon 6 years ago
parent
commit
5020a93631
  1. 6
      src/gtest/test_joinsplit.cpp
  2. 2
      src/utiltest.cpp
  3. 2
      src/wallet/asyncrpcoperation_mergetoaddress.cpp
  4. 6
      src/wallet/asyncrpcoperation_sendmany.cpp
  5. 2
      src/wallet/gtest/test_wallet.cpp
  6. 2
      src/wallet/rpcdisclosure.cpp
  7. 18
      src/wallet/rpcwallet.cpp
  8. 16
      src/wallet/wallet.cpp
  9. 14
      src/wallet/wallet.h
  10. 2
      src/zcash/JoinSplit.cpp
  11. 10
      src/zcash/Note.cpp
  12. 10
      src/zcash/Note.hpp

6
src/gtest/test_joinsplit.cpp

@ -91,7 +91,7 @@ void test_full_api(ZCJoinSplit* js)
auto h_sig = js->h_sig(randomSeed, nullifiers, pubKeyHash);
ZCNoteDecryption decryptor(recipient_key.receiving_key());
auto note_pt = NotePlaintext::decrypt(
auto note_pt = SproutNotePlaintext::decrypt(
decryptor,
ciphertexts[0],
ephemeralKey,
@ -531,13 +531,13 @@ TEST(joinsplit, note_plaintexts)
boost::array<unsigned char, ZC_MEMO_SIZE> memo;
NotePlaintext note_pt(note, memo);
SproutNotePlaintext note_pt(note, memo);
ZCNoteEncryption::Ciphertext ct = note_pt.encrypt(encryptor, pk_enc);
ZCNoteDecryption decryptor(sk_enc);
auto decrypted = NotePlaintext::decrypt(decryptor, ct, epk, h_sig, 0);
auto decrypted = SproutNotePlaintext::decrypt(decryptor, ct, epk, h_sig, 0);
auto decrypted_note = decrypted.note(addr_pk);
ASSERT_TRUE(decrypted_note.a_pk == note.a_pk);

2
src/utiltest.cpp

@ -66,7 +66,7 @@ libzcash::SproutNote GetNote(ZCJoinSplit& params,
const CTransaction& tx, size_t js, size_t n) {
ZCNoteDecryption decryptor {sk.receiving_key()};
auto hSig = tx.vjoinsplit[js].h_sig(params, tx.joinSplitPubKey);
auto note_pt = libzcash::NotePlaintext::decrypt(
auto note_pt = libzcash::SproutNotePlaintext::decrypt(
decryptor,
tx.vjoinsplit[js].ciphertexts[n],
tx.vjoinsplit[js].ephemeralKey,

2
src/wallet/asyncrpcoperation_mergetoaddress.cpp

@ -455,7 +455,7 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
ZCNoteDecryption decryptor(changeKey.receiving_key());
auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
prevJoinSplit.ciphertexts[changeOutputIndex],
prevJoinSplit.ephemeralKey,

6
src/wallet/asyncrpcoperation_sendmany.cpp

@ -571,7 +571,7 @@ bool AsyncRPCOperation_sendmany::main_impl() {
ZCNoteDecryption decryptor(spendingkey_.receiving_key());
auto hSig = prevJoinSplit.h_sig(*pzcashParams, tx_.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
prevJoinSplit.ciphertexts[changeOutputIndex],
prevJoinSplit.ephemeralKey,
@ -877,13 +877,13 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
bool AsyncRPCOperation_sendmany::find_unspent_notes() {
std::vector<CNotePlaintextEntry> entries;
std::vector<CSproutNotePlaintextEntry> entries;
{
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->GetFilteredNotes(entries, fromaddress_, mindepth_);
}
for (CNotePlaintextEntry & entry : entries) {
for (CSproutNotePlaintextEntry & entry : entries) {
z_inputs_.push_back(SendManyInputJSOP(entry.jsop, entry.plaintext.note(frompaymentaddress_), CAmount(entry.plaintext.value)));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
LogPrint("zrpcunsafe", "%s: found unspent note (txid=%s, vjoinsplit=%d, ciphertext=%d, amount=%s, memo=%s)\n",

2
src/wallet/gtest/test_wallet.cpp

@ -155,7 +155,7 @@ TEST(wallet_tests, find_unspent_notes) {
EXPECT_FALSE(wallet.IsSpent(nullifier));
// We currently have an unspent and unconfirmed note in the wallet (depth of -1)
std::vector<CNotePlaintextEntry> entries;
std::vector<CSproutNotePlaintextEntry> entries;
wallet.GetFilteredNotes(entries, "", 0);
EXPECT_EQ(0, entries.size());
entries.clear();

2
src/wallet/rpcdisclosure.cpp

@ -274,7 +274,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
CDataStream ssPlain(SER_NETWORK, PROTOCOL_VERSION);
ssPlain << plaintext;
NotePlaintext npt;
SproutNotePlaintext npt;
ssPlain >> npt;
string memoHexString = HexStr(npt.memo.data(), npt.memo.data() + npt.memo.size());

18
src/wallet/rpcwallet.cpp

@ -2539,9 +2539,9 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
UniValue results(UniValue::VARR);
if (zaddrs.size() > 0) {
std::vector<CUnspentNotePlaintextEntry> entries;
std::vector<CUnspentSproutNotePlaintextEntry> entries;
pwalletMain->GetUnspentFilteredNotes(entries, zaddrs, nMinDepth, nMaxDepth, !fIncludeWatchonly);
for (CUnspentNotePlaintextEntry & entry : entries) {
for (CUnspentSproutNotePlaintextEntry & entry : entries) {
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
obj.push_back(Pair("jsindex", (int)entry.jsop.js ));
@ -2809,7 +2809,7 @@ UniValue zc_raw_receive(const UniValue& params, bool fHelp)
ZCNoteDecryption decryptor(k.receiving_key());
NotePlaintext npt = NotePlaintext::decrypt(
SproutNotePlaintext npt = SproutNotePlaintext::decrypt(
decryptor,
ct,
epk,
@ -2901,7 +2901,7 @@ UniValue zc_raw_joinsplit(const UniValue& params, bool fHelp)
keys.push_back(k);
NotePlaintext npt;
SproutNotePlaintext npt;
{
CDataStream ssData(ParseHexV(name_, "note"), SER_NETWORK, PROTOCOL_VERSION);
@ -3175,7 +3175,7 @@ CAmount getBalanceTaddr(std::string transparentAddress, int minDepth=1, bool ign
CAmount getBalanceZaddr(std::string address, int minDepth = 1, bool ignoreUnspendable=true) {
CAmount balance = 0;
std::vector<CNotePlaintextEntry> entries;
std::vector<CSproutNotePlaintextEntry> entries;
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->GetFilteredNotes(entries, address, minDepth, true, ignoreUnspendable);
for (auto & entry : entries) {
@ -3235,9 +3235,9 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
UniValue result(UniValue::VARR);
std::vector<CNotePlaintextEntry> entries;
std::vector<CSproutNotePlaintextEntry> entries;
pwalletMain->GetFilteredNotes(entries, fromaddress, nMinDepth, false, false);
for (CNotePlaintextEntry & entry : entries) {
for (CSproutNotePlaintextEntry & entry : entries) {
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
@ -4140,11 +4140,11 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
if (useAny || useAnyNote || zaddrs.size() > 0) {
// Get available notes
std::vector<CNotePlaintextEntry> entries;
std::vector<CSproutNotePlaintextEntry> entries;
pwalletMain->GetFilteredNotes(entries, zaddrs);
// Find unspent notes and update estimated size
for (CNotePlaintextEntry& entry : entries) {
for (CSproutNotePlaintextEntry& entry : entries) {
noteCounter++;
CAmount nValue = entry.plaintext.value;

16
src/wallet/wallet.cpp

@ -1264,7 +1264,7 @@ boost::optional<uint256> CWallet::GetNoteNullifier(const JSDescription& jsdesc,
uint8_t n) const
{
boost::optional<uint256> ret;
auto note_pt = libzcash::NotePlaintext::decrypt(
auto note_pt = libzcash::SproutNotePlaintext::decrypt(
dec,
jsdesc.ciphertexts[n],
jsdesc.ephemeralKey,
@ -3712,7 +3712,7 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee)
* Find notes in the wallet filtered by payment address, min depth and ability to spend.
* These notes are decrypted and added to the output parameter vector, outEntries.
*/
void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, std::string address, int minDepth, bool ignoreSpent, bool ignoreUnspendable)
void CWallet::GetFilteredNotes(std::vector<CSproutNotePlaintextEntry> & outEntries, std::string address, int minDepth, bool ignoreSpent, bool ignoreUnspendable)
{
std::set<PaymentAddress> filterAddresses;
@ -3728,7 +3728,7 @@ void CWallet::GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries, st
* These notes are decrypted and added to the output parameter vector, outEntries.
*/
void CWallet::GetFilteredNotes(
std::vector<CNotePlaintextEntry>& outEntries,
std::vector<CSproutNotePlaintextEntry>& outEntries,
std::set<PaymentAddress>& filterAddresses,
int minDepth,
bool ignoreSpent,
@ -3786,14 +3786,14 @@ void CWallet::GetFilteredNotes(
// determine amount of funds in the note
auto hSig = wtx.vjoinsplit[i].h_sig(*pzcashParams, wtx.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
wtx.vjoinsplit[i].ciphertexts[j],
wtx.vjoinsplit[i].ephemeralKey,
hSig,
(unsigned char) j);
outEntries.push_back(CNotePlaintextEntry{jsop, pa, plaintext});
outEntries.push_back(CSproutNotePlaintextEntry{jsop, pa, plaintext});
} catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key
@ -3809,7 +3809,7 @@ void CWallet::GetFilteredNotes(
/* Find unspent notes filtered by payment address, min depth and max depth */
void CWallet::GetUnspentFilteredNotes(
std::vector<CUnspentNotePlaintextEntry>& outEntries,
std::vector<CUnspentSproutNotePlaintextEntry>& outEntries,
std::set<PaymentAddress>& filterAddresses,
int minDepth,
int maxDepth,
@ -3862,14 +3862,14 @@ void CWallet::GetUnspentFilteredNotes(
// determine amount of funds in the note
auto hSig = wtx.vjoinsplit[i].h_sig(*pzcashParams, wtx.joinSplitPubKey);
try {
NotePlaintext plaintext = NotePlaintext::decrypt(
SproutNotePlaintext plaintext = SproutNotePlaintext::decrypt(
decryptor,
wtx.vjoinsplit[i].ciphertexts[j],
wtx.vjoinsplit[i].ephemeralKey,
hSig,
(unsigned char) j);
outEntries.push_back(CUnspentNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()});
outEntries.push_back(CUnspentSproutNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()});
} catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key

14
src/wallet/wallet.h

@ -265,18 +265,18 @@ public:
typedef std::map<JSOutPoint, CNoteData> mapNoteData_t;
/** Decrypted note and its location in a transaction. */
struct CNotePlaintextEntry
struct CSproutNotePlaintextEntry
{
JSOutPoint jsop;
libzcash::PaymentAddress address;
libzcash::NotePlaintext plaintext;
libzcash::SproutNotePlaintext plaintext;
};
/** Decrypted note, location in a transaction, and confirmation height. */
struct CUnspentNotePlaintextEntry {
struct CUnspentSproutNotePlaintextEntry {
JSOutPoint jsop;
libzcash::PaymentAddress address;
libzcash::NotePlaintext plaintext;
libzcash::SproutNotePlaintext plaintext;
int nHeight;
};
@ -1139,21 +1139,21 @@ public:
void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
/* Find notes filtered by payment address, min depth, ability to spend */
void GetFilteredNotes(std::vector<CNotePlaintextEntry> & outEntries,
void GetFilteredNotes(std::vector<CSproutNotePlaintextEntry> & outEntries,
std::string address,
int minDepth=1,
bool ignoreSpent=true,
bool ignoreUnspendable=true);
/* Find notes filtered by payment addresses, min depth, ability to spend */
void GetFilteredNotes(std::vector<CNotePlaintextEntry>& outEntries,
void GetFilteredNotes(std::vector<CSproutNotePlaintextEntry>& outEntries,
std::set<libzcash::PaymentAddress>& filterAddresses,
int minDepth=1,
bool ignoreSpent=true,
bool ignoreUnspendable=true);
/* Find unspent notes filtered by payment address, min depth and max depth */
void GetUnspentFilteredNotes(std::vector<CUnspentNotePlaintextEntry>& outEntries,
void GetUnspentFilteredNotes(std::vector<CUnspentSproutNotePlaintextEntry>& outEntries,
std::set<libzcash::PaymentAddress>& filterAddresses,
int minDepth=1,
int maxDepth=INT_MAX,

2
src/zcash/JoinSplit.cpp

@ -246,7 +246,7 @@ public:
ZCNoteEncryption encryptor(h_sig);
for (size_t i = 0; i < NumOutputs; i++) {
NotePlaintext pt(out_notes[i], outputs[i].memo);
SproutNotePlaintext pt(out_notes[i], outputs[i].memo);
out_ciphertexts[i] = pt.encrypt(encryptor, outputs[i].addr.pk_enc);
}

10
src/zcash/Note.cpp

@ -38,7 +38,7 @@ uint256 SproutNote::nullifier(const SpendingKey& a_sk) const {
return PRF_nf(a_sk, rho);
}
NotePlaintext::NotePlaintext(
SproutNotePlaintext::SproutNotePlaintext(
const SproutNote& note,
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
{
@ -47,12 +47,12 @@ NotePlaintext::NotePlaintext(
r = note.r;
}
SproutNote NotePlaintext::note(const PaymentAddress& addr) const
SproutNote SproutNotePlaintext::note(const PaymentAddress& addr) const
{
return SproutNote(addr.a_pk, value, rho, r);
}
NotePlaintext NotePlaintext::decrypt(const ZCNoteDecryption& decryptor,
SproutNotePlaintext SproutNotePlaintext::decrypt(const ZCNoteDecryption& decryptor,
const ZCNoteDecryption::Ciphertext& ciphertext,
const uint256& ephemeralKey,
const uint256& h_sig,
@ -64,7 +64,7 @@ NotePlaintext NotePlaintext::decrypt(const ZCNoteDecryption& decryptor,
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << plaintext;
NotePlaintext ret;
SproutNotePlaintext ret;
ss >> ret;
assert(ss.size() == 0);
@ -72,7 +72,7 @@ NotePlaintext NotePlaintext::decrypt(const ZCNoteDecryption& decryptor,
return ret;
}
ZCNoteEncryption::Ciphertext NotePlaintext::encrypt(ZCNoteEncryption& encryptor,
ZCNoteEncryption::Ciphertext SproutNotePlaintext::encrypt(ZCNoteEncryption& encryptor,
const uint256& pk_enc
) const
{

10
src/zcash/Note.hpp

@ -38,16 +38,16 @@ public:
uint256 nullifier(const SpendingKey& a_sk) const;
};
class NotePlaintext {
class SproutNotePlaintext {
public:
uint64_t value = 0;
uint256 rho;
uint256 r;
boost::array<unsigned char, ZC_MEMO_SIZE> memo;
NotePlaintext() {}
SproutNotePlaintext() {}
NotePlaintext(const SproutNote& note, boost::array<unsigned char, ZC_MEMO_SIZE> memo);
SproutNotePlaintext(const SproutNote& note, boost::array<unsigned char, ZC_MEMO_SIZE> memo);
SproutNote note(const PaymentAddress& addr) const;
@ -59,7 +59,7 @@ public:
READWRITE(leadingByte);
if (leadingByte != 0x00) {
throw std::ios_base::failure("lead byte of NotePlaintext is not recognized");
throw std::ios_base::failure("lead byte of SproutNotePlaintext is not recognized");
}
READWRITE(value);
@ -68,7 +68,7 @@ public:
READWRITE(memo);
}
static NotePlaintext decrypt(const ZCNoteDecryption& decryptor,
static SproutNotePlaintext decrypt(const ZCNoteDecryption& decryptor,
const ZCNoteDecryption::Ciphertext& ciphertext,
const uint256& ephemeralKey,
const uint256& h_sig,

Loading…
Cancel
Save