private async Task UpdatePoolBalancesAsync(PoolConfig pool, IPayoutHandler handler, IPayoutScheme scheme) { // get pending blockRepo for pool var pendingBlocks = await cf.Run(con => blockRepo.GetPendingBlocksForPoolAsync(con, pool.Id)); // classify var updatedBlocks = await handler.ClassifyBlocksAsync(pendingBlocks); if (updatedBlocks.Any()) { foreach (var block in updatedBlocks.OrderBy(x => x.Created)) { logger.Info(() => $"Processing payments for pool {pool.Id}, block {block.BlockHeight}, effort {block.Effort}"); await cf.RunTx(async (con, tx) => { if (!block.Effort.HasValue) // fill block effort if empty { await CalculateBlockEffortAsync(pool, block, handler); } switch (block.Status) { case BlockStatus.Confirmed: // blockchains that do not support block-reward payments via coinbase Tx // must generate balance records for all reward recipients instead var blockReward = await handler.UpdateBlockRewardBalancesAsync(con, tx, block, pool); logger.Info(() => $" --Pool {pool}"); logger.Info(() => $" --Block {block}"); logger.Info(() => $" --Block reward {blockReward}"); logger.Info(() => $" --Con {con}"); logger.Info(() => $" --tx {tx}"); await scheme.UpdateBalancesAsync(con, tx, pool, handler, block, blockReward); await blockRepo.UpdateBlockAsync(con, tx, block); break; case BlockStatus.Orphaned: await blockRepo.UpdateBlockAsync(con, tx, block); break; case BlockStatus.Pending: await blockRepo.UpdateBlockAsync(con, tx, block); break; } }); } } else { logger.Info(() => $"No updated blocks for pool {pool.Id}"); } }
private async Task UpdatePoolBalancesAsync(PoolConfig pool, IPayoutHandler handler, IPayoutScheme scheme) { // get pending blockRepo for pool var pendingBlocks = cf.Run(con => blockRepo.GetPendingBlocksForPool(con, pool.Id)); // classify var updatedBlocks = await handler.ClassifyBlocksAsync(pendingBlocks); if (updatedBlocks.Any()) { foreach (var block in updatedBlocks.OrderBy(x => x.Created)) { logger.Info(() => $"Processing payments for pool {pool.Id}, block {block.BlockHeight}"); await cf.RunTxAsync(async (con, tx) => { // fill block effort if empty if (!block.Effort.HasValue) { await CalculateBlockEffort(pool, block, handler); } switch (block.Status) { case BlockStatus.Confirmed: // blockchains that do not support block-reward payments via coinbase Tx // must generate balance records for all reward recipients instead var blockReward = await handler.UpdateBlockRewardBalancesAsync(con, tx, block, pool); // update share submitter balances through configured payout scheme await scheme.UpdateBalancesAsync(con, tx, pool, handler, block, blockReward); // finally update block status blockRepo.UpdateBlock(con, tx, block); break; case BlockStatus.Orphaned: logger.Info(() => $"Deleting orphaned block {block.BlockHeight} on pool {pool.Id}"); blockRepo.DeleteBlock(con, tx, block); break; case BlockStatus.Pending: blockRepo.UpdateBlock(con, tx, block); break; } }); } } else { logger.Info(() => $"No updated blocks for {pool.Id}"); } }
private async Task UpdatePoolBalancesAsync(PoolConfig pool, IPayoutHandler handler, IPayoutScheme scheme) { var pendingBlocks = cf.Run(con => blockRepo.GetPendingBlocksForPool(con, pool.Id)); var updatedBlocks = await handler.ClassifyBlocksAsync(pendingBlocks); if (updatedBlocks.Any()) { foreach (var block in updatedBlocks.OrderBy(x => x.Created)) { logger.Info(() => $"Processing payments for pool {pool.Id}, block {block.BlockHeight}"); await cf.RunTxAsync(async (con, tx) => { if (!block.Effort.HasValue) { await CalculateBlockEffort(pool, block, handler); } switch (block.Status) { case BlockStatus.Confirmed: var blockReward = await handler.UpdateBlockRewardBalancesAsync(con, tx, block, pool); await scheme.UpdateBalancesAsync(con, tx, pool, handler, block, blockReward); blockRepo.UpdateBlock(con, tx, block); break; case BlockStatus.Orphaned: case BlockStatus.Pending: blockRepo.UpdateBlock(con, tx, block); break; } }); } } else { logger.Info(() => $"No updated blocks for pool {pool.Id}"); } }