Skip to content

Commit

Permalink
Add AutoStart to config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Jan 13, 2021
1 parent 82e1571 commit d3c393e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/dBFT/DBFTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Neo.Consensus
{
public class DBFTPlugin : Plugin, IConsensusProvider, IP2PPlugin
{
private IWalletProvider walletProvider;
private IActorRef consensus;
private bool started = false;

Expand All @@ -16,10 +17,23 @@ protected override void Configure()
Settings.Load(GetConfiguration());
}

protected override void OnPluginsLoaded()
{
walletProvider = GetService<IWalletProvider>();
if (Settings.Default.AutoStart)
walletProvider.WalletOpened += WalletProvider_WalletOpened;
}

private void WalletProvider_WalletOpened(object sender, Wallet wallet)
{
walletProvider.WalletOpened -= WalletProvider_WalletOpened;
Start(wallet);
}

[ConsoleCommand("start consensus", Category = "Consensus", Description = "Start consensus service (dBFT)")]
private void OnStart()
{
Start(GetService<IWalletProvider>().GetWallet());
Start(walletProvider.GetWallet());
}

public void Start(Wallet wallet)
Expand Down
2 changes: 2 additions & 0 deletions src/dBFT/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class Settings
{
public string RecoveryLogs { get; }
public bool IgnoreRecoveryLogs { get; }
public bool AutoStart { get; }

public static Settings Default { get; private set; }

private Settings(IConfigurationSection section)
{
RecoveryLogs = section.GetValue("RecoveryLogs", "ConsensusState");
IgnoreRecoveryLogs = section.GetValue("IgnoreRecoveryLogs", false);
AutoStart = section.GetValue("AutoStart", false);
}

public static void Load(IConfigurationSection section)
Expand Down
3 changes: 2 additions & 1 deletion src/dBFT/dBFT/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"PluginConfiguration": {
"RecoveryLogs": "ConsensusState",
"IgnoreRecoveryLogs": false
"IgnoreRecoveryLogs": false,
"AutoStart": false
}
}

0 comments on commit d3c393e

Please sign in to comment.