public async Task BroadCastTransactionAsync(Guid operationId, Transaction tx)
        {
            var operation = await _operationMetaRepository.GetAsync(operationId);

            if (operation == null)
            {
                throw new BusinessException("Operation not found", ErrorCode.BadInputParameter);
            }

            if (await _operationEventRepository.ExistAsync(operationId, OperationEventType.Broadcasted))
            {
                throw new BusinessException("Transaction already brodcasted", ErrorCode.TransactionAlreadyBroadcasted);
            }
            var hash = tx.GetHash().ToString();
            await _transactionBlobStorage.AddOrReplaceTransactionAsync(operationId, hash,
                                                                       TransactionBlobType.BeforeBroadcast, tx.ToHex());

            var lastBlockHeight = await _blockChainProvider.GetLastBlockHeightAsync();

            await _blockChainProvider.BroadCastTransactionAsync(tx);

            await _observableOperationRepository.InsertOrReplaceAsync(ObervableOperation.Create(operation,
                                                                                                BroadcastStatus.InProgress, hash, lastBlockHeight));

            await _unconfirmedTransactionRepository.InsertOrReplaceAsync(
                UnconfirmedTransaction.Create(operationId, hash));

            await _transactionOutputsService.CompleteTxOutputs(operationId, tx);

            await _operationEventRepository.InsertIfNotExistAsync(OperationEvent.Create(operationId,
                                                                                        OperationEventType.Broadcasted));
        }
        private async Task CheckUnconfirmedTransaction(IUnconfirmedTransaction unconfirmedTransaction)
        {
            var operationMeta = await _operationMetaRepository.GetAsync(unconfirmedTransaction.OperationId);

            if (operationMeta == null)
            {
                _log.Warning(unconfirmedTransaction.ToJson(), "OperationMeta not found");

                return;
            }

            var confirmationCount = await _blockChainProvider.GetTxConfirmationCountAsync(unconfirmedTransaction.TxHash);

            var isCompleted = confirmationCount >= _confirmationsSettings.MinConfirmationsToDetectOperation;

            ;
            if (isCompleted)
            {
                //Force update balances
                var fromAddressUpdatedBalance = await operationMeta.Inputs.SelectAsync(async o => await _walletBalanceService.UpdateBtcBalanceAsync(o.Address,
                                                                                                                                                    _confirmationsSettings.MinConfirmationsToDetectOperation))
                ;

                var toAddressUpdatedBalance = await operationMeta.Outputs.SelectAsync(async o =>
                                                                                      await _walletBalanceService.UpdateBtcBalanceAsync(o.Address,
                                                                                                                                        _confirmationsSettings.MinConfirmationsToDetectOperation));


                var operationCompletedLoggingContext = new
                {
                    unconfirmedTransaction.OperationId,
                    unconfirmedTransaction.TxHash,
                    fromAddressUpdatedBalance,
                    toAddressUpdatedBalance
                };

                await _operationEventRepository.InsertIfNotExistAsync(OperationEvent.Create(
                                                                          unconfirmedTransaction.OperationId,
                                                                          OperationEventType.DetectedOnBlockChain, operationCompletedLoggingContext));

                _log.Info(operationCompletedLoggingContext.ToJson(), "Operation completed");


                await _unconfirmedTransactionRepository.DeleteIfExistAsync(unconfirmedTransaction.OperationId);
            }

            var status = isCompleted
                ? BroadcastStatus.Completed
                : BroadcastStatus.InProgress;

            var lastBlockHeight = await _blockChainProvider.GetLastBlockHeightAsync();

            await _observableOperationRepository.InsertOrReplaceAsync(ObervableOperation.Create(operationMeta, status,
                                                                                                unconfirmedTransaction.TxHash,
                                                                                                lastBlockHeight));
        }