Example #1
0
        public void TryGet_Null()
        {
            int chainId = 123;

            var actualBlockInfoCache = _crossChainCacheEntityProvider.GetChainCacheEntity(chainId);

            Assert.Null(actualBlockInfoCache);
        }
Example #2
0
        public T Take <T>(int crossChainId, long height, bool isCacheSizeLimited) where T : IMessage, new()
        {
            var chainCacheEntity = _crossChainCacheEntityProvider.GetChainCacheEntity(crossChainId);

            if (chainCacheEntity == null || !chainCacheEntity.TryTake(height, out var blockCacheEntity, isCacheSizeLimited))
            {
                return(default(T));
            }
            var t = new T();

            t.MergeFrom(blockCacheEntity.ToByteString());
            return(t);
        }
Example #3
0
        public bool TryAddBlockCacheEntity(IBlockCacheEntity blockCacheEntity)
        {
            if (blockCacheEntity == null)
            {
                throw new ArgumentNullException(nameof(blockCacheEntity));
            }
            var chainCacheEntity = _crossChainCacheEntityProvider.GetChainCacheEntity(blockCacheEntity.ChainId);

            if (chainCacheEntity == null)
            {
                return(false);
            }
            var res = chainCacheEntity.TryAdd(blockCacheEntity);

            Logger.LogTrace(
                $"Cached height {blockCacheEntity.Height} from chain {ChainHelper.ConvertChainIdToBase58(blockCacheEntity.ChainId)}, {res}");
            return(res);
        }
 public long GetTargetHeightForChainCacheEntity(int chainId)
 {
     return(_crossChainCacheEntityProvider.GetChainCacheEntity(chainId).TargetChainHeight());
 }