Exemple #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,
                    _ => throw new NotImplementedException()
                }
            };
        }
Exemple #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()
                },
Exemple #3
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
     };
 }
Exemple #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);

            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()
                },
Exemple #5
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);
        }
Exemple #6
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
            };
        }
Exemple #7
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);
        }
Exemple #8
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 NotImplementedException()
                },
Exemple #9
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);
        }
Exemple #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);
        }
Exemple #11
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);
        }