示例#1
0
        public void RandomHash_Test()
        {
            var blockHash = Hash.FromString("blockHash");
            var result    = _randomHashCacheService.GetRandomHash(blockHash);

            result.ShouldBe(Hash.Empty);

            var randomHash = Hash.FromString("randomHash");

            _randomHashCacheService.SetRandomHash(blockHash, randomHash);

            var queryResult = _randomHashCacheService.GetRandomHash(blockHash);

            queryResult.ShouldBe(randomHash);
        }
示例#2
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());
        }