-
Notifications
You must be signed in to change notification settings - Fork 34
/
offchain_storage.hpp
62 lines (52 loc) · 1.79 KB
/
offchain_storage.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <boost/optional.hpp>
#include "common/buffer_or_view.hpp"
#include "outcome/outcome.hpp"
namespace kagome::offchain {
/**
* A wrapper for a storage of offchain data
* Provides a convenient interface to work with it
*/
class OffchainStorage {
public:
virtual ~OffchainStorage() = default;
/**
* @brief Sets a value in the storage
* @param key a pointer-size indicating the key
* @param value a pointer-size indicating the value
* @return success or error
*/
virtual outcome::result<void> set(const common::BufferView &key,
common::BufferOrView value) = 0;
/**
* @brief Remove a value from the local storage
* @param key a pointer-size indicating the key
* @return success or error
*/
virtual outcome::result<void> clear(const common::BufferView &key) = 0;
/**
* @brief Sets a new value in the local storage if the condition matches the
* current value
* @param key a pointer-size indicating the key
* @param expected a pointer-size indicating the old value
* @param value a pointer-size indicating the new value
* @return bool as result, or error at failure
*/
virtual outcome::result<bool> compare_and_set(
const common::BufferView &key,
const std::optional<common::BufferView> &expected,
common::Buffer value) = 0;
/**
* @brief Gets a value from the local storage
* @param key a pointer-size indicating the key
* @return value for success, or error at failure
*/
virtual outcome::result<common::Buffer> get(
const common::BufferView &key) = 0;
};
} // namespace kagome::offchain