Exemplo n.º 1
0
        public async Task <Snapshot <T>[]> GetAsync <T>(string entityId, CancellationToken cancellationToken = default)
        {
            var(start, end) = _claims.GetRange() ?? (0, _snapshotMaxReturn);
            var count   = Math.Clamp(end - start, 0, _snapshotMaxReturn);
            var reverse = bool.TryParse(_claims.QueryParams.GetValueOrDefault("reverse"), out var r) && r;

            return(await _snapshots.GetAsync <T>(entityId, start, count, reverse, cancellationToken));
        }
        public async Task CreatePlanAsync(
            DateTime from,
            DateTime to)
        {
            _log.Info($"Creating distribution plan for {from:s} - {to:s}...");

            var claimedGasAmounts = await _claimedGasAmountRepository.GetAsync(from, to);

            _log.Info("Claimed GAS amount found", new
            {
                claimedGasAmounts
            });

            var snapshots = await _snapshotRepository.GetAsync(from, to);

            _log.Info($"{snapshots.Count} balance snapshots found");

            var scale = _assetService.AssetGet(_gasAssetId).Accuracy;

            _log.Info($"GAS scale {scale}");

            var distributionAmounts = DistributionPlanCalculator.CalculateAmounts(snapshots, claimedGasAmounts, scale).ToArray();

            _log.Info($"{distributionAmounts.Length} distribution amounts gotten");

            var distributionPlan = DistributionPlanAggregate.Create(to, distributionAmounts);

            _log.Info($"Distribution plan {distributionPlan.Id} created");

            await _distributionPlanRepository.SaveAsync(distributionPlan);
        }