14 #include "validation.h"
26 std::pair<TxNullifiers::iterator, TxNullifiers::iterator> range;
44 std::pair<TxNullifiers::const_iterator, TxNullifiers::const_iterator> range;
47 for (TxNullifiers::const_iterator it = range.first; it != range.second; ++it) {
48 const uint256& wtxid = it->second;
49 std::map<uint256, CWalletTx>::const_iterator mit =
wallet->
mapWallet.find(wtxid);
50 if (mit !=
wallet->
mapWallet.end() && mit->second.GetDepthInMainChain() >= 0) {
60 for (
const auto& tx : pblock->
vtx) {
94 uint64_t position = nd.
witnesses.front().position();
103 auto optNote = optPlaintext.get().note(ivk);
107 auto optNullifier = optNote.get().nullifier(extfvk.fvk, position);
125 if (item.second.nullifier) {
132 template<
typename NoteDataMap>
135 for (
auto& item : noteDataMap) {
136 auto* nd = &(item.second);
138 if (!nd->IsMyNote())
continue;
140 if (nd->witnessHeight < indexHeight) {
146 assert(nWitnessCacheSize >= (int64_t) nd->witnesses.size());
149 assert((nd->witnessHeight == -1) || (nd->witnessHeight == indexHeight - 1));
151 if (nd->witnesses.size() > 0) {
152 nd->witnesses.push_front(nd->witnesses.front());
154 if (nd->witnesses.size() > WITNESS_CACHE_SIZE) {
155 nd->witnesses.pop_back();
169 assert(nWitnessCacheSize >= (int64_t) nd->
witnesses.size());
170 nd->
witnesses.front().append(note_commitment);
174 template<
typename Witness>
177 int64_t nWitnessCacheSize,
178 const Witness& witness)
192 LogPrintf(
"Inconsistent witness cache state found\n- Cache size: %d\n- Top (height %d): %s\n- New (height %d): %s\n",
196 witness.root().GetHex());
203 assert(nWitnessCacheSize >= (int64_t) nd->
witnesses.size());
206 template <
typename NoteDataMap>
209 for (
auto& item : noteDataMap) {
210 auto* nd = &(item.second);
212 if (!nd->IsMyNote())
continue;
213 if (nd->witnessHeight < indexHeight) {
214 nd->witnessHeight = indexHeight;
217 assert(nWitnessCacheSize >= (int64_t) nd->witnesses.size());
235 int minHeight = INT_MAX;
245 std::vector<CBlock> cblocks;
248 while (currentHeight >= minHeight) {
251 cblocks.insert(cblocks.begin(), cblock);
252 pIndex = pIndex->
pprev;
253 currentHeight = pIndex->
nHeight;
259 errorStr =
"Cannot fetch the sapling anchor!";
263 int height = minHeight;
264 for (
CBlock& block : cblocks) {
266 std::vector<uint256> noteCommitments;
267 std::vector<SaplingNoteData*> inBlockArrivingNotes;
268 for (
const auto& tx : block.vtx) {
269 const auto& hash = tx->GetHash();
273 if (!tx->IsShieldedTx())
continue;
274 for (uint32_t i = 0; i < tx->sapData->vShieldedOutput.size(); i++) {
275 const auto& cmu = tx->sapData->vShieldedOutput[i].cmu;
276 noteCommitments.emplace_back(cmu);
277 for (
auto& item : inBlockArrivingNotes) {
278 item->witnesses.front().append(cmu);
280 initialSaplingTree.
append(cmu);
287 inBlockArrivingNotes.emplace_back(nd);
295 it2.second.emplace_front(it2.second.front());
297 for (
auto& noteComm : noteCommitments) {
298 it2.second.front().append(noteComm);
301 for (
auto nd : inBlockArrivingNotes) {
303 std::list<SaplingWitness> witnesses;
304 witnesses.push_front(nd->witnesses.front());
318 int chainHeight = pindex->
nHeight;
329 std::vector<uint256> noteCommitments;
330 std::vector<std::pair<CWalletTx*, SaplingNoteData*>> inBlockArrivingNotes;
331 for (
const auto& tx : pblock->
vtx) {
332 if (!tx->IsShieldedTx())
continue;
334 const auto& hash = tx->GetHash();
338 for (uint32_t i = 0; i < tx->sapData->vShieldedOutput.size(); i++) {
339 const auto& cmu = tx->sapData->vShieldedOutput[i].cmu;
340 noteCommitments.emplace_back(cmu);
346 for (
auto& item : inBlockArrivingNotes) {
352 saplingTreeRes.
append(cmu);
359 inBlockArrivingNotes.emplace_back(std::make_pair(wtx, nd));
366 for (
auto& item : inBlockArrivingNotes) {
381 for (
auto& noteComm : noteCommitments) {
399 void ResetNoteWitnesses(std::map<SaplingOutPoint, SaplingNoteData>& noteDataMap, std::map<
uint256, std::list<SaplingWitness>>& cachedWitnessMap,
int indexHeight)
402 for (
auto& item : noteDataMap) {
403 auto& nd = (item.second);
405 if (!nd.IsMyNote())
continue;
407 nd.witnesses.clear();
411 if (nd.witnessHeight <= indexHeight) {
412 assert((nd.witnessHeight == -1) || (nd.witnessHeight == indexHeight));
415 nd.witnessHeight = indexHeight - 1;
416 if (nd.nullifier && cachedWitnessMap.at(*nd.nullifier).size() > 0) {
418 nd.witnesses.push_front(cachedWitnessMap.at(*nd.nullifier).front());
419 cachedWitnessMap.at(*nd.nullifier).pop_front();
425 template<
typename NoteDataMap>
428 for (
auto& item : noteDataMap) {
429 auto* nd = &(item.second);
431 if (!nd->IsMyNote())
continue;
433 if (nd->witnessHeight <= indexHeight) {
437 assert(nWitnessCacheSize >= (int64_t) nd->witnesses.size());
441 assert((nd->witnessHeight == -1) || (nd->witnessHeight == indexHeight));
442 if (nd->witnesses.size() > 0) {
443 nd->witnesses.pop_front();
447 nd->witnessHeight = indexHeight - 1;
459 if (nd->witnessHeight < indexHeight) {
462 assert((nWitnessCacheSize - 1) >= (int64_t) nd->witnesses.size());
471 int nChainHeight = pindex->
nHeight;
474 for (std::pair<const uint256, CWalletTx>& wtxItem :
wallet->
mapWallet) {
475 if (!wtxItem.second.mapSaplingNoteData.empty()) {
491 for (std::pair<const uint256, CWalletTx>& wtxItem :
wallet->
mapWallet) {
497 if (
Params().IsRegTestNet()) {
528 for (uint32_t i = 0; i < tx.
sapData->vShieldedOutput.size(); ++i) {
540 viewingKeysToAdd[address.get()] = ivk;
547 nd.
amount = result->value();
549 const auto& memo = result->memo();
551 if (memo[0] < 0xF6) {
554 noteData.insert(std::make_pair(op, nd));
559 return std::make_pair(noteData, viewingKeysToAdd);
565 std::vector<libzcash::SaplingPaymentAddress> ret;
578 ret.emplace_back(address.get());
586 std::vector<SaplingNoteEntry>& saplingEntriesRet)
const
588 for (
const auto& outpoint : saplingOutpoints) {
590 if (!wtx)
throw std::runtime_error(
"No transaction available for hash " + outpoint.hash.GetHex());
592 const auto& it = wtx->mapSaplingNoteData.find(outpoint);
593 if (it != wtx->mapSaplingNoteData.end()) {
601 auto optNotePtAndAddress = wtx->DecryptSaplingNote(op);
602 assert(
static_cast<bool>(optNotePtAndAddress));
607 auto note = notePt.
note(ivk).get();
609 saplingEntriesRet.emplace_back(op, pa, note, notePt.
memo(), depth);
619 std::vector<SaplingNoteEntry>& saplingEntries,
623 bool requireSpendingKey,
624 bool ignoreLocked)
const
626 std::set<libzcash::PaymentAddress> filterAddresses;
629 filterAddresses.insert(*address);
632 GetFilteredNotes(saplingEntries, filterAddresses, minDepth, INT_MAX, ignoreSpent, requireSpendingKey, ignoreLocked);
641 std::vector<SaplingNoteEntry>& saplingEntries,
642 std::set<libzcash::PaymentAddress>& filterAddresses,
646 bool requireSpendingKey,
647 bool ignoreLocked)
const
662 depth < minDepth || depth > maxDepth) {
674 assert(
static_cast<bool>(optNotePtAndAddress));
679 auto note = notePt.
note(ivk).get();
682 if (!(filterAddresses.empty() || filterAddresses.count(pa))) {
700 saplingEntries.emplace_back(op, pa, note, notePt.
memo(), depth);
708 std::vector<SaplingNoteEntry> notes;
712 std::map<libzcash::SaplingPaymentAddress, std::vector<SaplingNoteEntry>> result;
713 for (
const auto& note : notes) {
714 result[note.address].emplace_back(std::move(note));
723 if (!wtx)
return nullopt;
730 if (!wtx->
tx->sapData || wtx->
tx->sapData->vShieldedSpend.empty())
return nullopt;
749 const std::set<libzcash::PaymentAddress> & addresses)
const
752 std::set<std::pair<libzcash::PaymentAddress, uint256>> nullifierSet;
755 std::map<libzcash::SaplingIncomingViewingKey, std::vector<libzcash::SaplingPaymentAddress>> ivkMap;
756 for (
const auto& addr : addresses) {
757 auto saplingAddr = boost::get<libzcash::SaplingPaymentAddress>(&addr);
758 if (saplingAddr !=
nullptr) {
761 ivkMap[ivk].push_back(*saplingAddr);
765 for (
const auto & noteDataPair : txPair.second.mapSaplingNoteData) {
766 const auto& noteData = noteDataPair.second;
769 if (!noteData.IsMyNote())
continue;
772 const auto& nullifier = noteData.nullifier;
773 if (nullifier && ivkMap.count(ivk)) {
774 for (
const auto & addr : ivkMap[ivk]) {
775 nullifierSet.insert(std::make_pair(addr, nullifier.get()));
789 return it->second.address;
798 return it->second.amount ? *(it->second.amount) : 0;
806 auto& memo = *(it->second.memo);
808 if (memo[0] <= 0xf4) {
809 std::string memoStr(memo.begin(), end.base());
813 return HexStr(std::vector<unsigned char>(memo.begin(), end.base()));
822 assert(txId == op.
hash);
824 std::set<uint256> ovks;
830 if (!tx.
tx->vin.empty()) {
834 LogPrintf(
"WARNING: No CommonOVK found. Some notes might not be correctly recovered. "
835 "Unlock the wallet and call 'viewshieldtransaction %s' to fix.\n", txId.
ToString());
838 for (
const auto& spend : tx.
tx->sapData->vShieldedSpend) {
843 if (!txPrev)
continue;
850 ovks.emplace(extfvk.
fvk.
ovk);
863 const auto addr = ndIt->second.address;
877 if (!tx.
tx->IsShieldedTx() || tx.
tx->sapData->vShieldedOutput.empty()) {
881 for (
int i = 0; i < (int) tx.
tx->sapData->vShieldedOutput.size(); ++i) {
924 const auto& wtx = wit->second;
925 auto nit = wtx.mapSaplingNoteData.find(op);
926 assert(nit != wtx.mapSaplingNoteData.end());
927 const auto& nd = nit->second;
928 assert(nd.IsMyNote());
929 assert(
static_cast<bool>(nd.amount));
932 nDebit += *(nd.amount);
935 throw std::runtime_error(
"SaplingScriptPubKeyMan::GetDebit() : value out of range");
943 if (!wtx.
tx->IsShieldedTx() || wtx.
tx->sapData->vShieldedOutput.empty()) {
949 for (uint32_t pos = 0; pos < (uint32_t) wtx.
tx->sapData->vShieldedOutput.size(); ++pos) {
953 const auto& nd = it->second;
954 if (!nd.IsMyNote() || !
static_cast<bool>(nd.address) || !
static_cast<bool>(nd.amount))
continue;
956 nChange += *(nd.amount);
958 throw std::runtime_error(
"GetShieldedChange() : value out of range");
967 std::set<libzcash::PaymentAddress> shieldedAddresses = {address};
983 if (tx.tx->sapData) {
985 if (nullifierSet.count(std::make_pair(address, spend.
nullifier))) {
998 witnesses.resize(notes.size());
1004 auto nit = it->second.mapSaplingNoteData.find(note);
1005 if (nit != it->second.mapSaplingNoteData.end() &&
1006 nit->second.witnesses.size() > 0) {
1007 witnesses[i] = nit->second.witnesses.front();
1009 rt = witnesses[i]->root();
1011 assert(*rt == witnesses[i]->root());
1026 if (!unchangedSaplingFlag) {
1030 for (
const std::pair <SaplingOutPoint, SaplingNoteData> nd : wtx.
mapSaplingNoteData) {
1031 if (tmp.count(nd.first) && nd.second.witnesses.size() > 0) {
1032 tmp.at(nd.first).witnesses.assign(
1033 nd.second.witnesses.cbegin(), nd.second.witnesses.cend());
1035 tmp.at(nd.first).witnessHeight = nd.second.witnessHeight;
1042 return !unchangedSaplingFlag;
1048 for (std::pair<const uint256, CWalletTx>& wtxItem :
wallet->
mapWallet) {
1049 for (mapSaplingNoteData_t::value_type& item : wtxItem.second.mapSaplingNoteData) {
1050 item.second.witnesses.clear();
1051 item.second.witnessHeight = -1;
1092 throw std::runtime_error(std::string(__func__) +
": HD seed not found");
1112 throw std::runtime_error(std::string(__func__) +
": Writing HD chain model failed");
1115 int64_t nCreationTime =
GetTime();
1118 metadata.
key_origin.
path.push_back(32 | BIP32_HARDENED_KEY_LIMIT);
1119 metadata.
key_origin.
path.push_back(119 | BIP32_HARDENED_KEY_LIMIT);
1125 throw std::runtime_error(std::string(__func__) +
": AddSaplingZKey failed");
1140 std::pair<TxNullifiers::const_iterator, TxNullifiers::const_iterator> range_o;
1142 if (wtx.
tx->IsShieldedTx()) {
1149 for (TxNullifiers::const_iterator it = range_o.first; it != range_o.second; ++it) {
1150 result.insert(it->second);
1173 auto extfvk = sk.
ToXFVK();
1192 nTimeToSet = std::max((int64_t) 154051200, nTime);
1208 return error(
"%s: Sapling spkm not enabled", __func__ );
1236 std::vector<unsigned char> vchCryptedSecret;
1240 auto extfvk = sk.ToXFVK();
1279 auto extfvk = sk.
ToXFVK();
1280 std::vector<unsigned char> vchCryptedSecret;
1281 if (!
EncryptSecret(vMasterKeyIn, vchSecret, extfvk.fvk.GetFingerprint(), vchCryptedSecret)) {
1293 const std::vector<unsigned char> &vchCryptedSecret)
1336 const std::vector<unsigned char> &vchCryptedSecret)
1376 throw std::runtime_error(std::string(__func__) +
": sapling trying to set a hd seed on an already created chain");
1382 CHDChain newHdChain(HDChain::ChainCounterType::Sapling);
1383 if (!newHdChain.
SetSeed(keyID) ) {
1384 throw std::runtime_error(std::string(__func__) +
": set sapling hd seed failed");
1392 throw std::runtime_error(std::string(__func__) +
": writing sapling commonOVK failed");
1399 if (chain.
chainType != HDChain::ChainCounterType::Sapling)
1400 throw std::runtime_error(std::string(__func__) +
": trying to store an invalid chain type");
1403 throw std::runtime_error(std::string(__func__) +
": writing sapling chain failed");
1409 throw std::runtime_error(std::string(__func__) +
": Not found sapling seed in wallet");
1429 throw std::runtime_error(
"Unable to write sapling Common OVK to database");
1442 throw std::runtime_error(
"HD seed not found, wallet must be un-locked");
bool IsValidPaymentAddress(const libzcash::PaymentAddress &zaddr)
Check whether a PaymentAddress is not an InvalidEncoding.
int64_t CAmount
Amount in PIV (Can be negative)
const CChainParams & Params()
Return the currently selected parameters.
const_iterator end() const
const_iterator begin() const
SaplingSpendingKeyMap mapSaplingSpendingKeys
virtual bool GetSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk, libzcash::SaplingExtendedFullViewingKey &extfvkOut) const
virtual bool HaveSaplingFullViewingKey(const libzcash::SaplingIncomingViewingKey &ivk) const
virtual bool AddSaplingIncomingViewingKey(const libzcash::SaplingIncomingViewingKey &ivk, const libzcash::SaplingPaymentAddress &addr)
Sapling incoming viewing keys.
SaplingIncomingViewingKeyMap mapSaplingIncomingViewingKeys
virtual bool GetSaplingIncomingViewingKey(const libzcash::SaplingPaymentAddress &addr, libzcash::SaplingIncomingViewingKey &ivkOut) const
virtual bool AddSaplingFullViewingKey(const libzcash::SaplingExtendedFullViewingKey &extfvk)
Support for Sapling full viewing keys.
SaplingFullViewingKeyMap mapSaplingFullViewingKeys
bool AddSaplingSpendingKey(const libzcash::SaplingExtendedSpendingKey &sk)
Sapling.
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,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint256 hashFinalSaplingRoot
int nHeight
height of the entry in the chain. The genesis block has height 0
int Height() const
Return the maximal height in the chain.
const Consensus::Params & GetConsensus() const
bool GetKey(const CKeyID &address, CKey &keyOut) const override
bool HaveSaplingSpendingKey(const libzcash::SaplingExtendedFullViewingKey &extfvk) const override
bool HaveKey(const CKeyID &address) const override
Check whether a key corresponding to a given address is present in the store.
virtual bool AddCryptedSaplingSpendingKey(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret)
Sapling.
bool SetSeed(const CKeyID &seedId)
uint32_t nExternalChainCounter
An encapsulated private key.
CPrivKey GetPrivKey() const
Convert the private key to a CPrivKey (serialized secp256k1 private key data).
A reference to a CKey: the Hash160 of its serialized public key.
RecursiveMutex cs_KeyStore
An encapsulated public key.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
The basic transaction that is broadcasted on the network and contained in blocks.
bool IsShieldedTx() const
const uint256 & GetHash() const
Optional< SaplingTxData > sapData
WalletBatch * encrypted_batch
std::map< uint256, CWalletTx > mapWallet
int GetLastBlockHeight() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
Get last block processed height.
WalletDatabase & GetDBHandle() const
A transaction with a bunch of additional info that only the owner cares about.
Optional< std::pair< libzcash::SaplingNotePlaintext, libzcash::SaplingPaymentAddress > > RecoverSaplingNote(const SaplingOutPoint &op, const std::set< uint256 > &ovks) const
int GetDepthInMainChain() const NO_THREAD_SAFETY_ANALYSIS
Return depth of transaction in blockchain: <0 : conflicts with a transaction this deep in the blockch...
Optional< std::pair< libzcash::SaplingNotePlaintext, libzcash::SaplingPaymentAddress > > DecryptSaplingNote(const SaplingOutPoint &op) const
mapSaplingNoteData_t mapSaplingNoteData
const uint256 & GetHash() const
A shielded output to a transaction.
uint256 cmu
The u-coordinate of the note commitment for the output note.
libzcash::SaplingEncCiphertext encCiphertext
A ciphertext component for the encrypted output note.
uint256 ephemeralKey
A Jubjub public key.
Optional< CAmount > amount
Cached note amount.
Optional< uint256 > nullifier
Cached note nullifier.
std::list< SaplingWitness > witnesses
Optional< std::array< unsigned char, ZC_MEMO_SIZE > > memo
Cached note memo (only for non-empty memo) It will be loaded the first time that the note is decrypte...
Optional< libzcash::SaplingIncomingViewingKey > ivk
int witnessHeight
Block height corresponding to the most current witness.
Optional< libzcash::SaplingPaymentAddress > address
Cached shielded address It will be loaded the first time that the note is decrypted (when the tx is a...
An outpoint - a combination of a transaction hash and an index n into its sapling output description ...
std::map< libzcash::SaplingIncomingViewingKey, CKeyMetadata > mapSaplingZKeyMetadata
bool BuildWitnessChain(const CBlockIndex *pTargetBlock, const Consensus::Params ¶ms, std::string &errorStr)
Build the old witness chain.
bool LoadSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key)
Adds spending key to the store, without saving it to disk (used by LoadWallet)
bool UpdatedNoteData(const CWalletTx &wtxIn, CWalletTx &wtx)
Update note data if is needed.
bool IsNoteSaplingChange(const std::set< std::pair< libzcash::PaymentAddress, uint256 >> &nullifierSet, const libzcash::PaymentAddress &address, const SaplingOutPoint &entry) const
Optional< std::string > GetOutPointMemo(const CWalletTx &tx, const SaplingOutPoint &op) const
Return the memo value of a specific outpoint of wallet transaction.
int64_t GetKeyCreationTime(const libzcash::SaplingIncomingViewingKey &ivk)
bool IsSaplingSpent(const SaplingOutPoint &op) const
bool IsSaplingNullifierFromMe(const uint256 &nullifier) const
Whether the nullifier is from this wallet.
Optional< libzcash::SaplingExtendedFullViewingKey > GetViewingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &addr) const
Return the full viewing key for the shielded address.
bool HaveSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &zaddr) const
Returns true if the wallet contains the spending key.
std::vector< libzcash::SaplingPaymentAddress > FindMySaplingAddresses(const CTransaction &tx) const
Find all of the addresses in the given tx that have been sent to a SaplingPaymentAddress in this wall...
bool AddCryptedSaplingSpendingKeyDB(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret)
void AddToSaplingSpends(const uint256 &nullifier, const uint256 &wtxid)
Keep track of the used nullifier.
std::map< libzcash::SaplingPaymentAddress, std::vector< SaplingNoteEntry > > ListNotes() const
Optional< libzcash::SaplingExtendedSpendingKey > GetSpendingKeyForPaymentAddress(const libzcash::SaplingPaymentAddress &addr) const
Return the spending key for the payment address (nullopt if the wallet has no spending key for such a...
bool AddSaplingSpendingKey(const libzcash::SaplingExtendedSpendingKey &sk)
int64_t nWitnessCacheSize
void IncrementNoteWitnesses(const CBlockIndex *pindex, const CBlock *pblock, SaplingMerkleTree &saplingTree)
pindex is the new tip being connected.
bool nWitnessCacheNeedsUpdate
void UpdateSaplingNullifierNoteMap(SaplingNoteData &nd, const SaplingOutPoint &op, const Optional< uint256 > &nullifier)
Update mapSaplingNullifiersToNotes, and NoteData of a specific outpoint, directly with nullifier prov...
uint256 getCommonOVKFromSeed() const
CAmount GetCredit(const CWalletTx &tx, const isminefilter &filter, const bool fUnspent=false) const
Return the shielded credit of the tx.
bool SetupGeneration(const CKeyID &keyID, bool force=false, bool memonly=false)
Set and initialize the Sapling HD chain.
const CHDChain & GetHDChain() const
void UpdateNullifierNoteMapWithTx(const CWalletTx &wtx)
Update mapSaplingNullifiersToNotes with the cached nullifiers in this tx.
Optional< std::pair< libzcash::SaplingNotePlaintext, libzcash::SaplingPaymentAddress > > TryToRecoverNote(const CWalletTx &tx, const SaplingOutPoint &op)
Try to recover the note using the wallet's ovks (mostly used when the outpoint is a debit)
bool LoadCryptedSaplingZKey(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret)
Adds an encrypted spending key to the store, without saving it to disk (used by LoadWallet)
TxNullifiers mapTxSaplingNullifiers
isminetype IsMine(const CWalletTx &wtx, const SaplingOutPoint &op) const
Return true if the wallet can decrypt & spend the shielded output.
bool LoadSaplingZKeyMetadata(const libzcash::SaplingIncomingViewingKey &ivk, const CKeyMetadata &meta)
Load spending key metadata (used by LoadWallet)
Optional< libzcash::SaplingPaymentAddress > GetOutPointAddress(const CWalletTx &tx, const SaplingOutPoint &op) const
Return the shielded address of a specific outpoint of wallet transaction.
std::map< uint256, SaplingOutPoint > mapSaplingNullifiersToNotes
The reverse mapping of nullifiers to notes.
bool LoadSaplingPaymentAddress(const libzcash::SaplingPaymentAddress &addr, const libzcash::SaplingIncomingViewingKey &ivk)
Adds a Sapling payment address -> incoming viewing key map entry, without saving it to disk (used by ...
KeyAddResult AddViewingKeyToWallet(const libzcash::SaplingExtendedFullViewingKey &extfvk) const
bool AddSaplingIncomingViewingKey(const libzcash::SaplingIncomingViewingKey &ivk, const libzcash::SaplingPaymentAddress &addr)
bool PaymentAddressBelongsToWallet(const libzcash::SaplingPaymentAddress &zaddr) const
Returns true if the wallet contains the spending and viewing key for the shielded address.
CAmount GetOutPointValue(const CWalletTx &tx, const SaplingOutPoint &op) const
Return the shielded value of a specific outpoint of wallet transaction.
std::map< uint256, std::list< SaplingWitness > > cachedWitnessMap
void GetNotes(const std::vector< SaplingOutPoint > &saplingOutpoints, std::vector< SaplingNoteEntry > &saplingEntriesRet) const
Find notes for the outpoints.
Optional< libzcash::SaplingPaymentAddress > GetAddressFromInputIfPossible(const CWalletTx *wtx, int index) const
Return the address from where the shielded spend is taking the funds from (if possible)
bool AddSaplingZKey(const libzcash::SaplingExtendedSpendingKey &key)
Adds Sapling spending key to the store, and saves it to disk.
std::pair< mapSaplingNoteData_t, SaplingIncomingViewingKeyMap > FindMySaplingNotes(const CTransaction &tx) const
Finds all output notes in the given tx that have been sent to a SaplingPaymentAddress in this wallet.
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 DecrementNoteWitnesses(const CBlockIndex *pindex)
pindex is the old tip being disconnected.
libzcash::SaplingPaymentAddress GenerateNewSaplingZKey()
Generates new Sapling key.
std::set< std::pair< libzcash::PaymentAddress, uint256 > > GetNullifiersForAddresses(const std::set< libzcash::PaymentAddress > &addresses) const
void SetHDSeed(const CPubKey &key, bool force=false, bool memonly=false)
Optional< uint256 > commonOVK
void UpdateSaplingNullifierNoteMapWithTx(CWalletTx &wtx)
Update mapSaplingNullifiersToNotes, computing the nullifier from a cached witness if necessary.
bool EncryptSaplingKeys(CKeyingMaterial &vMasterKeyIn)
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 SetHDChain(CHDChain &chain, bool memonly)
CAmount GetDebit(const CTransaction &tx, const isminefilter &filter) const
Return the shielded debit of the tx.
void UpdateSaplingNullifierNoteMapForBlock(const CBlock *pblock)
Iterate over transactions in a block and update the cached Sapling nullifiers for transactions which ...
void ClearNoteWitnessCache()
Clear every notesData from every wallet tx and reset the witness cache size.
void GetConflicts(const CWalletTx &wtx, std::set< uint256 > &result) const
CAmount GetShieldedChange(const CWalletTx &wtx) const
Return the shielded change of the tx.
KeyAddResult AddSpendingKeyToWallet(const Consensus::Params ¶ms, const libzcash::SaplingExtendedSpendingKey &sk, int64_t nTime)
A shielded input to a transaction.
uint256 nullifier
The nullifier of the input note.
Access to the wallet database.
bool WriteSaplingPaymentAddress(const libzcash::SaplingPaymentAddress &addr, const libzcash::SaplingIncomingViewingKey &ivk)
bool WriteCryptedSaplingZKey(const libzcash::SaplingExtendedFullViewingKey &extfvk, const std::vector< unsigned char > &vchCryptedSecret, const CKeyMetadata &keyMeta)
bool ReadSaplingCommonOVK(uint256 &ovkRet)
bool WriteHDChain(const CHDChain &chain)
write the hdchain model (external/internal chain child index counter)
bool WriteSaplingCommonOVK(const uint256 &ovk)
Common output viewing key, used when shielding transparent funds.
bool WriteSaplingZKey(const libzcash::SaplingIncomingViewingKey &ivk, const libzcash::SaplingExtendedSpendingKey &key, const CKeyMetadata &keyMeta)
Write extended spending key to wallet database, where the key is the incoming viewing key.
std::string ToString() const
const std::array< unsigned char, ZC_MEMO_SIZE > & memo() const
IncrementalWitness< Depth, Hash > witness() const
SaplingFullViewingKey full_viewing_key() const
SaplingIncomingViewingKey in_viewing_key() const
Optional< SaplingPaymentAddress > address(diversifier_t d) const
Optional< SaplingNote > note(const SaplingIncomingViewingKey &ivk) const
static Optional< SaplingNotePlaintext > decrypt(const SaplingEncCiphertext &ciphertext, const uint256 &ivk, const uint256 &epk, const uint256 &cmu)
bool EncryptSecret(const CKeyingMaterial &vMasterKey, const CKeyingMaterial &vchPlaintext, const uint256 &nIV, std::vector< unsigned char > &vchCiphertext)
std::vector< unsigned char, secure_allocator< unsigned char > > CKeyingMaterial
bool IsLockedNote(const SaplingOutPoint &op) const
const CKeyingMaterial & GetEncryptionKey() const
const CWalletTx * GetWalletTx(const uint256 &hash) const
void SyncMetaDataN(std::pair< TxSpendMap< uint256 >::iterator, TxSpendMap< uint256 >::iterator > range)
libzcash::IncrementalMerkleTree< SAPLING_INCREMENTAL_MERKLE_TREE_DEPTH, libzcash::PedersenHash > SaplingMerkleTree
isminetype
IsMine() return codes.
@ ISMINE_SPENDABLE_SHIELDED
Indicates that we have the spending key of a shielded spend/output.
@ ISMINE_WATCH_ONLY_SHIELDED
Indicates that we don't have the spending key of a shielded spend/output.
uint8_t isminefilter
used for bitflags of isminetype
std::map< libzcash::SaplingPaymentAddress, libzcash::SaplingIncomingViewingKey > SaplingIncomingViewingKeyMap
boost::variant< InvalidEncoding, SaplingPaymentAddress > PaymentAddress
RecursiveMutex cs_main
Global state.
boost::optional< T > Optional
Substitute for C++17 std::optional.
void CopyPreviousWitnesses(NoteDataMap ¬eDataMap, int indexHeight, int64_t nWitnessCacheSize)
void UpdateWitnessHeights(NoteDataMap ¬eDataMap, int indexHeight, int64_t nWitnessCacheSize)
void DecrementNoteWitnesses(NoteDataMap ¬eDataMap, int indexHeight, int64_t nWitnessCacheSize)
void ResetNoteWitnesses(std::map< SaplingOutPoint, SaplingNoteData > ¬eDataMap, std::map< uint256, std::list< SaplingWitness >> &cachedWitnessMap, int indexHeight)
void AppendNoteCommitment(SaplingNoteData *nd, int indexHeight, int64_t nWitnessCacheSize, const uint256 ¬e_commitment)
void WitnessNoteIfMine(SaplingNoteData *nd, int indexHeight, int64_t nWitnessCacheSize, const Witness &witness)
std::map< SaplingOutPoint, SaplingNoteData > mapSaplingNoteData_t
static constexpr int ALWAYS_ACTIVE
Special value for nActivationHeight indicating that the upgrade is always active.
int nActivationHeight
Height of the first block for which the new consensus rules will be active.
Parameters that influence chain consensus.
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]
bool MoneyRange(const CAmount &nValue) const
bool NetworkUpgradeActive(int nHeight, Consensus::UpgradeIndex idx) const
Returns true if the given network upgrade is active as of the given block height.
std::vector< uint32_t > path
libzcash::SaplingFullViewingKey fvk
libzcash::SaplingExpandedSpendingKey expsk
libzcash::SaplingPaymentAddress DefaultAddress() const
SaplingExtendedSpendingKey Derive(uint32_t i) const
static SaplingExtendedSpendingKey Master(const HDSeed &seed)
SaplingExtendedFullViewingKey ToXFVK() const
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define AssertLockHeld(cs)
bool error(const char *fmt, const Args &... args)
int64_t GetAdjustedTime()
bool IsFinalTx(const CTransactionRef &tx, int nBlockHeight, int64_t nBlockTime)
Check if transaction is final and can be included in a block with the specified height and time.
const uint256 UINT256_ZERO
constant uint256 instances
std::string HexStr(const Span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
bool IsValidUTF8(const std::string &str)
Checks for valid 4-byte UTF-8 encoding in a string.
T FindFirstNonZero(T itbegin, T itend)
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos)
CBlockIndex * GetChainTip()
Return a reliable pointer (in mapBlockIndex) to the chain's tip index.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
uint256 ovkForShieldingFromTaddr(HDSeed &seed)
const uint32_t ZIP32_HARDENED_KEY_LIMIT