Exemplo n.º 1
0
        public async Task <BytesValue> GetTriggerInformationForConsensusTransactionsAsync(BytesValue consensusCommandBytes)
        {
            if (consensusCommandBytes == null)
            {
                return(new AElfConsensusTriggerInformation
                {
                    Pubkey = PublicKey,
                    Behaviour = AElfConsensusBehaviour.UpdateValue
                }.ToBytesValue());
            }

            var command   = consensusCommandBytes.ToConsensusCommand();
            var behaviour = command.Hint.ToAElfConsensusHint().Behaviour;
            var bestChainLastBlockHeader = await _blockchainService.GetBestChainLastBlockHeaderAsync();

            if (behaviour == AElfConsensusBehaviour.UpdateValue ||
                behaviour == AElfConsensusBehaviour.UpdateValueWithoutPreviousInValue)
            {
                var trigger = new AElfConsensusTriggerInformation
                {
                    Pubkey             = PublicKey,
                    RandomHash         = _randomHashCacheService.GetRandomHash(bestChainLastBlockHeader.GetHash()),
                    PreviousRandomHash = _randomHashCacheService.GetLatestGeneratedBlockRandomHash(),
                    Behaviour          = behaviour
                };

                return(trigger.ToBytesValue());
            }

            return(new AElfConsensusTriggerInformation
            {
                Pubkey = PublicKey,
                Behaviour = behaviour
            }.ToBytesValue());
        }
Exemplo n.º 2
0
        public BytesValue GetTriggerInformationForConsensusTransactions(BytesValue consensusCommandBytes)
        {
            if (consensusCommandBytes == null)
            {
                return(new AElfConsensusTriggerInformation
                {
                    Pubkey = Pubkey,
                    Behaviour = AElfConsensusBehaviour.UpdateValue
                }.ToBytesValue());
            }

            var command = consensusCommandBytes.ToConsensusCommand();
            var hint    = command.Hint.ToAElfConsensusHint();

            if (hint.Behaviour == AElfConsensusBehaviour.UpdateValue)
            {
                var inValue = _inValueCache.GetInValue(hint.RoundId);
                var trigger = new AElfConsensusTriggerInformation
                {
                    Pubkey          = Pubkey,
                    InValue         = inValue,
                    PreviousInValue = _inValueCache.GetInValue(hint.PreviousRoundId),
                    Behaviour       = hint.Behaviour,
                };

                var secretPieces = _secretSharingService.GetEncryptedPieces(hint.RoundId);
                foreach (var secretPiece in secretPieces)
                {
                    trigger.EncryptedPieces.Add(secretPiece.Key, ByteString.CopyFrom(secretPiece.Value));
                }

                var decryptedPieces = _secretSharingService.GetDecryptedPieces(hint.RoundId);
                foreach (var decryptedPiece in decryptedPieces)
                {
                    trigger.DecryptedPieces.Add(decryptedPiece.Key, ByteString.CopyFrom(decryptedPiece.Value));
                }

                var revealedInValues = _secretSharingService.GetRevealedInValues(hint.RoundId);
                foreach (var revealedInValue in revealedInValues)
                {
                    trigger.RevealedInValues.Add(revealedInValue.Key, revealedInValue.Value);
                }

                return(trigger.ToBytesValue());
            }

            return(new AElfConsensusTriggerInformation
            {
                Pubkey = Pubkey,
                Behaviour = hint.Behaviour
            }.ToBytesValue());
        }
Exemplo n.º 3
0
        public BytesValue GetTriggerInformationForBlockHeaderExtraData(BytesValue consensusCommandBytes)
        {
            if (consensusCommandBytes == null)
            {
                return(new AElfConsensusTriggerInformation
                {
                    Pubkey = Pubkey,
                    Behaviour = AElfConsensusBehaviour.UpdateValue
                }.ToBytesValue());
            }

            var command = consensusCommandBytes.ToConsensusCommand();
            var hint    = command.Hint.ToAElfConsensusHint();

            if (hint.Behaviour == AElfConsensusBehaviour.UpdateValue)
            {
                var newInValue      = _inValueCache.GetInValue(hint.RoundId);
                var previousInValue = _inValueCache.GetInValue(hint.PreviousRoundId);
                Logger.LogTrace($"New in value {newInValue} for round of id {hint.RoundId}");
                Logger.LogTrace($"Previous in value {previousInValue} for round of id {hint.PreviousRoundId}");
                var trigger = new AElfConsensusTriggerInformation
                {
                    Pubkey          = Pubkey,
                    InValue         = newInValue,
                    PreviousInValue = previousInValue,
                    Behaviour       = hint.Behaviour
                };

                return(trigger.ToBytesValue());
            }

            return(new AElfConsensusTriggerInformation
            {
                Pubkey = Pubkey,
                Behaviour = hint.Behaviour
            }.ToBytesValue());
        }