Example #1
0
        protected async Task <bool> UnlockAccount(KeyStore account, string password, KeyStoreTypes keyStoreType)
        {
            if (account == null)
            {
                return(false);
            }

            if (account.KeyStoreType != keyStoreType)
            {
                return(false);
            }

            try
            {
                if (await account.DecryptKeyAsync(password, false))
                {
                    Log.Trace($"Account unlocked: {account.Name}, id {account.AccountId}, chainid {account.ChainId}, keyindex {account.KeyIndex}.", this);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Log.IgnoreException(ex, this);
            }
            return(false);
        }
Example #2
0
        protected List <T> GetStoredAccounts <T>(KeyStoreTypes keyStoreType, int chainId) where T : KeyStore
        {
            var result = new List <T>();
            var path   = Path.Combine(_accountsPath, keyStoreType.ToString().ToLower());
            var files  = _storage.GetFiles(path, "*.*");

            foreach (var file in files)
            {
                try
                {
                    var ext = file.Extension;
                    if (ext != ".keystore")
                    {
                        continue;
                    }

                    var store = KeyStore.Restore <T>(_storage.ReadFileText(Path.Combine(path, file.Name)));
                    if (chainId > 0)
                    {
                        if (store.ChainId != chainId)
                        {
                            continue;
                        }
                    }
                    if (store.KeyStoreType != keyStoreType)
                    {
                        continue;
                    }

                    result.Add(store);
                }
                catch (Exception ex)
                {
                    Log.IgnoreException(ex, this);
                }
            }

            return(result);
        }