Ejemplo n.º 1
0
        private void ___writeTransactions(Stream stream)
        {
            // Check for no transaction conditions first
            if(Transactions==null && transactionsParsed)
            { return; }

            // Confirmed we must have transactions either cached or as objects.
            if(transactionBytesValid && Bytes!=null && Bytes.Length>=Offset+Length)
            {
                stream.Write(Bytes,Offset+HeaderSize,Length-HeaderSize);
                return;
            }

            if(Transactions!=null)
            {
                byte[] buffer=new VarInt((ulong)Transactions.Count).Encode();
                stream.Write(buffer,0,buffer.Length);

                foreach(Transaction tx in Transactions)
                { tx.BitcoinSerializeToStream(stream); }
            }
        }
Ejemplo n.º 2
0
        public string ReadString()
        {
            var varInt=new VarInt(Bytes,Cursor);
            if(varInt.Value==0)
            {
                Cursor+=1;
                return string.Empty;
            }

            Cursor+=varInt.SizeInBytes;
            return Encoding.UTF8.GetString(Bytes,Cursor,(int)varInt.Value);
        }
Ejemplo n.º 3
0
 public VarInt ReadVarInt(int offset)
 {
     VarInt varint=new VarInt(Bytes,Cursor+offset);
     Cursor+=offset+varint.SizeInBytes;
     return varint;
 }
Ejemplo n.º 4
0
		protected static int calcLength(byte[] buf,int cursor,int offset)
		{
			VarInt varint;
			// jump past version (uint32)
			cursor = offset + 4;

			int i;
			long scriptLen;

			varint = new VarInt(buf, cursor);
			long txInCount = varint.value;
			cursor += varint.getOriginalSizeInBytes();

			for (i = 0; i < txInCount; i++) {
				// 36 = length of previous_outpoint
				cursor += 36;
				varint = new VarInt(buf, cursor);
				scriptLen = varint.value;
				// 4 = length of sequence field (unint32)
				cursor += scriptLen + 4 + varint.getOriginalSizeInBytes();
			}

			varint = new VarInt(buf, cursor);
			long txOutCount = varint.value;
			cursor += varint.getOriginalSizeInBytes();

			for (i = 0; i < txOutCount; i++) {
				// 8 = length of tx value field (uint64)
				cursor += 8;
				varint = new VarInt(buf, cursor);
				scriptLen = varint.value;
				cursor += scriptLen + varint.getOriginalSizeInBytes();
			}
			// 4 = length of lock_time field (uint32)
			return cursor - offset + 4;
		}