private async Task UpdateColoredBalance(IObservableWallet wallet, int height, int minConfirmations) { var coloredCoins = await _blockChainProvider.GetColoredUnspentOutputsAsync(wallet.Address, minConfirmations); if (!coloredCoins.Any()) { return; } var coloredAssets = await _assetService.GetColoredAssetsAsync(); foreach (var coinsGroup in coloredCoins.GroupBy(o => o.AssetId)) { var blockchainAssetId = coinsGroup.Key.GetWif(_network).ToWif(); var coloredAsset = coloredAssets.FirstOrDefault(o => o.BlockchainAssetId == blockchainAssetId); if (coloredAsset == null) { _log.Warning($"Detected unknown colored asset deposit on address {wallet.Address}"); continue; } var balance = coinsGroup.Sum(o => o.Amount.Quantity); var walletBalanceEntity = WalletBalance.Create(wallet.Address, balance, height, coloredAsset.AssetId); await _balanceRepository.InsertOrReplaceAsync(walletBalanceEntity); } }
public async Task InsertAsync(IObservableWallet wallet) { if (!await _storage.TryInsertAsync(ObservableWalletEntity.Create(wallet))) { throw new BusinessException($"Wallet {wallet.Address} already exist", ErrorCode.EntityAlreadyExist); } }
public static ObservableWalletEntity Create(IObservableWallet source) { return(new ObservableWalletEntity { Address = source.Address, PartitionKey = GeneratePartitionKey(source.Address), RowKey = GenerateRowKey(source.Address) }); }
private async Task UpdateBalanceAsync(IObservableWallet wallet, int minConfirmations) { var lastBlock = await _blockChainProvider.GetLastBlockHeightAsync(); _log.Info("Updating balance of address", context: new { Address = wallet.Address, Height = lastBlock }); await UpdateBitcoinBalance(wallet, lastBlock, minConfirmations); await UpdateColoredBalance(wallet, lastBlock, minConfirmations); }
public async Task Insert(IObservableWallet wallet) { try { await _storage.InsertAsync(ObservableWalletEntity.Create(wallet)); } catch (StorageException e) when(e.RequestInformation.HttpStatusCode == EntityExistsHttpStatusCode) { throw new BusinessException($"Wallet {wallet.Address} already exist", ErrorCode.EntityAlreadyExist); } }
public async Task <IWalletBalance> UpdateBalance(IObservableWallet wallet) { if (wallet != null) { var balance = await _blockChainProvider.GetBalanceSatoshiFromUnspentOutputs(wallet.Address, _confirmationsSettings.MinConfirmationsToDetectOperation); var lastBlock = await _blockChainProvider.GetLastBlockHeight(); return(await UpdateBalance(wallet.Address, balance, lastBlock)); } return(null); }
private async Task <IWalletBalance> UpdateBitcoinBalance(IObservableWallet wallet, int height, int minConfirmations) { var balance = await _blockChainProvider.GetBalanceSatoshiFromUnspentOutputsAsync(wallet.Address, minConfirmations); if (balance != 0) { var walletBalanceEntity = WalletBalance.Create(wallet.Address, balance, height, Constants.Assets.Bitcoin.AssetId); await _balanceRepository.InsertOrReplaceAsync(walletBalanceEntity); return(walletBalanceEntity); } await _balanceRepository.DeleteIfExistAsync(wallet.Address, Constants.Assets.Bitcoin.AssetId); return(null); }
public async Task <IWalletBalance> UpdateBalance(IObservableWallet wallet) { if (wallet != null) { var balance = await _blockChainProvider.GetBalanceSatoshi(wallet.Address); if (balance != 0) { var walletBalanceEntity = WalletBalance.Create(wallet.Address, balance); await _balanceRepository.InsertOrReplace(walletBalanceEntity); return(walletBalanceEntity); } else { await _balanceRepository.DeleteIfExist(wallet.Address); } } return(null); }
public async Task <IWalletBalance> UpdateBalance(IObservableWallet wallet) { if (wallet != null) { var balance = await _blockChainProvider.GetBalanceSatoshiFromUnspentOutputs(wallet.Address, _confirmationsSettings.MinConfirmationsToDetectOperation); var lastBlock = await _blockChainProvider.GetLastBlockHeight(); if (balance != 0) { var walletBalanceEntity = WalletBalance.Create(wallet.Address, balance, lastBlock); await _balanceRepository.InsertOrReplace(walletBalanceEntity); return(walletBalanceEntity); } await _balanceRepository.DeleteIfExist(wallet.Address); } return(null); }
private async Task <IWalletBalance> UpdateBitcoinBalance(IObservableWallet wallet, int height, int minConfirmations) { var unspentOutputs = await _blockChainProvider.GetUnspentOutputsAsync(wallet.Address, minConfirmations); var coins = await _unspentCoinsProvider.FilterAsync(unspentOutputs); var balance = coins.Select(o => o.Amount).DefaultIfEmpty().Sum(p => p?.Satoshi ?? 0); _log.Info("Bitcoin balance retrieved from provider and filtered", context: new { Address = wallet.Address, Height = height, MinConfirmation = minConfirmations, Balance = balance }); if (balance != 0) { var walletBalanceEntity = WalletBalance.Create(wallet.Address, balance, height, Constants.Assets.Bitcoin.AssetId); await _balanceRepository.InsertOrReplaceAsync(walletBalanceEntity); return(walletBalanceEntity); } await _balanceRepository.DeleteIfExistAsync(wallet.Address, Constants.Assets.Bitcoin.AssetId); return(null); }
public async Task Insert(IObservableWallet wallet) { await _storage.InsertAsync(ObservableWalletEntity.Create(wallet)); }