예제 #1
0
파일: Validator.cs 프로젝트: rjumawan/tzkt
        protected async Task ValidateOrigination(RawOriginationContent origination, RawBlock rawBlock)
        {
            if (!await Cache.Accounts.ExistsAsync(origination.Source))
            {
                throw new ValidationException("unknown source account");
            }

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

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

            if (origination.Metadata.Result.BalanceUpdates != null)
            {
                ValidateTransferBalanceUpdates(
                    origination.Metadata.Result.BalanceUpdates,
                    origination.Source,
                    origination.Metadata.Result.OriginatedContracts[0],
                    origination.Balance,
                    (origination.Metadata.Result.PaidStorageSizeDiff + Protocol.OriginationSize) * Protocol.ByteCost);
            }
        }
예제 #2
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 = (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,
                    "failed" => OperationStatus.Failed,
                    _ => throw new NotImplementedException()
                },