Example #1
0
        /// <inheritdoc />
        public virtual async Task DeleteWalletAsync(WalletConfiguration configuration, WalletCredentials credentials)
        {
            if (Wallets.TryRemove(configuration.Id, out var wallet))
            {
                if (wallet.IsOpen)
                {
                    await wallet.CloseAsync();
                }

                wallet.Dispose();
            }
            await Wallet.DeleteWalletAsync(configuration.ToJson(), credentials.ToJson());
        }
Example #2
0
        /// <inheritdoc />
        public virtual async Task <Wallet> GetWalletAsync(WalletConfiguration configuration, WalletCredentials credentials)
        {
            var wallet = GetWalletFromCache(configuration);

            if (wallet != null)
            {
                return(wallet);
            }

            try
            {
                wallet = await Wallet.OpenWalletAsync(configuration.ToJson(), credentials.ToJson());

                Wallets.TryAdd(configuration.Id, wallet);
            }
            catch (WalletAlreadyOpenedException)
            {
                wallet = GetWalletFromCache(configuration);
            }

            return(wallet);
        }
        private async Task <Wallet> OpenWalletWithMutexAsync(WalletConfiguration configuration, WalletCredentials credentials)
        {
            Wallet wallet;

            await OpenWalletSemaphore.WaitAsync();

            try
            {
                wallet = GetWalletFromCache(configuration);

                if (wallet == null)
                {
                    wallet = await Wallet.OpenWalletAsync(configuration.ToJson(), credentials.ToJson());

                    Wallets.TryAdd(configuration.Id, wallet);
                }
            }
            finally
            {
                OpenWalletSemaphore.Release();
            }

            return(wallet);
        }
Example #4
0
 /// <inheritdoc />
 public virtual async Task CreateWalletAsync(WalletConfiguration configuration, WalletCredentials credentials)
 {
     await Wallet.CreateWalletAsync(configuration.ToJson(), credentials.ToJson());
 }