public void Load(BitcoinStream stream) { using (@lock.LockWrite()) { try { int height = 0; while (true) { uint256.MutableUint256 id = null; stream.ReadWrite <uint256.MutableUint256>(ref id); BlockHeader header = null; stream.ReadWrite(ref header); if (height == 0) { _BlocksByHeight.Clear(); _BlocksById.Clear(); _Tip = null; SetTipNoLock(new ChainedBlock(header, 0)); } else { SetTipNoLock(new ChainedBlock(header, id.Value, Tip)); } height++; } } catch (EndOfStreamException) { } } }
public void Load(BitcoinStream stream) { using (this.lockObject.LockWrite()) { try { int height = 0; while (true) { uint256.MutableUint256 id = null; stream.ReadWrite <uint256.MutableUint256>(ref id); BlockHeader header = null; stream.ReadWrite(ref header); if (height == 0) { this.blocksByHeight.Clear(); this.blocksById.Clear(); this.tip = null; this.SetTipLocked(new ChainedBlock(header, header.GetHash(), 0)); } else { this.SetTipLocked(new ChainedBlock(header, id.Value, this.Tip)); } height++; } } catch (EndOfStreamException) { } } }
public void ReadWrite(uint256 value) { value = value ?? uint256.Zero; var v = new uint256.MutableUint256(value); this.ReadWrite(ref v); value = v.Value; }
public void Load(BitcoinStream stream, ChainSerializationFormat format) { format = format ?? new ChainSerializationFormat(); format.AssertCoherent(); var genesis = this.Genesis; using (@lock.LockWrite()) { try { int height = 0; while (true) { uint256.MutableUint256 id = null; if (format.SerializePrecomputedBlockHash) { stream.ReadWrite <uint256.MutableUint256>(ref id); } BlockHeader header = null; if (format.SerializeBlockHeader) { stream.ReadWrite(ref header); } if (height == 0) { _BlocksByHeight = new ChainedBlock[0]; _BlocksById.Clear(); _Tip = null; if (header != null && genesis != null && header.GetHash() != genesis.HashBlock) { throw new InvalidOperationException("Unexpected genesis block"); } SetTipNoLock(new ChainedBlock(genesis?.Header ?? header, 0)); } else if (!format.SerializeBlockHeader || (_Tip.HashBlock == header.HashPrevBlock && !(header.IsNull && header.Nonce == 0))) { SetTipNoLock(new ChainedBlock(header, id?.Value, Tip)); } else { break; } height++; } } catch (EndOfStreamException) { } } }
public void Load(BitcoinStream stream) { stream.ConsensusFactory = this.network.Consensus.ConsensusFactory; using (this.lockObject.LockWrite()) { try { int height = 0; while (true) { uint256.MutableUint256 id = null; stream.ReadWrite <uint256.MutableUint256>(ref id); BlockHeader header = null; stream.ReadWrite(ref header); if (height == 0) { this.blocksByHeight.Clear(); this.blocksById.Clear(); this.tip = null; this.SetTipLocked(new ChainedHeader(header, header.GetHash(), 0)); } else if (this.tip.HashBlock == header.HashPrevBlock && !(header.IsNull && header.Nonce == 0)) { this.SetTipLocked(new ChainedHeader(header, id.Value, this.Tip)); } else { break; } height++; } } catch (EndOfStreamException) { } } }