public async Task <bool> CheckExchange(Exchange exchange)
        {
            bool changed = false;

            try
            {
                decimal addedValue = 0;

                var lastHash = await AccountPoolService.GetLastTransactionHash(exchange.PayWalletAddress);

                var status = await TransactionManager.GetTransactionsByAddress(exchange.PayWalletAddress);

                if (status == null)
                {
                    return(changed);
                }

                var lastRecord = status.Result.OrderByDescending(x => x.BlockNumber).FirstOrDefault();

                if (lastRecord == null || lastRecord.Hash == lastHash)
                {
                    return(changed);
                }

                if (lastRecord.IsError == 1)
                {
                    if (exchange.InTxStatus != PaymentStatus.Fail)
                    {
                        exchange.InTxStatus = PaymentStatus.Fail;
                        changed             = true;
                    }
                }
                else
                {
                    if (long.TryParse(lastRecord.Value, out long val))
                    {
                        addedValue = EthereumLib.Converter.AtomicToDecimal(val);
                    }

                    if (exchange.InTxStatus != PaymentStatus.Received ||
                        exchange.ReceivedConfirmations != (int)lastRecord.Confirmations ||
                        exchange.ReceivedAmount != addedValue)
                    {
                        exchange.InTxStatus            = PaymentStatus.Received;
                        exchange.ReceivedConfirmations = (int)lastRecord.Confirmations;
                        exchange.ReceivedAmount        = addedValue;
                    }
                }

                await AccountPoolService.SetInactive(exchange.PayWalletAddress, lastRecord.Hash, addedValue);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Ethereum Check Exchange failed");
                throw;
            }
            return(changed);
        }
Beispiel #2
0
        public async Task CheckPayment(Payment payment)
        {
            try
            {
                decimal addedBalance = 0;

                var lastHash = await AccountPoolService.GetLastTransactionHash(payment.PayWalletAddress);

                var status = await TransactionManager.GetTransactionsByAddress(payment.PayWalletAddress);

                if (status == null)
                {
                    return;
                }

                var lastRecord = status.Result.OrderByDescending(x => x.BlockNumber).FirstOrDefault();

                if (lastRecord == null || lastRecord.Hash == lastHash)
                {
                    return;
                }

                if (lastRecord.IsError == 1)
                {
                    payment.Status = Graft.Infrastructure.PaymentStatus.Fail;
                }
                else
                {
                    payment.Status = Graft.Infrastructure.PaymentStatus.Received;
                    payment.ReceivedConfirmations = (int)lastRecord.Confirmations;
                    if (long.TryParse(lastRecord.Value, out long val))
                    {
                        addedBalance           = EthereumLib.Converter.AtomicToDecimal(val);
                        payment.ReceivedAmount = addedBalance;
                    }
                }

                await AccountPoolService.SetInactive(payment.PayWalletAddress, lastRecord.Hash, addedBalance);
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Etherium Check Payment failed");
                throw;
            }
        }