示例#1
0
        public void BlockExecutedData_Test()
        {
            _blockchainExecutedDataCacheProvider.SetBlockExecutedData("key1", 1);
            _blockchainExecutedDataCacheProvider.TryGetBlockExecutedData("key1", out var value);
            value.ShouldBe(1);

            _blockchainExecutedDataCacheProvider.RemoveBlockExecutedData("key1");
            _blockchainExecutedDataCacheProvider.TryGetBlockExecutedData("key1", out _).ShouldBeFalse();
        }
        public T GetBlockExecutedData(IBlockIndex chainContext, string key)
        {
            if (!_blockchainExecutedDataCacheProvider.TryGetChangeHeight(key, out _) &&
                _blockchainExecutedDataCacheProvider.TryGetBlockExecutedData(key, out var value))
            {
                return(value);
            }

            var ret = AsyncHelper.RunSync(() => _blockchainExecutedDataManager.GetExecutedCacheAsync(key,
                                                                                                     chainContext.BlockHeight,
                                                                                                     chainContext.BlockHash));

            var blockExecutedData = Deserialize(ret.Value);

            //if executed is in Store, it will not change when forking
            if (ret.IsInStore && !_blockchainExecutedDataCacheProvider.TryGetChangeHeight(key, out _))
            {
                _blockchainExecutedDataCacheProvider.SetBlockExecutedData(key, blockExecutedData);
            }
            return(blockExecutedData);
        }