Skip to content

Commit bfe81fe

Browse files
Feature/in memory repository (#45)
Signed-off-by: Alexey-N-Chernyshov <[email protected]>
1 parent 42dd489 commit bfe81fe

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

core/storage/repository/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ target_link_libraries(filesystem_repository
2121
outcome
2222
repository
2323
)
24+
25+
add_library(in_memory_repository
26+
impl/in_memory_repository.cpp
27+
)
28+
target_link_libraries(in_memory_repository
29+
repository
30+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "storage/repository/impl/in_memory_repository.hpp"
7+
8+
#include "crypto/bls_provider/impl/bls_provider_impl.hpp"
9+
#include "libp2p/crypto/secp256k1_provider/secp256k1_provider_impl.hpp"
10+
#include "primitives/address/impl/address_verifier_impl.hpp"
11+
#include "storage/ipfs/impl/in_memory_datastore.hpp"
12+
#include "storage/keystore/impl/in_memory/in_memory_keystore.hpp"
13+
14+
using fc::crypto::bls::impl::BlsProviderImpl;
15+
using fc::primitives::address::AddressVerifierImpl;
16+
using fc::storage::ipfs::InMemoryDatastore;
17+
using fc::storage::keystore::InMemoryKeyStore;
18+
using fc::storage::repository::InMemoryRepository;
19+
using fc::storage::repository::Repository;
20+
using libp2p::crypto::secp256k1::Secp256k1ProviderImpl;
21+
22+
InMemoryRepository::InMemoryRepository()
23+
: Repository(std::make_shared<InMemoryDatastore>(),
24+
std::make_shared<InMemoryKeyStore>(
25+
std::make_shared<BlsProviderImpl>(),
26+
std::make_shared<Secp256k1ProviderImpl>(),
27+
std::make_shared<AddressVerifierImpl>()),
28+
std::make_shared<Config>()) {}
29+
30+
fc::outcome::result<std::shared_ptr<Repository>> InMemoryRepository::create(
31+
const std::string &config_path) {
32+
auto res = std::make_shared<InMemoryRepository>();
33+
OUTCOME_TRY(res->loadConfig(config_path));
34+
return res;
35+
}
36+
37+
fc::outcome::result<unsigned int> InMemoryRepository::getVersion() const {
38+
return kInMemoryRepositoryVersion;
39+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#ifndef FILECOIN_CORE_STORAGE_IMPL_IN_MEMORY_REPOSITORY_HPP
7+
#define FILECOIN_CORE_STORAGE_IMPL_IN_MEMORY_REPOSITORY_HPP
8+
9+
#include "storage/repository/repository.hpp"
10+
11+
namespace fc::storage::repository {
12+
13+
using Version = Repository::Version;
14+
15+
static constexpr Version kInMemoryRepositoryVersion = 1;
16+
17+
/**
18+
* @brief In-memory implementation of Repository
19+
*/
20+
class InMemoryRepository : public Repository {
21+
public:
22+
InMemoryRepository();
23+
24+
/**
25+
* Create Repository in-memory
26+
* @param config_path - path to config file
27+
* @return InMemoryRepository
28+
*/
29+
static fc::outcome::result<std::shared_ptr<Repository>> create(
30+
const std::string &config_path);
31+
32+
/** @copydoc Repository::getVersion() */
33+
outcome::result<Version> getVersion() const override;
34+
};
35+
36+
} // namespace fc::storage::repository
37+
38+
#endif // FILECOIN_CORE_STORAGE_IMPL_IN_MEMORY_REPOSITORY_HPP

0 commit comments

Comments
 (0)