Example #1
0
 public BitcoinVarString(string text)
 {
     byte[] lengthAsVarInt = new BitcoinVarInt((ulong)text.Length).VarIntBytes;
     byte[] textBytes      = Encoding.ASCII.GetBytes(text);
     this.VarStringBytes = new byte[lengthAsVarInt.Length + textBytes.Length];
     Buffer.BlockCopy(lengthAsVarInt, 0, this.VarStringBytes, 0, lengthAsVarInt.Length);
     Buffer.BlockCopy(textBytes, 0, this.VarStringBytes, lengthAsVarInt.Length, textBytes.Length);
     this.Text             = text;
     this.SerializedLength = this.VarStringBytes.Length;
 }
Example #2
0
        public BitcoinVarString(byte[] varStringBytes, int startIndex = 0)
        {
            this.VarStringBytes = varStringBytes;
            BitcoinVarInt length = new BitcoinVarInt(varStringBytes, startIndex);

            this.Text = Encoding.ASCII.GetString(varStringBytes, startIndex + length.SerializedLength,
                                                 (int)length.Value);
            this.SerializedLength = length.SerializedLength + (int)length.Value;
            this.VarStringBytes   = new byte[this.SerializedLength];
            Buffer.BlockCopy(varStringBytes, startIndex, this.VarStringBytes, 0, this.VarStringBytes.Length);
        }
Example #3
0
        public BitcoinAddrPayload(byte[] serialized)
        {
            this.Addresses = new List <BitcoinNetworkAddressPayload>();
            this.AddrCount = new BitcoinVarInt(serialized);
            var currentOffset = this.AddrCount.SerializedLength;

            for (var i = currentOffset; i < 30 * (int)this.AddrCount.Value; i += 30)
            {
                var addr = new BitcoinNetworkAddressPayload(serialized, i, true);
                this.Addresses.Add(addr);
            }
        }