Raven Core  3.0.0
P2P Digital Currency
assetdb.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 #ifndef RAVEN_ASSETDB_H
6 #define RAVEN_ASSETDB_H
7 
8 #include "fs.h"
9 #include "serialize.h"
10 
11 #include <string>
12 #include <map>
13 #include <dbwrapper.h>
14 
16 
17 class CNewAsset;
18 class uint256;
19 class COutPoint;
21 
23 {
26  std::string strIPFS;
27  int32_t nUnits;
28  int8_t version;
30  std::string verifierString;
31 
33 
34  template <typename Stream, typename Operation>
35  inline void SerializationOp(Stream& s, Operation ser_action) {
36  READWRITE(fChangedUnits);
37  READWRITE(fChangedIPFS);
38  READWRITE(strIPFS);
39  READWRITE(nUnits);
40  if (ser_action.ForRead()) {
41  if (!s.empty() and s.size() >= 1) {
42  int8_t nVersionCheck;
43  ::Unserialize(s, nVersionCheck);
44 
45  if (nVersionCheck == ASSET_UNDO_INCLUDES_VERIFIER_STRING) {
46  ::Unserialize(s, fChangedVerifierString);
47  ::Unserialize(s, verifierString);
48  }
49  version = nVersionCheck;
50  }
51  } else {
53  ::Serialize(s, fChangedVerifierString);
54  ::Serialize(s, verifierString);
55  }
56  }
57 };
58 
60 class CAssetsDB : public CDBWrapper
61 {
62 public:
63  explicit CAssetsDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false);
64 
65  CAssetsDB(const CAssetsDB&) = delete;
66  CAssetsDB& operator=(const CAssetsDB&) = delete;
67 
68  // Write to database functions
69  bool WriteAssetData(const CNewAsset& asset, const int nHeight, const uint256& blockHash);
70  bool WriteAssetAddressQuantity(const std::string& assetName, const std::string& address, const CAmount& quantity);
71  bool WriteAddressAssetQuantity( const std::string& address, const std::string& assetName, const CAmount& quantity);
72  bool WriteBlockUndoAssetData(const uint256& blockhash, const std::vector<std::pair<std::string, CBlockAssetUndo> >& assetUndoData);
73  bool WriteReissuedMempoolState();
74 
75  // Read from database functions
76  bool ReadAssetData(const std::string& strName, CNewAsset& asset, int& nHeight, uint256& blockHash);
77  bool ReadAssetAddressQuantity(const std::string& assetName, const std::string& address, CAmount& quantity);
78  bool ReadAddressAssetQuantity(const std::string& address, const std::string& assetName, CAmount& quantity);
79  bool ReadBlockUndoAssetData(const uint256& blockhash, std::vector<std::pair<std::string, CBlockAssetUndo> >& assetUndoData);
80  bool ReadReissuedMempoolState();
81 
82  // Erase from database functions
83  bool EraseAssetData(const std::string& assetName);
84  bool EraseMyAssetData(const std::string& assetName);
85  bool EraseAssetAddressQuantity(const std::string &assetName, const std::string &address);
86  bool EraseAddressAssetQuantity(const std::string &address, const std::string &assetName);
87 
88  // Helper functions
89  bool LoadAssets();
90  bool AssetDir(std::vector<CDatabasedAssetData>& assets, const std::string filter, const size_t count, const long start);
91  bool AssetDir(std::vector<CDatabasedAssetData>& assets);
92 
93  bool AddressDir(std::vector<std::pair<std::string, CAmount> >& vecAssetAmount, int& totalEntries, const bool& fGetTotal, const std::string& address, const size_t count, const long start);
94  bool AssetAddressDir(std::vector<std::pair<std::string, CAmount> >& vecAddressAmount, int& totalEntries, const bool& fGetTotal, const std::string& assetName, const size_t count, const long start);
95 };
96 
97 
98 #endif //RAVEN_ASSETDB_H
#define READWRITE(obj)
Definition: serialize.h:163
bool fChangedUnits
Definition: assetdb.h:25
bool EraseAddressAssetQuantity(const std::string &address, const std::string &assetName)
void Serialize(Stream &s, char a)
Definition: serialize.h:182
int64_t CAmount
Amount in corbies (Can be negative)
Definition: amount.h:13
bool fChangedIPFS
Definition: assetdb.h:24
int8_t version
Definition: assetdb.h:28
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:22
std::string strIPFS
Definition: assetdb.h:26
256-bit opaque blob.
Definition: uint256.h:123
bool fChangedVerifierString
Definition: assetdb.h:29
std::string verifierString
Definition: assetdb.h:30
void SerializationOp(Stream &s, Operation ser_action)
Definition: assetdb.h:35
void Unserialize(Stream &s, char &a)
Definition: serialize.h:194
const int8_t ASSET_UNDO_INCLUDES_VERIFIER_STRING
Definition: assetdb.h:15
Access to the block database (blocks/index/)
Definition: assetdb.h:60
int32_t nUnits
Definition: assetdb.h:27