Beispiel #1
0
 public IActionResult Post([FromBody] Pool pool)
 {
     try
     {
         var poolRepository = new PoolRepository();
         poolRepository.Add(pool);
         return(Ok());
     }
     catch (Exception e)
     {
         AppSettings.Logger.Error($"Unable to connect to the database at: {AppSettings.Logger}");
         AppSettings.Logger.Error($"The error was: {e.Message}");
         return(StatusCode(500));
     }
 }
Beispiel #2
0
        private void ShowOperationResponse(EventSourceMessageEventArgs op)
        {
            if (op.Event == "open")
            {
                return;
            }
            var or = JsonSingleton.GetInstance <OperationResponse>(op.Message);

            SavePagingToken(or.PagingToken);

            if (or.GetType() != typeof(PaymentOperationResponse))
            {
                return;
            }
            var payment = (PaymentOperationResponse)or;

            if (payment.From.AccountId == _keyPair.AccountId)
            {
                return;
            }

            AppSettings.Logger.Information(
                $@"Transaction received: Id: {or.Id}, Source: {or.SourceAccount.AccountId}, Type: {or.Type}");

            // Need to make sure the payment was at least $10 worth of XRP
            // If it isn't enough, refund the money minus a small transaction fee.
            var paymentAmount = decimal.Parse(payment.Amount);

            if (GetMinimumLumensRequired() > paymentAmount)
            {
                AppSettings.Logger.Information(
                    $"Received underfunded pament of {paymentAmount} lumens from {payment.From.AccountId}! Refunding...");

                SendPayment(
                    payment.From.AccountId,
                    (paymentAmount - 0.0000200m).ToString("0.0000000"),
                    "Err: http://bit.ly/2FW9r0m");

                return;
            }

            AppSettings.Logger.Information("Connecting to the database to get the availale pool...");
            var poolId = _poolRepository.GetAvailablePoolByPayer(payment.From.AccountId);

            if (poolId == 0)
            {
                poolId = _poolRepository.Add(new Pool
                {
                    CreateDate = DateTime.Now
                });

                AppSettings.Logger.Information($"Created new Pool {poolId}.");
            }

            var celebId = _poolRepository.GetAvailablePoolCelebrity(poolId);

            var ticketId = _ticketRepository.Add(new Ticket
            {
                PlayerAddress = payment.From.AccountId,
                CelebrityId   = celebId,
                PoolId        = poolId
            });

            AppSettings.Logger.Information(
                "Created a new Ticket: \n " +
                $"Ticket ID: {ticketId} \n " +
                $"Player Address: {payment.From.AccountId} \n" +
                $"Celebrity ID: {celebId} \n" +
                $"Pool ID: {poolId}");

            SendPayment(
                or.SourceAccount.AccountId,
                "0.0000001",
                $"Raffle Ticket Id: {ticketId}");
        }