-\feffusing System;
+\feff/**
+ * Novacoin classes library
+ * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com)
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using System;
using System.Text;
using System.Collections.Generic;
/// <param name="txBytes">Byte sequence</param>
public CTransaction(IList<byte> txBytes)
{
- ByteQueue wBytes = new ByteQueue(txBytes);
+ var wBytes = new ByteQueue(txBytes);
nVersion = BitConverter.ToUInt32(wBytes.Get(4), 0);
nTime = BitConverter.ToUInt32(wBytes.Get(4), 0);
/// <returns>Transactions array</returns>
public static CTransaction[] ReadTransactionsList(ref ByteQueue wTxBytes)
{
- CTransaction[] tx;
-
// Read amount of transactions
int nTransactions = (int)wTxBytes.GetVarInt();
- tx = new CTransaction[nTransactions];
+ var tx = new CTransaction[nTransactions];
for (int nTx = 0; nTx < nTransactions; nTx++)
{
}
}
+ /// <summary>
+ /// Transaction hash
+ /// </summary>
+ public Hash256 Hash
+ {
+ get { return Hash256.Compute256(Bytes); }
+ }
+ /// <summary>
+ /// A sequence of bytes, which corresponds to the current state of CTransaction.
+ /// </summary>
public IList<byte> Bytes
{
get
{
- List<byte> resultBytes = new List<byte>();
+ var resultBytes = new List<byte>();
// Typical transaction example:
//
resultBytes.AddRange(BitConverter.GetBytes(nTime));
resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength));
- foreach (CTxIn input in vin)
+ foreach (var input in vin)
{
resultBytes.AddRange(input.Bytes);
}
resultBytes.AddRange(VarInt.EncodeVarInt(vout.LongLength));
- foreach (CTxOut output in vout)
+ foreach (var output in vout)
{
resultBytes.AddRange(output.Bytes);
}
public override string ToString()
{
- StringBuilder sb = new StringBuilder();
+ var sb = new StringBuilder();
sb.AppendFormat("CTransaction(\n nVersion={0},\n nTime={1},\n", nVersion, nTime);
- foreach (CTxIn txin in vin)
+ foreach (var txin in vin)
{
sb.AppendFormat(" {0},\n", txin.ToString());
}
- foreach (CTxOut txout in vout)
+ foreach (var txout in vout)
{
sb.AppendFormat(" {0},\n", txout.ToString());
}