51 CCoinsMap::iterator it =
cacheCoins.find(outpoint);
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()) {
68 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
70 coin = it->second.coin;
77 assert(!coin.IsSpent());
78 if (coin.out.scriptPubKey.IsUnspendable())
return;
79 CCoinsMap::iterator it;
81 std::tie(it, inserted) =
cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
86 if (!possible_overwrite) {
87 if (!it->second.coin.IsSpent()) {
88 throw std::logic_error(
"Adding new coin that replaces non-pruned entry");
92 it->second.coin = std::move(coin);
106 std::string strAddress;
109 std::string ownerName;
110 std::string ownerAddress;
114 if (!assetsCache->
AddNewAsset(asset, strAddress, nHeight, blockHash))
115 error(
"%s : Failed at adding a new asset to our cache. asset: %s", __func__,
120 error(
"%s : Failed at adding a new asset to our cache. asset: %s", __func__,
125 std::string strAddress;
128 int reissueIndex = tx.
vout.size() - 1;
133 error(
"%s: Failed to get the original asset that is getting reissued. Asset Name : %s",
137 error(
"%s: Failed to reissue an asset. Asset Name : %s", __func__, reissue.
strName);
140 bool fFoundRestrictedAsset =
false;
144 fFoundRestrictedAsset =
true;
149 bool fUnitsChanged = reissue.
nUnits != -1;
150 bool fVerifierChanged =
false;
151 std::string strOldVerifier =
"";
154 if (fFoundRestrictedAsset) {
157 for (
auto index: tx.
vout) {
158 if (index.scriptPubKey.IsNullAssetVerifierTxDataScript()) {
160 error(
"%s: Failed to get asset null verifier data and add it to the coins CTxOut: %s", __func__,
165 fVerifierChanged =
true;
172 error(
"%s : Failed to get asset original verifier string that is getting reissued, Asset Name: %s", __func__, asset.
strName);
174 if (fVerifierChanged) {
175 strOldVerifier = oldVerifer.verifier_string;
180 error(
"%s : Failed at adding a restricted verifier to our cache: asset: %s, verifier : %s",
185 if (fIPFSChanged || fUnitsChanged || fVerifierChanged) {
186 undoAssetData->first = reissue.
strName;
190 for (
int n = 0; n < (int)tx.
vout.size(); n++) {
191 auto out = tx.
vout[n];
194 std::string strAddress;
200 if (!assetsCache->
AddNewAsset(asset, strAddress, nHeight, blockHash))
201 error(
"%s : Failed at adding a new asset to our cache. asset: %s", __func__,
207 std::string strAddress;
211 if (!assetsCache->
AddNewAsset(asset, strAddress, nHeight, blockHash))
212 error(
"%s : Failed at adding a new asset to our cache. asset: %s", __func__,
216 std::string strAddress;
220 if (!assetsCache->
AddNewAsset(asset, strAddress, nHeight, blockHash))
221 error(
"%s : Failed at adding a new qualifier asset to our cache. asset: %s", __func__,
225 std::string strAddress;
229 if (!assetsCache->
AddNewAsset(asset, strAddress, nHeight, blockHash))
230 error(
"%s : Failed at adding a new restricted asset to our cache. asset: %s", __func__,
236 for (
auto index: tx.
vout) {
237 if (index.scriptPubKey.IsNullAssetVerifierTxDataScript()) {
240 error(
"%s: Failed to get asset null data and add it to the coins CTxOut: %s", __func__,
245 error(
"%s : Failed at adding a restricted verifier to our cache: asset: %s, verifier : %s",
256 for (
size_t i = 0; i < tx.
vout.size(); ++i) {
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());
276 LogPrintf(
"%s : ERROR - Failed to add transfer asset CTxOut: %s\n", __func__,
277 tx.
vout[i].ToString());
356 CCoinsMap::iterator it =
FetchCoin(outpoint);
362 Coin tempCoin = it->second.coin;
366 *moveout = std::move(it->second.coin);
372 it->second.coin.Clear();
379 return error(
"%s : Failed to try and spend the asset. COutPoint : %s", __func__, outpoint.
ToString());
388 static const Coin coinEmpty;
391 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
395 return it->second.coin;
400 CCoinsMap::const_iterator it =
FetchCoin(outpoint);
401 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
405 CCoinsMap::const_iterator it =
cacheCoins.find(outpoint);
406 return (it !=
cacheCoins.end() && !it->second.coin.IsSpent());
420 for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
422 CCoinsMap::iterator itUs =
cacheCoins.find(it->first);
430 entry.
coin = std::move(it->second.coin);
445 throw std::logic_error(
"FRESH flag misapplied to cache entry for base transaction with spendable outputs");
457 itUs->second.coin = std::move(it->second.coin);
468 CCoinsMap::iterator itOld = it++;
469 mapCoins.erase(itOld);
484 CCoinsMap::iterator it =
cacheCoins.find(hash);
485 if (it !=
cacheCoins.end() && it->second.flags == 0) {
501 for (
unsigned int i = 0; i < tx.
vin.size(); i++)
510 for (
unsigned int i = 0; i < tx.
vin.size(); i++) {
527 if (!alternate.
IsSpent())
return alternate;
bool QualifierAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
const Coin & AccessByTxid(const CCoinsViewCache &view, const uint256 &txid)
Utility function to find any unspent output with a given txid.
void AddChannel(const std::string &name)
void AddCoin(const COutPoint &outpoint, Coin &&coin, bool potential_overwrite)
Add a coin.
CCoinsViewCache(CCoinsView *baseIn)
virtual bool GetCoin(const COutPoint &outpoint, Coin &coin) const
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr, CAssetsCache *assetsCache=nullptr)
Spend a coin.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or a pruned one if not found.
bool Flush()
Push the modifications applied to this cache to its base.
bool IsNewRestrictedAsset() const
Make sure to call VerifyNewAsset if this call returns true.
void SetBackend(CCoinsView &viewIn)
bool TrySpendCoin(const COutPoint &out, const CTxOut &coin)
Cache only validation functions.
bool AddOwnerAsset(const std::string &assetsName, const std::string address)
Changes Memory Only.
unsigned int GetMaxBlockWeight()
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
bool AssetFromScript(const CScript &scriptPubKey, CNewAsset &assetNew, std::string &strAddress)
bool TransferAssetFromScript(const CScript &scriptPubKey, CAssetTransfer &assetTransfer, std::string &strAddress)
Get specific asset type metadata from the given scripts.
size_t DynamicMemoryUsage() const
Calculate the size of the cache (in bytes)
CTxOut out
unspent transaction output
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
virtual bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock)
Do a bulk modification (multiple Coin changes + BestBlock change).
bool AssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
These types of asset tx, have specific metadata at certain indexes in the transaction.
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
isminetype IsMine(const CKeyStore &keystore, const CScript &scriptPubKey, SigVersion sigversion)
std::vector< CWalletRef > vpwallets
virtual bool HaveCoin(const COutPoint &outpoint) const
Just check whether a given outpoint is unspent.
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
bool AssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData, std::string &strAddress)
std::string ToString() const
bool HaveInputs(const CTransaction &tx) const
Check whether all prevouts of the transaction are present in the UTXO set represented by this view...
bool IsNewQualifierAsset() const
Make sure to call VerifyNewQualifierAsset if this call returns true.
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
CLRUCache< std::string, int > * pMessageSubscribedChannelsCache
Global variable that points to the subscribed channel LRU Cache (protected by cs_main) ...
bool IsNewAsset() const
RVN START.
const std::vector< CTxIn > vin
bool GetAssetData(const CScript &script, CAssetOutputEntry &data)
bool IsAddressSeen(const std::string &address)
int64_t CAmount
Amount in corbies (Can be negative)
void SetBestBlock(const uint256 &hashBlock)
bool OwnerFromTransaction(const CTransaction &tx, std::string &ownerName, std::string &strAddress)
unsigned int GetCacheSize() const
Calculate the size of the cache (in number of transaction outputs)
bool GlobalAssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData)
bool IsAssetNameValid(const std::string &name, AssetType &assetType, std::string &error)
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
bool AreAssetsDeployed()
RVN START.
Abstract view on the open txout dataset.
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...
bool MsgChannelAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
const uint256 & GetHash() const
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
const std::vector< CTxOut > vout
virtual std::vector< uint256 > GetHeadBlocks() const
Retrieve the range of blocks that may have been only partially written.
CCriticalSection cs_messaging
An output of a transaction.
An outpoint - a combination of a transaction hash and an index n into its vout.
CCoinsViewBacked(CCoinsView *viewIn)
bool AddGlobalRestricted(const std::string &assetName, const RestrictedType type)
Changes Memory Only, this only called when adding a block to the chain.
bool RestrictedAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
void AddAddressSeen(const std::string &address)
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
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.
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
uint256 hashBlock
Make mutable so that we can "fill the cache" even from Get-methods declared as "const".
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.
bool AddTransferAsset(const CAssetTransfer &transferAsset, const std::string &address, const COutPoint &out, const CTxOut &txOut)
bool AddNewAsset(const CNewAsset &asset, const std::string address, const int &nHeight, const uint256 &blockHash)
Cache only add asset functions.
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
std::string EncodeDestination(const CTxDestination &dest)
bool ReissueAssetFromTransaction(const CTransaction &tx, CReissueAsset &reissue, std::string &strAddress)
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
bool IsNewMsgChannelAsset() const
Make sure to call VerifyNewUniqueAsset if this call returns true.
bool IsNullAssetTxDataScript() const
Serialized script, used inside transaction inputs and outputs.
void Uncache(const COutPoint &outpoint)
Removes the UTXO with the given outpoint from the cache, if it is not modified.
std::string GetParentName(const std::string &name)
Get the root name of an asset.
virtual uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
std::string verifier_string
size_t DynamicMemoryUsage() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
CAmount GetValueIn(const CTransaction &tx) const
Amount of ravens coming in to a transaction Note that lightweight clients may not know anything besid...
bool error(const char *fmt, const Args &... args)
bool AssetNullVerifierDataFromScript(const CScript &scriptPubKey, CNullAssetTxVerifierString &verifierData)
CCoinsMap::iterator FetchCoin(const COutPoint &outpoint) const
bool AddRestrictedVerifier(const std::string &assetName, const std::string &verifier)
Changes Memory Only.
bool IsReissueAsset() const
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...
The basic transaction that is broadcasted on the network and contained in blocks. ...
CCoinsView backed by another CCoinsView.
bool AddReissueAsset(const CReissueAsset &reissue, const std::string address, const COutPoint &out)
Changes Memory Only.
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
CCoinsView that adds a memory cache for transactions to another CCoinsView.
const int8_t ASSET_UNDO_INCLUDES_VERIFIER_STRING
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's outputs to a cache.
CTxDestination destination
bool IsNewUniqueAsset() const
Make sure to call VerifyNewUniqueAsset if this call returns true.
bool IsNullGlobalRestrictionAssetTxDataScript() const
UniValue reissue(const JSONRPCRequest &request)
uint64_t GetRand(uint64_t nMax)
bool IsChannelSubscribed(const std::string &name)
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
bool IsScriptNewUniqueAsset(const CScript &scriptPubKey)
Check script and see if it matches the unquie issuance template.
Cursor for iterating over CoinsView state.