public bool TryReadBlockHeader(ref ByteSequenceReader r) { if (r.Data.Remaining < BlockHeaderSize) { return(false); } var start = r.Data.Position; if (!r.TryReadLittleEndian(out _version)) { return(false); } if (!r.TryReadUInt256(ref _hashPrevBlock)) { return(false); } if (!r.TryReadUInt256(ref _hashMerkleRoot)) { return(false); } if (!r.TryReadLittleEndian(out _time)) { return(false); } if (!r.TryReadLittleEndian(out _bits)) { return(false); } if (!r.TryReadLittleEndian(out _nonce)) { return(false); } var end = r.Data.Position; var blockBytes = r.Data.Sequence.Slice(start, end).ToArray(); using var sha256 = SHA256.Create(); var hash1 = sha256.ComputeHash(blockBytes); var hash2 = sha256.ComputeHash(hash1); hash2.CopyTo(_hash.Span); return(true); }
public bool TryReadOutPoint(ref ByteSequenceReader r) { var txHash = TxId; if (!r.TryReadUInt256(ref txHash) || !r.TryReadLittleEndian(out int index)) { return(false); } TxId = txHash; Index = index; return(true); }