private void UnlockAccount(string address, bool timeout = true) { var accounts = _keyStore.ListAccounts(); if (accounts == null || accounts.Count <= 0) { _screenManager.PrintError("error: the account '" + address + "' does not exist."); return; } if (!accounts.Contains(address)) { _screenManager.PrintError("account does not exist!"); return; } var password = _screenManager.AskInvisible("password: "******"incorrect password!"); } else if (tryOpen == AElfKeyStore.Errors.AccountAlreadyUnlocked) { _screenManager.PrintError("account already unlocked!"); } else if (tryOpen == AElfKeyStore.Errors.None) { _screenManager.PrintLine("account successfully unlocked!"); } }
public async Task Account_Create_And_Open() { var keyPair = await _keyStore.CreateAsync("123", "AELF"); keyPair.ShouldNotBe(null); _keyStore.ListAccountsAsync().Result.Count.ShouldBeGreaterThanOrEqualTo(1); var address = Address.FromPublicKey(keyPair.PublicKey); var addString = address.GetFormatted(); address.ShouldNotBe(null); //Open account var errResult = await _keyStore.OpenAsync(addString, "12", true); errResult.ShouldBe(AElfKeyStore.Errors.WrongPassword); errResult = await _keyStore.OpenAsync(addString, "123"); errResult.ShouldBe(AElfKeyStore.Errors.None); errResult = await _keyStore.OpenAsync(addString, "123"); errResult.ShouldBe(AElfKeyStore.Errors.AccountAlreadyUnlocked); errResult = await _keyStore.OpenAsync(addString, "123", false); errResult.ShouldBe(AElfKeyStore.Errors.AccountAlreadyUnlocked); Directory.Delete("/tmp/keys", true); await Should.ThrowAsync <KeyStoreNotFoundException>(() => _keyStore.ReadKeyPairAsync(addString + "_fake", "123")); }
public CommandInfo UnlockAccount(string address, string password = "", string notimeout = "") { var result = new CommandInfo("account list", "account"); if (password == "") { password = AskInvisible("password:"******"{0} {1} {2}", address, password, notimeout); var accounts = _keyStore.ListAccounts(); if (accounts == null || accounts.Count == 0) { result.ErrorMsg.Add("Error: the account '" + address + "' does not exist."); return(result); } if (!accounts.Contains(address)) { result.ErrorMsg.Add("Error: the account '" + address + "' does not exist."); return(result); } bool timeout = (notimeout == "") ? true : false; var tryOpen = _keyStore.OpenAsync(address, password, timeout); if (tryOpen == AElfKeyStore.Errors.WrongPassword) { result.ErrorMsg.Add("Error: incorrect password!"); } else if (tryOpen == AElfKeyStore.Errors.AccountAlreadyUnlocked) { result.InfoMsg.Add("Account already unlocked!"); result.Result = true; } else if (tryOpen == AElfKeyStore.Errors.None) { result.InfoMsg.Add("Account successfully unlocked!"); result.Result = true; } return(result); }
public void Init(ContainerBuilder builder) { ECKeyPair nodeKey = null; if (!string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccount)) { try { var ks = new AElfKeyStore(ApplicationHelpers.GetDefaultConfigPath()); var pass = string.IsNullOrWhiteSpace(NodeConfig.Instance.NodeAccountPassword) ? AskInvisible(NodeConfig.Instance.NodeAccount) : NodeConfig.Instance.NodeAccountPassword; ks.OpenAsync(NodeConfig.Instance.NodeAccount, pass, false); NodeConfig.Instance.NodeAccountPassword = pass; nodeKey = ks.GetAccountKeyPair(NodeConfig.Instance.NodeAccount); if (nodeKey == null) { Console.WriteLine("Load keystore failed"); } } catch (Exception e) { throw new Exception("Load keystore failed"); } } TransactionPoolConfig.Instance.EcKeyPair = nodeKey; NetworkConfig.Instance.EcKeyPair = nodeKey; builder.RegisterModule(new NodeAutofacModule()); }