public void MakeTransactions()
        {
            var pendingCreation = EscrowResultBusiness.ListPendingCreation();

            foreach (var pending in pendingCreation)
            {
                try
                {
                    var    from  = UserBusiness.GetWithWallet(pending.LastTransaction.UserId).Wallet.Address;
                    var    value = Math.Max(pending.OwnerTokenResult, pending.BuyerTokenResult);
                    string to;
                    if (pending.OwnerTokenResult > 0)
                    {
                        to = UserBusiness.GetOwner(pending.BuyId).Wallet.Address;
                    }
                    else
                    {
                        to = from;
                    }

                    var transactionHash = Web3.Web3Business.MakeEscrowResultTransaction(from, to, value).TransactionHash;
                    TransactionBusiness.SetTransactionHash(pending.LastTransaction, transactionHash);
                }
                catch (Exception ex)
                {
                    Logger.LogCritical(ex, $"Exception on make escrow result transaction for {pending.Id}");
                }
            }
        }
Beispiel #2
0
        public void SetTransactionHash(string email, int buyId, string transactionHash)
        {
            var user = UserBusiness.GetValidUser(email);
            var buy  = BuyBusiness.Get(buyId);

            if (buy == null || buy.UserId != user.Id || buy.ExpirationDate.HasValue)
            {
                throw new ArgumentException("Invalid purchase.");
            }

            if (buy.LastTransaction.TransactionStatus == TransactionStatus.Pending.Value && string.IsNullOrEmpty(buy.LastTransaction.TransactionHash))
            {
                TransactionBusiness.SetTransactionHash(buy.LastTransaction, transactionHash);
            }
            else if (buy.LastTransaction.TransactionStatus == TransactionStatus.Error.Value)
            {
                Create(user.Id, buyId, transactionHash);
            }
            else if (buy.LastTransaction.TransactionStatus == TransactionStatus.Pending.Value && TransactionBusiness.TransactionCanBeConsideredLost(buy.LastTransaction) &&
                     buy.LastTransaction.TransactionHash != transactionHash.ToLower().Trim())
            {
                try
                {
                    var transaction = Web3.Web3Business.CheckTransaction(buy.LastTransaction.TransactionHash);
                    throw new ArgumentException(transaction.BlockNumber.HasValue ? "Before transaction was processed." : "Before transaction is still pending.");
                }
                catch (DomainObjects.Web3.Web3Exception ex)
                {
                    if (ex.Code == 404)
                    {
                        HandleLostTransaction(buy.LastTransaction, user.Id, buyId, transactionHash);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            else
            {
                throw new ArgumentException("Invalid transaction status.");
            }
        }