Raven Core  3.0.0
P2P Digital Currency
assets.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2019 The Raven Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 
6 #ifndef RAVENCOIN_ASSET_PROTOCOL_H
7 #define RAVENCOIN_ASSET_PROTOCOL_H
8 
9 #include "amount.h"
10 #include "tinyformat.h"
11 #include "assettypes.h"
12 
13 #include <string>
14 #include <set>
15 #include <map>
16 #include <unordered_map>
17 #include <list>
18 
19 #define RVN_R 114
20 #define RVN_V 118
21 #define RVN_N 110
22 #define RVN_Q 113
23 #define RVN_T 116
24 #define RVN_O 111
25 
26 #define DEFAULT_UNITS 0
27 #define DEFAULT_REISSUABLE 1
28 #define DEFAULT_HAS_IPFS 0
29 #define DEFAULT_IPFS ""
30 #define MIN_ASSET_LENGTH 3
31 #define MAX_ASSET_LENGTH 32
32 #define OWNER_TAG "!"
33 #define OWNER_LENGTH 1
34 #define OWNER_UNITS 0
35 #define OWNER_ASSET_AMOUNT 1 * COIN
36 #define UNIQUE_ASSET_AMOUNT 1 * COIN
37 #define UNIQUE_ASSET_UNITS 0
38 #define UNIQUE_ASSETS_REISSUABLE 0
39 
40 #define RESTRICTED_CHAR '$'
41 #define QUALIFIER_CHAR '#'
42 
43 #define QUALIFIER_ASSET_MIN_AMOUNT 1 * COIN
44 #define QUALIFIER_ASSET_MAX_AMOUNT 10 * COIN
45 #define QUALIFIER_ASSET_UNITS 0
46 
47 #define ASSET_TRANSFER_STRING "transfer_asset"
48 #define ASSET_NEW_STRING "new_asset"
49 #define ASSET_REISSUE_STRING "reissue_asset"
50 
51 class CScript;
52 class CDataStream;
53 class CTransaction;
54 class CTxOut;
55 class Coin;
56 class CWallet;
57 class CReserveKey;
58 class CWalletTx;
59 struct CAssetOutputEntry;
60 class CCoinControl;
61 struct CBlockAssetUndo;
62 class COutput;
63 
64 // 2500 * 82 Bytes == 205 KB (kilobytes) of memory
65 #define MAX_CACHE_ASSETS_SIZE 2500
66 
67 // Create map that store that state of current reissued transaction that the mempool as accepted.
68 // If an asset name is in this map, any other reissue transactions wont be accepted into the mempool
69 extern std::map<uint256, std::string> mapReissuedTx;
70 extern std::map<std::string, uint256> mapReissuedAssets;
71 
72 class CAssets {
73 public:
74  std::map<std::pair<std::string, std::string>, CAmount> mapAssetsAddressAmount; // pair < Asset Name , Address > -> Quantity of tokens in the address
75 
76  // Dirty, Gets wiped once flushed to database
77  std::map<std::string, CNewAsset> mapReissuedAssetData; // Asset Name -> New Asset Data
78 
79  CAssets(const CAssets& assets) {
80  this->mapAssetsAddressAmount = assets.mapAssetsAddressAmount;
81  this->mapReissuedAssetData = assets.mapReissuedAssetData;
82  }
83 
84  CAssets& operator=(const CAssets& other) {
85  mapAssetsAddressAmount = other.mapAssetsAddressAmount;
86  mapReissuedAssetData = other.mapReissuedAssetData;
87  return *this;
88  }
89 
90  CAssets() {
91  SetNull();
92  }
93 
94  void SetNull() {
95  mapAssetsAddressAmount.clear();
96  mapReissuedAssetData.clear();
97  }
98 };
99 
100 class CAssetsCache : public CAssets
101 {
102 private:
103  bool AddBackSpentAsset(const Coin& coin, const std::string& assetName, const std::string& address, const CAmount& nAmount, const COutPoint& out);
104  void AddToAssetBalance(const std::string& strName, const std::string& address, const CAmount& nAmount);
105  bool UndoTransfer(const CAssetTransfer& transfer, const std::string& address, const COutPoint& outToRemove);
106 public :
108  std::vector<CAssetCacheUndoAssetAmount> vUndoAssetAmount;
109  std::vector<CAssetCacheSpendAsset> vSpentAssets;
110 
112  std::set<CAssetCacheNewAsset> setNewAssetsToRemove;
113  std::set<CAssetCacheNewAsset> setNewAssetsToAdd;
114 
116  std::set<CAssetCacheReissueAsset> setNewReissueToRemove;
117  std::set<CAssetCacheReissueAsset> setNewReissueToAdd;
118 
120  std::set<CAssetCacheNewOwner> setNewOwnerAssetsToAdd;
121  std::set<CAssetCacheNewOwner> setNewOwnerAssetsToRemove;
122 
124  std::set<CAssetCacheNewTransfer> setNewTransferAssetsToAdd;
125  std::set<CAssetCacheNewTransfer> setNewTransferAssetsToRemove;
126 
128  std::set<CAssetCacheQualifierAddress> setNewQualifierAddressToAdd;
129  std::set<CAssetCacheQualifierAddress> setNewQualifierAddressToRemove;
130 
132  std::set<CAssetCacheRestrictedAddress> setNewRestrictedAddressToAdd;
133  std::set<CAssetCacheRestrictedAddress> setNewRestrictedAddressToRemove;
134 
136  std::set<CAssetCacheRestrictedGlobal> setNewRestrictedGlobalToAdd;
137  std::set<CAssetCacheRestrictedGlobal> setNewRestrictedGlobalToRemove;
138 
140  std::set<CAssetCacheRestrictedVerifiers> setNewRestrictedVerifierToAdd;
141  std::set<CAssetCacheRestrictedVerifiers> setNewRestrictedVerifierToRemove;
142 
144  std::map<CAssetCacheRootQualifierChecker, std::set<std::string> > mapRootQualifierAddressesAdd;
145  std::map<CAssetCacheRootQualifierChecker, std::set<std::string> > mapRootQualifierAddressesRemove;
146 
148  {
149  SetNull();
150  ClearDirtyCache();
151  }
152 
153  CAssetsCache(const CAssetsCache& cache) : CAssets(cache)
154  {
156  this->vSpentAssets = cache.vSpentAssets;
157  this->vUndoAssetAmount = cache.vUndoAssetAmount;
158 
160  this->setNewTransferAssetsToAdd = cache.setNewTransferAssetsToAdd;
161  this->setNewTransferAssetsToRemove = cache.setNewTransferAssetsToRemove;
162 
164  this->setNewAssetsToRemove = cache.setNewAssetsToRemove;
165  this->setNewAssetsToAdd = cache.setNewAssetsToAdd;
166 
168  this->setNewReissueToRemove = cache.setNewReissueToRemove;
169  this->setNewReissueToAdd = cache.setNewReissueToAdd;
170 
172  this->setNewOwnerAssetsToAdd = cache.setNewOwnerAssetsToAdd;
173  this->setNewOwnerAssetsToRemove = cache.setNewOwnerAssetsToRemove;
174 
176  this->setNewQualifierAddressToAdd = cache.setNewQualifierAddressToAdd;
177  this->setNewQualifierAddressToRemove = cache.setNewQualifierAddressToRemove;
178 
180  this->setNewRestrictedAddressToAdd = cache.setNewRestrictedAddressToAdd;
181  this->setNewRestrictedAddressToRemove = cache.setNewRestrictedAddressToRemove;
182 
184  this->setNewRestrictedGlobalToAdd = cache.setNewRestrictedGlobalToAdd;
185  this->setNewRestrictedGlobalToRemove = cache.setNewRestrictedGlobalToRemove;
186 
188  this->setNewRestrictedVerifierToAdd = cache.setNewRestrictedVerifierToAdd;
189  this->setNewRestrictedVerifierToRemove = cache.setNewRestrictedVerifierToRemove;
190 
192  this->mapRootQualifierAddressesAdd = cache.mapRootQualifierAddressesAdd;
193  this->mapRootQualifierAddressesRemove = cache.mapRootQualifierAddressesRemove;
194  }
195 
197  {
200 
202  this->vSpentAssets = cache.vSpentAssets;
203  this->vUndoAssetAmount = cache.vUndoAssetAmount;
204 
206  this->setNewTransferAssetsToAdd = cache.setNewTransferAssetsToAdd;
207  this->setNewTransferAssetsToRemove = cache.setNewTransferAssetsToRemove;
208 
210  this->setNewAssetsToRemove = cache.setNewAssetsToRemove;
211  this->setNewAssetsToAdd = cache.setNewAssetsToAdd;
212 
214  this->setNewReissueToRemove = cache.setNewReissueToRemove;
215  this->setNewReissueToAdd = cache.setNewReissueToAdd;
216 
218  this->setNewOwnerAssetsToAdd = cache.setNewOwnerAssetsToAdd;
219  this->setNewOwnerAssetsToRemove = cache.setNewOwnerAssetsToRemove;
220 
222  this->setNewQualifierAddressToAdd = cache.setNewQualifierAddressToAdd;
223  this->setNewQualifierAddressToRemove = cache.setNewQualifierAddressToRemove;
224 
226  this->setNewRestrictedAddressToAdd = cache.setNewRestrictedAddressToAdd;
227  this->setNewRestrictedAddressToRemove = cache.setNewRestrictedAddressToRemove;
228 
230  this->setNewRestrictedGlobalToAdd = cache.setNewRestrictedGlobalToAdd;
231  this->setNewRestrictedGlobalToRemove = cache.setNewRestrictedGlobalToRemove;
232 
234  this->setNewRestrictedVerifierToAdd = cache.setNewRestrictedVerifierToAdd;
235  this->setNewRestrictedVerifierToRemove = cache.setNewRestrictedVerifierToRemove;
236 
238  this->mapRootQualifierAddressesAdd = cache.mapRootQualifierAddressesAdd;
239  this->mapRootQualifierAddressesRemove = cache.mapRootQualifierAddressesRemove;
240 
241  return *this;
242  }
243 
245  bool RemoveNewAsset(const CNewAsset& asset, const std::string address);
246  bool RemoveTransfer(const CAssetTransfer& transfer, const std::string& address, const COutPoint& out);
247  bool RemoveOwnerAsset(const std::string& assetsName, const std::string address);
248  bool RemoveReissueAsset(const CReissueAsset& reissue, const std::string address, const COutPoint& out, const std::vector<std::pair<std::string, CBlockAssetUndo> >& vUndoIPFS);
249  bool UndoAssetCoin(const Coin& coin, const COutPoint& out);
250  bool RemoveQualifierAddress(const std::string& assetName, const std::string& address, const QualifierType type);
251  bool RemoveRestrictedAddress(const std::string& assetName, const std::string& address, const RestrictedType type);
252  bool RemoveGlobalRestricted(const std::string& assetName, const RestrictedType type);
253  bool RemoveRestrictedVerifier(const std::string& assetName, const std::string& verifier, const bool fUndoingReissue = false);
254 
256  bool AddNewAsset(const CNewAsset& asset, const std::string address, const int& nHeight, const uint256& blockHash);
257  bool AddTransferAsset(const CAssetTransfer& transferAsset, const std::string& address, const COutPoint& out, const CTxOut& txOut);
258  bool AddOwnerAsset(const std::string& assetsName, const std::string address);
259  bool AddReissueAsset(const CReissueAsset& reissue, const std::string address, const COutPoint& out);
260  bool AddQualifierAddress(const std::string& assetName, const std::string& address, const QualifierType type);
261  bool AddRestrictedAddress(const std::string& assetName, const std::string& address, const RestrictedType type);
262  bool AddGlobalRestricted(const std::string& assetName, const RestrictedType type);
263  bool AddRestrictedVerifier(const std::string& assetName, const std::string& verifier);
264 
266  bool TrySpendCoin(const COutPoint& out, const CTxOut& coin);
267 
269  bool ContainsAsset(const CNewAsset& asset);
270  bool ContainsAsset(const std::string& assetName);
271 
273  bool CheckIfAssetExists(const std::string& name, bool fForceDuplicateCheck = true);
274 
276  bool GetAssetMetaDataIfExists(const std::string &name, CNewAsset &asset);
277  bool GetAssetMetaDataIfExists(const std::string &name, CNewAsset &asset, int& nHeight, uint256& blockHash);
278 
280  bool GetAssetVerifierStringIfExists(const std::string &name, CNullAssetTxVerifierString& verifier, bool fSkipTempCache = false);
281 
283  bool CheckForAddressQualifier(const std::string &qualifier_name, const std::string& address, bool fSkipTempCache = false);
284 
286  bool CheckForAddressRestriction(const std::string &restricted_name, const std::string& address, bool fSkipTempCache = false);
287 
289  bool CheckForGlobalRestriction(const std::string &restricted_name, bool fSkipTempCache = false);
290 
292  size_t DynamicMemoryUsage() const;
293 
295  size_t GetCacheSize() const;
296  size_t GetCacheSizeV2() const;
297 
299  bool Flush();
300 
302  bool DumpCacheToDatabase();
303 
306 
307  vUndoAssetAmount.clear();
308  vSpentAssets.clear();
309 
310  setNewAssetsToRemove.clear();
311  setNewAssetsToAdd.clear();
312 
313  setNewReissueToAdd.clear();
314  setNewReissueToRemove.clear();
315 
316  setNewTransferAssetsToAdd.clear();
317  setNewTransferAssetsToRemove.clear();
318 
319  setNewOwnerAssetsToAdd.clear();
320  setNewOwnerAssetsToRemove.clear();
321 
322  mapReissuedAssetData.clear();
323  mapAssetsAddressAmount.clear();
324 
325  setNewQualifierAddressToAdd.clear();
326  setNewQualifierAddressToRemove.clear();
327 
328  setNewRestrictedAddressToAdd.clear();
329  setNewRestrictedAddressToRemove.clear();
330 
331  setNewRestrictedGlobalToAdd.clear();
332  setNewRestrictedGlobalToRemove.clear();
333 
334  setNewRestrictedVerifierToAdd.clear();
335  setNewRestrictedVerifierToRemove.clear();
336 
337  mapRootQualifierAddressesAdd.clear();
338  mapRootQualifierAddressesRemove.clear();
339  }
340 
341  std::string CacheToString() const {
342 
343  return strprintf(
344  "vNewAssetsToRemove size : %d, vNewAssetsToAdd size : %d, vNewTransfer size : %d, vSpentAssets : %d\n"
345  "setNewQualifierAddressToAdd size : %d, setNewQualifierAddressToRemove size : %d, setNewRestrictedAddressToAdd size : %d\n"
346  "setNewRestrictedAddressToRemove size : %d, setNewRestrictedGlobalToAdd size : %d, setNewRestrictedGlobalToRemove : %d",
347  setNewAssetsToRemove.size(), setNewAssetsToAdd.size(), setNewTransferAssetsToAdd.size(),
348  vSpentAssets.size(), setNewQualifierAddressToAdd.size(), setNewQualifierAddressToRemove.size(), setNewRestrictedAddressToAdd.size(),
349  setNewRestrictedAddressToRemove.size(), setNewRestrictedGlobalToAdd.size(), setNewRestrictedGlobalToRemove.size());
350  }
351 };
352 
363 CAmount GetBurnAmount(const AssetType type);
364 CAmount GetBurnAmount(const int nType);
365 
367 std::string GetBurnAddress(const AssetType type);
368 std::string GetBurnAddress(const int nType);
369 
370 void GetTxOutAssetTypes(const std::vector<CTxOut>& vout, int& issues, int& reissues, int& transfers, int& owners);
371 
373 bool IsAssetNameValid(const std::string& name);
374 bool IsAssetNameValid(const std::string& name, AssetType& assetType);
375 bool IsAssetNameValid(const std::string& name, AssetType& assetType, std::string& error);
376 
378 bool IsUniqueTagValid(const std::string& tag);
379 
381 bool IsAssetNameAnOwner(const std::string& name);
382 
384 bool IsAssetNameAnRestricted(const std::string& name);
385 
387 bool IsAssetNameAQualifier(const std::string& name);
388 
390 bool IsAssetNameASubQualifier(const std::string& name);
391 
393 bool IsAssetNameAnMsgChannel(const std::string& name);
394 
396 std::string GetParentName(const std::string& name); // Gets the parent name of a subasset TEST/TESTSUB would return TEST
397 
399 std::string GetUniqueAssetName(const std::string& parent, const std::string& tag);
400 
402 bool IsTypeCheckNameValid(const AssetType type, const std::string& name, std::string& error);
403 
406 bool AssetFromTransaction(const CTransaction& tx, CNewAsset& asset, std::string& strAddress);
407 bool OwnerFromTransaction(const CTransaction& tx, std::string& ownerName, std::string& strAddress);
408 bool ReissueAssetFromTransaction(const CTransaction& tx, CReissueAsset& reissue, std::string& strAddress);
409 bool UniqueAssetFromTransaction(const CTransaction& tx, CNewAsset& asset, std::string& strAddress);
410 bool MsgChannelAssetFromTransaction(const CTransaction& tx, CNewAsset& asset, std::string& strAddress);
411 bool QualifierAssetFromTransaction(const CTransaction& tx, CNewAsset& asset, std::string& strAddress);
412 bool RestrictedAssetFromTransaction(const CTransaction& tx, CNewAsset& asset, std::string& strAddress);
413 
415 bool TransferAssetFromScript(const CScript& scriptPubKey, CAssetTransfer& assetTransfer, std::string& strAddress);
416 bool AssetFromScript(const CScript& scriptPubKey, CNewAsset& asset, std::string& strAddress);
417 bool OwnerAssetFromScript(const CScript& scriptPubKey, std::string& assetName, std::string& strAddress);
418 bool ReissueAssetFromScript(const CScript& scriptPubKey, CReissueAsset& reissue, std::string& strAddress);
419 bool MsgChannelAssetFromScript(const CScript& scriptPubKey, CNewAsset& asset, std::string& strAddress);
420 bool QualifierAssetFromScript(const CScript& scriptPubKey, CNewAsset& asset, std::string& strAddress);
421 bool RestrictedAssetFromScript(const CScript& scriptPubKey, CNewAsset& asset, std::string& strAddress);
422 bool AssetNullDataFromScript(const CScript& scriptPubKey, CNullAssetTxData& assetData, std::string& strAddress);
423 bool AssetNullVerifierDataFromScript(const CScript& scriptPubKey, CNullAssetTxVerifierString& verifierData);
424 bool GlobalAssetNullDataFromScript(const CScript& scriptPubKey, CNullAssetTxData& assetData);
425 
427 bool CheckIssueBurnTx(const CTxOut& txOut, const AssetType& type, const int numberIssued);
428 bool CheckIssueBurnTx(const CTxOut& txOut, const AssetType& type);
429 
430 // TODO, maybe remove this function and input that check into the CheckIssueBurnTx.
432 bool CheckReissueBurnTx(const CTxOut& txOut);
433 
435 bool CheckIssueDataTx(const CTxOut& txOut); // OP_RAVEN_ASSET RVNQ (That is a Q as in Que not an O)
436 bool CheckOwnerDataTx(const CTxOut& txOut);// OP_RAVEN_ASSET RVNO
437 bool CheckReissueDataTx(const CTxOut& txOut);// OP_RAVEN_ASSET RVNR
438 bool CheckTransferOwnerTx(const CTxOut& txOut);// OP_RAVEN_ASSET RVNT
439 
441 bool CheckEncoded(const std::string& hash, std::string& strError);
442 
444 bool CheckAmountWithUnits(const CAmount& nAmount, const int8_t nUnits);
445 
447 bool IsScriptNewAsset(const CScript& scriptPubKey);
448 bool IsScriptNewAsset(const CScript& scriptPubKey, int& nStartingIndex);
449 
451 bool IsScriptNewUniqueAsset(const CScript& scriptPubKey);
452 bool IsScriptNewUniqueAsset(const CScript &scriptPubKey, int &nStartingIndex);
453 
455 bool IsScriptOwnerAsset(const CScript& scriptPubKey);
456 bool IsScriptOwnerAsset(const CScript& scriptPubKey, int& nStartingIndex);
457 
459 bool IsScriptReissueAsset(const CScript& scriptPubKey);
460 bool IsScriptReissueAsset(const CScript& scriptPubKey, int& nStartingIndex);
461 
463 bool IsScriptTransferAsset(const CScript& scriptPubKey);
464 bool IsScriptTransferAsset(const CScript& scriptPubKey, int& nStartingIndex);
465 
467 bool IsScriptNewMsgChannelAsset(const CScript& scriptPubKey);
468 bool IsScriptNewMsgChannelAsset(const CScript& scriptPubKey, int& nStartingIndex);
469 
471 bool IsScriptNewQualifierAsset(const CScript& scriptPubKey);
472 bool IsScriptNewQualifierAsset(const CScript &scriptPubKey, int &nStartingIndex);
473 
475 bool IsScriptNewRestrictedAsset(const CScript& scriptPubKey);
476 bool IsScriptNewRestrictedAsset(const CScript &scriptPubKey, int &nStartingIndex);
477 
478 bool IsNewOwnerTxValid(const CTransaction& tx, const std::string& assetName, const std::string& address, std::string& errorMsg);
479 
480 void GetAllAdministrativeAssets(CWallet *pwallet, std::vector<std::string> &names, int nMinConf = 1);
481 void GetAllMyAssets(CWallet* pwallet, std::vector<std::string>& names, int nMinConf = 1, bool fIncludeAdministrator = false, bool fOnlyAdministrator = false);
482 
483 bool GetAssetInfoFromCoin(const Coin& coin, std::string& strName, CAmount& nAmount);
484 bool GetAssetInfoFromScript(const CScript& scriptPubKey, std::string& strName, CAmount& nAmount);
485 
486 bool GetAssetData(const CScript& script, CAssetOutputEntry& data);
487 
488 bool GetBestAssetAddressAmount(CAssetsCache& cache, const std::string& assetName, const std::string& address);
489 
490 bool GetAllMyAssetBalances(std::map<std::string, std::vector<COutput> >& outputs, std::map<std::string, CAmount>& amounts, const int confirmations = 0, const std::string& prefix = "");
491 
493 bool VerifyWalletHasAsset(const std::string& asset_name, std::pair<int, std::string>& pairError);
494 
496 std::string DecodeAssetData(std::string encoded);
497 std::string EncodeAssetData(std::string decoded);
498 std::string DecodeIPFS(std::string encoded);
499 std::string EncodeIPFS(std::string decoded);
500 
502 bool CreateAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const CNewAsset& asset, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired, std::string* verifier_string = nullptr);
503 bool CreateAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const std::vector<CNewAsset> assets, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired, std::string* verifier_string = nullptr);
504 
506 bool CreateReissueAssetTransaction(CWallet* pwallet, CCoinControl& coinControl, const CReissueAsset& asset, const std::string& address, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired, std::string* verifier_string = nullptr);
507 
509 bool CreateTransferAssetTransaction(CWallet* pwallet, const CCoinControl& coinControl, const std::vector< std::pair<CAssetTransfer, std::string> >vTransfers, const std::string& changeAddress, std::pair<int, std::string>& error, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRequired, std::vector<std::pair<CNullAssetTxData, std::string> >* nullAssetTxData = nullptr, std::vector<CNullAssetTxData>* nullGlobalRestrictionData = nullptr);
510 
512 bool SendAssetTransaction(CWallet* pwallet, CWalletTx& transaction, CReserveKey& reserveKey, std::pair<int, std::string>& error, std::string& txid);
513 
515 bool ParseAssetScript(CScript scriptPubKey, uint160 &hashBytes, std::string &assetName, CAmount &assetAmount);
516 
518 void ExtractVerifierStringQualifiers(const std::string& verifier, std::set<std::string>& qualifiers, bool fWithTag = true);
519 bool CheckVerifierString(const std::string& verifier, std::set<std::string>& setFoundQualifiers, std::string& strError, bool fWithTags = false);
520 std::string GetStrippedVerifierString(const std::string& verifier);
521 
523 bool VerifyNullAssetDataFlag(const int& flag, std::string& strError);
524 bool VerifyQualifierChange(CAssetsCache& cache, const CNullAssetTxData& data, const std::string& address, std::string& strError);
525 bool VerifyRestrictedAddressChange(CAssetsCache& cache, const CNullAssetTxData& data, const std::string& address, std::string& strError);
526 bool VerifyGlobalRestrictedChange(CAssetsCache& cache, const CNullAssetTxData& data, std::string& strError);
527 
529 bool CheckVerifierAssetTxOut(const CTxOut& txout, std::string& strError);
530 bool CheckNewAsset(const CNewAsset& asset, std::string& strError);
531 bool CheckReissueAsset(const CReissueAsset& asset, std::string& strError);
532 
534 bool ContextualCheckNullAssetTxOut(const CTxOut& txout, CAssetsCache* assetCache, std::string& strError);
535 bool ContextualCheckGlobalAssetTxOut(const CTxOut& txout, CAssetsCache* assetCache, std::string& strError);
536 bool ContextualCheckVerifierAssetTxOut(const CTxOut& txout, CAssetsCache* assetCache, std::string& strError);
537 bool ContextualCheckVerifierString(CAssetsCache* cache, const std::string& verifier, const std::string& check_address, std::string& strError, bool fWithTags = false);
538 bool ContextualCheckNewAsset(CAssetsCache* assetCache, const CNewAsset& asset, std::string& strError, bool fCheckMempool = false);
539 bool ContextualCheckTransferAsset(CAssetsCache* assetCache, const CAssetTransfer& transfer, const std::string& address, std::string& strError);
540 bool ContextualCheckReissueAsset(CAssetsCache* assetCache, const CReissueAsset& reissue_asset, std::string& strError, const CTransaction& tx);
541 bool ContextualCheckReissueAsset(CAssetsCache* assetCache, const CReissueAsset& reissue_asset, std::string& strError);
542 bool ContextualCheckUniqueAssetTx(CAssetsCache* assetCache, std::string& strError, const CTransaction& tx);
543 bool ContextualCheckUniqueAsset(CAssetsCache* assetCache, const CNewAsset& unique_asset, std::string& strError);
544 
545 #endif //RAVENCOIN_ASSET_PROTOCOL_H
std::set< CAssetCacheRestrictedVerifiers > setNewRestrictedVerifierToAdd
Restricted Assets Verifier Caches.
Definition: assets.h:140
bool ContextualCheckVerifierAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
Definition: assets.cpp:4960
bool CheckReissueDataTx(const CTxOut &txOut)
Definition: assets.cpp:3077
bool CheckVerifierAssetTxOut(const CTxOut &txout, std::string &strError)
Definition: assets.cpp:4888
CAmount GetReissueAssetBurnAmount()
Definition: assets.cpp:3534
bool ReissueAssetFromScript(const CScript &scriptPubKey, CReissueAsset &reissue, std::string &strAddress)
Definition: assets.cpp:789
std::string CacheToString() const
Definition: assets.h:341
std::set< CAssetCacheRestrictedAddress > setNewRestrictedAddressToAdd
Restricted Address Asset Caches.
Definition: assets.h:132
bool ContextualCheckReissueAsset(CAssetsCache *assetCache, const CReissueAsset &reissue_asset, std::string &strError, const CTransaction &tx)
Definition: assets.cpp:5273
void GetAllMyAssets(CWallet *pwallet, std::vector< std::string > &names, int nMinConf=1, bool fIncludeAdministrator=false, bool fOnlyAdministrator=false)
Definition: assets.cpp:3507
bool QualifierAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:549
RestrictedType
Definition: assettypes.h:43
bool IsAssetNameAnRestricted(const std::string &name)
Check if an asset is a restricted asset.
Definition: assets.cpp:301
A UTXO entry.
Definition: coins.h:32
Definition: assets.h:72
#define strprintf
Definition: tinyformat.h:1054
std::string GetStrippedVerifierString(const std::string &verifier)
Definition: assets.cpp:4728
bool GetAssetInfoFromScript(const CScript &scriptPubKey, std::string &strName, CAmount &nAmount)
Definition: assets.cpp:3423
std::set< CAssetCacheQualifierAddress > setNewQualifierAddressToRemove
Definition: assets.h:129
bool CheckTransferOwnerTx(const CTxOut &txOut)
Definition: assets.cpp:3093
bool AssetNullVerifierDataFromScript(const CScript &scriptPubKey, CNullAssetTxVerifierString &verifierData)
Definition: assets.cpp:860
const char * prefix
Definition: rest.cpp:568
bool OwnerAssetFromScript(const CScript &scriptPubKey, std::string &assetName, std::string &strAddress)
Definition: assets.cpp:764
std::set< CAssetCacheNewOwner > setNewOwnerAssetsToRemove
Definition: assets.h:121
bool IsScriptTransferAsset(const CScript &scriptPubKey)
Check script and see if it matches the transfer asset template.
Definition: assets.cpp:3202
bool GlobalAssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData)
Definition: assets.cpp:840
bool CreateAssetTransaction(CWallet *pwallet, CCoinControl &coinControl, const CNewAsset &asset, const std::string &address, std::pair< int, std::string > &error, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRequired, std::string *verifier_string=nullptr)
Creates new asset issuance transaction.
Definition: assets.cpp:3745
bool VerifyGlobalRestrictedChange(CAssetsCache &cache, const CNullAssetTxData &data, std::string &strError)
Definition: assets.cpp:4858
std::string DecodeIPFS(std::string encoded)
Definition: assets.cpp:3729
bool CreateReissueAssetTransaction(CWallet *pwallet, CCoinControl &coinControl, const CReissueAsset &asset, const std::string &address, std::pair< int, std::string > &error, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRequired, std::string *verifier_string=nullptr)
Create a reissue asset transaction.
Definition: assets.cpp:3917
CAmount GetIssueAssetBurnAmount()
Functions to be used to get access to the current burn amount required for specific asset issuance tr...
Definition: assets.cpp:3529
bool ContextualCheckNewAsset(CAssetsCache *assetCache, const CNewAsset &asset, std::string &strError, bool fCheckMempool=false)
Definition: assets.cpp:5187
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
bool CheckOwnerDataTx(const CTxOut &txOut)
Definition: assets.cpp:3085
std::set< CAssetCacheNewTransfer > setNewTransferAssetsToRemove
Definition: assets.h:125
bool MsgChannelAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:537
bool IsAssetNameASubQualifier(const std::string &name)
Check if an asset is a sub qualifier.
Definition: assets.cpp:196
bool QualifierAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:714
bool ContextualCheckUniqueAsset(CAssetsCache *assetCache, const CNewAsset &unique_asset, std::string &strError)
Definition: assets.cpp:5437
bool AssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData, std::string &strAddress)
Definition: assets.cpp:815
Coin Control Features.
Definition: coincontrol.h:17
std::set< CAssetCacheNewOwner > setNewOwnerAssetsToAdd
Ownership Assets Caches.
Definition: assets.h:120
RVN START.
Definition: wallet.h:191
bool MsgChannelAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:689
void SetNull()
Definition: assets.h:94
bool GetAssetData(const CScript &script, CAssetOutputEntry &data)
Definition: assets.cpp:3440
bool IsAssetNameAnMsgChannel(const std::string &name)
Check if an asset is a message channel.
Definition: assets.cpp:311
bool IsScriptNewQualifierAsset(const CScript &scriptPubKey)
Check script and see if it matches the qualifier issuance template.
Definition: assets.cpp:3219
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
std::vector< CAssetCacheUndoAssetAmount > vUndoAssetAmount
These are memory only containers that show dirty entries that will be databased when flushed...
Definition: assets.h:108
std::set< CAssetCacheNewAsset > setNewAssetsToRemove
New Assets Caches.
Definition: assets.h:112
std::vector< CAssetCacheSpendAsset > vSpentAssets
Definition: assets.h:109
CAssetsCache()
Definition: assets.h:147
CAmount GetIssueUniqueAssetBurnAmount()
Definition: assets.cpp:3544
CAssetsCache & operator=(const CAssetsCache &cache)
Definition: assets.h:196
bool VerifyNullAssetDataFlag(const int &flag, std::string &strError)
Helper methods that validate changes to null asset data transaction databases.
Definition: assets.cpp:4796
bool VerifyQualifierChange(CAssetsCache &cache, const CNullAssetTxData &data, const std::string &address, std::string &strError)
Definition: assets.cpp:4807
bool IsScriptNewAsset(const CScript &scriptPubKey)
Check script and see if it matches the asset issuance template.
Definition: assets.cpp:3101
bool GetAllMyAssetBalances(std::map< std::string, std::vector< COutput > > &outputs, std::map< std::string, CAmount > &amounts, const int confirmations=0, const std::string &prefix="")
sets balances with the total quantity of each owned asset
Definition: assets.cpp:3673
bool ContextualCheckTransferAsset(CAssetsCache *assetCache, const CAssetTransfer &transfer, const std::string &address, std::string &strError)
Definition: assets.cpp:5036
std::string EncodeAssetData(std::string decoded)
Definition: assets.cpp:3716
bool VerifyRestrictedAddressChange(CAssetsCache &cache, const CNullAssetTxData &data, const std::string &address, std::string &strError)
Definition: assets.cpp:4831
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
std::set< CAssetCacheRestrictedAddress > setNewRestrictedAddressToRemove
Definition: assets.h:133
CAssets()
Definition: assets.h:90
bool CheckReissueBurnTx(const CTxOut &txOut)
Check to make sure the script contains the reissue burn data.
Definition: assets.cpp:3046
std::string DecodeAssetData(std::string encoded)
Decode and Encode IPFS hashes, or OIP hashes.
Definition: assets.cpp:3699
bool SendAssetTransaction(CWallet *pwallet, CWalletTx &transaction, CReserveKey &reserveKey, std::pair< int, std::string > &error, std::string &txid)
Send any type of asset transaction to the network.
Definition: assets.cpp:4243
bool IsScriptNewRestrictedAsset(const CScript &scriptPubKey)
Check script and see if it matches the restricted issueance template.
Definition: assets.cpp:3244
bool IsAssetNameValid(const std::string &name)
Check is an asset name is valid, and being able to return the asset type if needed.
Definition: assets.cpp:283
UniValue transfer(const JSONRPCRequest &request)
Definition: assets.cpp:1101
CAssets(const CAssets &assets)
Definition: assets.h:79
bool ContextualCheckUniqueAssetTx(CAssetsCache *assetCache, std::string &strError, const CTransaction &tx)
Definition: assets.cpp:5416
void ClearDirtyCache()
Clear all dirty cache sets, vetors, and maps.
Definition: assets.h:305
std::map< std::string, uint256 > mapReissuedAssets
Definition: assets.cpp:41
CAmount GetIssueMsgChannelAssetBurnAmount()
Definition: assets.cpp:3549
bool UniqueAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:584
bool ContextualCheckGlobalAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
Definition: assets.cpp:4943
bool RestrictedAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:739
bool CheckVerifierString(const std::string &verifier, std::set< std::string > &setFoundQualifiers, std::string &strError, bool fWithTags=false)
Definition: assets.cpp:4739
void ExtractVerifierStringQualifiers(const std::string &verifier, std::set< std::string > &qualifiers, bool fWithTag=true)
Helper method for extracting #TAGS from a verifier string.
Definition: assets.cpp:4709
CAmount GetAddNullQualifierTagBurnAmount()
Definition: assets.cpp:3569
bool IsScriptReissueAsset(const CScript &scriptPubKey)
Check script and see if it matches the reissue template.
Definition: assets.cpp:3185
bool VerifyWalletHasAsset(const std::string &asset_name, std::pair< int, std::string > &pairError)
Verifies that this wallet owns the give asset.
Definition: assets.cpp:4255
bool RestrictedAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:560
std::set< CAssetCacheQualifierAddress > setNewQualifierAddressToAdd
Qualfier Address Asset Caches.
Definition: assets.h:128
CAssets & operator=(const CAssets &other)
Definition: assets.h:84
An output of a transaction.
Definition: transaction.h:137
bool TransferAssetFromScript(const CScript &scriptPubKey, CAssetTransfer &assetTransfer, std::string &strAddress)
Get specific asset type metadata from the given scripts.
Definition: assets.cpp:638
bool CheckIssueBurnTx(const CTxOut &txOut, const AssetType &type, const int numberIssued)
Check to make sure the script contains the burn transaction.
Definition: assets.cpp:3005
bool ReissueAssetFromTransaction(const CTransaction &tx, CReissueAsset &reissue, std::string &strAddress)
Definition: assets.cpp:572
bool OwnerFromTransaction(const CTransaction &tx, std::string &ownerName, std::string &strAddress)
Definition: assets.cpp:626
std::string GetParentName(const std::string &name)
Get the root name of an asset.
Definition: assets.cpp:366
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
std::map< uint256, std::string > mapReissuedTx
Definition: assets.cpp:40
bool GetBestAssetAddressAmount(CAssetsCache &cache, const std::string &assetName, const std::string &address)
This will get the amount that an address for a certain asset contains from the database if they cache...
Definition: assets.cpp:3645
bool ContextualCheckNullAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
Definition: assets.cpp:4915
void GetTxOutAssetTypes(const std::vector< CTxOut > &vout, int &issues, int &reissues, int &transfers, int &owners)
Definition: assets.cpp:4299
bool CheckEncoded(const std::string &hash, std::string &strError)
Check the Encoded hash and make sure it is either an IPFS hash or a OIP hash.
Definition: assets.cpp:4282
std::map< std::pair< std::string, std::string >, CAmount > mapAssetsAddressAmount
Definition: assets.h:74
std::string GetBurnAddress(const AssetType type)
Functions to be used to get access to the burn address for a given asset type issuance.
Definition: assets.cpp:3614
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:285
std::map< CAssetCacheRootQualifierChecker, std::set< std::string > > mapRootQualifierAddressesAdd
Root Qualifier Address Map.
Definition: assets.h:144
AssetType
Definition: assettypes.h:21
std::set< CAssetCacheReissueAsset > setNewReissueToRemove
New Reissue Caches.
Definition: assets.h:116
bool IsTypeCheckNameValid(const AssetType type, const std::string &name, std::string &error)
Given a type, and an asset name, return if that name is valid based on the type.
Definition: assets.cpp:317
std::set< CAssetCacheNewAsset > setNewAssetsToAdd
Definition: assets.h:113
bool IsUniqueTagValid(const std::string &tag)
Check if an unique tagname is valid.
Definition: assets.cpp:126
CAmount GetIssueQualifierAssetBurnAmount()
Definition: assets.cpp:3554
256-bit opaque blob.
Definition: uint256.h:123
bool IsScriptNewUniqueAsset(const CScript &scriptPubKey)
Check script and see if it matches the unquie issuance template.
Definition: assets.cpp:3117
bool IsScriptNewMsgChannelAsset(const CScript &scriptPubKey)
Check script and see if it matches the message channel issuance template.
Definition: assets.cpp:3142
std::string EncodeIPFS(std::string decoded)
Definition: assets.cpp:3737
std::set< CAssetCacheReissueAsset > setNewReissueToAdd
Definition: assets.h:117
bool IsAssetNameAQualifier(const std::string &name)
Check if an asset is a qualifier asset or sub qualifier.
Definition: assets.cpp:306
CAmount GetIssueSubAssetBurnAmount()
Definition: assets.cpp:3539
A key allocated from the key pool.
Definition: wallet.h:1193
CAssetsCache(const CAssetsCache &cache)
Definition: assets.h:153
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:396
bool IsAssetNameAnOwner(const std::string &name)
Check if an asset is an owner.
Definition: assets.cpp:296
std::set< CAssetCacheRestrictedGlobal > setNewRestrictedGlobalToRemove
Definition: assets.h:137
std::set< CAssetCacheRestrictedGlobal > setNewRestrictedGlobalToAdd
Restricted Global Asset Caches.
Definition: assets.h:136
bool CreateTransferAssetTransaction(CWallet *pwallet, const CCoinControl &coinControl, const std::vector< std::pair< CAssetTransfer, std::string > >vTransfers, const std::string &changeAddress, std::pair< int, std::string > &error, CWalletTx &wtxNew, CReserveKey &reservekey, CAmount &nFeeRequired, std::vector< std::pair< CNullAssetTxData, std::string > > *nullAssetTxData=nullptr, std::vector< CNullAssetTxData > *nullGlobalRestrictionData=nullptr)
Create a transfer asset transaction.
Definition: assets.cpp:4094
bool IsScriptOwnerAsset(const CScript &scriptPubKey)
Check script and see if it matches the owner issuance template.
Definition: assets.cpp:3167
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:673
160-bit opaque blob.
Definition: uint256.h:112
CAmount GetIssueSubQualifierAssetBurnAmount()
Definition: assets.cpp:3559
bool error(const char *fmt, const Args &... args)
Definition: util.h:168
std::string GetUniqueAssetName(const std::string &parent, const std::string &tag)
Build a unique asset buy giving the root name, and the tag name (ROOT, TAG) => ROOT::TAG.
Definition: assets.cpp:399
CAmount GetIssueRestrictedAssetBurnAmount()
Definition: assets.cpp:3564
bool CheckNewAsset(const CNewAsset &asset, std::string &strError)
Definition: assets.cpp:5105
bool CheckAmountWithUnits(const CAmount &nAmount, const int8_t nUnits)
Checks the amount and units, and makes sure that the amount uses the correct decimals.
Definition: assets.cpp:4277
std::map< CAssetCacheRootQualifierChecker, std::set< std::string > > mapRootQualifierAddressesRemove
Definition: assets.h:145
QualifierType
Definition: assettypes.h:37
bool CheckReissueAsset(const CReissueAsset &asset, std::string &strError)
Definition: assets.cpp:5232
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:270
bool ContextualCheckVerifierString(CAssetsCache *cache, const std::string &verifier, const std::string &check_address, std::string &strError, bool fWithTags=false)
Definition: assets.cpp:4979
std::set< CAssetCacheNewTransfer > setNewTransferAssetsToAdd
Transfer Assets Caches.
Definition: assets.h:124
bool AssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
Definition: assets.cpp:664
bool CheckIssueDataTx(const CTxOut &txOut)
issue asset scripts to make sure script meets the standards
Definition: assets.cpp:3068
std::set< CAssetCacheRestrictedVerifiers > setNewRestrictedVerifierToRemove
Definition: assets.h:141
bool IsNewOwnerTxValid(const CTransaction &tx, const std::string &assetName, const std::string &address, std::string &errorMsg)
Definition: assets.cpp:596
std::map< std::string, CNewAsset > mapReissuedAssetData
Definition: assets.h:77
CAmount GetBurnAmount(const AssetType type)
Definition: assets.cpp:3579
UniValue reissue(const JSONRPCRequest &request)
Definition: assets.cpp:1465
void GetAllAdministrativeAssets(CWallet *pwallet, std::vector< std::string > &names, int nMinConf=1)
Definition: assets.cpp:3499
bool ParseAssetScript(CScript scriptPubKey, uint160 &hashBytes, std::string &assetName, CAmount &assetAmount)
Helper method for extracting address bytes, asset name and amount from an asset script.
Definition: assets.cpp:4317
bool GetAssetInfoFromCoin(const Coin &coin, std::string &strName, CAmount &nAmount)
Definition: assets.cpp:3435