public async Task Gold(CommandContext ctx, [Description("This is your PUBLIC Address")] string publickey = "") { //Debug var username = ctx.Member.Username; var eyes = DiscordEmoji.FromName(ctx.Client, ":eyes:"); await ctx.Message.CreateReactionAsync(eyes).ConfigureAwait(false); var oldmessage = ctx.Message; Console.WriteLine("User: "******" requested NCG value against key: " + publickey); //debug end var ncg = new NCG(); string result = ncg.NCGGold(publickey); Console.WriteLine(result); var comms = new Communication(); if (result == null) { if (ncg.NCGGold("0xa49d64c31A2594e8Fb452238C9a03beFD1119963") == null) { await comms.SnapshotDown(ctx, oldmessage); } else { await comms.GenericError(ctx, oldmessage, username); } } else { await comms.NormalNCG(ctx, oldmessage, username, result); } }
public async Task SetProfileKey(CommandContext ctx, [Description("This is what you want to call your profile")] string alias, [Description("This is your PUBLIC Address")] string publickey) { Console.WriteLine("SetProfileReceived"); ulong userid = ctx.Member.Id; var username = ctx.Member.DisplayName; var eyes = DiscordEmoji.FromName(ctx.Client, ":eyes:"); var comms = new Communication(); var setup = new Setup(); var oldmessage = ctx.Message; bool state = setup.SetProfileNew(publickey, alias, userid); await ctx.Message.CreateReactionAsync(eyes).ConfigureAwait(false); if (state) { await comms.SetProfile(ctx, oldmessage, username, alias, publickey); } else { var ncg = new NCG(); if (ncg.NCGGold("0xa49d64c31A2594e8Fb452238C9a03beFD1119963") == null) { await comms.SnapshotDown(ctx, oldmessage); } else { await comms.GenericError(ctx, oldmessage, username); } } }
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); } } } } }
public static async Task <bool> QueueTips(TipModel profile, string key, float amount, ulong userid) { //checks how much NCG is available - the amount of Tips already provided to users. //Available balance = Total NCG - Amount of Tops already given. var ncg = new NCG(); var db = new SqliteDataAccess(); string botaccount = "0x083B1ad95AF96B754E055384B260a3024d02c7ba"; //let's do every possible check in existance. string balance = ncg.NCGGold(botaccount); Console.WriteLine(balance); float floatPot = float.Parse(balance.ToString()); if (profile.Balance < amount) { return(false); } if (amount > floatPot) { return(false); } //Insert Anti-Exploit Function here. ///////////////////////////////////// //Everything Looks fine, let's go ahead. // float transferamount = amount; amount = profile.Balance - amount; bool check = await db.UpdateTipbalance(profile, amount); if (check) { bool check2 = await db.QueueWithdraw(profile, userid, key, transferamount, 1); if (check2) { await db.DumpTransfer("PaymentQueued", profile, profile, transferamount); return(true); } else { await db.UpdateTipbalance(profile, amount + amount); return(false); } } return(false); }
public static async Task <float> AdminBalanceCheck() { //checks how much NCG is available - the amount of Tips already provided to users. //Available balance = Total NCG - Amount of Tops already given. string botaccount = "0x083B1ad95AF96B754E055384B260a3024d02c7ba"; var ncg = new NCG(); var db = new SqliteDataAccess(); string balance = ncg.NCGGold(botaccount); var usedBalance = db.AdminBalance(); float result = float.Parse(balance) - float.Parse(usedBalance.Result); return(result); }
public async Task GoldBeforeHash(CommandContext ctx, [Description("This is your PUBLIC Address")] string publickey, [Description("Hash of the block you want to check against")] string hash) { //Debug var username = ctx.Member.Username; Console.WriteLine("User: "******" requested NCG value against key: " + publickey + " with hash " + hash + "."); //debug end var ncg = new NCG(); string result = ncg.NCGGoldBeforeHash(publickey, hash); if (result == "false") { await ctx.Channel.SendMessageAsync(username + ", I'm sorry, something went wrong.\nPlease ensure that you provided the public key on your request. \nIf this error persists please contact the developer of this bot").ConfigureAwait(false); } else { await ctx.Channel.SendMessageAsync(username + ", The requested public key had **" + result + "** NCG before the requested hash, according to my snapshot.").ConfigureAwait(false); } }
public async Task GoldProfile(CommandContext ctx, [Description("This is what you called your profile")] string alias = "givemeall") { var username = ctx.Member.DisplayName; var userid = ctx.Member.Id; var eyes = DiscordEmoji.FromName(ctx.Client, ":eyes:"); await ctx.Message.CreateReactionAsync(eyes).ConfigureAwait(false); var oldmessage = ctx.Message; SqliteDataAccess sqli = new SqliteDataAccess(); var ncg = new NCG(); //Debug Console.WriteLine("User: "******" requested NCG value against profile: " + username); //debug end if (alias == "givemeall") { ProfileModel[] array = await sqli.LoadProfileALL(ctx.User.Id, alias); int count = array.Length; int y = 1; List <DiscordMessage> messagesall = new List <DiscordMessage>(); foreach (var entry in array) { var result = await ncg.NCGProfileNewAsync(entry.PublicKey); var comms = new Communication(); if (result == null) { //snapshot down? if (ncg.NCGGold("0xa49d64c31A2594e8Fb452238C9a03beFD1119963") == null) { //f**k snapshot is down. await comms.SnapshotDown(ctx, oldmessage); } else { await comms.GenericError(ctx, oldmessage, username); } } else { bool state = await sqli.UpdateProfile(userid, entry.alias, result); if (state) { float increase = float.Parse(result) - entry.Value; messagesall = await comms.ProfileNCGALL(ctx, oldmessage, username, result, increase, entry.alias, count, y, messagesall); } else { await comms.GenericError(ctx, oldmessage, username); } } y++; } } else { ProfileModel profile = await sqli.LoadProfile(userid, alias); var result = await ncg.NCGProfileNewAsync(profile.PublicKey); var comms = new Communication(); if (result == null) { //snapshot down? if (ncg.NCGGold("0xa49d64c31A2594e8Fb452238C9a03beFD1119963") == null) { //f**k snapshot is down. await comms.SnapshotDown(ctx, oldmessage); } else { await comms.GenericError(ctx, oldmessage, username); } } else { bool state = await sqli.UpdateProfile(userid, alias, result); if (state) { float increase = float.Parse(result) - profile.Value; await comms.ProfileNCG(ctx, oldmessage, username, result, increase, alias); } else { await comms.GenericError(ctx, oldmessage, username); } } } }
public static async Task <Enum> TipsSystemAsync(ulong discordid, ulong mentionid, float amount) { //Let's Check if profile exists before we do anything var db = new SqliteDataAccess(); var userProfile = new TipModel(); var mentionProfile = new TipModel(); userProfile = await ProfileExistsNew(discordid); mentionProfile = await ProfileExistsNew(mentionid); if (userProfile.Role == "Admin") { ///Soft Tip Cap based on available ncg - already given out tips. /// var ncg = new NCG(); var balance = AdminBalanceCheck(); // Needs to check that Total balance of all users is less than Balance if (balance.Result < amount) { return(Status.NEB); //Not Enough Balance } else if (userProfile.Id == mentionProfile.Id) { return(Status.PASS); //Can't Tip yourself. } else { //balance we are going to attribute to the receiver float mentionbalance = mentionProfile.Balance + amount; //verify that we managed to update the receiver. bool check = await db.UpdateTipbalance(mentionProfile, mentionbalance); if (check) { //Let's log the transaction. bool done2 = await db.DumpTransfer("AdminTip", userProfile, mentionProfile, amount); if (done2) { return(Status.ACOMPLETE); } else { //we should never see this. return(Status.WTF); } } else { return(Status.FAIL); } } } else { ///Hard Tip Cap / NON-Admin Request /// if (userProfile.Balance < amount) { return(Status.NEB); //Not Enough Balance } else if (userProfile.Id == mentionProfile.Id) { return(Status.PASS); //Can't Tip yourself. } else { float userbalance = userProfile.Balance - amount; float mentionblanace = mentionProfile.Balance + amount; //verify that we managed to update the senders's balance bool check = await db.UpdateTipbalance(userProfile, userbalance); if (check) { //now let's add the tip to the sender's balance. bool done = await db.UpdateTipbalance(mentionProfile, mentionblanace); if (done) { //All went well, let's log transaction. bool done2 = await db.DumpTransfer("UserTip", userProfile, mentionProfile, amount); if (done2) { return(Status.COMPLETE); } else { return(Status.WTF); } } else { //shit happened, revert the transaction, give the tip back to the sender and log failure. await db.UpdateTipbalance(userProfile, mentionblanace - amount); await db.DumpTransfer("REVERT", userProfile, mentionProfile, amount); return(Status.FAIL); } } return(Status.FAIL); } } }