public async Task Init(Block block, RawOperation op, RawRevealContent content) { var id = Cache.AppState.NextOperationId(); var sender = await Cache.Accounts.GetAsync(content.Source); sender.Delegate ??= Cache.Accounts.GetDelegate(sender.DelegateId); PubKey = content.PublicKey; Reveal = new RevealOperation { Id = id, OpHash = op.Hash, Block = block, Level = block.Level, Timestamp = block.Timestamp, BakerFee = content.Fee, Counter = content.Counter, GasLimit = content.GasLimit, StorageLimit = content.StorageLimit, Sender = sender, Status = content.Metadata.Result.Status switch { "applied" => OperationStatus.Applied, "backtracked" => OperationStatus.Backtracked, "failed" => OperationStatus.Failed, _ => throw new NotImplementedException() },
public async Task Init(Block block, RawOperation op, RawDelegationContent content) { var sender = await Cache.Accounts.GetAsync(content.Source); sender.Delegate ??= Cache.Accounts.GetDelegate(sender.DelegateId); var delegat = Cache.Accounts.GetDelegateOrDefault(content.Delegate); IsSelfDelegation = content.Source == content.Delegate; Delegation = new DelegationOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, BakerFee = content.Fee, Counter = content.Counter, GasLimit = content.GasLimit, StorageLimit = content.StorageLimit, Sender = sender, Delegate = delegat, PrevDelegate = sender.Delegate, Status = content.Metadata.Result.Status switch { "applied" => OperationStatus.Applied, "failed" => OperationStatus.Failed, "skipped" => OperationStatus.Skipped, _ => throw new NotImplementedException() },
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") } }; }
public async Task Init(Block block, RawOperation op, RawOriginationContent content) { var sender = await Cache.Accounts.GetAsync(content.Source); sender.Delegate ??= Cache.Accounts.GetDelegate(sender.DelegateId); var manager = (User)await Cache.Accounts.GetAsync(content.Manager); var delegat = Cache.Accounts.GetDelegateOrDefault(content.Delegate); var contract = content.Metadata.Result.Status == "applied" ? new Contract { Id = Cache.AppState.NextAccountId(), Address = content.Metadata.Result.OriginatedContracts[0], Balance = content.Balance, Counter = 0, Delegate = delegat, DelegationLevel = delegat != null ? (int?)block.Level : null, Creator = sender, Manager = manager, Staked = delegat?.Staked ?? false, Type = AccountType.Contract, Kind = content.Script == null ? ContractKind.DelegatorContract : ContractKind.SmartContract, Spendable = content.Spendable == false ? content.Spendable : null } : null; Origination = new OriginationOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Balance = content.Balance, BakerFee = content.Fee, Counter = content.Counter, GasLimit = content.GasLimit, StorageLimit = content.StorageLimit, Sender = sender, Manager = manager, Delegate = delegat, Contract = contract, Status = content.Metadata.Result.Status switch { "applied" => OperationStatus.Applied, "backtracked" => OperationStatus.Backtracked, "failed" => OperationStatus.Failed, "skipped" => OperationStatus.Skipped, _ => throw new NotImplementedException() },
public async Task Init(Block block, RawOperation op, RawActivationContent content) { Activation = new ActivationOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Account = (User)await Cache.Accounts.GetAsync(content.Address), Balance = content.Metadata.BalanceUpdates[0].Change }; }
public Task Init(Block block, RawOperation op, RawEndorsementContent content) { Endorsement = new EndorsementOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Slots = content.Metadata.Slots.Count, Delegate = Cache.Accounts.GetDelegate(content.Metadata.Delegate), Reward = content.Metadata.BalanceUpdates.FirstOrDefault(x => x is RewardsUpdate)?.Change ?? 0 }; return(Task.CompletedTask); }
public async Task Init(Block block, RawOperation op, RawNonceRevelationContent content) { var revealedBlock = await Cache.Blocks.GetAsync(content.Level); Revelation = new NonceRevelationOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Baker = block.Baker, Sender = Cache.Accounts.GetDelegate(revealedBlock.BakerId), RevealedBlock = revealedBlock, RevealedLevel = content.Level }; }
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 }); } }
public Task Init(Block block, RawOperation op, RawDoubleBakingEvidenceContent content) { DoubleBaking = new DoubleBakingOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, AccusedLevel = content.Block1.Level, Accuser = block.Baker, Offender = Cache.Accounts.GetDelegate(content.Metadata.BalanceUpdates.First(x => x.Change < 0).Target), AccuserReward = content.Metadata.BalanceUpdates.Where(x => x.Change > 0).Sum(x => x.Change), OffenderLostDeposit = content.Metadata.BalanceUpdates.Where(x => x.Change < 0 && x is DepositsUpdate).Sum(x => - x.Change), OffenderLostReward = content.Metadata.BalanceUpdates.Where(x => x.Change < 0 && x is RewardsUpdate).Sum(x => - x.Change), OffenderLostFee = content.Metadata.BalanceUpdates.Where(x => x.Change < 0 && x is FeesUpdate).Sum(x => - x.Change) }; return(Task.CompletedTask); }
public async Task Init(Block block, RawOperation op, RawTransactionContent content) { var sender = await Cache.Accounts.GetAsync(content.Source); sender.Delegate ??= Cache.Accounts.GetDelegate(sender.DelegateId); var target = await Cache.Accounts.GetAsync(content.Destination); if (target != null) { target.Delegate ??= Cache.Accounts.GetDelegate(target.DelegateId); } Transaction = new TransactionOperation { Id = Cache.AppState.NextOperationId(), Block = block, Level = block.Level, Timestamp = block.Timestamp, OpHash = op.Hash, Amount = content.Amount, BakerFee = content.Fee, Counter = content.Counter, GasLimit = content.GasLimit, StorageLimit = content.StorageLimit, Sender = sender, Target = target, Parameters = OperationParameters.Parse(content.Parameters), Status = content.Metadata.Result.Status switch { "applied" => OperationStatus.Applied, "backtracked" => OperationStatus.Backtracked, "failed" => OperationStatus.Failed, "skipped" => OperationStatus.Skipped, _ => throw new NotImplementedException() },
public static async Task <NonceRevelationsCommit> Apply(ProtocolHandler proto, Block block, RawOperation op, RawNonceRevelationContent content) { var commit = new NonceRevelationsCommit(proto); await commit.Init(block, op, content); await commit.Apply(); return(commit); }
public static async Task <DoubleBakingCommit> Apply(ProtocolHandler proto, Block block, RawOperation op, RawDoubleBakingEvidenceContent content) { var commit = new DoubleBakingCommit(proto); await commit.Init(block, op, content); await commit.Apply(); return(commit); }
public static async Task <EndorsementsCommit> Apply(ProtocolHandler proto, Block block, RawOperation op, RawEndorsementContent content) { var commit = new EndorsementsCommit(proto); await commit.Init(block, op, content); await commit.Apply(); return(commit); }