/// <exception cref="IOException"/> public override void BitcoinSerializeToStream(Stream stream) { Outpoint.BitcoinSerializeToStream(stream); stream.Write(new VarInt((ulong)ScriptBytes.Length).Encode()); stream.Write(ScriptBytes); Utils.Uint32ToByteStreamLe(_sequence, stream); }
/// <exception cref="System.IO.IOException" /> private void WriteHeader(Stream stream) { Utils.Uint32ToByteStreamLe(_version, stream); stream.Write(Utils.ReverseBytes(_prevBlockHash)); stream.Write(Utils.ReverseBytes(MerkleRoot)); Utils.Uint32ToByteStreamLe(_time, stream); Utils.Uint32ToByteStreamLe(_difficultyTarget, stream); Utils.Uint32ToByteStreamLe(_nonce, stream); }
/// <exception cref="IOException"/> public override void BitcoinSerializeToStream(Stream stream) { stream.Write(new VarInt((ulong)_items.Count).Encode()); foreach (var i in _items) { // Write out the type code. Utils.Uint32ToByteStreamLe((uint)i.Type, stream); // And now the hash. stream.Write(Utils.ReverseBytes(i.Hash.Bytes)); } }
/// <exception cref="IOException"/> public override void BitcoinSerializeToStream(Stream stream) { Utils.Uint32ToByteStreamLe(_version, stream); stream.Write(new VarInt((ulong)_inputs.Count).Encode()); foreach (var @in in _inputs) { @in.BitcoinSerializeToStream(stream); } stream.Write(new VarInt((ulong)_outputs.Count).Encode()); foreach (var @out in _outputs) { @out.BitcoinSerializeToStream(stream); } Utils.Uint32ToByteStreamLe(_lockTime, stream); }
private byte[] HashTransactionForSignature(SigHash type, bool anyoneCanPay) { using (var bos = new MemoryStream()) { BitcoinSerializeToStream(bos); // We also have to write a hash type. var hashType = (uint)type + 1; if (anyoneCanPay) { hashType |= 0x80; } Utils.Uint32ToByteStreamLe(hashType, bos); // Note that this is NOT reversed to ensure it will be signed correctly. If it were to be printed out // however then we would expect that it is IS reversed. return(Utils.DoubleDigest(bos.ToArray())); } }
public override byte[] BitcoinSerialize() { using (var buf = new MemoryStream()) { // Version, for some reason. Utils.Uint32ToByteStreamLe(NetworkParameters.ProtocolVersion, buf); // Then a vector of block hashes. This is actually a "block locator", a set of block // identifiers that spans the entire chain with exponentially increasing gaps between // them, until we end up at the genesis block. See CBlockLocator::Set() buf.Write(new VarInt((ulong) _locator.Count).Encode()); foreach (var hash in _locator) { // Have to reverse as wire format is little endian. buf.Write(Utils.ReverseBytes(hash.Bytes)); } // Next, a block ID to stop at. buf.Write(_stopHash.Bytes); return buf.ToArray(); } }
/// <exception cref="System.IO.IOException" /> public override void BitcoinSerializeToStream(Stream buf) { Utils.Uint32ToByteStreamLe(ClientVersion, buf); Utils.Uint64ToByteStreamLe(LocalServices, buf); Utils.Uint64ToByteStreamLe(Time, buf); // My address. MyAddr.BitcoinSerializeToStream(buf); // Their address. TheirAddr.BitcoinSerializeToStream(buf); // Next up is the "local host nonce", this is to detect the case of connecting // back to yourself. We don't care about this as we won't be accepting inbound // connections. Utils.Uint64ToByteStreamLe(_localHostNonce, buf); // Now comes subVer. var subVerBytes = Encoding.UTF8.GetBytes(SubVer); buf.Write(new VarInt((ulong)subVerBytes.Length).Encode()); buf.Write(subVerBytes); // Size of known block chain. Utils.Uint32ToByteStreamLe(BestHeight, buf); }
/// <exception cref="System.IO.IOException" /> public override void BitcoinSerializeToStream(Stream stream) { if (ProtocolVersion >= 31402) { var secs = UnixTime.ToUnixTime(DateTime.UtcNow); Utils.Uint32ToByteStreamLe((uint)secs, stream); } Utils.Uint64ToByteStreamLe(_services, stream); // nServices. // Java does not provide any utility to map an IPv4 address into IPv6 space, so we have to do it by hand. var ipBytes = Addr.GetAddressBytes(); if (ipBytes.Length == 4) { var v6Addr = new byte[16]; Array.Copy(ipBytes, 0, v6Addr, 12, 4); v6Addr[10] = 0xFF; v6Addr[11] = 0xFF; ipBytes = v6Addr; } stream.Write(ipBytes); // And write out the port. Unlike the rest of the protocol, address and port is in big endian byte order. stream.Write((byte)(Port >> 8)); stream.Write((byte)Port); }
/// <exception cref="IOException"/> public override void BitcoinSerializeToStream(Stream stream) { stream.Write(Utils.ReverseBytes(Hash.Bytes)); Utils.Uint32ToByteStreamLe((uint)Index, stream); }
/// <exception cref="System.IO.IOException" /> public override void BitcoinSerializeToStream(Stream stream) { Debug.Assert(Hash.Length == 32); stream.Write(Utils.ReverseBytes(Hash)); Utils.Uint32ToByteStreamLe((uint)Index, stream); }