aboutsummaryrefslogtreecommitdiff
path: root/src/DatabaseStorage.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-02-13 00:46:46 +0100
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:25:12 +0200
commit00a2777fc154537fe9fc9cfac082a29f70bf6b75 (patch)
tree8c8a1489afe9d430cfdb1a19c63341d320f7543e /src/DatabaseStorage.cpp
parenta9a7ecaa25e6bc11062e21affd458e2de78747ff (diff)
Add database storage (in memory), need to store it on disk later
Diffstat (limited to 'src/DatabaseStorage.cpp')
-rw-r--r--src/DatabaseStorage.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/DatabaseStorage.cpp b/src/DatabaseStorage.cpp
new file mode 100644
index 0000000..2028c63
--- /dev/null
+++ b/src/DatabaseStorage.cpp
@@ -0,0 +1,35 @@
+#include "../include/DatabaseStorage.hpp"
+
+using namespace std;
+
+namespace odhtdb
+{
+ void DatabaseStorage::createStorage(const Key &key, vector<Group*> &&groups, u64 timestamp)
+ {
+ if(storageMap.find(key) != storageMap.end())
+ {
+ string errMsg = "Database storage with key ";
+ errMsg += key.hashedKey.toString();
+ errMsg += " already exists";
+ throw DatabaseStorageAlreadyExists(errMsg);
+ }
+
+ DatabaseStorageObjectList *databaseStorageObjectList = new DatabaseStorageObjectList();
+ databaseStorageObjectList->timestamp = timestamp;
+ databaseStorageObjectList->groups = move(groups);
+ storageMap[key] = databaseStorageObjectList;
+ }
+
+ void DatabaseStorage::appendStorage(const Key &key, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey)
+ {
+ auto it = storageMap.find(key);
+ if(it == storageMap.end())
+ {
+ string errMsg = "Database storage with key ";
+ errMsg += key.hashedKey.toString();
+ errMsg += " not found";
+ throw DatabaseStorageNotFound(errMsg);
+ }
+ it->second->objects.push_back({data, timestamp, creatorPublicKey});
+ }
+}