Ejemplo n.º 1
0
        public GetHeadersPayload(uint version, Hash[] hashStart, Hash hashStop)
        {
            Contract.Requires<ArgumentNullException>(hashStart != null, "hashStart");
            Contract.Requires<ArgumentNullException>(hashStop != null, "hashStop");

            Version = version;
            HashStart = new VarArray<Hash>(hashStart);
            StartCount = new VarInt((uint)hashStart.Length);
            HashStop = hashStop;

            ByteSize = Version.ByteSize() + StartCount.ByteSize + HashStart.ByteSize + HashStop.ByteSize;
        }
Ejemplo n.º 2
0
        public VarString(byte[] buffer, int offset)
        {
            Contract.Requires<ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires<ArgumentException>(buffer.Length >= VarString.MinimumByteSize, "buffer");
            Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - VarString.MinimumByteSize, "offset");
            Contract.EnsuresOnThrow<IndexOutOfRangeException>(Contract.ValueAtReturn(out this).Length == 0);
            Contract.EnsuresOnThrow<IndexOutOfRangeException>(Contract.ValueAtReturn(out this).Value.Length == 0);

            var l = new VarInt(buffer, offset);
            var v = Encoding.ASCII.GetString(buffer, (int)((uint)offset + l.ByteSize), (int)l.Value);

            _length = l;
            _value = v;
        }
Ejemplo n.º 3
0
        public VarString(byte[] buffer, int offset)
        {
            Contract.Requires <ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires <ArgumentException>(buffer.Length >= VarString.MinimumByteSize, "buffer");
            Contract.Requires <ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires <ArgumentOutOfRangeException>(offset <= buffer.Length - VarString.MinimumByteSize, "offset");
            Contract.EnsuresOnThrow <IndexOutOfRangeException>(Contract.ValueAtReturn(out this).Length == 0);
            Contract.EnsuresOnThrow <IndexOutOfRangeException>(Contract.ValueAtReturn(out this).Value.Length == 0);

            var l = new VarInt(buffer, offset);
            var v = Encoding.ASCII.GetString(buffer, (int)((uint)offset + l.ByteSize), (int)l.Value);

            _length = l;
            _value  = v;
        }
Ejemplo n.º 4
0
        public GetHeadersPayload(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires<ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires<ArgumentException>(buffer.Length >= GetHeadersPayload.MinimumByteSize, "buffer");
            Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - GetHeadersPayload.MinimumByteSize, "offset");

            Version = buffer.ReadUInt32(offset);
            StartCount = new VarInt(buffer, StartCount_Offset(ref offset));
            HashStart = new VarArray<Hash>(buffer, HashStart_Offset(ref offset));
            HashStop = new Hash(buffer, HashStop_Offset(ref offset));

            ByteSize = Version.ByteSize() + StartCount.ByteSize + HashStart.ByteSize + HashStop.ByteSize;
        }
Ejemplo n.º 5
0
        public GetBlocksPayload(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires <ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires <ArgumentException>(buffer.Length >= GetBlocksPayload.MinimumByteSize, "buffer");
            Contract.Requires <ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires <ArgumentOutOfRangeException>(offset <= buffer.Length - GetBlocksPayload.MinimumByteSize, "offset");

            Version    = buffer.ReadUInt32(offset);
            StartCount = new VarInt(buffer, StartCount_Offset(ref offset));
            HashStart  = new VarArray <Hash>(buffer, HashStart_Offset(ref offset));
            HashStop   = new Hash(buffer, HashStop_Offset(ref offset));

            ByteSize = Version.ByteSize() + StartCount.ByteSize + HashStart.ByteSize + HashStop.ByteSize;
        }
Ejemplo n.º 6
0
        public TxOut(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires<ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires<ArgumentException>(buffer.Length >= TxOut.MinimumByteSize, "buffer");
            Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - TxOut.MinimumByteSize, "offset");

            Value = buffer.ReadUInt64(offset);
            ScriptLength = new VarInt(buffer, offset + SCRIPTLEN_OFFSET);
            var script = new byte[ScriptLength];
            Array.Copy(buffer, offset + SCRIPTLEN_OFFSET + (int)ScriptLength.ByteSize, script, 0, (int)ScriptLength.Value);
            _script = script;

            ByteSize = Value.ByteSize() + ScriptLength.ByteSize + (uint)ScriptLength.Value * BufferOperations.UINT8_SIZE;
        }
Ejemplo n.º 7
0
        public TxOut(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires <ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires <ArgumentException>(buffer.Length >= TxOut.MinimumByteSize, "buffer");
            Contract.Requires <ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires <ArgumentOutOfRangeException>(offset <= buffer.Length - TxOut.MinimumByteSize, "offset");

            Value        = buffer.ReadUInt64(offset);
            ScriptLength = new VarInt(buffer, offset + SCRIPTLEN_OFFSET);
            var script = new byte[ScriptLength];

            Array.Copy(buffer, offset + SCRIPTLEN_OFFSET + (int)ScriptLength.ByteSize, script, 0, (int)ScriptLength.Value);
            _script = script;

            ByteSize = Value.ByteSize() + ScriptLength.ByteSize + (uint)ScriptLength.Value * BufferOperations.UINT8_SIZE;
        }
Ejemplo n.º 8
0
 public VarString(string value)
 {
     _value = value;
     _length = new VarInt((ulong)value.Length);
 }
Ejemplo n.º 9
0
 public static uint GetByteSize(string value)
 {
     return((uint)value.Length + VarInt.GetByteSize((ulong)value.Length));
 }
Ejemplo n.º 10
0
 public VarString(string value)
 {
     _value  = value;
     _length = new VarInt((ulong)value.Length);
 }