public async Task Execute(CancellationToken cancellationToken) { // why is the await Task.Run here? await Task.Run(() => { IKeyStoreConfig keyStoreConfig = _context.Config <IKeyStoreConfig>(); INetworkConfig networkConfig = _context.Config <INetworkConfig>(); AesEncrypter encrypter = new AesEncrypter( keyStoreConfig, _context.LogManager); _context.KeyStore = new FileKeyStore( keyStoreConfig, _context.EthereumJsonSerializer, encrypter, _context.CryptoRandom, _context.LogManager); _context.Wallet = _context.Config <IInitConfig>() switch { var config when config.EnableUnsecuredDevWallet&& config.KeepDevWalletInMemory => new DevWallet(_context.Config <IWalletConfig>(), _context.LogManager), var config when config.EnableUnsecuredDevWallet&& !config.KeepDevWalletInMemory => new DevKeyStoreWallet(_context.KeyStore, _context.LogManager), _ => new ProtectedKeyStoreWallet(_context.KeyStore, new ProtectedPrivateKeyFactory(_context.CryptoRandom, _context.Timestamper), _context.Timestamper, _context.LogManager), }; INodeKeyManager nodeKeyManager = new NodeKeyManager(_context.CryptoRandom, _context.KeyStore, keyStoreConfig, _context.LogManager); _context.NodeKey = nodeKeyManager.LoadNodeKey(); _context.OriginalSignerKey = nodeKeyManager.LoadSignerKey(); _context.Enode = new Enode(_context.NodeKey.PublicKey, IPAddress.Parse(networkConfig.ExternalIp), networkConfig.P2PPort); _context.LogManager.SetGlobalVariable("enode", _context.Enode.ToString()); }); }
public async Task Execute(CancellationToken cancellationToken) { var(_get, _set) = _api.ForInit; // why is the await Task.Run here? await Task.Run(() => { IKeyStoreConfig keyStoreConfig = _get.Config <IKeyStoreConfig>(); INetworkConfig networkConfig = _get.Config <INetworkConfig>(); AesEncrypter encrypter = new AesEncrypter( keyStoreConfig, _get.LogManager); var keyStore = _set.KeyStore = new FileKeyStore( keyStoreConfig, _get.EthereumJsonSerializer, encrypter, _get.CryptoRandom, _get.LogManager, new PrivateKeyStoreIOSettingsProvider(keyStoreConfig)); _set.Wallet = _get.Config <IInitConfig>() switch { var config when config.EnableUnsecuredDevWallet&& config.KeepDevWalletInMemory => new DevWallet(_get.Config <IWalletConfig>(), _get.LogManager), var config when config.EnableUnsecuredDevWallet&& !config.KeepDevWalletInMemory => new DevKeyStoreWallet(_get.KeyStore, _get.LogManager), _ => new ProtectedKeyStoreWallet(keyStore, new ProtectedPrivateKeyFactory(_get.CryptoRandom, _get.Timestamper), _get.Timestamper, _get.LogManager), }; new AccountUnlocker(keyStoreConfig, _get.Wallet, _get.LogManager, new KeyStorePasswordProvider(keyStoreConfig)) .UnlockAccounts(); var passwordProvider = new KeyStorePasswordProvider(keyStoreConfig) .OrReadFromConsole($"Provide password for validator account { keyStoreConfig.BlockAuthorAccount}"); INodeKeyManager nodeKeyManager = new NodeKeyManager(_get.CryptoRandom, _get.KeyStore, keyStoreConfig, _get.LogManager, passwordProvider, _get.FileSystem); var nodeKey = _set.NodeKey = nodeKeyManager.LoadNodeKey(); _set.OriginalSignerKey = nodeKeyManager.LoadSignerKey(); var enode = _set.Enode = new Enode(nodeKey.PublicKey, IPAddress.Parse(networkConfig.ExternalIp), networkConfig.P2PPort); _get.LogManager.SetGlobalVariable("enode", enode.ToString()); }, cancellationToken); }