Example #1
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,
                    "failed" => OperationStatus.Failed,
                    _ => throw new NotImplementedException()
                },
Example #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,
                    "failed" => OperationStatus.Failed,
                    _ => throw new NotImplementedException()
                },
Example #3
0
        public async Task Init(Block block, RawOperation op, RawRevealContent content)
        {
            var sender = await Cache.Accounts.GetAsync(content.Source);

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

            PubKey = content.PublicKey;
            Reveal = new RevealOperation
            {
                Id           = Cache.AppState.NextOperationId(),
                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,
                    _ => throw new NotImplementedException()
                }
            };
        }
Example #4
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()
                },
Example #5
0
 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
     };
 }
Example #6
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);
        }
Example #7
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
            };
        }
Example #8
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);
        }
Example #9
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);
        }