20 return "Trie was not created or already was destructed.";
22 return "Unknown error";
27 std::shared_ptr<Codec> codec,
28 std::shared_ptr<TrieSerializer> serializer,
29 std::optional<std::shared_ptr<changes_trie::ChangesTracker>> changes,
30 std::shared_ptr<PolkadotTrie> trie) {
31 std::unique_ptr<PersistentTrieBatchImpl> ptr(
33 std::move(serializer),
40 std::shared_ptr<Codec> codec,
41 std::shared_ptr<TrieSerializer> serializer,
42 std::optional<std::shared_ptr<changes_trie::ChangesTracker>> changes,
43 std::shared_ptr<PolkadotTrie> trie)
44 :
codec_{std::move(codec)},
47 trie_{std::move(trie)} {
48 BOOST_ASSERT(
codec_ !=
nullptr);
52 BOOST_ASSERT(
trie_ !=
nullptr);
58 return std::move(root);
62 return std::make_unique<TopperTrieBatchImpl>(shared_from_this());
67 return trie_->get(key);
70 outcome::result<std::optional<BufferConstRef>>
72 return trie_->tryGet(key);
76 return std::make_unique<PolkadotTrieCursorImpl>(
trie_);
81 return trie_->contains(key);
85 return trie_->empty();
88 outcome::result<std::tuple<bool, uint32_t>>
90 std::optional<uint64_t> limit) {
92 return trie_->clearPrefix(
93 prefix, limit, [&](
const auto &key,
auto &&) -> outcome::result<void> {
97 return outcome::success();
105 auto res =
trie_->put(key, value);
109 changes_.value()->onPut(key, value, is_new_entry);
116 return put(key, value);
121 OUTCOME_TRY(
trie_->remove(key));
126 return outcome::success();
Class represents arbitrary (including empty) byte buffer.
outcome::result< BufferConstRef > get(const BufferView &key) const override
Get value by key.
PersistentTrieBatchImpl(std::shared_ptr< Codec > codec, std::shared_ptr< TrieSerializer > serializer, std::optional< std::shared_ptr< changes_trie::ChangesTracker >> changes, std::shared_ptr< PolkadotTrie > trie)
#define SL_TRACE_FUNC_CALL(logger, ret,...)
std::unique_ptr< TopperTrieBatch > batchOnTop() override
std::shared_ptr< TrieSerializer > serializer_
bool empty() const override
Returns true if the storage is empty.
static std::unique_ptr< PersistentTrieBatchImpl > create(std::shared_ptr< Codec > codec, std::shared_ptr< TrieSerializer > serializer, std::optional< std::shared_ptr< changes_trie::ChangesTracker >> changes, std::shared_ptr< PolkadotTrie > trie)
OUTCOME_CPP_DEFINE_CATEGORY(kagome::storage::trie, PersistentTrieBatchImpl::Error, e)
std::shared_ptr< PolkadotTrie > trie_
outcome::result< RootHash > commit() override
std::unique_ptr< PolkadotTrieCursor > trieCursor() override
outcome::result< std::tuple< bool, uint32_t > > clearPrefix(const BufferView &prefix, std::optional< uint64_t > limit=std::nullopt) override
outcome::result< void > put(const BufferView &key, const Buffer &value) override
Store value by key.
outcome::result< std::optional< BufferConstRef > > tryGet(const BufferView &key) const override
Get value by key.
outcome::result< void > remove(const BufferView &key) override
Remove value by key.
std::shared_ptr< Codec > codec_
outcome::result< bool > contains(const BufferView &key) const override
Checks if given key-value binding exists in the storage.
#define SL_TRACE_VOID_FUNC_CALL(logger,...)
std::optional< std::shared_ptr< changes_trie::ChangesTracker > > changes_