6 #ifndef RAVENCOIN_ASSET_PROTOCOL_H 7 #define RAVENCOIN_ASSET_PROTOCOL_H 16 #include <unordered_map> 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 33 #define OWNER_LENGTH 1 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 40 #define RESTRICTED_CHAR '$' 41 #define QUALIFIER_CHAR '#' 43 #define QUALIFIER_ASSET_MIN_AMOUNT 1 * COIN 44 #define QUALIFIER_ASSET_MAX_AMOUNT 10 * COIN 45 #define QUALIFIER_ASSET_UNITS 0 47 #define ASSET_TRANSFER_STRING "transfer_asset" 48 #define ASSET_NEW_STRING "new_asset" 49 #define ASSET_REISSUE_STRING "reissue_asset" 65 #define MAX_CACHE_ASSETS_SIZE 2500 95 mapAssetsAddressAmount.clear();
96 mapReissuedAssetData.clear();
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);
245 bool RemoveNewAsset(
const CNewAsset& asset,
const std::string address);
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);
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);
256 bool AddNewAsset(
const CNewAsset& asset,
const std::string address,
const int& nHeight,
const uint256& blockHash);
258 bool AddOwnerAsset(
const std::string& assetsName,
const std::string address);
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);
269 bool ContainsAsset(
const CNewAsset& asset);
270 bool ContainsAsset(
const std::string& assetName);
273 bool CheckIfAssetExists(
const std::string& name,
bool fForceDuplicateCheck =
true);
276 bool GetAssetMetaDataIfExists(
const std::string &name,
CNewAsset &asset);
277 bool GetAssetMetaDataIfExists(
const std::string &name,
CNewAsset &asset,
int& nHeight,
uint256& blockHash);
280 bool GetAssetVerifierStringIfExists(
const std::string &name,
CNullAssetTxVerifierString& verifier,
bool fSkipTempCache =
false);
283 bool CheckForAddressQualifier(
const std::string &qualifier_name,
const std::string& address,
bool fSkipTempCache =
false);
286 bool CheckForAddressRestriction(
const std::string &restricted_name,
const std::string& address,
bool fSkipTempCache =
false);
289 bool CheckForGlobalRestriction(
const std::string &restricted_name,
bool fSkipTempCache =
false);
292 size_t DynamicMemoryUsage()
const;
295 size_t GetCacheSize()
const;
296 size_t GetCacheSizeV2()
const;
302 bool DumpCacheToDatabase();
307 vUndoAssetAmount.clear();
308 vSpentAssets.clear();
310 setNewAssetsToRemove.clear();
311 setNewAssetsToAdd.clear();
313 setNewReissueToAdd.clear();
314 setNewReissueToRemove.clear();
316 setNewTransferAssetsToAdd.clear();
317 setNewTransferAssetsToRemove.clear();
319 setNewOwnerAssetsToAdd.clear();
320 setNewOwnerAssetsToRemove.clear();
325 setNewQualifierAddressToAdd.clear();
326 setNewQualifierAddressToRemove.clear();
328 setNewRestrictedAddressToAdd.clear();
329 setNewRestrictedAddressToRemove.clear();
331 setNewRestrictedGlobalToAdd.clear();
332 setNewRestrictedGlobalToRemove.clear();
334 setNewRestrictedVerifierToAdd.clear();
335 setNewRestrictedVerifierToRemove.clear();
337 mapRootQualifierAddressesAdd.clear();
338 mapRootQualifierAddressesRemove.clear();
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());
370 void GetTxOutAssetTypes(
const std::vector<CTxOut>& vout,
int& issues,
int& reissues,
int& transfers,
int& owners);
441 bool CheckEncoded(
const std::string& hash, std::string& strError);
481 void GetAllMyAssets(
CWallet* pwallet, std::vector<std::string>& names,
int nMinConf = 1,
bool fIncludeAdministrator =
false,
bool fOnlyAdministrator =
false);
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 =
"");
493 bool VerifyWalletHasAsset(
const std::string& asset_name, std::pair<int, std::string>& pairError);
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);
519 bool CheckVerifierString(
const std::string& verifier, std::set<std::string>& setFoundQualifiers, std::string& strError,
bool fWithTags =
false);
545 #endif //RAVENCOIN_ASSET_PROTOCOL_H std::set< CAssetCacheRestrictedVerifiers > setNewRestrictedVerifierToAdd
Restricted Assets Verifier Caches.
bool ContextualCheckVerifierAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
bool CheckReissueDataTx(const CTxOut &txOut)
bool CheckVerifierAssetTxOut(const CTxOut &txout, std::string &strError)
CAmount GetReissueAssetBurnAmount()
bool ReissueAssetFromScript(const CScript &scriptPubKey, CReissueAsset &reissue, std::string &strAddress)
std::string CacheToString() const
std::set< CAssetCacheRestrictedAddress > setNewRestrictedAddressToAdd
Restricted Address Asset Caches.
bool ContextualCheckReissueAsset(CAssetsCache *assetCache, const CReissueAsset &reissue_asset, std::string &strError, const CTransaction &tx)
void GetAllMyAssets(CWallet *pwallet, std::vector< std::string > &names, int nMinConf=1, bool fIncludeAdministrator=false, bool fOnlyAdministrator=false)
bool QualifierAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
bool IsAssetNameAnRestricted(const std::string &name)
Check if an asset is a restricted asset.
std::string GetStrippedVerifierString(const std::string &verifier)
bool GetAssetInfoFromScript(const CScript &scriptPubKey, std::string &strName, CAmount &nAmount)
std::set< CAssetCacheQualifierAddress > setNewQualifierAddressToRemove
bool CheckTransferOwnerTx(const CTxOut &txOut)
bool AssetNullVerifierDataFromScript(const CScript &scriptPubKey, CNullAssetTxVerifierString &verifierData)
bool OwnerAssetFromScript(const CScript &scriptPubKey, std::string &assetName, std::string &strAddress)
std::set< CAssetCacheNewOwner > setNewOwnerAssetsToRemove
bool IsScriptTransferAsset(const CScript &scriptPubKey)
Check script and see if it matches the transfer asset template.
bool GlobalAssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData)
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.
bool VerifyGlobalRestrictedChange(CAssetsCache &cache, const CNullAssetTxData &data, std::string &strError)
std::string DecodeIPFS(std::string encoded)
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.
CAmount GetIssueAssetBurnAmount()
Functions to be used to get access to the current burn amount required for specific asset issuance tr...
bool ContextualCheckNewAsset(CAssetsCache *assetCache, const CNewAsset &asset, std::string &strError, bool fCheckMempool=false)
Double ended buffer combining vector and stream-like interfaces.
bool CheckOwnerDataTx(const CTxOut &txOut)
std::set< CAssetCacheNewTransfer > setNewTransferAssetsToRemove
bool MsgChannelAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
bool IsAssetNameASubQualifier(const std::string &name)
Check if an asset is a sub qualifier.
bool QualifierAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
bool ContextualCheckUniqueAsset(CAssetsCache *assetCache, const CNewAsset &unique_asset, std::string &strError)
bool AssetNullDataFromScript(const CScript &scriptPubKey, CNullAssetTxData &assetData, std::string &strAddress)
std::set< CAssetCacheNewOwner > setNewOwnerAssetsToAdd
Ownership Assets Caches.
bool MsgChannelAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
bool GetAssetData(const CScript &script, CAssetOutputEntry &data)
bool IsAssetNameAnMsgChannel(const std::string &name)
Check if an asset is a message channel.
bool IsScriptNewQualifierAsset(const CScript &scriptPubKey)
Check script and see if it matches the qualifier issuance template.
int64_t CAmount
Amount in corbies (Can be negative)
std::vector< CAssetCacheUndoAssetAmount > vUndoAssetAmount
These are memory only containers that show dirty entries that will be databased when flushed...
std::set< CAssetCacheNewAsset > setNewAssetsToRemove
New Assets Caches.
std::vector< CAssetCacheSpendAsset > vSpentAssets
CAmount GetIssueUniqueAssetBurnAmount()
CAssetsCache & operator=(const CAssetsCache &cache)
bool VerifyNullAssetDataFlag(const int &flag, std::string &strError)
Helper methods that validate changes to null asset data transaction databases.
bool VerifyQualifierChange(CAssetsCache &cache, const CNullAssetTxData &data, const std::string &address, std::string &strError)
bool IsScriptNewAsset(const CScript &scriptPubKey)
Check script and see if it matches the asset issuance template.
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
bool ContextualCheckTransferAsset(CAssetsCache *assetCache, const CAssetTransfer &transfer, const std::string &address, std::string &strError)
std::string EncodeAssetData(std::string decoded)
bool VerifyRestrictedAddressChange(CAssetsCache &cache, const CNullAssetTxData &data, const std::string &address, std::string &strError)
bool AssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
These types of asset tx, have specific metadata at certain indexes in the transaction.
std::set< CAssetCacheRestrictedAddress > setNewRestrictedAddressToRemove
bool CheckReissueBurnTx(const CTxOut &txOut)
Check to make sure the script contains the reissue burn data.
std::string DecodeAssetData(std::string encoded)
Decode and Encode IPFS hashes, or OIP hashes.
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.
bool IsScriptNewRestrictedAsset(const CScript &scriptPubKey)
Check script and see if it matches the restricted issueance template.
bool IsAssetNameValid(const std::string &name)
Check is an asset name is valid, and being able to return the asset type if needed.
UniValue transfer(const JSONRPCRequest &request)
CAssets(const CAssets &assets)
bool ContextualCheckUniqueAssetTx(CAssetsCache *assetCache, std::string &strError, const CTransaction &tx)
void ClearDirtyCache()
Clear all dirty cache sets, vetors, and maps.
std::map< std::string, uint256 > mapReissuedAssets
CAmount GetIssueMsgChannelAssetBurnAmount()
bool UniqueAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
bool ContextualCheckGlobalAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
bool RestrictedAssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
bool CheckVerifierString(const std::string &verifier, std::set< std::string > &setFoundQualifiers, std::string &strError, bool fWithTags=false)
void ExtractVerifierStringQualifiers(const std::string &verifier, std::set< std::string > &qualifiers, bool fWithTag=true)
Helper method for extracting #TAGS from a verifier string.
CAmount GetAddNullQualifierTagBurnAmount()
bool IsScriptReissueAsset(const CScript &scriptPubKey)
Check script and see if it matches the reissue template.
bool VerifyWalletHasAsset(const std::string &asset_name, std::pair< int, std::string > &pairError)
Verifies that this wallet owns the give asset.
bool RestrictedAssetFromTransaction(const CTransaction &tx, CNewAsset &asset, std::string &strAddress)
std::set< CAssetCacheQualifierAddress > setNewQualifierAddressToAdd
Qualfier Address Asset Caches.
CAssets & operator=(const CAssets &other)
An output of a transaction.
bool TransferAssetFromScript(const CScript &scriptPubKey, CAssetTransfer &assetTransfer, std::string &strAddress)
Get specific asset type metadata from the given scripts.
bool CheckIssueBurnTx(const CTxOut &txOut, const AssetType &type, const int numberIssued)
Check to make sure the script contains the burn transaction.
bool ReissueAssetFromTransaction(const CTransaction &tx, CReissueAsset &reissue, std::string &strAddress)
bool OwnerFromTransaction(const CTransaction &tx, std::string &ownerName, std::string &strAddress)
std::string GetParentName(const std::string &name)
Get the root name of an asset.
An outpoint - a combination of a transaction hash and an index n into its vout.
std::map< uint256, std::string > mapReissuedTx
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...
bool ContextualCheckNullAssetTxOut(const CTxOut &txout, CAssetsCache *assetCache, std::string &strError)
void GetTxOutAssetTypes(const std::vector< CTxOut > &vout, int &issues, int &reissues, int &transfers, int &owners)
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.
std::map< std::pair< std::string, std::string >, CAmount > mapAssetsAddressAmount
std::string GetBurnAddress(const AssetType type)
Functions to be used to get access to the burn address for a given asset type issuance.
A transaction with a bunch of additional info that only the owner cares about.
std::map< CAssetCacheRootQualifierChecker, std::set< std::string > > mapRootQualifierAddressesAdd
Root Qualifier Address Map.
std::set< CAssetCacheReissueAsset > setNewReissueToRemove
New Reissue Caches.
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.
std::set< CAssetCacheNewAsset > setNewAssetsToAdd
bool IsUniqueTagValid(const std::string &tag)
Check if an unique tagname is valid.
CAmount GetIssueQualifierAssetBurnAmount()
bool IsScriptNewUniqueAsset(const CScript &scriptPubKey)
Check script and see if it matches the unquie issuance template.
bool IsScriptNewMsgChannelAsset(const CScript &scriptPubKey)
Check script and see if it matches the message channel issuance template.
std::string EncodeIPFS(std::string decoded)
std::set< CAssetCacheReissueAsset > setNewReissueToAdd
bool IsAssetNameAQualifier(const std::string &name)
Check if an asset is a qualifier asset or sub qualifier.
CAmount GetIssueSubAssetBurnAmount()
A key allocated from the key pool.
CAssetsCache(const CAssetsCache &cache)
Serialized script, used inside transaction inputs and outputs.
bool IsAssetNameAnOwner(const std::string &name)
Check if an asset is an owner.
std::set< CAssetCacheRestrictedGlobal > setNewRestrictedGlobalToRemove
std::set< CAssetCacheRestrictedGlobal > setNewRestrictedGlobalToAdd
Restricted Global Asset Caches.
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.
bool IsScriptOwnerAsset(const CScript &scriptPubKey)
Check script and see if it matches the owner issuance template.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
CAmount GetIssueSubQualifierAssetBurnAmount()
bool error(const char *fmt, const Args &... args)
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.
CAmount GetIssueRestrictedAssetBurnAmount()
bool CheckNewAsset(const CNewAsset &asset, std::string &strError)
bool CheckAmountWithUnits(const CAmount &nAmount, const int8_t nUnits)
Checks the amount and units, and makes sure that the amount uses the correct decimals.
std::map< CAssetCacheRootQualifierChecker, std::set< std::string > > mapRootQualifierAddressesRemove
bool CheckReissueAsset(const CReissueAsset &asset, std::string &strError)
The basic transaction that is broadcasted on the network and contained in blocks. ...
bool ContextualCheckVerifierString(CAssetsCache *cache, const std::string &verifier, const std::string &check_address, std::string &strError, bool fWithTags=false)
std::set< CAssetCacheNewTransfer > setNewTransferAssetsToAdd
Transfer Assets Caches.
bool AssetFromScript(const CScript &scriptPubKey, CNewAsset &asset, std::string &strAddress)
bool CheckIssueDataTx(const CTxOut &txOut)
issue asset scripts to make sure script meets the standards
std::set< CAssetCacheRestrictedVerifiers > setNewRestrictedVerifierToRemove
bool IsNewOwnerTxValid(const CTransaction &tx, const std::string &assetName, const std::string &address, std::string &errorMsg)
std::map< std::string, CNewAsset > mapReissuedAssetData
CAmount GetBurnAmount(const AssetType type)
UniValue reissue(const JSONRPCRequest &request)
void GetAllAdministrativeAssets(CWallet *pwallet, std::vector< std::string > &names, int nMinConf=1)
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.
bool GetAssetInfoFromCoin(const Coin &coin, std::string &strName, CAmount &nAmount)