Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        private async Task <IWalletBalance> UpdateBalance(string address, long balance, int lastBlock)
        {
            if (balance != 0)
            {
                var walletBalanceEntity = WalletBalance.Create(address, balance, lastBlock);
                await _balanceRepository.InsertOrReplace(walletBalanceEntity);

                return(walletBalanceEntity);
            }

            await _balanceRepository.DeleteIfExist(address);

            return(null);
        }
 private async Task UpdateBalanceInRepo(int lastBlock, string address, decimal balance, string assetId)
 {
     if (balance != 0)
     {
         _log.Info($"[{lastBlock}] Detected balance on {address}: {balance} {assetId}");
         await _walletBalanceRepository.InsertOrReplace(
             WalletBalance.Create(address,
                                  balance: balance,
                                  assetId: assetId,
                                  updatedAtBlock: lastBlock));
     }
     else
     {
         await _walletBalanceRepository.DeleteIfExist(address, assetId);
     }
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
        }