Beispiel #1
0
        public static async Task PaymentProcessor(DiscordClient client)
        {
            var db    = new SqliteDataAccess();
            var comms = new Communication();

            while (true)
            {
                //every 2 minutes we take 1 payment to process.
                var sw1 = Stopwatch.StartNew();
                for (int ix = 0; ix < 120; ++ix)
                {
                    Thread.Sleep(1000);
                }
                sw1.Stop();
                Console.WriteLine("Sleep: {0}", sw1.ElapsedMilliseconds);

                PaymentModel paymentprofile = await db.CheckPaymentQueue();

                TipModel profile = await db.LoadTipProfileForBalance(paymentprofile.DiscordUserId.ToString());

                if (paymentprofile.Id != 0)
                {
                    var ncg = new NCG();
                    if (ncg.NCGGold("0xa49d64c31A2594e8Fb452238C9a03beFD1119963") == null)
                    {
                        //Bot's Snapshot is down, we can't do any transfers.
                        Console.WriteLine("Down");
                    }
                    else
                    {
                        var txid = await ncg.SendNCG(paymentprofile.Key, paymentprofile.Amount);

                        if (txid == null)
                        {
                            //Something made the payment fail, maybe the snapsshot is down. Let's keep it here for a re-try.
                            //This logic can be expanded later to try 3~ times before it puts the transaction "on-hold" until someone reviews it. For now it will keep trying.
                            await db.DumpPayment("RedeemFail", paymentprofile, paymentprofile, paymentprofile.Amount, txid);
                        }
                        else
                        {
                            await db.RemoveWithdrawl(paymentprofile);

                            Console.WriteLine("Payment Succesful");
                            await comms.RedeemSuccess(client, paymentprofile, txid);

                            await db.DumpPayment("RedeemSuccesful", paymentprofile, paymentprofile, paymentprofile.Amount, txid);
                        }
                    }
                }
            }
        }