Browse Source

Replace CSproutNotePlaintextEntry with SproutNoteEntry to match Sapling

pull/245/head
Eirik0 5 years ago
parent
commit
a630f50349
  1. 19
      src/wallet/asyncrpcoperation_saplingmigration.cpp
  2. 10
      src/wallet/asyncrpcoperation_sendmany.cpp
  3. 2
      src/wallet/gtest/test_wallet.cpp
  4. 30
      src/wallet/rpcwallet.cpp
  5. 7
      src/wallet/wallet.cpp
  6. 11
      src/wallet/wallet.h

19
src/wallet/asyncrpcoperation_saplingmigration.cpp

@ -69,7 +69,7 @@ void AsyncRPCOperation_saplingmigration::main() {
bool AsyncRPCOperation_saplingmigration::main_impl() {
LogPrint("zrpcunsafe", "%s: Beginning AsyncRPCOperation_saplingmigration.\n", getId());
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
{
LOCK2(cs_main, pwalletMain->cs_wallet);
@ -79,8 +79,8 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, "", 11);
}
CAmount availableFunds = 0;
for (const CSproutNotePlaintextEntry& sproutEntry : sproutEntries) {
availableFunds += sproutEntry.plaintext.value();
for (const SproutNoteEntry& sproutEntry : sproutEntries) {
availableFunds += sproutEntry.note.value();
}
// If the remaining amount to be migrated is less than 0.01 ZEC, end the migration.
if (availableFunds < CENT) {
@ -106,25 +106,24 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
auto builder = TransactionBuilder(consensusParams, targetHeight_, MIGRATION_EXPIRY_DELTA, pwalletMain, pzcashParams,
&coinsView, &cs_main);
LogPrint("zrpcunsafe", "%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - FEE));
std::vector<CSproutNotePlaintextEntry> fromNotes;
std::vector<SproutNoteEntry> fromNotes;
CAmount fromNoteAmount = 0;
while (fromNoteAmount < amountToSend) {
auto sproutEntry = sproutEntries[noteIndex++];
fromNotes.push_back(sproutEntry);
fromNoteAmount += sproutEntry.plaintext.value();
fromNoteAmount += sproutEntry.note.value();
}
availableFunds -= fromNoteAmount;
for (const CSproutNotePlaintextEntry& sproutEntry : fromNotes) {
std::string data(sproutEntry.plaintext.memo().begin(), sproutEntry.plaintext.memo().end());
for (const SproutNoteEntry& sproutEntry : fromNotes) {
std::string data(sproutEntry.memo.begin(), sproutEntry.memo.end());
LogPrint("zrpcunsafe", "%s: Adding Sprout note input (txid=%s, vjoinsplit=%d, jsoutindex=%d, amount=%s, memo=%s)\n",
getId(),
sproutEntry.jsop.hash.ToString().substr(0, 10),
sproutEntry.jsop.js,
int(sproutEntry.jsop.n), // uint8_t
FormatMoney(sproutEntry.plaintext.value()),
FormatMoney(sproutEntry.note.value()),
HexStr(data).substr(0, 10)
);
libzcash::SproutNote sproutNote = sproutEntry.plaintext.note(sproutEntry.address);
libzcash::SproutSpendingKey sproutSk;
pwalletMain->GetSproutSpendingKey(sproutEntry.address, sproutSk);
std::vector<JSOutPoint> vOutPoints = {sproutEntry.jsop};
@ -134,7 +133,7 @@ bool AsyncRPCOperation_saplingmigration::main_impl() {
uint256 inputAnchor;
std::vector<boost::optional<SproutWitness>> vInputWitnesses;
pwalletMain->GetSproutNoteWitnesses(vOutPoints, vInputWitnesses, inputAnchor);
builder.AddSproutInput(sproutSk, sproutNote, vInputWitnesses[0].get());
builder.AddSproutInput(sproutSk, sproutEntry.note, vInputWitnesses[0].get());
}
// The amount chosen *includes* the 0.0001 ZEC fee for this transaction, i.e.
// the value of the Sapling output will be 0.0001 ZEC less.

10
src/wallet/asyncrpcoperation_sendmany.cpp

@ -1029,7 +1029,7 @@ bool AsyncRPCOperation_sendmany::find_utxos(bool fAcceptCoinbase=false) {
bool AsyncRPCOperation_sendmany::find_unspent_notes() {
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
{
LOCK2(cs_main, pwalletMain->cs_wallet);
@ -1045,15 +1045,15 @@ bool AsyncRPCOperation_sendmany::find_unspent_notes() {
saplingEntries.clear();
}
for (CSproutNotePlaintextEntry & entry : sproutEntries) {
z_sprout_inputs_.push_back(SendManyInputJSOP(entry.jsop, entry.plaintext.note(boost::get<libzcash::SproutPaymentAddress>(frompaymentaddress_)), CAmount(entry.plaintext.value())));
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
for (SproutNoteEntry & entry : sproutEntries) {
z_sprout_inputs_.push_back(SendManyInputJSOP(entry.jsop, entry.note, CAmount(entry.note.value())));
std::string data(entry.memo.begin(), entry.memo.end());
LogPrint("zrpcunsafe", "%s: found unspent Sprout note (txid=%s, vjoinsplit=%d, jsoutindex=%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.note.value()),
HexStr(data).substr(0, 10)
);
}

2
src/wallet/gtest/test_wallet.cpp

@ -188,7 +188,7 @@ TEST(WalletTests, FindUnspentSproutNotes) {
EXPECT_FALSE(wallet.IsSproutSpent(nullifier));
// We currently have an unspent and unconfirmed note in the wallet (depth of -1)
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
wallet.GetFilteredNotes(sproutEntries, saplingEntries, "", 0);
EXPECT_EQ(0, sproutEntries.size());

30
src/wallet/rpcwallet.cpp

@ -2567,7 +2567,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
UniValue results(UniValue::VARR);
if (zaddrs.size() > 0) {
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs, nMinDepth, nMaxDepth, true, !fIncludeWatchonly, false);
std::set<std::pair<PaymentAddress, uint256>> nullifierSet = pwalletMain->GetNullifiersForAddresses(zaddrs);
@ -2581,8 +2581,8 @@ UniValue z_listunspent(const UniValue& params, bool fHelp)
bool hasSproutSpendingKey = pwalletMain->HaveSproutSpendingKey(boost::get<libzcash::SproutPaymentAddress>(entry.address));
obj.push_back(Pair("spendable", hasSproutSpendingKey));
obj.push_back(Pair("address", EncodePaymentAddress(entry.address)));
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("amount", ValueFromAmount(CAmount(entry.note.value()))));
std::string data(entry.memo.begin(), entry.memo.end());
obj.push_back(Pair("memo", HexStr(data)));
if (hasSproutSpendingKey) {
obj.push_back(Pair("change", pwalletMain->IsNoteSproutChange(nullifierSet, entry.address, entry.jsop)));
@ -3291,12 +3291,12 @@ 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<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
LOCK2(cs_main, pwalletMain->cs_wallet);
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, address, minDepth, true, ignoreUnspendable);
for (auto & entry : sproutEntries) {
balance += CAmount(entry.plaintext.value());
balance += CAmount(entry.note.value());
}
for (auto & entry : saplingEntries) {
balance += CAmount(entry.note.value());
@ -3356,7 +3356,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
}
UniValue result(UniValue::VARR);
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, fromaddress, nMinDepth, false, false);
@ -3367,11 +3367,11 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp)
}
if (boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr) {
for (CSproutNotePlaintextEntry & entry : sproutEntries) {
for (SproutNoteEntry & entry : sproutEntries) {
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());
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value()))));
std::string data(entry.memo.begin(), entry.memo.end());
obj.push_back(Pair("memo", HexStr(data)));
obj.push_back(Pair("jsindex", entry.jsop.js));
obj.push_back(Pair("jsoutindex", entry.jsop.n));
@ -3965,7 +3965,7 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) {
// account failed transactions, that were not mined within their expiration
// height.
{
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
std::set<PaymentAddress> noFilter;
// Here we are looking for any and all Sprout notes for which we have the spending key, including those
@ -3973,7 +3973,7 @@ UniValue z_getmigrationstatus(const UniValue& params, bool fHelp) {
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, noFilter, 0, INT_MAX, true, true, false);
CAmount unmigratedAmount = 0;
for (const auto& sproutEntry : sproutEntries) {
unmigratedAmount += sproutEntry.plaintext.value();
unmigratedAmount += sproutEntry.note.value();
}
migrationStatus.push_back(Pair("unmigrated_amount", FormatMoney(unmigratedAmount)));
}
@ -4525,7 +4525,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
if (useAnySprout || useAnySapling || zaddrs.size() > 0) {
// Get available notes
std::vector<CSproutNotePlaintextEntry> sproutEntries;
std::vector<SproutNoteEntry> sproutEntries;
std::vector<SaplingNoteEntry> saplingEntries;
pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs);
@ -4547,9 +4547,9 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
}
// Find unspent notes and update estimated size
for (const CSproutNotePlaintextEntry& entry : sproutEntries) {
for (const SproutNoteEntry& entry : sproutEntries) {
noteCounter++;
CAmount nValue = entry.plaintext.value();
CAmount nValue = entry.note.value();
if (!maxedOutNotesFlag) {
// If we haven't added any notes yet and the merge is to a
@ -4564,7 +4564,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp)
auto zaddr = entry.address;
SproutSpendingKey zkey;
pwalletMain->GetSproutSpendingKey(zaddr, zkey);
sproutNoteInputs.emplace_back(entry.jsop, entry.plaintext.note(zaddr), nValue, zkey);
sproutNoteInputs.emplace_back(entry.jsop, entry.note, nValue, zkey);
mergedNoteValue += nValue;
}
}

7
src/wallet/wallet.cpp

@ -4483,7 +4483,7 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectAbsurdFee)
* These notes are decrypted and added to the output parameter vector, outEntries.
*/
void CWallet::GetFilteredNotes(
std::vector<CSproutNotePlaintextEntry>& sproutEntries,
std::vector<SproutNoteEntry>& sproutEntries,
std::vector<SaplingNoteEntry>& saplingEntries,
std::string address,
int minDepth,
@ -4505,7 +4505,7 @@ void CWallet::GetFilteredNotes(
* These notes are decrypted and added to the output parameter vector, outEntries.
*/
void CWallet::GetFilteredNotes(
std::vector<CSproutNotePlaintextEntry>& sproutEntries,
std::vector<SproutNoteEntry>& sproutEntries,
std::vector<SaplingNoteEntry>& saplingEntries,
std::set<PaymentAddress>& filterAddresses,
int minDepth,
@ -4572,7 +4572,8 @@ void CWallet::GetFilteredNotes(
hSig,
(unsigned char) j);
sproutEntries.push_back(CSproutNotePlaintextEntry{jsop, pa, plaintext, wtx.GetDepthInMainChain()});
sproutEntries.push_back(SproutNoteEntry {
jsop, pa, plaintext.note(pa), plaintext.memo(), wtx.GetDepthInMainChain() });
} catch (const note_decryption_failed &err) {
// Couldn't decrypt with this spending key

11
src/wallet/wallet.h

@ -312,12 +312,13 @@ public:
typedef std::map<JSOutPoint, SproutNoteData> mapSproutNoteData_t;
typedef std::map<SaplingOutPoint, SaplingNoteData> mapSaplingNoteData_t;
/** Decrypted note, its location in a transaction, and number of confirmations. */
struct CSproutNotePlaintextEntry
/** Sprout note, its location in a transaction, and number of confirmations. */
struct SproutNoteEntry
{
JSOutPoint jsop;
libzcash::SproutPaymentAddress address;
libzcash::SproutNotePlaintext plaintext;
libzcash::SproutNote note;
std::array<unsigned char, ZC_MEMO_SIZE> memo;
int confirmations;
};
@ -1301,7 +1302,7 @@ public:
bool LoadCryptedHDSeed(const uint256& seedFp, const std::vector<unsigned char>& seed);
/* Find notes filtered by payment address, min depth, ability to spend */
void GetFilteredNotes(std::vector<CSproutNotePlaintextEntry>& sproutEntries,
void GetFilteredNotes(std::vector<SproutNoteEntry>& sproutEntries,
std::vector<SaplingNoteEntry>& saplingEntries,
std::string address,
int minDepth=1,
@ -1310,7 +1311,7 @@ public:
/* Find notes filtered by payment addresses, min depth, max depth, if they are spent,
if a spending key is required, and if they are locked */
void GetFilteredNotes(std::vector<CSproutNotePlaintextEntry>& sproutEntries,
void GetFilteredNotes(std::vector<SproutNoteEntry>& sproutEntries,
std::vector<SaplingNoteEntry>& saplingEntries,
std::set<libzcash::PaymentAddress>& filterAddresses,
int minDepth=1,

Loading…
Cancel
Save