public async Task Init(Block block, RawOperation op, RawBallotContent content) { var period = await Cache.Periods.CurrentAsync(); var proposal = await Cache.Proposals.GetAsync((period as ExplorationPeriod)?.ProposalId ?? (period as PromotionPeriod).ProposalId); var sender = Cache.Accounts.GetDelegate(content.Source); var rolls = (await Db.VotingSnapshots.FirstAsync(x => x.PeriodId == period.Id && x.DelegateId == sender.Id)).Rolls; Ballot = new BallotOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Sender = sender, Rolls = rolls, Period = period, Proposal = proposal, Vote = content.Ballot switch { "yay" => Vote.Yay, "nay" => Vote.Nay, "pass" => Vote.Pass, _ => throw new Exception("invalid ballot value") } }; }
protected async Task ValidateBallot(RawBallotContent ballot, RawBlock rawBlock) { var period = await Cache.Periods.CurrentAsync(); var proposal = await Cache.Proposals.GetAsync((period as ExplorationPeriod)?.ProposalId ?? (period as PromotionPeriod).ProposalId); if (proposal.Hash != ballot.Proposal) { throw new ValidationException("invalid ballot proposal"); } if (!Cache.Accounts.DelegateExists(ballot.Source)) { throw new ValidationException("invalid proposal sender"); } if (ballot.Period != rawBlock.Metadata.LevelInfo.VotingPeriod) { throw new ValidationException("invalid proposal voting period"); } }
public static async Task <BallotsCommit> Apply(ProtocolHandler proto, Block block, RawOperation op, RawBallotContent content) { var commit = new BallotsCommit(proto); await commit.Init(block, op, content); await commit.Apply(); return(commit); }