From d3c393e78b4077f9d00513f67590c82d5aa91b4a Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 13 Jan 2021 17:18:32 +0800 Subject: [PATCH] Add AutoStart to config.json --- src/dBFT/DBFTPlugin.cs | 16 +++++++++++++++- src/dBFT/Settings.cs | 2 ++ src/dBFT/dBFT/config.json | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/dBFT/DBFTPlugin.cs b/src/dBFT/DBFTPlugin.cs index 91afec37f..5c1229307 100644 --- a/src/dBFT/DBFTPlugin.cs +++ b/src/dBFT/DBFTPlugin.cs @@ -8,6 +8,7 @@ namespace Neo.Consensus { public class DBFTPlugin : Plugin, IConsensusProvider, IP2PPlugin { + private IWalletProvider walletProvider; private IActorRef consensus; private bool started = false; @@ -16,10 +17,23 @@ protected override void Configure() Settings.Load(GetConfiguration()); } + protected override void OnPluginsLoaded() + { + walletProvider = GetService(); + 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().GetWallet()); + Start(walletProvider.GetWallet()); } public void Start(Wallet wallet) diff --git a/src/dBFT/Settings.cs b/src/dBFT/Settings.cs index 284a78da2..307e352c0 100644 --- a/src/dBFT/Settings.cs +++ b/src/dBFT/Settings.cs @@ -6,6 +6,7 @@ class Settings { public string RecoveryLogs { get; } public bool IgnoreRecoveryLogs { get; } + public bool AutoStart { get; } public static Settings Default { get; private set; } @@ -13,6 +14,7 @@ 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) diff --git a/src/dBFT/dBFT/config.json b/src/dBFT/dBFT/config.json index 95643892c..c3ee760e9 100644 --- a/src/dBFT/dBFT/config.json +++ b/src/dBFT/dBFT/config.json @@ -1,6 +1,7 @@ { "PluginConfiguration": { "RecoveryLogs": "ConsensusState", - "IgnoreRecoveryLogs": false + "IgnoreRecoveryLogs": false, + "AutoStart": false } }