Пример #1
0
        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,
                    "skipped" => OperationStatus.Skipped,
                    _ => throw new Exception($"Invalid status '{content.Metadata.Result.Status}'")
                },
Пример #2
0
        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,
                    "backtracked" => OperationStatus.Backtracked,
                    "failed" => OperationStatus.Failed,
                    "skipped" => OperationStatus.Skipped,
                    _ => throw new Exception($"Invalid status '{content.Metadata.Result.Status}'")
                },
Пример #3
0
        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 = ManagerTz.Test(content.Script.Code, content.Script.Storage)
                ? (User)await Cache.Accounts.GetAsync(ManagerTz.GetManager(content.Script.Storage))
                : null;

            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            = manager != null ? ContractKind.DelegatorContract : ContractKind.SmartContract
            }
                : 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 Exception($"Invalid status '{content.Metadata.Result.Status}'")
                },
Пример #4
0
        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);
        }
Пример #5
0
        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
            };
        }
Пример #6
0
        public async Task Init(Block block, RawOperation op, RawActivationContent content)
        {
            var account = (User)await Cache.Accounts.GetAsync(content.Address);

            account.Delegate ??= Cache.Accounts.GetDelegate(account.DelegateId);

            Activation = new ActivationOperation
            {
                Id        = Cache.AppState.NextOperationId(),
                Block     = block,
                Level     = block.Level,
                Timestamp = block.Timestamp,
                OpHash    = op.Hash,
                Account   = account,
                Balance   = content.Metadata.BalanceUpdates[0].Change
            };
        }
Пример #7
0
        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 = 0;

            if (block.Events.HasFlag(BlockEvents.VotingPeriodBegin))
            {
                rolls = (int)(sender.StakingBalance / block.Protocol.TokensPerRoll);
            }
            else
            {
                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")
                }
            };
        }
Пример #8
0
        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);
        }
Пример #9
0
        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 Exception($"Invalid status '{content.Metadata.Result.Status}'")
                },
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }