16 #include <boost/filesystem.hpp>
17 #include <boost/test/unit_test.hpp>
26 wallet.SetupSPKM(
false);
34 assert(
static_cast<bool>(saplingNoteData));
45 const std::vector<ShieldedDestination>& vDest,
73 std::vector<ShieldedDestination> vDest;
74 vDest.push_back({extskOut, amount});
93 const auto& ivk = *(nd.
ivk);
95 wtx.
tx->sapData->vShieldedOutput[sapPoint.
n].encCiphertext,
97 wtx.
tx->sapData->vShieldedOutput[sapPoint.
n].ephemeralKey,
98 wtx.
tx->sapData->vShieldedOutput[sapPoint.
n].cmu);
99 assert(
static_cast<bool>(maybe_pt));
104 auto commitment = note.
cmu().get();
107 auto anchor = tree.
root();
116 return {note, anchor, witness};
145 CAmount firstCredit = COIN * 10;
161 CAmount firstDebitShieldedChange = firstDebit -
fee;
166 builder.AddSaplingSpend(
178 wallet.
AddToWallet({&wallet, MakeTransactionRef(tx)});
199 return m.DefaultAddress();
209 builder.AddSaplingSpend(
216 builder.AddSaplingOutput(
225 wallet.
AddToWallet({&wallet, MakeTransactionRef(tx)});
245 CAmount firstCredit = COIN * 20;
268 CAmount expectedShieldedChange = firstCredit - destAmount -
fee;
331 std::vector<ShieldedDestination> vDest;
332 vDest.push_back({extskOut, credit / 2});
333 vDest.push_back({extskOut, credit / 2});
351 std::vector<SaplingNoteEntry> saplingEntries;
357 std::vector<SaplingOutPoint> ops = {saplingEntries[0].op};
359 std::vector<Optional<SaplingWitness>> witnesses;
366 CAmount destAmount = credit / 2 -
fee - change;
int64_t CAmount
Amount in PIV (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
static std::unique_ptr< BerkeleyDatabase > CreateDummy()
Return object for accessing dummy database with no read/write capabilities.
bool GetSaplingExtendedSpendingKey(const libzcash::SaplingPaymentAddress &addr, libzcash::SaplingExtendedSpendingKey &extskOut) const
std::vector< CTransactionRef > vtx
The block chain is a tree shaped structure starting with the genesis block at the root,...
uint256 GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
const uint256 * phashBlock
pointer to the hash of the block, if any. memory is owned by this CBlockIndex
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
const Consensus::Params & GetConsensus() const
The basic transaction that is broadcasted on the network and contained in blocks.
const uint256 & GetHash() const
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
std::map< uint256, CWalletTx > mapWallet
void IncrementNoteWitnesses(const CBlockIndex *pindex, const CBlock *pblock, SaplingMerkleTree &saplingTree)
pindex is the new tip being connected.
void SetLastBlockProcessed(const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Set last block processed height, currently only use in unit test.
SaplingScriptPubKeyMan * GetSaplingScriptPubKeyMan() const
libzcash::SaplingPaymentAddress GenerateNewSaplingZKey(std::string label="")
Generates new Sapling key.
A transaction with a bunch of additional info that only the owner cares about.
CAmount GetShieldedChange() const
void SetSaplingNoteData(mapSaplingNoteData_t ¬eData)
bool fShieldedChangeCached
mapSaplingNoteData_t mapSaplingNoteData
CAmount GetShieldedAvailableCredit(bool fUseCache=true) const
const uint256 & GetHash() const
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
Optional< libzcash::SaplingIncomingViewingKey > ivk
An outpoint - a combination of a transaction hash and an index n into its sapling output description ...
bool IsNoteSaplingChange(const std::set< std::pair< libzcash::PaymentAddress, uint256 >> &nullifierSet, const libzcash::PaymentAddress &address, const SaplingOutPoint &entry) const
int64_t nWitnessCacheSize
void GetSaplingNoteWitnesses(const std::vector< SaplingOutPoint > ¬es, std::vector< Optional< SaplingWitness >> &witnesses, uint256 &final_anchor) const
Return all of the witnesses for the input notes.
void UpdateSaplingNullifierNoteMapWithTx(CWalletTx &wtx)
Update mapSaplingNullifiersToNotes, computing the nullifier from a cached witness if necessary.
void GetFilteredNotes(std::vector< SaplingNoteEntry > &saplingEntries, Optional< libzcash::SaplingPaymentAddress > &address, int minDepth=1, bool ignoreSpent=true, bool requireSpendingKey=true, bool ignoreLocked=true) const
Find notes in the wallet filtered by payment address, min depth and ability to spend and if the notes...
void UpdateSaplingNullifierNoteMapForBlock(const CBlock *pblock)
Iterate over transactions in a block and update the cached Sapling nullifiers for transactions which ...
IncrementalWitness< Depth, Hash > witness() const
Optional< uint256 > cmu() const
static Optional< SaplingNotePlaintext > decrypt(const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk, const uint256 &cmu)
BOOST_AUTO_TEST_SUITE_END()
bool IsAmountCached(AmountType type, const isminefilter &filter) const
bool SetMinVersion(enum WalletFeature, WalletBatch *batch_in=nullptr, bool fExplicit=false)
signify that a particular wallet feature is now used. this may change nWalletVersion and nWalletMaxVe...
bool AddToWallet(const CWalletTx &wtxIn, bool fFlushOnClose=true)
CAmount GetDebit(const isminefilter &filter) const
filter decides which addresses will count towards the debit
bool FindNotesDataAndAddMissingIVKToKeystore(const CTransaction &tx, Optional< mapSaplingNoteData_t > &saplingNoteData)
CAmount GetCredit(const isminefilter &filter, bool recalculate=false) const
bool SetupSPKM(bool newKeypool=true, bool memOnly=false)
Generates hd wallet //.
CAmount GetAvailableCredit(bool fUseCache=true, const isminefilter &filter=ISMINE_SPENDABLE) const
@ ISMINE_SPENDABLE_SHIELDED
Indicates that we have the spending key of a shielded spend/output.
uint256 BlockMerkleRoot(const CBlock &block, bool *mutated)
RecursiveMutex cs_main
Global state.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
boost::optional< T > Optional
Substitute for C++17 std::optional.
Parameters that influence chain consensus.
const SaplingWitness witness
libzcash::SaplingNote note
libzcash::SaplingExpandedSpendingKey expsk
static SaplingExtendedSpendingKey Master(const HDSeed &seed)
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
CWalletTx GetValidSaplingReceive(const Consensus::Params &consensusParams, CBasicKeyStore &keyStoreFrom, std::vector< TransparentInput > vIn, std::vector< ShieldedDestination > vDest, const CWallet *pwalletIn)
One or many inputs from keyStoreFrom, one or many shielded outputs to pwalletIn (if not nullptr).
CScript CreateDummyDestinationScript()
Generates a dummy destination script.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
FakeBlock SimpleFakeMine(CWalletTx &wtx, SaplingMerkleTree ¤tTree, CWallet &wallet)
CWalletTx & SetWalletNotesData(CWallet *wallet, CWalletTx &wtx)
BOOST_AUTO_TEST_CASE(GetShieldedSimpleCachedCreditAndDebit)
Validates: 1) CWalletTx getCredit for shielded credit.
SaplingSpendValues UpdateWalletInternalNotesData(CWalletTx &wtx, const SaplingOutPoint &sapPoint, CWallet &wallet)
Update the wallet internally as if the wallet would had received a valid block containing wtx.
void setupWallet(CWallet &wallet)
CWalletTx & AddShieldedBalanceToWallet(CAmount inputAmount, const std::vector< ShieldedDestination > &vDest, CWallet *wallet, const Consensus::Params &consensusParams)
Creates and send a tx with an input of 'inputAmount' to 'vDest'.
CWalletTx & buildTxAndLoadToWallet(CWallet &wallet, const libzcash::SaplingExtendedSpendingKey &extskOut, const SaplingSpendValues &sapSpendValues, libzcash::SaplingPaymentAddress dest, const CAmount &destAmount, const Consensus::Params &consensus)
libzcash::SaplingPaymentAddress getNewDummyShieldedAddress()