示例#1
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}'")
                },
示例#2
0
        protected async Task ValidateDelegation(RawDelegationContent delegation, RawBlock rawBlock)
        {
            if (!await Cache.Accounts.ExistsAsync(delegation.Source))
            {
                throw new ValidationException("unknown source account");
            }

            ValidateFeeBalanceUpdates(
                delegation.Metadata.BalanceUpdates,
                rawBlock.Metadata.Baker,
                delegation.Source,
                delegation.Fee,
                rawBlock.Metadata.LevelInfo.Cycle);

            if (delegation.Metadata.Result.Status == "applied" && delegation.Delegate != null)
            {
                if (delegation.Source != delegation.Delegate && !Cache.Accounts.DelegateExists(delegation.Delegate))
                {
                    throw new ValidationException("unknown delegate account");
                }
            }
        }