private async Task SetChainBlockIndexAsync(long blockHeight, Hash blockHash) { await _chainBlockIndexes.SetAsync(ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator + blockHeight.ToStorageKey(), new ChainBlockIndex() { BlockHash = blockHash }); }
private async Task SetChainBlockIndexesAsync(IDictionary <long, Hash> blockIndexes) { var prefix = ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator; await _chainBlockIndexes.SetAllAsync(blockIndexes.ToDictionary(d => prefix + d.Key.ToStorageKey(), d => new ChainBlockIndex { BlockHash = d.Value })); }
private async Task SetChainBlockLinksAsync(IList <ChainBlockLink> chainBlockLinks) { var prefix = ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator; await _chainBlockLinks.SetAllAsync(chainBlockLinks.ToDictionary(l => prefix + l.BlockHash.ToStorageKey(), l => l)); foreach (var chainBlockLink in chainBlockLinks) { _chainBlockLinkCacheProvider.SetChainBlockLink(chainBlockLink); } }
public async Task <Chain> CreateAsync(Hash genesisBlock) { var chain = await _chains.GetAsync(ChainId.ToStorageKey()); if (chain != null) { throw new InvalidOperationException("chain already exists"); } chain = new Chain() { Id = ChainId, LongestChainHeight = AElfConstants.GenesisBlockHeight, LongestChainHash = genesisBlock, BestChainHeight = AElfConstants.GenesisBlockHeight, BestChainHash = genesisBlock, GenesisBlockHash = genesisBlock, LastIrreversibleBlockHash = genesisBlock, LastIrreversibleBlockHeight = AElfConstants.GenesisBlockHeight, Branches = { { genesisBlock.ToStorageKey(), AElfConstants.GenesisBlockHeight } } }; await SetChainBlockLinkAsync(new ChainBlockLink() { BlockHash = genesisBlock, Height = AElfConstants.GenesisBlockHeight, PreviousBlockHash = Hash.Empty, IsLinked = true, IsIrreversibleBlock = true }); await SetChainBlockIndexAsync(AElfConstants.GenesisBlockHeight, genesisBlock); await _chains.SetAsync(ChainId.ToStorageKey(), chain); return(chain); }
public async Task <ChainBlockIndex> GetChainBlockIndexAsync(long blockHeight) { return(await _chainBlockIndexes.GetAsync(ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator + blockHeight.ToStorageKey())); }
public async Task RemoveChainBlockLinkAsync(Hash blockHash) { await _chainBlockLinks.RemoveAsync(ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator + blockHash.ToStorageKey()); _chainBlockLinkCacheProvider.RemoveChainBlockLink(blockHash); }
public async Task SetChainBlockLinkAsync(ChainBlockLink chainBlockLink) { await _chainBlockLinks.SetAsync(ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator + chainBlockLink.BlockHash.ToStorageKey(), chainBlockLink); _chainBlockLinkCacheProvider.SetChainBlockLink(chainBlockLink); }
private async Task <List <ChainBlockLink> > GetChainBlockLinksAsync(IList <string> blockHashes) { var prefix = ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator; return(await _chainBlockLinks.GetAllAsync(blockHashes.Select(h => prefix + h).ToList())); }
private async Task <ChainBlockLink> GetChainBlockLinkAsync(string blockHash) { return(await _chainBlockLinks.GetAsync(ChainId.ToStorageKey() + KernelConstants.StorageKeySeparator + blockHash)); }
public async Task <Chain> GetAsync() { var chain = await _chains.GetAsync(ChainId.ToStorageKey()); return(chain); }