5 #ifndef RAVENCOIN_NEWASSET_H 6 #define RAVENCOIN_NEWASSET_H 11 #include <unordered_map> 58 template <
typename Stream,
typename Operation>
62 if (ser_action.ForRead())
65 if (!s.empty() and s.size() >= 33) {
68 std::basic_string<char> hash;
71 std::ostringstream os;
77 os << hash.substr(0, 32);
78 strIPFSHash = os.str();
84 if (strIPFSHash.length() == 34) {
88 }
else if (strIPFSHash.length() == 32) {
112 CNewAsset(
const std::string& strName,
const CAmount& nAmount,
const int& units,
const int& nReissuable,
const int& nHasIPFS,
const std::string& strIPFSHash);
123 nReissuable = int8_t(0);
124 nHasIPFS = int8_t(0);
129 std::string ToString();
131 void ConstructTransaction(
CScript& script)
const;
132 void ConstructOwnerTransaction(
CScript& script)
const;
136 template <
typename Stream,
typename Operation>
178 template <
typename Stream,
typename Operation>
210 template <
typename Stream,
typename Operation>
217 if (ser_action.ForRead()) {
218 if (!s.empty() && s.size() >=
sizeof(int64_t)) {
222 if (nExpireTime != 0) {
230 CAssetTransfer(
const std::string& strAssetName,
const CAmount& nAmount,
const std::string& message =
"",
const int64_t& nExpireTime = 0);
231 bool IsValid(std::string& strError)
const;
232 void ConstructTransaction(
CScript& script)
const;
233 bool ContextualCheckAgainstVerifyString(
CAssetsCache *assetCache,
const std::string& address, std::string& strError)
const;
261 template <
typename Stream,
typename Operation>
271 CReissueAsset(
const std::string& strAssetName,
const CAmount& nAmount,
const int& nUnits,
const int& nReissuable,
const std::string& strIPFSHash);
272 void ConstructTransaction(
CScript& script)
const;
294 template <
typename Stream,
typename Operation>
302 bool IsValid(std::string& strError,
CAssetsCache& assetCache,
bool fForceCheckPrimaryAssetExists)
const;
303 void ConstructTransaction(
CScript& script)
const;
304 void ConstructGlobalRestrictionTransaction(
CScript &script)
const;
324 template <
typename Stream,
typename Operation>
331 void ConstructTransaction(
CScript& script)
const;
345 this->address = address;
346 this->blockHash = blockHash;
347 this->blockHeight = blockHeight;
368 this->address = address;
370 this->blockHash = blockHash;
371 this->blockHeight = blockHeight;
376 return out < rhs.
out;
390 this->address = address;
396 return out < rhs.
out;
407 this->assetName = assetName;
408 this->address = address;
426 this->assetName = assetName;
427 this->address = address;
428 this->nAmount = nAmount;
440 this->assetName = assetName;
441 this->address = address;
442 this->nAmount = nAmount;
452 this->assetName = assetName;
453 this->address = address;
469 this->rootAssetName = assetName;
470 this->address = address;
488 this->assetName = assetName;
489 this->address = address;
508 this->assetName = assetName;
526 this->assetName = assetName;
527 this->verifier = verifier;
528 fUndoingRessiue =
false;
538 template<
typename cache_key_t,
typename cache_value_t>
553 void Put(
const cache_key_t& key,
const cache_value_t& value)
555 auto it = cacheItemsMap.find(key);
556 cacheItemsList.push_front(key_value_pair_t(key, value));
557 if (it != cacheItemsMap.end())
559 cacheItemsList.erase(it->second);
560 cacheItemsMap.erase(it);
562 cacheItemsMap[key] = cacheItemsList.begin();
564 if (cacheItemsMap.size() > maxSize)
566 auto last = cacheItemsList.end();
568 cacheItemsMap.erase(last->first);
569 cacheItemsList.pop_back();
575 auto it = cacheItemsMap.find(key);
576 if (it != cacheItemsMap.end())
578 cacheItemsList.erase(it->second);
579 cacheItemsMap.erase(it);
583 const cache_value_t&
Get(
const cache_key_t& key)
585 auto it = cacheItemsMap.find(key);
586 if (it == cacheItemsMap.end())
588 throw std::range_error(
"There is no such key in cache");
592 cacheItemsList.splice(cacheItemsList.begin(), cacheItemsList, it->second);
593 return it->second->second;
597 bool Exists(
const cache_key_t& key)
const 599 return cacheItemsMap.find(key) != cacheItemsMap.end();
604 return cacheItemsMap.size();
610 cacheItemsMap.clear();
611 cacheItemsList.clear();
631 const std::unordered_map<cache_key_t, list_iterator_t>&
GetItemsMap()
633 return cacheItemsMap;
638 return cacheItemsList;
655 #endif //RAVENCOIN_NEWASSET_H bool operator<(const CAssetCacheNewAsset &rhs) const
bool operator<(const CAssetCacheNewOwner &rhs) const
bool ReadWriteAssetHash(Stream &s, Operation ser_action, std::string &strIPFSHash)
void Erase(const cache_key_t &key)
CAssetCacheUndoAssetAmount(const std::string &assetName, const std::string &address, const CAmount &nAmount)
std::list< key_value_pair_t >::iterator list_iterator_t
const std::unordered_map< cache_key_t, list_iterator_t > & GetItemsMap()
CAssetCacheQualifierAddress(const std::string &assetName, const std::string &address, const QualifierType &type)
void Put(const cache_key_t &key, const cache_value_t &value)
std::unordered_map< cache_key_t, list_iterator_t > cacheItemsMap
THESE ARE ONLY TO BE USED WHEN ADDING THINGS TO THE CACHE DURING CONNECT AND DISCONNECT BLOCK...
CAssetCacheNewOwner(const std::string &assetName, const std::string &address)
void SerializationOp(Stream &s, Operation ser_action)
CAssetCacheRootQualifierChecker(const std::string &assetName, const std::string &address)
CAssetCacheReissueAsset(const CReissueAsset &reissue, const std::string &address, const COutPoint &out, const int &blockHeight, const uint256 &blockHash)
CAssetCacheRestrictedGlobal(const std::string &assetName, const RestrictedType &type)
bool Exists(const cache_key_t &key) const
void SerializationOp(Stream &s, Operation ser_action)
bool operator<(const CAssetCacheQualifierAddress &rhs) const
void SetSize(const size_t size)
void Serialize(Stream &s, char a)
int64_t CAmount
Amount in corbies (Can be negative)
void SerializationOp(Stream &s, Operation ser_action)
UniValue transfer(const JSONRPCRequest &request)
CAssetCacheRestrictedVerifiers(const std::string &assetName, const std::string &verifier)
void SerializationOp(Stream &s, Operation ser_action)
CNullAssetTxVerifierString()
An outpoint - a combination of a transaction hash and an index n into its vout.
void SerializationOp(Stream &s, Operation ser_action)
bool operator<(const CAssetCacheReissueAsset &rhs) const
std::pair< cache_key_t, cache_value_t > key_value_pair_t
CLRUCache(size_t max_size)
const char IPFS_SHA2_256_LEN
bool operator<(const CAssetCacheRestrictedAddress &rhs) const
bool operator()(const CNewAsset &s1, const CNewAsset &s2) const
Serialized script, used inside transaction inputs and outputs.
bool operator<(const CAssetCacheRestrictedVerifiers &rhs) const
const std::list< key_value_pair_t > & GetItemsList()
std::string verifier_string
std::string rootAssetName
void SerializationOp(Stream &s, Operation ser_action)
AssetType AssetTypeFromInt(int nType)
bool operator<(const CAssetCacheRestrictedGlobal &rhs) const
CLRUCache(const CLRUCache &cache)
CAssetCacheRestrictedAddress(const std::string &assetName, const std::string &address, const RestrictedType &type)
bool operator<(const CAssetCacheNewTransfer &rhs) const
void Unserialize(Stream &s, char &a)
CAssetCacheSpendAsset(const std::string &assetName, const std::string &address, const CAmount &nAmount)
CAssetCacheNewTransfer(const CAssetTransfer &transfer, const std::string &address, const COutPoint &out)
std::list< key_value_pair_t > cacheItemsList
int IntFromAssetType(AssetType type)
const cache_value_t & Get(const cache_key_t &key)
CAssetCacheNewAsset(const CNewAsset &asset, const std::string &address, const int &blockHeight, const uint256 &blockHash)
bool operator<(const CAssetCacheRootQualifierChecker &rhs) const
UniValue reissue(const JSONRPCRequest &request)