Beispiel #1
0
        public async Task Init(Block block, NonceRevelationOperation revelation)
        {
            Revelation = revelation;

            Revelation.Block ??= block;
            Revelation.Block.Protocol ??= await Cache.Protocols.GetAsync(block.ProtoCode);

            Revelation.Block.Baker ??= Cache.Accounts.GetDelegate(block.BakerId);

            Revelation.Baker ??= Cache.Accounts.GetDelegate(revelation.BakerId);
            Revelation.Sender ??= Cache.Accounts.GetDelegate(revelation.SenderId);
            Revelation.RevealedBlock = await Cache.Blocks.GetAsync(Revelation.RevealedLevel);
        }
Beispiel #2
0
        public virtual async Task Apply(Block block, JsonElement op, JsonElement content)
        {
            #region init
            var revealedBlock = await Cache.Blocks.GetAsync(content.RequiredInt32("level"));

            var revelation = new NonceRevelationOperation
            {
                Id            = Cache.AppState.NextOperationId(),
                Block         = block,
                Level         = block.Level,
                Timestamp     = block.Timestamp,
                OpHash        = op.RequiredString("hash"),
                Baker         = block.Baker,
                Sender        = Cache.Accounts.GetDelegate(revealedBlock.BakerId),
                RevealedBlock = revealedBlock,
                RevealedLevel = revealedBlock.Level
            };
            #endregion

            #region entities
            //var block = revelation.Block;
            var blockBaker = block.Baker;
            var sender     = revelation.Sender;
            //var revealedBlock = revelation.RevealedBlock;

            //Db.TryAttach(block);
            Db.TryAttach(blockBaker);
            Db.TryAttach(sender);
            Db.TryAttach(revealedBlock);
            #endregion

            #region apply operation
            blockBaker.Balance       += block.Protocol.RevelationReward;
            blockBaker.FrozenRewards += block.Protocol.RevelationReward;

            sender.NonceRevelationsCount++;
            if (blockBaker != sender)
            {
                blockBaker.NonceRevelationsCount++;
            }

            block.Operations |= Operations.Revelations;

            revealedBlock.Revelation = revelation;
            #endregion

            Db.NonceRevelationOps.Add(revelation);
        }
Beispiel #3
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
            };
        }
Beispiel #4
0
        public virtual async Task Revert(Block block, NonceRevelationOperation revelation)
        {
            #region init
            revelation.Block ??= block;
            revelation.Block.Protocol ??= await Cache.Protocols.GetAsync(block.ProtoCode);

            revelation.Block.Baker ??= Cache.Accounts.GetDelegate(block.BakerId);

            revelation.Baker ??= Cache.Accounts.GetDelegate(revelation.BakerId);
            revelation.Sender ??= Cache.Accounts.GetDelegate(revelation.SenderId);
            revelation.RevealedBlock = await Cache.Blocks.GetAsync(revelation.RevealedLevel);

            #endregion

            #region entities
            //var block = revelation.Block;
            var blockBaker    = block.Baker;
            var sender        = revelation.Sender;
            var revealedBlock = revelation.RevealedBlock;

            //Db.TryAttach(block);
            Db.TryAttach(blockBaker);
            Db.TryAttach(sender);
            Db.TryAttach(revealedBlock);
            #endregion

            #region apply operation
            blockBaker.Balance       -= block.Protocol.RevelationReward;
            blockBaker.FrozenRewards -= block.Protocol.RevelationReward;

            sender.NonceRevelationsCount--;
            if (blockBaker != sender)
            {
                blockBaker.NonceRevelationsCount--;
            }

            revealedBlock.Revelation   = null;
            revealedBlock.RevelationId = null;
            #endregion

            Db.NonceRevelationOps.Remove(revelation);
        }
Beispiel #5
0
        public static async Task <NonceRevelationsCommit> Revert(ProtocolHandler proto, Block block, NonceRevelationOperation op)
        {
            var commit = new NonceRevelationsCommit(proto);
            await commit.Init(block, op);

            await commit.Revert();

            return(commit);
        }