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 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); }