示例#1
0
        protected Task ValidateProposal(RawProposalContent proposal, RawBlock rawBlock)
        {
            if (!Cache.Accounts.DelegateExists(proposal.Source))
            {
                throw new ValidationException("invalid proposal sender");
            }

            if (proposal.Period != rawBlock.Metadata.LevelInfo.VotingPeriod)
            {
                throw new ValidationException("invalid proposal voting period");
            }

            return(Task.CompletedTask);
        }
示例#2
0
        public async Task Init(Block block, RawOperation op, RawProposalContent content)
        {
            var period = (ProposalPeriod)await Cache.Periods.CurrentAsync();

            var sender = Cache.Accounts.GetDelegate(content.Source);
            var rolls  = (await Db.VotingSnapshots.FirstAsync(x => x.PeriodId == period.Id && x.DelegateId == sender.Id)).Rolls;

            ProposalOperations = new List <ProposalOperation>(4);
            foreach (var proposalHash in content.Proposals)
            {
                var proposal = await Cache.Proposals.GetOrCreateAsync(proposalHash, () => new Proposal
                {
                    Hash           = proposalHash,
                    Initiator      = sender,
                    ProposalPeriod = period,
                    Status         = ProposalStatus.Active
                });

                var duplicated = ProposalOperations.Any(x => x.Period.Id == period.Id && x.Sender.Id == sender.Id && x.Proposal.Hash == proposal.Hash);
                if (!duplicated)
                {
                    duplicated = block.Proposals?.Any(x => x.Period.Id == period.Id && x.Sender.Id == sender.Id && x.Proposal.Hash == proposal.Hash) ?? false;
                }
                if (!duplicated)
                {
                    duplicated = await Db.ProposalOps.AnyAsync(x => x.PeriodId == period.Id && x.SenderId == sender.Id && x.ProposalId == proposal.Id);
                }

                ProposalOperations.Add(new ProposalOperation
                {
                    Id         = Cache.AppState.NextOperationId(),
                    Block      = block,
                    Level      = block.Level,
                    Timestamp  = block.Timestamp,
                    OpHash     = op.Hash,
                    Sender     = sender,
                    Rolls      = rolls,
                    Duplicated = duplicated,
                    Period     = period,
                    Proposal   = proposal
                });
            }
        }
示例#3
0
        public static async Task <ProposalsCommit> Apply(ProtocolHandler proto, Block block, RawOperation op, RawProposalContent content)
        {
            var commit = new ProposalsCommit(proto);
            await commit.Init(block, op, content);

            await commit.Apply();

            return(commit);
        }