Skip to content

Commit

Permalink
Allow to load store from a specified path (neo-project#2172)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and cloud8little committed Jan 24, 2021
1 parent 37363d3 commit 2cbdba8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class NeoSystem : IDisposable
internal IActorRef TaskManager { get; }
public IActorRef Consensus { get; private set; }

private readonly string storage_engine;
private readonly IStore store;
private ChannelsConfig start_message = null;
private bool suspend = false;
Expand All @@ -32,12 +33,11 @@ static NeoSystem()
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}

public NeoSystem(string storageEngine = null)
public NeoSystem(string storageEngine = null, string storagePath = null)
{
Plugin.LoadPlugins(this);
this.store = string.IsNullOrEmpty(storageEngine) || storageEngine == nameof(MemoryStore)
? new MemoryStore()
: Plugin.Storages[storageEngine].GetStore();
this.storage_engine = storageEngine;
this.store = LoadStore(storagePath);
this.Blockchain = ActorSystem.ActorOf(Ledger.Blockchain.Props(this, store));
this.LocalNode = ActorSystem.ActorOf(Network.P2P.LocalNode.Props(this));
this.TaskManager = ActorSystem.ActorOf(Network.P2P.TaskManager.Props(this));
Expand Down Expand Up @@ -69,6 +69,13 @@ public void EnsureStoped(IActorRef actor)
inbox.Receive(TimeSpan.FromMinutes(5));
}

public IStore LoadStore(string path)
{
return string.IsNullOrEmpty(storage_engine) || storage_engine == nameof(MemoryStore)
? new MemoryStore()
: Plugin.Storages[storage_engine].GetStore(path);
}

internal void ResumeNodeStartup()
{
suspend = false;
Expand Down
2 changes: 1 addition & 1 deletion src/neo/Plugins/IStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Neo.Plugins
{
public interface IStorageProvider
{
IStore GetStore();
IStore GetStore(string path);
}
}

0 comments on commit 2cbdba8

Please sign in to comment.