Beispiel #1
0
        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:
                        case BlockStatus.Pending:
                            blockRepo.UpdateBlock(con, tx, block);
                            break;
                        }
                    });
                }
            }

            else
            {
                logger.Info(() => $"No updated blocks for pool {pool.Id}");
            }
        }
Beispiel #2
0
        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}");
            }
        }