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); } } }
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); }
public VarInt ReadVarInt(int offset) { VarInt varint=new VarInt(Bytes,Cursor+offset); Cursor+=offset+varint.SizeInBytes; return varint; }
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; }