aboutsummaryrefslogtreecommitdiff
path: root/include/DatabaseStorage.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'include/DatabaseStorage.hpp')
-rw-r--r--include/DatabaseStorage.hpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/DatabaseStorage.hpp b/include/DatabaseStorage.hpp
index fee6b72..863c5d9 100644
--- a/include/DatabaseStorage.hpp
+++ b/include/DatabaseStorage.hpp
@@ -1,10 +1,58 @@
#pragma once
+#include "Key.hpp"
+#include "DataView.hpp"
+#include "Signature.hpp"
+#include <vector>
+#include <stdexcept>
+
namespace odhtdb
{
+ class Group;
+
+ struct DatabaseStorageObject
+ {
+ DataView data;
+ u64 timestamp; // In microseconds
+ Signature::PublicKey creatorPublicKey;
+
+ DatabaseStorageObject(DataView &_data, u64 _timestamp, const Signature::PublicKey &_creatorPublicKey) :
+ data(_data), timestamp(_timestamp), creatorPublicKey(_creatorPublicKey)
+ {
+
+ }
+ };
+
+ struct DatabaseStorageObjectList
+ {
+ u64 timestamp; // In microseconds
+ std::vector<Group*> groups;
+ std::vector<DatabaseStorageObject> objects;
+ };
+
+ class DatabaseStorageAlreadyExists : public std::runtime_error
+ {
+ public:
+ DatabaseStorageAlreadyExists(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
+ class DatabaseStorageNotFound : public std::runtime_error
+ {
+ public:
+ DatabaseStorageNotFound(const std::string &errMsg) : std::runtime_error(errMsg) {}
+ };
+
+ using DatabaseStorageMap = KeyMap<DatabaseStorageObjectList*>;
+
class DatabaseStorage
{
public:
+ // Throws DatabaseStorageAlreadyExists if data with key already exists
+ void createStorage(const Key &key, std::vector<Group*> &&groups, u64 timestamp);
+ // Throws DatabaseStorageNotFound if data with key does not exist
+ void appendStorage(const Key &key, DataView &data, u64 timestamp, const Signature::PublicKey &creatorPublicKey);
+ private:
+ DatabaseStorageMap storageMap;
};
}