From f8dfad5d516a39038b5a1786e23b82213886661d Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Mon, 17 Aug 2015 16:29:04 +0300 Subject: [PATCH] Minor cleanup --- Novacoin/CBlock.cs | 15 +++++++-------- Novacoin/CTransaction.cs | 43 +++++++++++++++++++++---------------------- Novacoin/CTxIn.cs | 4 ++-- Novacoin/CTxOut.cs | 2 +- 4 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index f8b9e7e..4402480 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -17,7 +17,7 @@ namespace Novacoin /// /// Transactions array. /// - public CTransaction[] tx; + public CTransaction[] vtx; /// /// Block header signature. @@ -43,7 +43,7 @@ namespace Novacoin header.nNonce = Interop.LEBytesToUInt32(wBytes.GetItems(4)); // Parse transactions list - tx = CTransaction.ReadTransactionsList(ref wBytes); + vtx = CTransaction.ReadTransactionsList(ref wBytes); // Read block signature signature = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); @@ -58,11 +58,11 @@ namespace Novacoin List r = new List(); r.AddRange(header.ToBytes()); - r.AddRange(VarInt.EncodeVarInt(tx.LongLength)); // transactions count + r.AddRange(VarInt.EncodeVarInt(vtx.LongLength)); // transactions count - foreach (CTransaction t in tx) + foreach (CTransaction tx in vtx) { - r.AddRange(t.ToBytes()); + r.AddRange(tx.ToBytes()); } r.AddRange(VarInt.EncodeVarInt(signature.LongLength)); @@ -77,14 +77,13 @@ namespace Novacoin sb.AppendFormat("CBlock(\n header={0},\n", header.ToString()); - foreach(CTransaction t in tx) + foreach(CTransaction tx in vtx) { - sb.AppendFormat("{0}, \n", t.ToString()); + sb.AppendFormat("{0},\n", tx.ToString()); } sb.AppendFormat("signature={0})\n", Interop.ToHex(signature)); - // TODO return sb.ToString(); } diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index 6e40a0b..9ed33ca 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -22,12 +22,12 @@ namespace Novacoin /// /// Array of transaction inputs /// - public CTxIn[] inputs; + public CTxIn[] vin; /// /// Array of transaction outputs /// - public CTxOut[] outputs; + public CTxOut[] vout; /// /// Block height or timestamp when transaction is final @@ -53,28 +53,28 @@ namespace Novacoin nTime = Interop.LEBytesToUInt32(wBytes.GetItems(4)); int nInputs = (int)VarInt.ReadVarInt(ref wBytes); - inputs = new CTxIn[nInputs]; + vin = new CTxIn[nInputs]; for (int nCurrentInput = 0; nCurrentInput < nInputs; nCurrentInput++) { // Fill inputs array - inputs[nCurrentInput] = new CTxIn(); + vin[nCurrentInput] = new CTxIn(); - inputs[nCurrentInput].txID = new Hash256(wBytes.GetItems(32)); - inputs[nCurrentInput].n = Interop.LEBytesToUInt32(wBytes.GetItems(4)); - inputs[nCurrentInput].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); - inputs[nCurrentInput].nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4)); + vin[nCurrentInput].txID = new Hash256(wBytes.GetItems(32)); + vin[nCurrentInput].n = Interop.LEBytesToUInt32(wBytes.GetItems(4)); + vin[nCurrentInput].scriptSig = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); + vin[nCurrentInput].nSequence = Interop.LEBytesToUInt32(wBytes.GetItems(4)); } int nOutputs = (int)VarInt.ReadVarInt(ref wBytes); - outputs = new CTxOut[nOutputs]; + vout = new CTxOut[nOutputs]; for (int nCurrentOutput = 0; nCurrentOutput < nOutputs; nCurrentOutput++) { // Fill outputs array - outputs[nCurrentOutput] = new CTxOut(); - outputs[nCurrentOutput].nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8)); - outputs[nCurrentOutput].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); + vout[nCurrentOutput] = new CTxOut(); + vout[nCurrentOutput].nValue = Interop.LEBytesToUInt64(wBytes.GetItems(8)); + vout[nCurrentOutput].scriptPubKey = wBytes.GetItems((int)VarInt.ReadVarInt(ref wBytes)); } nLockTime = Interop.LEBytesToUInt32(wBytes.GetItems(4)); @@ -102,10 +102,10 @@ namespace Novacoin tx[nTx].nTime = Interop.LEBytesToUInt32(wTxBytes.GetItems(4)); // Inputs array - tx[nTx].inputs = CTxIn.ReadTxInList(ref wTxBytes); + tx[nTx].vin = CTxIn.ReadTxInList(ref wTxBytes); // outputs array - tx[nTx].outputs = CTxOut.ReadTxOutList(ref wTxBytes); + tx[nTx].vout = CTxOut.ReadTxOutList(ref wTxBytes); tx[nTx].nLockTime = Interop.LEBytesToUInt32(wTxBytes.GetItems(4)); } @@ -163,16 +163,16 @@ namespace Novacoin resultBytes.AddRange(Interop.LEBytes(nVersion)); resultBytes.AddRange(Interop.LEBytes(nTime)); - resultBytes.AddRange(VarInt.EncodeVarInt(inputs.LongLength)); + resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength)); - foreach(CTxIn input in inputs) + foreach(CTxIn input in vin) { resultBytes.AddRange(input.ToBytes()); } - resultBytes.AddRange(VarInt.EncodeVarInt(outputs.LongLength)); + resultBytes.AddRange(VarInt.EncodeVarInt(vout.LongLength)); - foreach(CTxOut output in outputs) + foreach(CTxOut output in vout) { resultBytes.AddRange(output.ToBytes()); } @@ -188,20 +188,19 @@ namespace Novacoin sb.AppendFormat("CTransaction(\n nVersion={0},\n nTime={1},\n", nVersion, nTime); - foreach (CTxIn txin in inputs) + foreach (CTxIn txin in vin) { sb.AppendFormat(" {0},\n", txin.ToString()); } - foreach (CTxOut txout in outputs) + foreach (CTxOut txout in vout) { sb.AppendFormat(" {0},\n", txout.ToString()); } - sb.AppendFormat("nLockTime={0})\n", nLockTime); + sb.AppendFormat("\nnLockTime={0}\n)", nLockTime); return sb.ToString(); } } } - diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index 1f3017c..bc6850a 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -104,11 +104,11 @@ namespace Novacoin 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), 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, (new CScript(scriptSig)).ToString(), nSequence); } return sb.ToString (); diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index eac9409..4f88955 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -75,7 +75,7 @@ namespace Novacoin 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, (new CScript(scriptPubKey)).ToString()); return sb.ToString (); } -- 1.7.1