/// Parse byte sequence and initialize new block instance
/// </summary>
/// <param name="blockBytes"></param>
- public CBlock (List<byte> blockBytes)
+ public CBlock (IList<byte> blockBytes)
{
header = new CBlockHeader();
/// <summary>
/// Parse byte sequence and initialize new instance of CTransaction
/// </summary>
- /// <param name="txBytes"></param>
+ /// <param name="txBytes">Byte sequence</param>
public CTransaction (IList<byte> txBytes)
{
WrappedList<byte> wBytes = new WrappedList<byte>(txBytes);
vin[nCurrentInput] = new CTxIn();
vin[nCurrentInput].txID = new Hash256(wBytes.GetItems(32));
- vin[nCurrentInput].n = BitConverter.ToUInt32(wBytes.GetItems(4),0);
- vin[nCurrentInput].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
- vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4),0);
+ vin[nCurrentInput].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
+
+ int nScriptSigLen = (int)VarInt.ReadVarInt(ref wBytes);
+ vin[nCurrentInput].scriptSig = new CScript(wBytes.GetItems(nScriptSigLen));
+ vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
}
int nOutputs = (int)VarInt.ReadVarInt(ref wBytes);
{
// Fill outputs array
vout[nCurrentOutput] = new CTxOut();
- vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.GetItems(8),0);
- vout[nCurrentOutput].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+ vout[nCurrentOutput].nValue = BitConverter.ToUInt64(wBytes.GetItems(8), 0);
+
+ int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+ vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
}
nLockTime = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
/// <summary>
/// First half of script, signatures for the scriptPubKey
/// </summary>
- public byte[] scriptSig;
+ public CScript scriptSig;
/// <summary>
/// Transaction variant number, irrelevant if nLockTime isn't specified. Its value is 0xffffffff by default.
vin[nIndex].txID = new Hash256(wBytes.GetItems(32));
vin[nIndex].n = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
- vin[nIndex].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+ vin[nIndex].scriptSig = new CScript(wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)));
vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.GetItems(4), 0);
}
inputBytes.AddRange(txID.hashBytes); // Input transaction id
inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number
- inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length
- inputBytes.AddRange(scriptSig); // scriptSig
+
+ List<byte> s = new List<byte>(scriptSig.Bytes);
+
+ inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length
+ inputBytes.AddRange(s); // scriptSig
inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence
return inputBytes;
if (IsCoinBase)
{
- sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence);
+ sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig.Bytes), nSequence);
}
else
{
- sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, (new CScript(scriptSig)).ToString(), nSequence);
+ sb.AppendFormat("CTxIn(txId={0}, n={1}, scriptSig={2}, nSequence={3})", txID.ToString(), n, scriptSig.ToString(), nSequence);
}
return sb.ToString ();
/// <summary>
/// Second half of script which contains spending instructions.
/// </summary>
- public byte[] scriptPubKey;
+ public CScript scriptPubKey;
/// <summary>
/// Initialize new CTxOut instance as a copy of another instance.
// Fill outputs array
vout[nIndex] = new CTxOut();
vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.GetItems(8), 0);
- vout[nIndex].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes));
+
+ int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes);
+ vout[nIndex].scriptPubKey = new CScript(wBytes.GetItems(nScriptPKLen));
}
return vout;
List<byte> resultBytes = new List<byte>();
resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value
- resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length
- resultBytes.AddRange(scriptPubKey); // scriptPubKey
+
+ List<byte> s = new List<byte>(scriptPubKey.Bytes);
+
+ resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length
+ resultBytes.AddRange(s); // scriptPubKey
return resultBytes;
}
public override string ToString ()
{
StringBuilder sb = new StringBuilder ();
- sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, (new CScript(scriptPubKey)).ToString());
+ sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString());
return sb.ToString ();
}