public void ReadWrite(CoinStream stream) { stream.ReadWrite(ref _chainHeight); stream.ReadWrite(ref _chainTipHash); stream.ReadWrite(ref _bitmap); stream.ReadWrite(ref _outputs); }
public void SavePeerFile(string filePath, ProtocolData network) { if (network == null) { throw new ArgumentNullException(nameof(network)); } if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } MemoryStream ms = new MemoryStream(); CoinStream stream = new CoinStream(ms, true); stream.Type = SerializationType.Disk; stream.ReadWrite(network.Magic); stream.ReadWrite(this); var hash = Hashes.Hash256(ms.ToArray()); stream.ReadWrite(hash.AsCoinSerializable()); string dirPath = Path.GetDirectoryName(filePath); if (!string.IsNullOrWhiteSpace(dirPath)) { Directory.CreateDirectory(dirPath); } File.WriteAllBytes(filePath, ms.ToArray()); }
public void ReadWrite(CoinStream stream) { stream.ReadWrite(ref _Address); stream.ReadWrite(ref source); stream.ReadWrite(ref nLastSuccess); stream.ReadWrite(ref nAttempts); }
public static void StaticWrite(CoinStream bs, ulong length) { if (!bs.Serializing) { throw new InvalidOperationException("Stream should be serializing"); } var stream = bs.Inner; bs.Counter.AddWritten(1); if (length < 0xFD) { stream.WriteByte((byte)length); } else if (length <= 0xffff) { var value = (ushort)length; stream.WriteByte((byte)0xFD); bs.ReadWrite(ref value); } else if (length <= 0xffff) { var value = (uint)length; stream.WriteByte((byte)0xFE); bs.ReadWrite(ref value); } else if (length <= 0xffffffff) { var value = length; stream.WriteByte((byte)0xFF); bs.ReadWrite(ref value); } }
public override void ReadWriteCore(CoinStream stream) { stream.ReadWrite(ref _Message); stream.ReadWrite(ref _Code); stream.ReadWrite(ref _Reason); if (Message == "tx" || Message == "block") { stream.ReadWrite(ref _Hash); } }
private void UpdateShortTxIDSelector() { MemoryStream ms = new MemoryStream(); CoinStream stream = new CoinStream(ms, true); stream.ReadWrite(ref _Header); stream.ReadWrite(ref _Nonce); uint256 shorttxidhash = new uint256(Hashes.SHA256(ms.ToArrayEfficient())); _ShortTxidk0 = Hashes.SipHasher.GetULong(shorttxidhash, 0); _ShortTxidk1 = Hashes.SipHasher.GetULong(shorttxidhash, 1); }
public void ReadWrite(CoinStream stream) { if (stream.Serializing) { ulong n = _Value; #if HAS_SPAN Span <byte> tmp = stackalloc byte[(_Size * 8 + 6) / 7]; #else byte[] tmp = new byte[(_Size * 8 + 6) / 7]; #endif int len = 0; while (true) { byte a = (byte)(n & 0x7F); byte b = (byte)(len != 0 ? 0x80 : 0x00); tmp[len] = (byte)(a | b); if (n <= 0x7F) { break; } n = (n >> 7) - 1; len++; } do { byte b = tmp[len]; stream.ReadWrite(ref b); } while (len-- != 0); } else { ulong n = 0; while (true) { byte chData = 0; stream.ReadWrite(ref chData); ulong a = (n << 7); byte b = (byte)(chData & 0x7F); n = (a | b); if ((chData & 0x80) != 0) { n++; } else { break; } } _Value = n; } }
public static AddressManager LoadPeerFile(string filePath, ProtocolData expectedNetwork = null) { var addrman = new AddressManager(); byte[] data, hash; using (var fs = File.Open(filePath, FileMode.Open, FileAccess.Read)) { data = new byte[fs.Length - 32]; fs.Read(data, 0, data.Length); hash = new byte[32]; fs.Read(hash, 0, 32); } var actual = Hashes.Hash256(data); var expected = new uint256(hash); if (expected != actual) { throw new FormatException("Invalid address manager file"); } CoinStream stream = new CoinStream(data); stream.Type = SerializationType.Disk; uint magic = 0; stream.ReadWrite(ref magic); if (expectedNetwork != null && expectedNetwork.Magic != magic) { throw new FormatException("This file is not for the expected network"); } addrman.ReadWrite(stream); return(addrman); }
public override void ReadWriteCore(CoinStream stream) { if (!stream.Serializing) { _Object = default(T); } stream.ReadWrite(ref _Object); }
public override void ReadWriteCore(CoinStream stream) { stream.ReadWrite(ref _BlockId); ulong indexes_size = (ulong)_Indices.Count; stream.ReadWriteAsVarInt(ref indexes_size); if (!stream.Serializing) { ulong i = 0; ulong indicesCount = 0; while ((ulong)_Indices.Count < indexes_size) { indicesCount = Math.Min(1000UL + (ulong)indicesCount, (ulong)indexes_size); for (; i < indicesCount; i++) { ulong index = 0; stream.ReadWriteAsVarInt(ref index); if (index > Int32.MaxValue) { throw new FormatException("indexes overflowed 31-bits"); } _Indices.Add((int)index); } } int offset = 0; for (var ii = 0; ii < _Indices.Count; ii++) { if ((ulong)(_Indices[ii]) + (ulong)(offset) > Int32.MaxValue) { throw new FormatException("indexes overflowed 31-bits"); } _Indices[ii] = _Indices[ii] + offset; offset = _Indices[ii] + 1; } } else { for (var i = 0; i < _Indices.Count; i++) { int index = _Indices[i] - (i == 0 ? 0 : (_Indices[i - 1] + 1)); stream.ReadWrite(ref index); } } }
public static void ReadWrite(this CoinStream serializable, ref HDFingerprint lFingerprint) { var bytes = lFingerprint.ToBytes(); serializable.ReadWrite(ref bytes); if (!serializable.Serializing) { lFingerprint = new HDFingerprint(bytes); } }
public static int GetSerializedSize(this ICoinSerializable serializable, uint version, SerializationType serializationType) { CoinStream s = new CoinStream(Stream.Null, true) { Type = serializationType }; s.ReadWrite(serializable); return((int)s.Counter.WrittenBytes); }
internal static void StaticRead(CoinStream bs, ref byte[] bytes) { var len = VarInt.StaticRead(bs); if (len > (uint)bs.MaxArraySize) { throw new ArgumentOutOfRangeException("Array size too big"); } bytes = new byte[len]; bs.ReadWrite(ref bytes); }
internal static void StaticWrite(CoinStream bs, byte[] bytes) { var len = bytes == null ? 0 : (ulong)bytes.Length; if (len > (uint)bs.MaxArraySize) { throw new ArgumentOutOfRangeException("Array size too big"); } VarInt.StaticWrite(bs, len); if (bytes != null) { bs.ReadWrite(ref bytes); } }
public static ulong StaticRead(CoinStream bs) { if (bs.Serializing) { throw new InvalidOperationException("Stream should not be serializing"); } var prefix = bs.Inner.ReadByte(); bs.Counter.AddReaden(1); if (prefix == -1) { throw new EndOfStreamException("No more byte to read"); } if (prefix < 0xFD) { return((byte)prefix); } else if (prefix == 0xFD) { var value = (ushort)0; bs.ReadWrite(ref value); return(value); } else if (prefix == 0xFE) { var value = (uint)0; bs.ReadWrite(ref value); return(value); } else { var value = (ulong)0; bs.ReadWrite(ref value); return(value); } }
public void ReadWrite(CoinStream stream) { using (stream.BigEndianScope()) { stream.ReadWrite(ref nDepth); stream.ReadWrite(ref parentFingerprint); stream.ReadWrite(ref nChild); stream.ReadWrite(ref vchChainCode); byte b = 0; stream.ReadWrite(ref b); stream.ReadWrite(ref key); } }
public override void ReadWriteCore(CoinStream stream) { stream.ReadWrite(ref version); stream.ReadWrite(ref blockLocators); stream.ReadWrite(ref _HashStop); }
public override void ReadWriteCore(CoinStream stream) { stream.ReadWrite(ref _PreferHeaderAndIDs); stream.ReadWrite(ref _Version); }
public override void ReadWriteCore(CoinStream stream) { stream.ReadWrite(ref addr_list); }
public void ReadWrite(CoinStream stream) { stream.ReadWrite(ref _version); stream.ReadWrite(ref _height); stream.ReadWrite(ref _txOut); }