Esempio n. 1
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);

            // WTF: [level:25054] - Manager and sender are not equal.
            var manager = (User)await Cache.Accounts.GetAsync(content.Manager);

            var originDelegate = await Cache.Accounts.GetAsync(content.Delegate);

            var delegat = originDelegate as Data.Models.Delegate;
            // WTF: [level:635] - Tezos allows to set non-existent 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,
                WeirdDelegate   = originDelegate?.Type == AccountType.User ? (User)originDelegate : 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()
                },
Esempio n. 2
0
        protected async Task ValidateOrigination(RawOriginationContent origination, RawBlock rawBlock)
        {
            if (!await Cache.Accounts.ExistsAsync(origination.Source))
            {
                throw new ValidationException("unknown source account");
            }

            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);
            }
        }