public void IncreaseShareCount(string guid, uint difficulty) { ConnectedWorker worker = Statics.ConnectedClients[guid]; double shareValue = (double)difficulty / int.Parse(Statics.Config.IniReadValue("base-difficulty")); Block block; if (Statics.RedisDb.Blocks.Any(x => x.BlockHeight == Statics.CurrentBlockHeight)) { block = Statics.RedisDb.Blocks.First(x => x.BlockHeight == Statics.CurrentBlockHeight); } else { block = new Block(Statics.CurrentBlockHeight); } Miner miner; if (Statics.RedisDb.Miners.Any(x => x.Address == worker.Address)) { miner = Statics.RedisDb.Miners.First(x => x.Address == worker.Address); } else { miner = new Miner(worker.Address, 0); } foreach (var fBlockReward in Statics.RedisDb.BlockRewards) { if (fBlockReward.Block == block.Identifier && fBlockReward.Miner == miner.Identifier) { Share fShare = new Share(fBlockReward.Identifier, shareValue); fBlockReward.Shares.Add(fShare.Identifier); Statics.RedisDb.SaveChanges(fBlockReward); Statics.RedisDb.SaveChanges(fShare); Statics.RedisDb.SaveChanges(miner); Statics.RedisDb.SaveChanges(block); return; } } BlockReward blockReward = new BlockReward(miner.Identifier, block.Identifier); Share share = new Share(blockReward.Identifier, shareValue); blockReward.Shares.Add(share.Identifier); miner.BlockReward.Add(blockReward.Identifier); block.BlockRewards.Add(blockReward.Identifier); Statics.RedisDb.SaveChanges(blockReward); Statics.RedisDb.SaveChanges(share); Statics.RedisDb.SaveChanges(miner); Statics.RedisDb.SaveChanges(block); }
public void IncreaseShareCount(string guid, uint difficulty) { var currentWorker = Program.ConnectedClients[guid]; var shareValue = difficulty / Program.Configuration.GetBaseDifficulty(); // Get the current block height. Block block = Program.RedisPoolDatabase.Blocks.Any(x => x.BlockHeight == Program.CurrentBlockHeight) ? Program.RedisPoolDatabase.Blocks.First(x => x.BlockHeight == Program.CurrentBlockHeight) : new Block(Program.CurrentBlockHeight); // Get the current miner's addrerss. Miner miner = Program.RedisPoolDatabase.Miners.Any(x => x.Address == currentWorker.Address) ? Program.RedisPoolDatabase.Miners.First(x => x.Address == currentWorker.Address) : new Miner(currentWorker.Address, 0); // Iterate through each block reward. foreach (var fBlockReward in Program.RedisPoolDatabase.BlockRewards) { // Check if the current block. if (fBlockReward.Block == block.Identifier && fBlockReward.Miner == miner.Identifier) { var fShare = new Share(fBlockReward.Identifier, shareValue); fBlockReward.Shares.Add(fShare.Identifier); // Save changes to the redis database. Program.RedisPoolDatabase.SaveChanges(fBlockReward); Program.RedisPoolDatabase.SaveChanges(fShare); Program.RedisPoolDatabase.SaveChanges(miner); Program.RedisPoolDatabase.SaveChanges(block); // Return so we stop burning cycles. return; } } // Get the block reward and current share. var blockReward = new BlockReward(miner.Identifier, block.Identifier); var share = new Share(blockReward.Identifier, shareValue); // Track the data in proper lists. blockReward.Shares.Add(share.Identifier); miner.BlockReward.Add(blockReward.Identifier); block.BlockRewards.Add(blockReward.Identifier); // Save all data to the redis database. Program.RedisPoolDatabase.SaveChanges(blockReward); Program.RedisPoolDatabase.SaveChanges(share); Program.RedisPoolDatabase.SaveChanges(miner); Program.RedisPoolDatabase.SaveChanges(block); }
public void SaveChanges(BlockReward blockReward) { SaveChanges <BlockReward>(blockReward); for (int i = 0; i < BlockRewards.Count; i++) { if (BlockRewards[i].Identifier == blockReward.Identifier) { BlockRewards.RemoveAt(i); BlockRewards.Insert(i, blockReward); return; } } BlockRewards.Add(blockReward); }