Ejemplo n.º 1
0
        public async Task <ChainBlockLink> GetChainBlockLinkAsync(Hash blockHash)
        {
            var chainBlockLink = _chainBlockLinkCacheProvider.GetChainBlockLink(blockHash);

            if (chainBlockLink != null)
            {
                return(chainBlockLink);
            }
            return(await GetChainBlockLinkAsync(blockHash.ToStorageKey()));
        }
Ejemplo n.º 2
0
        public CodeRemark GetCodeRemark(IChainContext chainContext, Address address)
        {
            var blockHash   = chainContext.BlockHash;
            var blockHeight = chainContext.BlockHeight;

            if (_forkCache.TryGetValue(address, out var codeRemarks))
            {
                var blockHashes = codeRemarks.Select(c => c.BlockHash).ToList();
                var minHeight   = codeRemarks.Select(s => s.BlockHeight).Min();
                do
                {
                    if (blockHashes.Contains(blockHash))
                    {
                        return(codeRemarks.First(c => c.BlockHash == blockHash));
                    }

                    var block = _chainBlockLinkCacheProvider.GetChainBlockLink(blockHash);
                    blockHash = block?.PreviousBlockHash;
                    blockHeight--;
                } while (blockHash != null && blockHeight >= minHeight);
            }

            _cache.TryGetValue(address, out var codeRemark);
            return(codeRemark);
        }