private static void Main(string[] args) { byte[] test = CryptoNight(new byte[] { 0x00, 0x01 }); json = new JsonRPC(config.IniReadValue("daemon-json-rpc")); Walletjson = new JsonRPC(config.IniReadValue("wallet-json-rpc")); redis = ConnectionMultiplexer.Connect(config.IniReadValue("redis-server")); redisDb = redis.GetDatabase(); JObject test2 = json.InvokeMethod("getblockcount"); CurrentBlockHeight = (int)test2["result"]["count"]; Console.WriteLine("beginning listen"); StartListening(); while (true) { Thread.Sleep(5000); test2 = json.InvokeMethod("getblockcount"); CurrentBlockHeight = (int)test2["result"]["count"]; /*ConnectedClients = * ConnectedClients.AsParallel() * .Where(x => (DateTime.Now - x.Value.last_heard).Seconds < 60) * .ToDictionary(x => x.Key, x => x.Value); */ //, new JObject(new JProperty("reserve_size", 4), new JProperty("wallet_address", "41jhre5xFk92GYaJgxvHuzUC5uZtQ4UDU1APv3aRAc27DWBqKEzubC2WSvmnbxaswLdB1BsQnSfxfYXvEqkXPvcuS4go3aV"))); } }
public static void ProcessBlock(byte[] blockData) { if ((string)json.InvokeMethod("submitblock", blockData)["result"]["status"] == "OK") { InitiatePayments(); } else { Console.WriteLine("Block submittance failed!"); } }
private static async void InitiatePayments() { Dictionary <string, long> sharePerAddress = new Dictionary <string, long>(); int lastPaidBlock = 0; long totalShares = 0; try { lastPaidBlock = int.Parse(redisDb.StringGet("lastpaidblock")); redisDb.StringSet("lastpaidblock", CurrentBlockHeight); } catch { lastPaidBlock = 0; redisDb.StringSet("lastpaidblock", CurrentBlockHeight); } RedisValue[] blockrewards = redisDb.SetMembers("blockreward"); foreach (RedisValue rBlockReward in blockrewards) { HashEntry[] blockReward = redisDb.HashGetAll((string)rBlockReward); if ((int)blockReward.First(x => x.Name == "block").Value < lastPaidBlock) { } else { string address = blockReward.First(x => x.Name == "address").Value; if (!sharePerAddress.ContainsKey(address)) { sharePerAddress.Add(address, 0); } sharePerAddress[address] += int.Parse(blockReward.First(x => x.Name == "shares").Value); } } JObject blockHeader = json.InvokeMethod("getblockheaderbyheight", CurrentBlockHeight); long reward = (long)blockHeader["result"]["blockheader"]["reward"]; int fee = 100 + int.Parse(config.IniReadValue("pool-fee")); double rewardPerShare = (double)reward / ((double)(fee * totalShares) / 100); JObject param = new JObject(); JArray destinations = new JArray(); foreach (KeyValuePair <string, long> addressShare in sharePerAddress) { JObject destination = new JObject(); destination["amount"] = (long)(addressShare.Value * rewardPerShare); destination["address"] = addressShare.Key; destinations.Add(destination); } param["destinations"] = destinations; param["fee"] = 0; param["mixin"] = 0; param["unlock_time"] = 0; JObject transfer = Walletjson.InvokeMethod("transfer", param); Console.WriteLine(transfer); }