16 std::shared_ptr<PolkadotTrieFactory> factory,
17 std::shared_ptr<Codec> codec,
18 std::shared_ptr<TrieStorageBackend> backend)
19 : trie_factory_{std::move(factory)},
23 BOOST_ASSERT(
codec_ !=
nullptr);
33 if (trie.
getRoot() ==
nullptr) {
39 outcome::result<std::shared_ptr<PolkadotTrie>>
42 [
this](
const std::shared_ptr<OpaqueTrieNode> &parent)
43 -> outcome::result<PolkadotTrie::NodePtr> {
45 return std::move(node);
51 return trie_factory_->createFromRoot(std::move(root), std::move(f));
59 codec_->encodeNodeAndStoreChildren(
61 return batch->put(hash, std::move(encoded));
63 auto key =
codec_->hash256(enc);
64 OUTCOME_TRY(batch->put(key, enc));
65 OUTCOME_TRY(batch->commit());
71 const std::shared_ptr<OpaqueTrieNode> &parent)
const {
72 if (
auto p = std::dynamic_pointer_cast<DummyNode>(parent); p !=
nullptr) {
76 return std::dynamic_pointer_cast<
TrieNode>(parent);
85 if (
codec_->isMerkleHash(db_key)) {
86 OUTCOME_TRY(db,
backend_->load(db_key));
92 OUTCOME_TRY(n,
codec_->decodeNode(enc));
93 return std::dynamic_pointer_cast<
TrieNode>(n);
Class represents arbitrary (including empty) byte buffer.
std::shared_ptr< PolkadotTrieFactory > trie_factory_
outcome::result< RootHash > storeTrie(PolkadotTrie &trie) override
TrieSerializerImpl(std::shared_ptr< PolkadotTrieFactory > factory, std::shared_ptr< Codec > codec, std::shared_ptr< TrieStorageBackend > backend)
outcome::result< std::shared_ptr< PolkadotTrie > > retrieveTrie(const common::Buffer &db_key) const override
std::shared_ptr< TrieStorageBackend > backend_
std::function< outcome::result< NodePtr >(std::shared_ptr< OpaqueTrieNode > const &)> NodeRetrieveFunctor
outcome::result< PolkadotTrie::NodePtr > retrieveNode(const common::Buffer &db_key) const
RootHash getEmptyRootHash() const override
virtual NodePtr getRoot()=0
std::shared_ptr< Codec > codec_
outcome::result< RootHash > storeRootNode(TrieNode &node)