-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Libplanet.Store; | ||
|
||
namespace Libplanet.Node.Services; | ||
|
||
public interface IStoreService | ||
{ | ||
IStore Store { get; } | ||
|
||
IStateStore StateStore { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Libplanet.Node.Options; | ||
using Libplanet.RocksDBStore; | ||
using Libplanet.Store; | ||
using Libplanet.Store.Trie; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Libplanet.Node.Services; | ||
|
||
internal sealed class StoreService : IStoreService | ||
{ | ||
public StoreService( | ||
IOptions<StoreOptions> storeOptions, | ||
ILogger<StoreService> logger) | ||
{ | ||
(Store, KeyValueStore) = CreateStore(storeOptions.Value); | ||
StateStore = new TrieStateStore(KeyValueStore); | ||
} | ||
|
||
public IStore Store { get; } | ||
|
||
public IKeyValueStore KeyValueStore { get; } | ||
|
||
public IStateStore StateStore { get; } | ||
|
||
private static (IStore, IKeyValueStore) CreateStore(StoreOptions storeOptions) | ||
{ | ||
return storeOptions.Type switch | ||
{ | ||
StoreType.RocksDB => CreateRocksDBStore(storeOptions), | ||
StoreType.InMemory => CreateMemoryStore(), | ||
_ => throw new NotSupportedException($"Unsupported store type: {storeOptions.Type}"), | ||
}; | ||
} | ||
|
||
private static (MemoryStore, MemoryKeyValueStore) CreateMemoryStore() | ||
{ | ||
var store = new MemoryStore(); | ||
var keyValueStore = new MemoryKeyValueStore(); | ||
return (store, keyValueStore); | ||
} | ||
|
||
private static (RocksDBStore.RocksDBStore, RocksDBKeyValueStore) CreateRocksDBStore( | ||
StoreOptions storeOptions) | ||
{ | ||
var store = new RocksDBStore.RocksDBStore(storeOptions.StoreName); | ||
var keyValueStore = new RocksDBKeyValueStore(storeOptions.StateStoreName); | ||
return (store, keyValueStore); | ||
} | ||
} |