Esempio n. 1
0
        public override async Task Revert()
        {
            var currBlock = await Cache.Blocks.CurrentAsync();

            await BakerCycleCommit.Revert(this);

            await DelegatorCycleCommit.Revert(this);

            await CycleCommit.Revert(this);

            await BakingRightsCommit.Revert(this);

            await VotingCommit.Revert(this, currBlock);

            await BootstrapCommit.Revert(this, currBlock);

            await BlockCommit.Revert(this, currBlock);

            await StateCommit.Revert(this, currBlock);
        }
Esempio n. 2
0
        public override async Task Revert()
        {
            var currBlock = await Cache.Blocks.CurrentAsync();

            #region load operations
            var query = Db.Blocks.AsQueryable();

            if (currBlock.Operations.HasFlag(Operations.Activations))
            {
                query = query.Include(x => x.Activations);
            }

            if (currBlock.Operations.HasFlag(Operations.Delegations))
            {
                query = query.Include(x => x.Delegations);
            }

            if (currBlock.Operations.HasFlag(Operations.Endorsements))
            {
                query = query.Include(x => x.Endorsements);
            }

            if (currBlock.Operations.HasFlag(Operations.Originations))
            {
                query = query.Include(x => x.Originations);
            }

            if (currBlock.Operations.HasFlag(Operations.Reveals))
            {
                query = query.Include(x => x.Reveals);
            }

            if (currBlock.Operations.HasFlag(Operations.Revelations))
            {
                query = query.Include(x => x.Revelations);
            }

            if (currBlock.Operations.HasFlag(Operations.Transactions))
            {
                query = query.Include(x => x.Transactions);
            }

            if (currBlock.Operations.HasFlag(Operations.DoubleBakings))
            {
                query = query.Include(x => x.DoubleBakings);
            }

            if (currBlock.Operations.HasFlag(Operations.DoubleEndorsings))
            {
                query = query.Include(x => x.DoubleEndorsings);
            }

            if (currBlock.Operations.HasFlag(Operations.Proposals))
            {
                query = query.Include(x => x.Proposals);
            }

            if (currBlock.Operations.HasFlag(Operations.Ballots))
            {
                query = query.Include(x => x.Ballots);
            }

            if (currBlock.Operations.HasFlag(Operations.RevelationPenalty))
            {
                query = query.Include(x => x.RevelationPenalties);
            }

            if (currBlock.Events.HasFlag(BlockEvents.NewAccounts))
            {
                query = query.Include(x => x.CreatedAccounts);
            }

            currBlock = await query.FirstOrDefaultAsync(x => x.Level == currBlock.Level);

            Cache.Blocks.Add(currBlock);

            var operations = new List <BaseOperation>(40);
            if (currBlock.Activations != null)
            {
                operations.AddRange(currBlock.Activations);
            }

            if (currBlock.Delegations != null)
            {
                operations.AddRange(currBlock.Delegations);
            }

            if (currBlock.Endorsements != null)
            {
                operations.AddRange(currBlock.Endorsements);
            }

            if (currBlock.Originations != null)
            {
                operations.AddRange(currBlock.Originations);
            }

            if (currBlock.Reveals != null)
            {
                operations.AddRange(currBlock.Reveals);
            }

            if (currBlock.Revelations != null)
            {
                operations.AddRange(currBlock.Revelations);
            }

            if (currBlock.Transactions != null)
            {
                operations.AddRange(currBlock.Transactions);
            }

            if (currBlock.DoubleBakings != null)
            {
                operations.AddRange(currBlock.DoubleBakings);
            }

            if (currBlock.DoubleEndorsings != null)
            {
                operations.AddRange(currBlock.DoubleEndorsings);
            }

            if (currBlock.Proposals != null)
            {
                operations.AddRange(currBlock.Proposals);
            }

            if (currBlock.Ballots != null)
            {
                operations.AddRange(currBlock.Ballots);
            }

            if (currBlock.CreatedAccounts != null)
            {
                foreach (var account in currBlock.CreatedAccounts)
                {
                    Cache.Accounts.Add(account);
                }
            }
            #endregion

            await BakerCycleCommit.Revert(this, currBlock);

            await DelegatorCycleCommit.Revert(this, currBlock);

            await CycleCommit.Revert(this, currBlock);

            await BakingRightsCommit.Revert(this, currBlock);

            foreach (var operation in operations.OrderByDescending(x => x.Id))
            {
                switch (operation)
                {
                case EndorsementOperation endorsement:
                    await EndorsementsCommit.Revert(this, currBlock, endorsement);

                    break;

                case ProposalOperation proposal:
                    await ProposalsCommit.Revert(this, currBlock, proposal);

                    break;

                case BallotOperation ballot:
                    await BallotsCommit.Revert(this, currBlock, ballot);

                    break;

                case ActivationOperation activation:
                    await ActivationsCommit.Revert(this, currBlock, activation);

                    break;

                case DoubleBakingOperation doubleBaking:
                    await DoubleBakingCommit.Revert(this, currBlock, doubleBaking);

                    break;

                case DoubleEndorsingOperation doubleEndorsing:
                    await DoubleEndorsingCommit.Revert(this, currBlock, doubleEndorsing);

                    break;

                case NonceRevelationOperation revelation:
                    await NonceRevelationsCommit.Revert(this, currBlock, revelation);

                    break;

                case RevealOperation reveal:
                    await RevealsCommit.Revert(this, currBlock, reveal);

                    break;

                case DelegationOperation delegation:
                    await DelegationsCommit.Revert(this, currBlock, delegation);

                    break;

                case OriginationOperation origination:
                    await OriginationsCommit.Revert(this, currBlock, origination);

                    break;

                case TransactionOperation transaction:
                    await TransactionsCommit.Revert(this, currBlock, transaction);

                    break;

                default:
                    throw new NotImplementedException($"'{operation.GetType()}' is not implemented");
                }
            }

            await DeactivationCommit.Revert(this, currBlock);

            await RevelationPenaltyCommit.Revert(this, currBlock);

            await FreezerCommit.Revert(this, currBlock);

            await VotingCommit.Revert(this, currBlock);

            await BlockCommit.Revert(this, currBlock);

            await StateCommit.Revert(this, currBlock);
        }