diff --git a/Traffic_Award/Program.cs b/Traffic_Award/Program.cs index 8492945..3bc9352 100644 --- a/Traffic_Award/Program.cs +++ b/Traffic_Award/Program.cs @@ -84,12 +84,15 @@ class Program static string getpoolwallets = configuration["getpoolwallets"]; static string geteligibility = configuration["geteligibility"]; static string getexchangetrans = configuration["getexchangetrans"]; + static string getexchangetransamt = configuration["getexchangetransamt"]; public static string getrecipients = configuration["getrecipients"]; static string checkfortable = configuration["checkfortable"]; static string createexchangetable = configuration["createexchangetable"]; static string createtranstable = configuration["createtranstable"]; static string createsummarytable = configuration["createsummarytable"]; static string getsummarytable = configuration["getsummarydata"]; + static string getnewbmfmembers = configuration["getnewbmfmembers"]; + static string getbmfdonations = configuration["getbmfdonations"]; public static string summarytableupsert = configuration["summarytableupsert"]; public static double startdayinterval = double.Parse(configuration["startdayinterval"]); public static double enddayinterval = double.Parse(configuration["enddayinterval"]); @@ -119,13 +122,15 @@ class Program public static List exchangewallets = new List{ poloid, bittid, liveid }; public static int transactionaward = int.Parse(configuration["transactionaward"]); public static int exchangeaward = int.Parse(configuration["exchangeaward"]); + public static int bmfaward = int.Parse(configuration["bmfaward"]); public static List summary = new List(); + static List examt = new List(); static string displaystr = null; #endregion #region Calculating timestamp - public static DateTime burstepoch = new DateTime(2014, 08, 11, 2, 0, 0); + public static DateTime burstepoch = new DateTime(2014, 08, 11, 2, 0, 0, DateTimeKind.Utc); public static DateTime startdate = DateTime.Now.AddDays(startdayinterval); public static DateTime enddate = DateTime.Now.AddDays(enddayinterval); public static string startdatetime = configuration["startdatetime"]; @@ -158,42 +163,44 @@ static void RunSetup() Console.WriteLine("Press any key to continue"); Console.ReadKey(true); } - //Console.WriteLine(Environment.NewLine + Environment.NewLine + "Running initial setup...this may take a moment." + Environment.NewLine + Environment.NewLine); + + #region Check for schema queryParameters.Add("@table_name", "exchange_wallets"); queryParameters.Add("@db_name", db_name); if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true))) { - Utilities.TestDBUpdate(createexchangetable, queryParameters, true); + Utilities.DBUpdate(createexchangetable, queryParameters, true); } queryParameters.Add("@table_name", "all_weekly_trans"); queryParameters.Add("@db_name", db_name); if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true))) { - Utilities.TestDBUpdate(createtranstable, queryParameters, true); + Utilities.DBUpdate(createtranstable, queryParameters, true); } queryParameters.Add("@table_name", "raffle_summary"); queryParameters.Add("@db_name", db_name); if (string.IsNullOrEmpty(Utilities.GetWinnerData(checkfortable, queryParameters, true))) { - Utilities.TestDBUpdate(createsummarytable, queryParameters, true); + Utilities.DBUpdate(createsummarytable, queryParameters, true); } #endregion + #region Clearing testdb tables - Utilities.TestDBUpdate("TRUNCATE TABLE exchange_wallets;", queryParameters, true); - Utilities.TestDBUpdate("TRUNCATE TABLE all_weekly_trans;", queryParameters, true); - Utilities.TestDBUpdate("TRUNCATE TABLE raffle_summary;", queryParameters, true); + Utilities.DBUpdate("TRUNCATE TABLE exchange_wallets;", queryParameters, true); + Utilities.DBUpdate("TRUNCATE TABLE all_weekly_trans;", queryParameters, true); + Utilities.DBUpdate("TRUNCATE TABLE raffle_summary;", queryParameters, true); #endregion + #region Capturing exchange wallets - //Console.WriteLine("Adding except for exchange wallets."); queryParameters.Add("@poloid", poloid); queryParameters.Add("@bittid", bittid); queryParameters.Add("@brsid", brsid); queryParameters.Add("@mortid", mortid); queryParameters.Add("@liveid", liveid); - Utilities.TestDBUpdate(allexchangewallets, queryParameters, false); + Utilities.DBUpdate(allexchangewallets, queryParameters, false); #endregion @@ -203,7 +210,6 @@ static void RunSetup() queryParameters.Add("@burstamount", burstamount); queryParameters.Add("@feeamount", feeamount); queryParameters.Add("@minfeeamount", minfeeamount); - //Console.WriteLine("Querying Burst blockchain for all transactions over " + burstamount + " planck between " + starttimestamp + " and " + endtimestamp + Environment.NewLine); using (DataTable dt = Utilities.DataTableQuery(getalltransactions, queryParameters, true)) { sb.Append("INSERT INTO all_weekly_trans (amount, fee, recipient_id, sender_id, timestamp, trans_id) VALUES "); @@ -214,7 +220,7 @@ static void RunSetup() sb.Append(string.Join(",", alltrans)).Append(";"); if (alltrans.Count > 0) { - Utilities.TestDBUpdate(sb.ToString(), queryParameters, true); + Utilities.DBUpdate(sb.ToString(), queryParameters, true); } else { @@ -286,15 +292,17 @@ static async Task RunAsync() } } while (string.IsNullOrEmpty(mySelection)); RunSetup(); + rafflemembers.Clear(); #endregion + Console.WriteLine("If you hang here, there may be a problem with your database connection."); Console.WriteLine("Close any open connections or restart the application."); + #region Collect Pool wallets if (removePoolAddresses) { - //Console.WriteLine("Collecting pool wallets..." + Environment.NewLine); using (DataTable dt = Utilities.DataTableQuery(getpoolwallets, queryParameters, true)) { foreach (DataRow row in dt.Rows) @@ -308,9 +316,48 @@ static async Task RunAsync() #endregion + #region Capturing qualifying BMF donations + queryParameters.Add("@starttime", starttimestamp); + queryParameters.Add("@endtime", endtimestamp); + queryParameters.Add("@bmfid", bmfid); + queryParameters.Add("@bmfaward", bmfaward); + queryParameters.Add("@burstamount", burstamount); + queryParameters.Add("@bmfpid", bmfpid); + queryParameters.Add("@devid", devid); + Utilities.DBUpdate(getbmfdonations, queryParameters, true); + using (DataTable dt = Utilities.DataTableQuery("SELECT * from raffle_summary where bmf_entries>0;", queryParameters, true)) + { + foreach (DataRow row in dt.Rows) + { + for (int i = 0; i < bmfaward; i++) + { + rafflemembers.Add(row[0].ToString()); + } + } + } + #endregion + + + #region Capturing qualifying BMF pool members + //queryParameters.Add("@starttime", starttimestamp); + //queryParameters.Add("@endtime", endtimestamp); + //queryParameters.Add("@bmfpid", bmfpid); + //queryParameters.Add("@bmfaward", bmfaward); + //Utilities.DBUpdate(getnewbmfmembers, queryParameters, true); + //using (DataTable dt = Utilities.DataTableQuery("SELECT * FROM raffle_summary WHERE bmf_entries>0;", queryParameters, true)) + //{ + // foreach (DataRow row in dt.Rows) + // { + // for (int i = 0; i < bmfaward; i++) + // { + // rafflemembers.Add(row[0].ToString()); + // } + // } + //} + #endregion + + #region Capturing qualifying transactions - rafflemembers.Clear(); - //Console.WriteLine("Querying blockchain to find qualifying transactions for the raffle" + Environment.NewLine); excheck.Clear(); queryParameters.Add("@poloid", poloid); queryParameters.Add("@bittid", bittid); @@ -333,7 +380,6 @@ static async Task RunAsync() #region Capture qualifying exchange purchases - //Console.WriteLine("Querying blockchain to find qualifying exchange purchases" + Environment.NewLine); excheck.Clear(); queryParameters.Add("@starttime", starttimestamp); queryParameters.Add("@endtime", endtimestamp); @@ -342,11 +388,28 @@ static async Task RunAsync() queryParameters.Add("@bittid", bittid); queryParameters.Add("@devid", devid); queryParameters.Add("@liveid", liveid); + using (DataTable dt = Utilities.DataTableQuery(getexchangetransamt, queryParameters, true)) + { + foreach (DataRow row in dt.Rows) + { + examt.Add(row[0].ToString()); + } + } + queryParameters.Add("@starttime", starttimestamp); + queryParameters.Add("@endtime", endtimestamp); + queryParameters.Add("@exchangemin", exchangemin); + queryParameters.Add("@poloid", poloid); + queryParameters.Add("@bittid", bittid); + queryParameters.Add("@devid", devid); + queryParameters.Add("@liveid", liveid); using (DataTable dt = Utilities.DataTableQuery(getexchangetrans, queryParameters, true)) { foreach (DataRow row in dt.Rows) { - excheck.Add(new ExCheck { recipientid = row[0].ToString(), penalize = false, penalid = -1 }); + if (examt.Contains(row[0].ToString())) + { + excheck.Add(new ExCheck { recipientid = row[0].ToString(), penalize = false, penalid = -1 }); + } } } Console.WriteLine("Checking all " + excheck.Count + " exchange purchases for sell activity. This may take a moment." + Environment.NewLine); @@ -380,7 +443,7 @@ static async Task RunAsync() { queryParameters.Add("@wallet_address", address.Value); queryParameters.Add("@wallet_id", address.Key); - Utilities.TestDBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true); + Utilities.DBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true); do { index = rafflemembers.IndexOf(address.Key); @@ -415,7 +478,7 @@ static async Task RunAsync() { queryParameters.Add("@wallet_address", address.Value); queryParameters.Add("@wallet_id", address.Key); - Utilities.TestDBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true); + Utilities.DBUpdate("UPDATE raffle_summary SET wallet_address=@wallet_address WHERE wallet_id=@wallet_id;", Program.queryParameters, true); } int reducecount = -1; var distinctlist = from item in rafflemembers group item by item into grp select new { member = grp.Key, count = grp.Count() }; @@ -449,20 +512,22 @@ static async Task RunAsync() queryParameters.Add("@total_entries", member.count); } queryParameters.Add("@wallet_address", member.member); - Utilities.TestDBUpdate("UPDATE raffle_summary SET total_entries=@total_entries WHERE wallet_address=@wallet_address;", Program.queryParameters, true); + Utilities.DBUpdate("UPDATE raffle_summary SET total_entries=@total_entries WHERE wallet_address=@wallet_address;", Program.queryParameters, true); } if (reducecount >= 0) { Console.WriteLine(Environment.NewLine + "There are now a total of " + rafflemembers.Count + " raffle entries." + Environment.NewLine); } sb.Clear(); - //distinctlist = from item in rafflemembers group item by item into grp select new { member = grp.Key, count = grp.Count() }; - using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc;", queryParameters, true)) + using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, bmf_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc;", queryParameters, true)) + //using (DataTable dt = Utilities.DataTableQuery("SELECT wallet_address, total_entries, exchange_entries, trans_entries, reductions FROM raffle_summary order by total_entries desc, wallet_address;", queryParameters, true)) { - sb.Append("Burst Address,Total Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine); + sb.Append("Burst Address,Total Entries,BMF Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine); + //sb.Append("Burst Address,Total Entries,Exchange Entries,Transaction Entries,Reductions").Append(Environment.NewLine); foreach (DataRow row in dt.Rows) { - sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(Environment.NewLine); + sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(",").Append(row[5].ToString()).Append(Environment.NewLine); + //sb.Append(row[0].ToString()).Append(",").Append(row[1].ToString()).Append(",").Append(row[2].ToString()).Append(",").Append(row[3].ToString()).Append(",").Append(row[4].ToString()).Append(Environment.NewLine); } } try diff --git a/Traffic_Award/Utilitiescs.cs b/Traffic_Award/Utilitiescs.cs index e7e1fa4..3053358 100644 --- a/Traffic_Award/Utilitiescs.cs +++ b/Traffic_Award/Utilitiescs.cs @@ -151,7 +151,7 @@ public static void AddRaffleEntries(int reward) Program.queryParameters.Add("@trans_entries", reward); } Program.queryParameters.Add("@reductions", reductions); - TestDBUpdate(Program.summarytableupsert, Program.queryParameters, true); + DBUpdate(Program.summarytableupsert, Program.queryParameters, true); for (int i = 0; i < loopcount; i++) { Program.rafflemembers.Add(recipient.recipientid); @@ -160,7 +160,7 @@ public static void AddRaffleEntries(int reward) } - public static void TestDBUpdate(string query, Dictionary parameters, bool showerrors) + public static void DBUpdate(string query, Dictionary parameters, bool showerrors) { try { diff --git a/Traffic_Award/appsettings.json b/Traffic_Award/appsettings.json index 943e21d..d41ecb4 100644 --- a/Traffic_Award/appsettings.json +++ b/Traffic_Award/appsettings.json @@ -1,7 +1,7 @@ { "allexchangewallets": "INSERT INTO exchange_wallets (wallet_id) VALUES (@poloid),(@bittid),(@brsid),(@mortid),(@liveid);", - "allexchangepurchases": "SELECT * from transaction trans INNER JOIN exchange_wallets wall ON trans.sender_id=wall.wallet_id AND trans.recipient_id<>wall.wallet_id WHERE trans.type=0 AND trans.timestamp>@starttime AND trans.amount>@exchangemin;", + "allexchangepurchases": "SELECT * from transaction trans INNER JOIN exchange_wallets wall ON trans.sender_id=wall.wallet_id AND trans.recipient_id<>wall.wallet_id WHERE trans.type=0 AND trans.timestamp>=@starttime AND trans.amount>=@exchangemin;", "exchangeminamount": "1000000000000", @@ -31,16 +31,22 @@ "liveid": "-3487892597769638279", - "getrecipients": "SELECT recipient_id FROM transaction WHERE timestamp > @starttime AND timestamp < @endtime AND type=0 AND sender_id=@recipient AND NOT recipient_id IS NULL", + "getrecipients": "SELECT recipient_id FROM transaction WHERE timestamp >= @starttime AND timestamp <= @endtime AND type=0 AND sender_id=@recipient AND NOT recipient_id IS NULL", - "getexchangetrans": "SELECT recipient_id from transaction trans INNER JOIN exchange_wallets wall ON trans.sender_id=wall.wallet_id AND trans.recipient_id<>wall.wallet_id WHERE trans.timestamp > @starttime AND trans.timestamp < @endtime AND trans.type=0 AND trans.amount>@exchangemin AND trans.recipient_id NOT IN (@poloid,@bittid,@devid,@liveid);", + "getexchangetrans": "SELECT recipient_id from transaction trans INNER JOIN exchange_wallets wall ON trans.sender_id=wall.wallet_id AND trans.recipient_id<>wall.wallet_id WHERE trans.timestamp >= @starttime AND trans.timestamp <= @endtime AND trans.type=0 AND trans.amount>=@exchangemin AND trans.recipient_id NOT IN (@poloid,@bittid,@devid,@liveid);", + + "getexchangetransamt": "SELECT recip.recipient_id FROM (SELECT SUM(amount) amt, recipient_id FROM transaction trans INNER JOIN exchange_wallets wall ON trans.sender_id=wall.wallet_id AND trans.recipient_id<>wall.wallet_id WHERE trans.timestamp >= @starttime AND trans.timestamp <= @endtime AND trans.type=0 AND trans.amount>=@exchangemin AND trans.recipient_id NOT IN (@poloid,@bittid,@devid,@liveid) group by recipient_id) recip LEFT JOIN (SELECT SUM(amount) amt, sender_id FROM transaction trans INNER JOIN exchange_wallets wall ON trans.recipient_id=wall.wallet_id AND trans.sender_id<>wall.wallet_id WHERE trans.timestamp >= @starttime AND trans.timestamp <= @endtime AND trans.type=0 group by sender_id) sender ON recip.recipient_id=sender.sender_id WHERE sender.sender_id IS NULL OR (recip.amt-sender.amt)>=@exchangemin;", - "getalltransactions": "SELECT trans.amount, trans.fee, trans.recipient_id, trans.sender_id, trans.timestamp, trans.id as trans_id FROM transaction as trans INNER JOIN block ON trans.block_id=block.id WHERE block.timestamp > @starttime AND block.timestamp < @endtime AND trans.type=0 AND trans.amount>=@burstamount;", + "getalltransactions": "SELECT trans.amount, trans.fee, trans.recipient_id, trans.sender_id, trans.timestamp, trans.id as trans_id FROM transaction as trans INNER JOIN block ON trans.block_id=block.id WHERE block.timestamp >= @starttime AND block.timestamp <= @endtime AND trans.type=0 AND trans.amount>=@burstamount;", "getqualifyingtransactions": "SELECT sender_id, amount, fee FROM all_weekly_trans as trans WHERE trans.recipient_id NOT IN (@poloid,@bittid,@brsid,@mortid,@liveid) AND sender_id NOT IN (SELECT wallet_id FROM exchange_wallets UNION SELECT recip_id as wallet_id from reward_recip_assign) AND sender_id NOT IN (@bmfid,@bmfpid,@devid);", "getpoolwallets": "SELECT DISTINCT recip_id from reward_recip_assign;", + "getnewbmfmembers": "INSERT INTO raffle_summary (wallet_id, total_entries, exchange_entries, trans_entries, bmf_entries, reductions) SELECT DISTINCT reward.account_id, 0, 0, 0, @bmfaward, 0 FROM reward_recip_assign reward INNER JOIN transaction trans ON reward.height=trans.height where recip_id=@bmfpid AND latest=true and trans.timestamp >= @starttime AND trans.timestamp <= @endtime ON DUPLICATE KEY UPDATE bmf_entries=@bmfaward;", + + "getbmfdonations": "INSERT INTO raffle_summary (wallet_id, total_entries, exchange_entries, trans_entries, bmf_entries, reductions) SELECT sender_id, 0, 0, 0, @bmfaward, 0 from transaction where recipient_id=@bmfid AND timestamp>=@starttime AND timestamp<=@endtime AND amount>=@burstamount AND sender_id NOT IN (SELECT wallet_id from exchange_wallets UNION SELECT recip_id FROM reward_recip_assign where latest=true group by recip_id having count(db_id)>1) and sender_id NOT IN (@bmfid,@bmfpid,@devid) ON DUPLICATE KEY UPDATE bmf_entries=(bmf_entries+@bmfaward);", + "exchangemin": "1000000000000", "startdayinterval": "-7", @@ -77,9 +83,9 @@ "createtranstable": "CREATE TABLE burstwallet.all_weekly_trans (db_id BIGINT(20) NOT NULL AUTO_INCREMENT,trans_id BIGINT(20) NOT NULL,amount BIGINT(20) NOT NULL,fee BIGINT(20) NOT NULL,`timestamp` INT(11) NOT NULL,recipient_id BIGINT(20) NULL,sender_id BIGINT(20) NOT NULL,PRIMARY KEY(db_id)) ENGINE INNODB COLLATE 'utf8_bin' ROW_FORMAT DEFAULT;", - "createsummarytable": "CREATE TABLE raffle_summary (wallet_id BIGINT(19) NOT NULL, wallet_address VARCHAR(30) NULL, total_entries INT(11) NOT NULL, exchange_entries INT(11) NOT NULL, trans_entries INT(11) NOT NULL, reductions INT(11) NOT NULL,PRIMARY KEY(wallet_id)) ENGINE INNODB COLLATE 'utf8_bin' ROW_FORMAT DEFAULT;", + "createsummarytable": "CREATE TABLE raffle_summary (wallet_id BIGINT(19) NOT NULL, wallet_address VARCHAR(30) NULL, total_entries INT(11) NOT NULL, exchange_entries INT(11) NOT NULL, trans_entries INT(11) NOT NULL, bmf_entries INT(11) NOT NULL, reductions INT(11) NOT NULL,PRIMARY KEY(wallet_id)) ENGINE INNODB COLLATE 'utf8_bin' ROW_FORMAT DEFAULT;", - "summarytableupsert": "INSERT INTO raffle_summary (wallet_id, total_entries, exchange_entries, trans_entries, reductions) VALUES (@wallet_id, 0, @exchange_entries, @trans_entries, @reductions) ON DUPLICATE KEY UPDATE exchange_entries=(exchange_entries + VALUES(exchange_entries)), trans_entries=(trans_entries + VALUES(trans_entries)), reductions=(reductions + VALUES(reductions));", + "summarytableupsert": "INSERT INTO raffle_summary (wallet_id, total_entries, exchange_entries, trans_entries, bmf_entries, reductions) VALUES (@wallet_id, 0, @exchange_entries, @trans_entries, 0, @reductions) ON DUPLICATE KEY UPDATE exchange_entries=(exchange_entries + VALUES(exchange_entries)), trans_entries=(trans_entries + VALUES(trans_entries)), reductions=(reductions + VALUES(reductions));", "getsummarydata": "SELECT * FROM raffle_summary;", @@ -91,5 +97,7 @@ "transactionaward": "1", - "exchangeaward": "5" + "exchangeaward": "5", + + "bmfaward": "10" } \ No newline at end of file