6 #include "validation.h" 8 #include <boost/thread.hpp> 10 static const char DB_FLAG =
'D';
11 static const char VERIFIER_FLAG =
'V';
12 static const char ADDRESS_QULAIFIER_FLAG =
'T';
13 static const char QULAIFIER_ADDRESS_FLAG =
'Q';
14 static const char RESTRICTED_ADDRESS_FLAG =
'R';
15 static const char GLOBAL_RESTRICTION_FLAG =
'G';
25 return Write(std::make_pair(VERIFIER_FLAG, assetName), verifier);
30 return Read(std::make_pair(VERIFIER_FLAG, assetName), verifier);
35 return Erase(std::make_pair(VERIFIER_FLAG, assetName));
42 return Write(std::make_pair(ADDRESS_QULAIFIER_FLAG, std::make_pair(address, tag)), i);
48 return Read(std::make_pair(ADDRESS_QULAIFIER_FLAG, std::make_pair(address, tag)), i);
53 return Erase(std::make_pair(ADDRESS_QULAIFIER_FLAG, std::make_pair(address, tag)));
60 return Write(std::make_pair(QULAIFIER_ADDRESS_FLAG, std::make_pair(tag, address)), i);
66 return Read(std::make_pair(QULAIFIER_ADDRESS_FLAG, std::make_pair(tag, address)), i);
71 return Erase(std::make_pair(QULAIFIER_ADDRESS_FLAG, std::make_pair(tag, address)));
79 return Write(std::make_pair(RESTRICTED_ADDRESS_FLAG, std::make_pair(address, assetName)), i);
85 return Read(std::make_pair(RESTRICTED_ADDRESS_FLAG, std::make_pair(address, assetName)), i);
90 return Erase(std::make_pair(RESTRICTED_ADDRESS_FLAG, std::make_pair(address, assetName)));
97 return Write(std::make_pair(GLOBAL_RESTRICTION_FLAG, assetName), i);
103 return Read(std::make_pair(GLOBAL_RESTRICTION_FLAG, assetName), i);
108 return Erase(std::make_pair(GLOBAL_RESTRICTION_FLAG, assetName));
113 return Write(std::make_pair(DB_FLAG, name), fValue ?
'1' :
'0');
119 if (!
Read(std::make_pair(DB_FLAG, name), ch))
129 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
131 pcursor->Seek(std::make_pair(QULAIFIER_ADDRESS_FLAG, std::make_pair(qualifier, std::string())));
134 while (pcursor->Valid()) {
135 boost::this_thread::interruption_point();
136 std::pair<char, std::pair<std::string, std::string> > key;
137 if (pcursor->GetKey(key) && key.first == QULAIFIER_ADDRESS_FLAG && key.second.first == qualifier) {
138 addresses.emplace_back(key.second.second);
150 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
152 pcursor->Seek(std::make_pair(ADDRESS_QULAIFIER_FLAG, std::make_pair(address, qualifier)));
155 while (pcursor->Valid()) {
156 boost::this_thread::interruption_point();
157 std::pair<char, std::pair<std::string, std::string> > key;
158 if (pcursor->GetKey(key) && key.first == ADDRESS_QULAIFIER_FLAG && key.second.first == address) {
159 if (key.second.second == qualifier || key.second.second.rfind(std::string(qualifier +
"/"), 0) == 0) {
175 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
177 pcursor->Seek(std::make_pair(ADDRESS_QULAIFIER_FLAG, std::make_pair(address, std::string())));
180 while (pcursor->Valid()) {
181 boost::this_thread::interruption_point();
182 std::pair<char, std::pair<std::string, std::string> > key;
183 if (pcursor->GetKey(key) && key.first == ADDRESS_QULAIFIER_FLAG && key.second.first == address) {
184 qualifiers.emplace_back(key.second.second);
198 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
200 pcursor->Seek(std::make_pair(RESTRICTED_ADDRESS_FLAG, std::make_pair(address, std::string())));
203 while (pcursor->Valid()) {
204 boost::this_thread::interruption_point();
205 std::pair<char, std::pair<std::string, std::string> > key;
206 if (pcursor->GetKey(key) && key.first == RESTRICTED_ADDRESS_FLAG && key.second.first == address) {
207 restrictions.emplace_back(key.second.second);
221 std::unique_ptr<CDBIterator> pcursor(
NewIterator());
223 pcursor->Seek(std::make_pair(GLOBAL_RESTRICTION_FLAG, std::string()));
226 while (pcursor->Valid()) {
227 boost::this_thread::interruption_point();
228 std::pair<char, std::string> key;
229 if (pcursor->GetKey(key) && key.first == GLOBAL_RESTRICTION_FLAG) {
230 restrictions.emplace_back(key.second);
bool WriteQualifierAddress(const std::string &address, const std::string &tag)
CRestrictedDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
bool WriteAddressQualifier(const std::string &address, const std::string &tag)
bool WriteFlag(const std::string &name, bool fValue)
bool EraseQualifierAddress(const std::string &address, const std::string &tag)
bool EraseAddressQualifier(const std::string &address, const std::string &tag)
bool GetAddressQualifiers(std::string &address, std::vector< std::string > &qualifiers)
bool ReadGlobalRestriction(const std::string &assetName)
CDBIterator * NewIterator()
bool Erase(const K &key, bool fSync=false)
bool EraseGlobalRestriction(const std::string &assetName)
bool ReadVerifier(const std::string &assetName, std::string &verifier)
bool EraseVerifier(const std::string &assetName)
bool CheckForAddressRootQualifier(const std::string &address, const std::string &qualifier)
bool EraseRestrictedAddress(const std::string &address, const std::string &assetName)
bool Read(const K &key, V &value) const
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
bool GetQualifierAddresses(std::string &qualifier, std::vector< std::string > &addresses)
bool ReadAddressQualifier(const std::string &address, const std::string &tag)
bool Write(const K &key, const V &value, bool fSync=false)
bool WriteRestrictedAddress(const std::string &address, const std::string &assetName)
bool ReadFlag(const std::string &name, bool &fValue)
bool ReadQualifierAddress(const std::string &address, const std::string &tag)
bool GetGlobalRestrictions(std::vector< std::string > &restrictions)
bool GetAddressRestrictions(std::string &address, std::vector< std::string > &restrictions)
bool WriteGlobalRestriction(const std::string &assetName)
const fs::path & GetDataDir(bool fNetSpecific)
bool WriteVerifier(const std::string &assetName, const std::string &verifier)
bool ReadRestrictedAddress(const std::string &address, const std::string &assetName)