// TODO: rename to AddBlock public void AddBlockItem(ulong mapId, byte[] block, int realSize) { lock (_lock) { var hash = _hash.Calculate(block); ulong metadataId; if (_metadataCache.Value.TryGetValue(hash, out metadataId)) { var item = _metadataRepository.GetById(metadataId); item.References++; _metadataRepository.Update(metadataId, item); } else { var dataId = _dataRepository.Add(block); var item = new MetadataItem { DataId = dataId, Checksum = hash, References = 1, Size = (ulong)realSize }; metadataId = _metadataRepository.Add(item); _metadataCache.Value.Add(hash, metadataId); } var mapRecordItem = new MapRecord(metadataId); _mapProvider[mapId].Add(mapRecordItem); } }
public string CalculateHash(IBlockDefinition block) { return(hash.Calculate(block.Index + block.PreviousHash + block.TimeStamp + block.Data?.ToContentString() + block.Difficulty + block.Nonce)); }