Create class hierarchy for SproutNotePlaintext.
BaseNotePlaintext contains member variable for common attribute, value.
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
|
||||
#include "zcash/prf.h"
|
||||
#include "util.h"
|
||||
#include "streams.h"
|
||||
#include "version.h"
|
||||
#include "serialize.h"
|
||||
|
||||
#include "zcash/JoinSplit.hpp"
|
||||
#include "zcash/Note.hpp"
|
||||
@@ -546,6 +549,17 @@ TEST(joinsplit, note_plaintexts)
|
||||
ASSERT_TRUE(decrypted_note.value() == note.value());
|
||||
|
||||
ASSERT_TRUE(decrypted.memo == note_pt.memo);
|
||||
|
||||
// Check serialization of note plaintext
|
||||
CDataStream ss(SER_DISK, PROTOCOL_VERSION);
|
||||
ss << note_pt;
|
||||
SproutNotePlaintext note_pt2;
|
||||
ss >> note_pt2;
|
||||
ASSERT_EQ(note_pt.value(), note.value());
|
||||
ASSERT_EQ(note_pt.value(), note_pt2.value());
|
||||
ASSERT_EQ(note_pt.memo, note_pt2.memo);
|
||||
ASSERT_EQ(note_pt.rho, note_pt2.rho);
|
||||
ASSERT_EQ(note_pt.r, note_pt2.r);
|
||||
}
|
||||
|
||||
TEST(joinsplit, note_class)
|
||||
|
||||
@@ -466,11 +466,11 @@ bool AsyncRPCOperation_mergetoaddress::main_impl()
|
||||
info.notes.push_back(note);
|
||||
info.zkeys.push_back(changeKey);
|
||||
|
||||
jsInputValue += plaintext.value;
|
||||
jsInputValue += plaintext.value();
|
||||
|
||||
LogPrint("zrpcunsafe", "%s: spending change (amount=%s)\n",
|
||||
getId(),
|
||||
FormatMoney(plaintext.value));
|
||||
FormatMoney(plaintext.value()));
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, strprintf("Error decrypting output note of previous JoinSplit: %s", e.what()));
|
||||
|
||||
@@ -581,11 +581,11 @@ bool AsyncRPCOperation_sendmany::main_impl() {
|
||||
SproutNote note = plaintext.note(frompaymentaddress_);
|
||||
info.notes.push_back(note);
|
||||
|
||||
jsInputValue += plaintext.value;
|
||||
jsInputValue += plaintext.value();
|
||||
|
||||
LogPrint("zrpcunsafe", "%s: spending change (amount=%s)\n",
|
||||
getId(),
|
||||
FormatMoney(plaintext.value)
|
||||
FormatMoney(plaintext.value())
|
||||
);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
@@ -884,14 +884,14 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
|
||||
}
|
||||
|
||||
for (CSproutNotePlaintextEntry & entry : entries) {
|
||||
z_inputs_.push_back(SendManyInputJSOP(entry.jsop, entry.plaintext.note(frompaymentaddress_), CAmount(entry.plaintext.value)));
|
||||
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",
|
||||
getId(),
|
||||
entry.jsop.hash.ToString().substr(0, 10),
|
||||
entry.jsop.js,
|
||||
int(entry.jsop.n), // uint8_t
|
||||
FormatMoney(entry.plaintext.value),
|
||||
FormatMoney(entry.plaintext.value()),
|
||||
HexStr(data).substr(0, 10)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
|
||||
|
||||
string memoHexString = HexStr(npt.memo.data(), npt.memo.data() + npt.memo.size());
|
||||
o.push_back(Pair("memo", memoHexString));
|
||||
o.push_back(Pair("value", ValueFromAmount(npt.value)));
|
||||
o.push_back(Pair("value", ValueFromAmount(npt.value())));
|
||||
|
||||
// Check the blockchain commitment matches decrypted note commitment
|
||||
uint256 cm_blockchain = jsdesc.commitments[pd.payload.n];
|
||||
|
||||
@@ -2549,7 +2549,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
|
||||
obj.push_back(Pair("confirmations", entry.nHeight));
|
||||
obj.push_back(Pair("spendable", pwalletMain->HaveSpendingKey(entry.address)));
|
||||
obj.push_back(Pair("address", CZCPaymentAddress(entry.address).ToString()));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value))));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
|
||||
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
|
||||
obj.push_back(Pair("memo", HexStr(data)));
|
||||
results.push_back(obj);
|
||||
@@ -3179,7 +3179,7 @@ CAmount getBalanceZaddr(std::string address, int minDepth = 1, bool ignoreUnspen
|
||||
LOCK2(cs_main, pwalletMain->cs_wallet);
|
||||
pwalletMain->GetFilteredNotes(entries, address, minDepth, true, ignoreUnspendable);
|
||||
for (auto & entry : entries) {
|
||||
balance += CAmount(entry.plaintext.value);
|
||||
balance += CAmount(entry.plaintext.value());
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
@@ -3240,7 +3240,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
|
||||
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))));
|
||||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
|
||||
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
|
||||
obj.push_back(Pair("memo", HexStr(data)));
|
||||
// (txid, jsindex, jsoutindex) is needed to globally identify a note
|
||||
@@ -4146,7 +4146,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
|
||||
// Find unspent notes and update estimated size
|
||||
for (CSproutNotePlaintextEntry& entry : entries) {
|
||||
noteCounter++;
|
||||
CAmount nValue = entry.plaintext.value;
|
||||
CAmount nValue = entry.plaintext.value();
|
||||
|
||||
if (!maxedOutNotesFlag) {
|
||||
// If we haven't added any notes yet and the merge is to a
|
||||
|
||||
@@ -42,14 +42,14 @@ SproutNotePlaintext::SproutNotePlaintext(
|
||||
const SproutNote& note,
|
||||
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
|
||||
{
|
||||
value = note.value();
|
||||
value_ = note.value();
|
||||
rho = note.rho;
|
||||
r = note.r;
|
||||
}
|
||||
|
||||
SproutNote SproutNotePlaintext::note(const PaymentAddress& addr) const
|
||||
{
|
||||
return SproutNote(addr.a_pk, value, rho, r);
|
||||
return SproutNote(addr.a_pk, value_, rho, r);
|
||||
}
|
||||
|
||||
SproutNotePlaintext SproutNotePlaintext::decrypt(const ZCNoteDecryption& decryptor,
|
||||
|
||||
@@ -38,9 +38,18 @@ public:
|
||||
uint256 nullifier(const SpendingKey& a_sk) const;
|
||||
};
|
||||
|
||||
class SproutNotePlaintext {
|
||||
class BaseNotePlaintext {
|
||||
protected:
|
||||
uint64_t value_ = 0;
|
||||
public:
|
||||
BaseNotePlaintext() {}
|
||||
virtual ~BaseNotePlaintext() {}
|
||||
|
||||
inline uint64_t value() const { return value_; }
|
||||
};
|
||||
|
||||
class SproutNotePlaintext : public BaseNotePlaintext {
|
||||
public:
|
||||
uint64_t value = 0;
|
||||
uint256 rho;
|
||||
uint256 r;
|
||||
boost::array<unsigned char, ZC_MEMO_SIZE> memo;
|
||||
@@ -51,6 +60,8 @@ public:
|
||||
|
||||
SproutNote note(const PaymentAddress& addr) const;
|
||||
|
||||
virtual ~SproutNotePlaintext() {}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
@@ -62,7 +73,7 @@ public:
|
||||
throw std::ios_base::failure("lead byte of SproutNotePlaintext is not recognized");
|
||||
}
|
||||
|
||||
READWRITE(value);
|
||||
READWRITE(value_);
|
||||
READWRITE(rho);
|
||||
READWRITE(r);
|
||||
READWRITE(memo);
|
||||
|
||||
Reference in New Issue
Block a user