Skip to content

Commit

Permalink
Move memo member varible from SproutNotePlaintext to BaseNotePlaintext.
Browse files Browse the repository at this point in the history
Add memo() accessor to BaseNotePlaintext.
  • Loading branch information
bitcartel committed Apr 26, 2018
1 parent d266f40 commit debf6af
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/gtest/test_joinsplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ TEST(joinsplit, note_plaintexts)
ASSERT_TRUE(decrypted_note.r == note.r);
ASSERT_TRUE(decrypted_note.value() == note.value());

ASSERT_TRUE(decrypted.memo == note_pt.memo);
ASSERT_TRUE(decrypted.memo() == note_pt.memo());

// Check serialization of note plaintext
CDataStream ss(SER_DISK, PROTOCOL_VERSION);
Expand All @@ -557,7 +557,7 @@ TEST(joinsplit, note_plaintexts)
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.memo(), note_pt2.memo());
ASSERT_EQ(note_pt.rho, note_pt2.rho);
ASSERT_EQ(note_pt.r, note_pt2.r);
}
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/asyncrpcoperation_sendmany.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ 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())));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
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),
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/rpcdisclosure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp)
SproutNotePlaintext npt;
ssPlain >> npt;

string memoHexString = HexStr(npt.memo.data(), npt.memo.data() + npt.memo.size());
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())));

Expand Down
4 changes: 2 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
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()))));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
obj.push_back(Pair("memo", HexStr(data)));
results.push_back(obj);
}
Expand Down Expand Up @@ -3241,7 +3241,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
UniValue obj(UniValue::VOBJ);
obj.push_back(Pair("txid",entry.jsop.hash.ToString()));
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value()))));
std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end());
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
obj.push_back(Pair("jsindex", entry.jsop.js));
Expand Down
3 changes: 1 addition & 2 deletions src/zcash/Note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ uint256 SproutNote::nullifier(const SpendingKey& a_sk) const {

SproutNotePlaintext::SproutNotePlaintext(
const SproutNote& note,
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : memo(memo)
boost::array<unsigned char, ZC_MEMO_SIZE> memo) : BaseNotePlaintext(note, memo)
{
value_ = note.value();
rho = note.rho;
r = note.r;
}
Expand Down
7 changes: 5 additions & 2 deletions src/zcash/Note.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ class SproutNote : public BaseNote {
class BaseNotePlaintext {
protected:
uint64_t value_ = 0;
boost::array<unsigned char, ZC_MEMO_SIZE> memo_;
public:
BaseNotePlaintext() {}
BaseNotePlaintext(const BaseNote& note, boost::array<unsigned char, ZC_MEMO_SIZE> memo)
: value_(note.value()), memo_(memo) {}
virtual ~BaseNotePlaintext() {}

inline uint64_t value() const { return value_; }
inline boost::array<unsigned char, ZC_MEMO_SIZE> memo() const { return memo_; }
};

class SproutNotePlaintext : public BaseNotePlaintext {
public:
uint256 rho;
uint256 r;
boost::array<unsigned char, ZC_MEMO_SIZE> memo;

SproutNotePlaintext() {}

Expand All @@ -76,7 +79,7 @@ class SproutNotePlaintext : public BaseNotePlaintext {
READWRITE(value_);
READWRITE(rho);
READWRITE(r);
READWRITE(memo);
READWRITE(memo_);
}

static SproutNotePlaintext decrypt(const ZCNoteDecryption& decryptor,
Expand Down

0 comments on commit debf6af

Please sign in to comment.