Raven Core  3.0.0
P2P Digital Currency
coins.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2016 The Bitcoin Core developers
2 // Copyright (c) 2017-2019 The Raven Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "coins.h"
7 
8 #include "consensus/consensus.h"
9 #include "memusage.h"
10 #include "random.h"
11 #include "util.h"
12 #include "validation.h"
13 #include "tinyformat.h"
14 #include "base58.h"
15 
16 #include <assert.h>
17 #include <assets/assets.h>
18 #include <wallet/wallet.h>
19 
20 bool CCoinsView::GetCoin(const COutPoint &outpoint, Coin &coin) const { return false; }
22 std::vector<uint256> CCoinsView::GetHeadBlocks() const { return std::vector<uint256>(); }
23 bool CCoinsView::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return false; }
24 CCoinsViewCursor *CCoinsView::Cursor() const { return nullptr; }
25 
26 bool CCoinsView::HaveCoin(const COutPoint &outpoint) const
27 {
28  Coin coin;
29  return GetCoin(outpoint, coin);
30 }
31 
33 bool CCoinsViewBacked::GetCoin(const COutPoint &outpoint, Coin &coin) const { return base->GetCoin(outpoint, coin); }
34 bool CCoinsViewBacked::HaveCoin(const COutPoint &outpoint) const { return base->HaveCoin(outpoint); }
36 std::vector<uint256> CCoinsViewBacked::GetHeadBlocks() const { return base->GetHeadBlocks(); }
37 void CCoinsViewBacked::SetBackend(CCoinsView &viewIn) { base = &viewIn; }
38 bool CCoinsViewBacked::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) { return base->BatchWrite(mapCoins, hashBlock); }
40 size_t CCoinsViewBacked::EstimateSize() const { return base->EstimateSize(); }
41 
42 SaltedOutpointHasher::SaltedOutpointHasher() : k0(GetRand(std::numeric_limits<uint64_t>::max())), k1(GetRand(std::numeric_limits<uint64_t>::max())) {}
43 
44 CCoinsViewCache::CCoinsViewCache(CCoinsView *baseIn) : CCoinsViewBacked(baseIn), cachedCoinsUsage(0) {}
45 
47  return memusage::DynamicUsage(cacheCoins) + cachedCoinsUsage;
48 }
49 
50 CCoinsMap::iterator CCoinsViewCache::FetchCoin(const COutPoint &outpoint) const {
51  CCoinsMap::iterator it = cacheCoins.find(outpoint);
52  if (it != cacheCoins.end())
53  return it;
54  Coin tmp;
55  if (!base->GetCoin(outpoint, tmp))
56  return cacheCoins.end();
57  CCoinsMap::iterator ret = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::forward_as_tuple(std::move(tmp))).first;
58  if (ret->second.coin.IsSpent()) {
59  // The parent only has an empty entry for this outpoint; we can consider our
60  // version as fresh.
61  ret->second.flags = CCoinsCacheEntry::FRESH;
62  }
63  cachedCoinsUsage += ret->second.coin.DynamicMemoryUsage();
64  return ret;
65 }
66 
67 bool CCoinsViewCache::GetCoin(const COutPoint &outpoint, Coin &coin) const {
68  CCoinsMap::const_iterator it = FetchCoin(outpoint);
69  if (it != cacheCoins.end()) {
70  coin = it->second.coin;
71  return !coin.IsSpent();
72  }
73  return false;
74 }
75 
76 void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
77  assert(!coin.IsSpent());
78  if (coin.out.scriptPubKey.IsUnspendable()) return;
79  CCoinsMap::iterator it;
80  bool inserted;
81  std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
82  bool fresh = false;
83  if (!inserted) {
84  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
85  }
86  if (!possible_overwrite) {
87  if (!it->second.coin.IsSpent()) {
88  throw std::logic_error("Adding new coin that replaces non-pruned entry");
89  }
90  fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY);
91  }
92  it->second.coin = std::move(coin);
93  it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0);
94  cachedCoinsUsage += it->second.coin.DynamicMemoryUsage();
95 }
96 
97 void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, uint256 blockHash, bool check, CAssetsCache* assetsCache, std::pair<std::string, CBlockAssetUndo>* undoAssetData) {
98  bool fCoinbase = tx.IsCoinBase();
99  const uint256& txid = tx.GetHash();
100 
102  if (AreAssetsDeployed()) {
103  if (assetsCache) {
104  if (tx.IsNewAsset()) { // This works are all new root assets, sub asset, and restricted assets
105  CNewAsset asset;
106  std::string strAddress;
107  AssetFromTransaction(tx, asset, strAddress);
108 
109  std::string ownerName;
110  std::string ownerAddress;
111  OwnerFromTransaction(tx, ownerName, ownerAddress);
112 
113  // Add the new asset to cache
114  if (!assetsCache->AddNewAsset(asset, strAddress, nHeight, blockHash))
115  error("%s : Failed at adding a new asset to our cache. asset: %s", __func__,
116  asset.strName);
117 
118  // Add the owner asset to cache
119  if (!assetsCache->AddOwnerAsset(ownerName, ownerAddress))
120  error("%s : Failed at adding a new asset to our cache. asset: %s", __func__,
121  asset.strName);
122 
123  } else if (tx.IsReissueAsset()) {
125  std::string strAddress;
126  ReissueAssetFromTransaction(tx, reissue, strAddress);
127 
128  int reissueIndex = tx.vout.size() - 1;
129 
130  // Get the asset before we change it
131  CNewAsset asset;
132  if (!assetsCache->GetAssetMetaDataIfExists(reissue.strName, asset))
133  error("%s: Failed to get the original asset that is getting reissued. Asset Name : %s",
134  __func__, reissue.strName);
135 
136  if (!assetsCache->AddReissueAsset(reissue, strAddress, COutPoint(txid, reissueIndex)))
137  error("%s: Failed to reissue an asset. Asset Name : %s", __func__, reissue.strName);
138 
139  // Check to see if we are reissuing a restricted asset
140  bool fFoundRestrictedAsset = false;
141  AssetType type;
142  IsAssetNameValid(asset.strName, type);
143  if (type == AssetType::RESTRICTED) {
144  fFoundRestrictedAsset = true;
145  }
146 
147  // Set the old IPFSHash for the blockundo
148  bool fIPFSChanged = !reissue.strIPFSHash.empty();
149  bool fUnitsChanged = reissue.nUnits != -1;
150  bool fVerifierChanged = false;
151  std::string strOldVerifier = "";
152 
153  // If we are reissuing a restricted asset, we need to check to see if the verifier string is being reissued
154  if (fFoundRestrictedAsset) {
156  // Search through all outputs until you find a restricted verifier change.
157  for (auto index: tx.vout) {
158  if (index.scriptPubKey.IsNullAssetVerifierTxDataScript()) {
159  if (!AssetNullVerifierDataFromScript(index.scriptPubKey, verifier)) {
160  error("%s: Failed to get asset null verifier data and add it to the coins CTxOut: %s", __func__,
161  index.ToString());
162  break;
163  }
164 
165  fVerifierChanged = true;
166  break;
167  }
168  }
169 
170  CNullAssetTxVerifierString oldVerifer{strOldVerifier};
171  if (fVerifierChanged && !assetsCache->GetAssetVerifierStringIfExists(asset.strName, oldVerifer))
172  error("%s : Failed to get asset original verifier string that is getting reissued, Asset Name: %s", __func__, asset.strName);
173 
174  if (fVerifierChanged) {
175  strOldVerifier = oldVerifer.verifier_string;
176  }
177 
178  // Add the verifier to the cache if there was one found
179  if (fVerifierChanged && !assetsCache->AddRestrictedVerifier(asset.strName, verifier.verifier_string))
180  error("%s : Failed at adding a restricted verifier to our cache: asset: %s, verifier : %s",
181  asset.strName, verifier.verifier_string);
182  }
183 
184  // If any of the following items were changed by reissuing, we need to database the old values so it can be undone correctly
185  if (fIPFSChanged || fUnitsChanged || fVerifierChanged) {
186  undoAssetData->first = reissue.strName; // Asset Name
187  undoAssetData->second = CBlockAssetUndo {fIPFSChanged, fUnitsChanged, asset.strIPFSHash, asset.units, ASSET_UNDO_INCLUDES_VERIFIER_STRING, fVerifierChanged, strOldVerifier}; // ipfschanged, unitchanged, Old Assets IPFSHash, old units
188  }
189  } else if (tx.IsNewUniqueAsset()) {
190  for (int n = 0; n < (int)tx.vout.size(); n++) {
191  auto out = tx.vout[n];
192 
193  CNewAsset asset;
194  std::string strAddress;
195 
196  if (IsScriptNewUniqueAsset(out.scriptPubKey)) {
197  AssetFromScript(out.scriptPubKey, asset, strAddress);
198 
199  // Add the new asset to cache
200  if (!assetsCache->AddNewAsset(asset, strAddress, nHeight, blockHash))
201  error("%s : Failed at adding a new asset to our cache. asset: %s", __func__,
202  asset.strName);
203  }
204  }
205  } else if (tx.IsNewMsgChannelAsset()) {
206  CNewAsset asset;
207  std::string strAddress;
208  MsgChannelAssetFromTransaction(tx, asset, strAddress);
209 
210  // Add the new asset to cache
211  if (!assetsCache->AddNewAsset(asset, strAddress, nHeight, blockHash))
212  error("%s : Failed at adding a new asset to our cache. asset: %s", __func__,
213  asset.strName);
214  } else if (tx.IsNewQualifierAsset()) {
215  CNewAsset asset;
216  std::string strAddress;
217  QualifierAssetFromTransaction(tx, asset, strAddress);
218 
219  // Add the new asset to cache
220  if (!assetsCache->AddNewAsset(asset, strAddress, nHeight, blockHash))
221  error("%s : Failed at adding a new qualifier asset to our cache. asset: %s", __func__,
222  asset.strName);
223  } else if (tx.IsNewRestrictedAsset()) {
224  CNewAsset asset;
225  std::string strAddress;
226  RestrictedAssetFromTransaction(tx, asset, strAddress);
227 
228  // Add the new asset to cache
229  if (!assetsCache->AddNewAsset(asset, strAddress, nHeight, blockHash))
230  error("%s : Failed at adding a new restricted asset to our cache. asset: %s", __func__,
231  asset.strName);
232 
233  // Find the restricted verifier string and cache it
235  // Search through all outputs until you find a restricted verifier change.
236  for (auto index: tx.vout) {
237  if (index.scriptPubKey.IsNullAssetVerifierTxDataScript()) {
239  if (!AssetNullVerifierDataFromScript(index.scriptPubKey, verifier))
240  error("%s: Failed to get asset null data and add it to the coins CTxOut: %s", __func__,
241  index.ToString());
242 
243  // Add the verifier to the cache
244  if (!assetsCache->AddRestrictedVerifier(asset.strName, verifier.verifier_string))
245  error("%s : Failed at adding a restricted verifier to our cache: asset: %s, verifier : %s",
246  asset.strName, verifier.verifier_string);
247 
248  break;
249  }
250  }
251  }
252  }
253  }
256  for (size_t i = 0; i < tx.vout.size(); ++i) {
257  bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase;
258  // Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly
259  // deal with the pre-BIP30 occurrences of duplicate coinbase transactions.
260  cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite);
261 
263  if (AreAssetsDeployed()) {
264  if (assetsCache) {
265  CAssetOutputEntry assetData;
266  if (GetAssetData(tx.vout[i].scriptPubKey, assetData)) {
267  if (assetData.type == TX_TRANSFER_ASSET && !tx.vout[i].scriptPubKey.IsUnspendable()) {
268  CAssetTransfer assetTransfer;
269  std::string address;
270  if (!TransferAssetFromScript(tx.vout[i].scriptPubKey, assetTransfer, address))
271  LogPrintf(
272  "%s : ERROR - Received a coin that was a Transfer Asset but failed to get the transfer object from the scriptPubKey. CTxOut: %s\n",
273  __func__, tx.vout[i].ToString());
274 
275  if (!assetsCache->AddTransferAsset(assetTransfer, address, COutPoint(txid, i), tx.vout[i]))
276  LogPrintf("%s : ERROR - Failed to add transfer asset CTxOut: %s\n", __func__,
277  tx.vout[i].ToString());
278 
282  if (vpwallets.size() && vpwallets[0]->IsMine(tx.vout[i]) == ISMINE_SPENDABLE) {
283  AssetType aType;
284  IsAssetNameValid(assetTransfer.strName, aType);
285 
286  if (aType == AssetType::ROOT || aType == AssetType::SUB) {
287  if (!IsChannelSubscribed(GetParentName(assetTransfer.strName) + OWNER_TAG)) {
288  if (!IsAddressSeen(address)) {
289  AddChannel(GetParentName(assetTransfer.strName) + OWNER_TAG);
290  AddAddressSeen(address);
291  }
292  }
293  } else if (aType == AssetType::OWNER || aType == AssetType::MSGCHANNEL) {
294  AddChannel(assetTransfer.strName);
295  AddAddressSeen(address);
296  }
297  }
298  }
299  } else if (assetData.type == TX_NEW_ASSET) {
303  if (vpwallets.size()) {
304  AssetType aType;
305  IsAssetNameValid(assetData.assetName, aType);
306  if (vpwallets[0]->IsMine(tx.vout[i]) == ISMINE_SPENDABLE) {
307  if (aType == AssetType::ROOT || aType == AssetType::SUB) {
308  AddChannel(assetData.assetName + OWNER_TAG);
310  } else if (aType == AssetType::OWNER || aType == AssetType::MSGCHANNEL) {
311  AddChannel(assetData.assetName);
313  }
314  } else {
315  if (aType == AssetType::MSGCHANNEL) {
317  AddChannel(assetData.assetName);
318  }
319  }
320  }
321  }
322  }
323  }
324  }
325 
326  CScript script = tx.vout[i].scriptPubKey;
327  if (script.IsNullAsset()) {
328  if (script.IsNullAssetTxDataScript()) {
329  CNullAssetTxData data;
330  std::string address;
331  AssetNullDataFromScript(script, data, address);
332 
333  AssetType type;
334  IsAssetNameValid(data.asset_name, type);
335 
336  if (type == AssetType::RESTRICTED) {
338  } else if (type == AssetType::QUALIFIER || type == AssetType::SUB_QUALIFIER) {
340  }
341  } else if (script.IsNullGlobalRestrictionAssetTxDataScript()) {
342  CNullAssetTxData data;
343  GlobalAssetNullDataFromScript(script, data);
344 
346  }
347  }
348  }
349  }
351  }
352 }
353 
354 bool CCoinsViewCache::SpendCoin(const COutPoint &outpoint, Coin* moveout, CAssetsCache* assetsCache) {
355 
356  CCoinsMap::iterator it = FetchCoin(outpoint);
357  if (it == cacheCoins.end())
358  return false;
359  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
360 
362  Coin tempCoin = it->second.coin;
365  if (moveout) {
366  *moveout = std::move(it->second.coin);
367  }
368  if (it->second.flags & CCoinsCacheEntry::FRESH) {
369  cacheCoins.erase(it);
370  } else {
371  it->second.flags |= CCoinsCacheEntry::DIRTY;
372  it->second.coin.Clear();
373  }
374 
376  if (AreAssetsDeployed()) {
377  if (assetsCache) {
378  if (!assetsCache->TrySpendCoin(outpoint, tempCoin.out)) {
379  return error("%s : Failed to try and spend the asset. COutPoint : %s", __func__, outpoint.ToString());
380  }
381  }
382  }
385  return true;
386 }
387 
388 static const Coin coinEmpty;
389 
390 const Coin& CCoinsViewCache::AccessCoin(const COutPoint &outpoint) const {
391  CCoinsMap::const_iterator it = FetchCoin(outpoint);
392  if (it == cacheCoins.end()) {
393  return coinEmpty;
394  } else {
395  return it->second.coin;
396  }
397 }
398 
399 bool CCoinsViewCache::HaveCoin(const COutPoint &outpoint) const {
400  CCoinsMap::const_iterator it = FetchCoin(outpoint);
401  return (it != cacheCoins.end() && !it->second.coin.IsSpent());
402 }
403 
404 bool CCoinsViewCache::HaveCoinInCache(const COutPoint &outpoint) const {
405  CCoinsMap::const_iterator it = cacheCoins.find(outpoint);
406  return (it != cacheCoins.end() && !it->second.coin.IsSpent());
407 }
408 
410  if (hashBlock.IsNull())
412  return hashBlock;
413 }
414 
415 void CCoinsViewCache::SetBestBlock(const uint256 &hashBlockIn) {
416  hashBlock = hashBlockIn;
417 }
418 
419 bool CCoinsViewCache::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlockIn) {
420  for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
421  if (it->second.flags & CCoinsCacheEntry::DIRTY) { // Ignore non-dirty entries (optimization).
422  CCoinsMap::iterator itUs = cacheCoins.find(it->first);
423  if (itUs == cacheCoins.end()) {
424  // The parent cache does not have an entry, while the child does
425  // We can ignore it if it's both FRESH and pruned in the child
426  if (!(it->second.flags & CCoinsCacheEntry::FRESH && it->second.coin.IsSpent())) {
427  // Otherwise we will need to create it in the parent
428  // and move the data up and mark it as dirty
429  CCoinsCacheEntry& entry = cacheCoins[it->first];
430  entry.coin = std::move(it->second.coin);
433  // We can mark it FRESH in the parent if it was FRESH in the child
434  // Otherwise it might have just been flushed from the parent's cache
435  // and already exist in the grandparent
436  if (it->second.flags & CCoinsCacheEntry::FRESH)
438  }
439  } else {
440  // Assert that the child cache entry was not marked FRESH if the
441  // parent cache entry has unspent outputs. If this ever happens,
442  // it means the FRESH flag was misapplied and there is a logic
443  // error in the calling code.
444  if ((it->second.flags & CCoinsCacheEntry::FRESH) && !itUs->second.coin.IsSpent())
445  throw std::logic_error("FRESH flag misapplied to cache entry for base transaction with spendable outputs");
446 
447  // Found the entry in the parent cache
448  if ((itUs->second.flags & CCoinsCacheEntry::FRESH) && it->second.coin.IsSpent()) {
449  // The grandparent does not have an entry, and the child is
450  // modified and being pruned. This means we can just delete
451  // it from the parent.
452  cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
453  cacheCoins.erase(itUs);
454  } else {
455  // A normal modification.
456  cachedCoinsUsage -= itUs->second.coin.DynamicMemoryUsage();
457  itUs->second.coin = std::move(it->second.coin);
458  cachedCoinsUsage += itUs->second.coin.DynamicMemoryUsage();
459  itUs->second.flags |= CCoinsCacheEntry::DIRTY;
460  // NOTE: It is possible the child has a FRESH flag here in
461  // the event the entry we found in the parent is pruned. But
462  // we must not copy that FRESH flag to the parent as that
463  // pruned state likely still needs to be communicated to the
464  // grandparent.
465  }
466  }
467  }
468  CCoinsMap::iterator itOld = it++;
469  mapCoins.erase(itOld);
470  }
471  hashBlock = hashBlockIn;
472  return true;
473 }
474 
476  bool fOk = base->BatchWrite(cacheCoins, hashBlock);
477  cacheCoins.clear();
478  cachedCoinsUsage = 0;
479  return fOk;
480 }
481 
483 {
484  CCoinsMap::iterator it = cacheCoins.find(hash);
485  if (it != cacheCoins.end() && it->second.flags == 0) {
486  cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage();
487  cacheCoins.erase(it);
488  }
489 }
490 
491 unsigned int CCoinsViewCache::GetCacheSize() const {
492  return cacheCoins.size();
493 }
494 
496 {
497  if (tx.IsCoinBase())
498  return 0;
499 
500  CAmount nResult = 0;
501  for (unsigned int i = 0; i < tx.vin.size(); i++)
502  nResult += AccessCoin(tx.vin[i].prevout).out.nValue;
503 
504  return nResult;
505 }
506 
508 {
509  if (!tx.IsCoinBase()) {
510  for (unsigned int i = 0; i < tx.vin.size(); i++) {
511  if (!HaveCoin(tx.vin[i].prevout)) {
512  return false;
513  }
514  }
515  }
516  return true;
517 }
518 
519 static const size_t MIN_TRANSACTION_OUTPUT_WEIGHT = WITNESS_SCALE_FACTOR * ::GetSerializeSize(CTxOut(), SER_NETWORK, PROTOCOL_VERSION);
520 //static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;
521 
522 const Coin& AccessByTxid(const CCoinsViewCache& view, const uint256& txid)
523 {
524  COutPoint iter(txid, 0);
525  while (iter.n < GetMaxBlockWeight() / MIN_TRANSACTION_OUTPUT_WEIGHT) {
526  const Coin& alternate = view.AccessCoin(iter);
527  if (!alternate.IsSpent()) return alternate;
528  ++iter.n;
529  }
530  return coinEmpty;
531 }
bool QualifierAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:549
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:35
CAmount nValue
Definition: transaction.h:140
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
Definition: coins.cpp:522
bool IsSpent() const
Definition: coins.h:78
void AddChannel(const std::string &name)
Definition: messages.cpp:130
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
Add a coin.
Definition: coins.cpp:76
CCoinsViewCache(CCoinsView *baseIn)
Definition: coins.cpp:44
Definition: coins.h:110
std::string strName
Definition: assettypes.h:239
int8_t units
Definition: assettypes.h:102
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:20
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr, CAssetsCache *assetsCache=nullptr)
Spend a coin.
Definition: coins.cpp:354
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or a pruned one if not found.
Definition: coins.cpp:390
bool Flush()
Push the modifications applied to this cache to its base.
Definition: coins.cpp:475
bool IsNewRestrictedAsset() const
Make sure to call VerifyNewAsset if this call returns true.
Definition: assets.cpp:1253
void SetBackend(CCoinsView &viewIn)
Definition: coins.cpp:37
bool TrySpendCoin(const COutPoint &out, const CTxOut &coin)
Cache only validation functions.
Definition: assets.cpp:1634
A UTXO entry.
Definition: coins.h:32
bool AddOwnerAsset(const std::string &assetsName, const std::string address)
Changes Memory Only.
Definition: assets.cpp:1979
unsigned int GetMaxBlockWeight()
Definition: consensus.cpp:8
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
Definition: serialize.h:967
bool AssetFromScript(const CScript &scriptPubKey, CNewAsset &assetNew, std::string &strAddress)
Definition: assets.cpp:664
txnouttype type
Definition: wallet.h:193
bool TransferAssetFromScript(const CScript &scriptPubKey, CAssetTransfer &assetTransfer, std::string &strAddress)
Get specific asset type metadata from the given scripts.
Definition: assets.cpp:638
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
Definition: coins.cpp:46
CTxOut out
unspent transaction output
Definition: coins.h:36
bool IsNullAsset() const
Definition: script.cpp:326
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:36
int8_t nUnits
Definition: assettypes.h:241
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:23
bool AssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
These types of asset tx, have specific metadata at certain indexes in the transaction.
Definition: assets.cpp:525
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
Definition: coins.cpp:404
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
Definition: coins.cpp:24
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
Definition: ismine.cpp:32
std::vector< CWalletRef > vpwallets
Definition: wallet.cpp:44
std::string strName
Definition: assettypes.h:100
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
Definition: coins.cpp:26
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
Definition: coins.cpp:39
bool AssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData, std::string &strAddress)
Definition: assets.cpp:815
std::string ToString() const
Definition: transaction.cpp:14
std::string strName
Definition: assettypes.h:190
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
Definition: coins.cpp:507
bool IsNewQualifierAsset() const
Make sure to call VerifyNewQualifierAsset if this call returns true.
Definition: assets.cpp:1164
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:419
std::string asset_name
Definition: assettypes.h:278
std::string strIPFSHash
Definition: assettypes.h:105
CLRUCache< std::string, int > * pMessageSubscribedChannelsCache
Global variable that points to the subscribed channel LRU Cache (protected by cs_main) ...
Definition: validation.cpp:230
bool IsNull() const
Definition: uint256.h:33
bool IsCoinBase() const
Definition: transaction.h:360
bool IsNewAsset() const
RVN START.
Definition: assets.cpp:881
const std::vector< CTxIn > vin
Definition: transaction.h:287
Definition: coins.h:116
RVN START.
Definition: wallet.h:191
bool GetAssetData(const CScript &script, CAssetOutputEntry &data)
Definition: assets.cpp:3440
bool IsAddressSeen(const std::string &address)
Definition: messages.cpp:267
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
void SetBestBlock(const uint256 &hashBlock)
Definition: coins.cpp:415
bool OwnerFromTransaction(const CTransaction &tx, std::string &ownerName, std::string &strAddress)
Definition: assets.cpp:626
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
Definition: coins.cpp:491
bool GlobalAssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData)
Definition: assets.cpp:840
bool IsAssetNameValid(const std::string &name, AssetType &assetType, std::string &error)
Definition: assets.cpp:207
CCoinsMap cacheCoins
Definition: coins.h:216
#define LogPrintf(...)
Definition: util.h:149
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: coins.cpp:38
bool AreAssetsDeployed()
RVN START.
Abstract view on the open txout dataset.
Definition: coins.h:152
bool GetAssetMetaDataIfExists(const std::string &name, CNewAsset &asset)
Returns true if an asset with the name exists, and it was able to get the asset metadata from databas...
Definition: assets.cpp:3340
bool MsgChannelAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:537
#define LOCK(cs)
Definition: sync.h:176
CCoinsView * base
Definition: coins.h:192
const uint256 & GetHash() const
Definition: transaction.h:320
#define OWNER_TAG
Definition: assets.h:32
std::string assetName
Definition: wallet.h:194
uint32_t n
Definition: transaction.h:26
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
Definition: coins.h:129
const std::vector< CTxOut > vout
Definition: transaction.h:288
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
Definition: coins.cpp:22
CCriticalSection cs_messaging
Definition: messages.cpp:26
An output of a transaction.
Definition: transaction.h:137
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
CCoinsViewBacked(CCoinsView *viewIn)
Definition: coins.cpp:32
bool AddGlobalRestricted(const std::string &assetName, const RestrictedType type)
Changes Memory Only, this only called when adding a block to the chain.
Definition: assets.cpp:2138
bool RestrictedAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:560
void AddAddressSeen(const std::string &address)
Definition: messages.cpp:293
AssetType
Definition: assettypes.h:21
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:409
bool AddQualifierAddress(const std::string &assetName, const std::string &address, const QualifierType type)
Changes Memory Only, this only called when adding a block to the chain.
Definition: assets.cpp:2031
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:34
256-bit opaque blob.
Definition: uint256.h:123
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
Definition: coins.h:215
bool AddRestrictedAddress(const std::string &assetName, const std::string &address, const RestrictedType type)
Changes Memory Only, this only called when adding a block to the chain.
Definition: assets.cpp:2096
bool AddTransferAsset(const CAssetTransfer &transferAsset, const std::string &address, const COutPoint &out, const CTxOut &txOut)
Definition: assets.cpp:1601
bool AddNewAsset(const CNewAsset &asset, const std::string address, const int &nHeight, const uint256 &blockHash)
Cache only add asset functions.
Definition: assets.cpp:1836
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:67
Definition: coins.h:117
std::string EncodeDestination(const CTxDestination &dest)
Definition: base58.cpp:326
bool ReissueAssetFromTransaction(const CTransaction &tx, CReissueAsset &reissue, std::string &strAddress)
Definition: assets.cpp:572
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
Definition: coins.h:184
bool IsNewMsgChannelAsset() const
Make sure to call VerifyNewUniqueAsset if this call returns true.
Definition: assets.cpp:1077
bool IsNullAssetTxDataScript() const
Definition: script.cpp:331
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
bool fMessaging
Definition: validation.cpp:82
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
Definition: coins.cpp:482
std::string GetParentName(const std::string &name)
Get the root name of an asset.
Definition: assets.cpp:366
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:21
size_t DynamicMemoryUsage() const
Definition: coins.h:86
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: coins.cpp:33
RVN START.
Definition: standard.h:69
CAmount GetValueIn(const CTransaction &tx) const
Amount of ravens coming in to a transaction Note that lightweight clients may not know anything besid...
Definition: coins.cpp:495
bool error(const char *fmt, const Args &... args)
Definition: util.h:168
size_t cachedCoinsUsage
Definition: coins.h:219
bool AssetNullVerifierDataFromScript(const CScript &scriptPubKey, CNullAssetTxVerifierString &verifierData)
Definition: assets.cpp:860
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
Definition: coins.cpp:50
bool AddRestrictedVerifier(const std::string &assetName, const std::string &verifier)
Changes Memory Only.
Definition: assets.cpp:2180
bool IsReissueAsset() const
Definition: assets.cpp:1384
bool GetAssetVerifierStringIfExists(const std::string &name, CNullAssetTxVerifierString &verifier, bool fSkipTempCache=false)
Returns true if the Asset Verifier String was found for an asset_name, if fSkipTempCache is true...
Definition: assets.cpp:4445
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
CCoinsView backed by another CCoinsView.
Definition: coins.h:189
bool AddReissueAsset(const CReissueAsset &reissue, const std::string address, const COutPoint &out)
Changes Memory Only.
Definition: assets.cpp:1857
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: coins.cpp:40
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:208
const int8_t ASSET_UNDO_INCLUDES_VERIFIER_STRING
Definition: assetdb.h:15
void AddCoins(CCoinsViewCache &cache, const CTransaction &tx, int nHeight, uint256 blockHash, bool check, CAssetsCache *assetsCache, std::pair< std::string, CBlockAssetUndo > *undoAssetData)
Utility function to add all of a transaction&#39;s outputs to a cache.
Definition: coins.cpp:97
CTxDestination destination
Definition: wallet.h:195
bool IsNewUniqueAsset() const
Make sure to call VerifyNewUniqueAsset if this call returns true.
Definition: assets.cpp:900
std::string strIPFSHash
Definition: assettypes.h:243
unsigned char flags
Definition: coins.h:113
bool IsNullGlobalRestrictionAssetTxDataScript() const
Definition: script.cpp:338
UniValue reissue(const JSONRPCRequest &request)
Definition: assets.cpp:1465
uint64_t GetRand(uint64_t nMax)
Definition: random.cpp:353
Coin coin
Definition: coins.h:112
bool IsChannelSubscribed(const std::string &name)
Definition: messages.cpp:67
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: coins.cpp:399
bool IsScriptNewUniqueAsset(const CScript &scriptPubKey)
Check script and see if it matches the unquie issuance template.
Definition: assets.cpp:3117
Cursor for iterating over CoinsView state.
Definition: coins.h:132