17 .reserve(prefix.size() + key.size())
24 std::shared_ptr<storage::BufferStorage> storage)
25 : storage_(
std::move(storage)),
26 log_(log::
createLogger(
"OffchainLocalStorage",
"offchain")) {
36 throw std::invalid_argument(
"Off-chain local storage is unavailable yet");
38 auto iKey = internalKey(key);
39 std::lock_guard lg(
mutex_);
40 return storage_->put(iKey, std::move(value));
49 throw std::invalid_argument(
"Off-chain local storage is unavailable yet");
51 std::lock_guard lg(
mutex_);
57 const std::optional<common::BufferView> &expected,
63 throw std::invalid_argument(
"Off-chain local storage is unavailable yet");
65 auto iKey = internalKey(key);
66 std::lock_guard lg(
mutex_);
67 OUTCOME_TRY(get_opt,
storage_->tryLoad(iKey));
69 std::optional<common::BufferView> existing;
70 if (get_opt.has_value()) {
71 existing = get_opt.value();
74 if (existing == expected) {
75 OUTCOME_TRY(
storage_->put(iKey, std::move(value)));
87 throw std::invalid_argument(
"Off-chain local storage is unavailable yet");
89 auto iKey = internalKey(key);
Class represents arbitrary (including empty) byte buffer.
outcome::result< common::Buffer > get(const common::BufferView &key) override
Gets a value from the local storage.
common::BufferView BufferView
const common::Buffer kOffchainWorkerStoragePrefix
std::shared_ptr< storage::BufferStorage > storage_
SLBuffer< std::numeric_limits< size_t >::max()> Buffer
OffchainLocalStorageImpl(std::shared_ptr< storage::BufferStorage > storage)
outcome::result< void > clear(const common::BufferView &key) override
Remove a value from the local storage.
Logger createLogger(const std::string &tag)
outcome::result< void > set(const common::BufferView &key, common::Buffer value) override
Sets a value in the storage.
outcome::result< bool > compare_and_set(const common::BufferView &key, const std::optional< common::BufferView > &expected, common::Buffer value) override
Sets a new value in the local storage if the condition matches the current value. ...