diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 482d2997b..859349052 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5286,6 +5286,13 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) // find all unspent and unlocked notes in this zaddr pwalletMain->GetFilteredNotes(saplingEntries, fromaddress); + // sort notes from largest to smallest, which means + // we will spend the largest first + std::sort(saplingEntries.begin(), saplingEntries.end(), + [](SaplingNoteEntry i, SaplingNoteEntry j) -> bool { + return i.note.value() > j.note.value(); + }); + CAmount total_value = 0; std::vector saplingNoteInputs;