From: CryptoManiac Date: Fri, 21 Aug 2015 19:10:30 +0000 (+0300) Subject: Removal of ReadVarInt X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=5dbcc039601f59dda25f856dcf2f6fa13e9c72aa Removal of ReadVarInt --- diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index 8f6fb76..82a8b88 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -51,7 +51,7 @@ namespace Novacoin vtx = CTransaction.ReadTransactionsList(ref wBytes); // Read block signature - signature = wBytes.Get((int)VarInt.ReadVarInt(ref wBytes)); + signature = wBytes.Get((int)wBytes.GetVarInt()); } public CBlock() diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index cd66ada..792c426 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -84,7 +84,7 @@ namespace Novacoin nVersion = BitConverter.ToUInt32(wBytes.Get(4), 0); nTime = BitConverter.ToUInt32(wBytes.Get(4), 0); - int nInputs = (int)VarInt.ReadVarInt(ref wBytes); + int nInputs = (int)(int)wBytes.GetVarInt(); vin = new CTxIn[nInputs]; for (int nCurrentInput = 0; nCurrentInput < nInputs; nCurrentInput++) @@ -94,13 +94,13 @@ namespace Novacoin vin[nCurrentInput].prevout = new COutPoint(wBytes.Get(36)); - int nScriptSigLen = (int)VarInt.ReadVarInt(ref wBytes); + int nScriptSigLen = (int)wBytes.GetVarInt(); vin[nCurrentInput].scriptSig = new CScript(wBytes.Get(nScriptSigLen)); vin[nCurrentInput].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0); } - int nOutputs = (int)VarInt.ReadVarInt(ref wBytes); + int nOutputs = (int)wBytes.GetVarInt(); vout = new CTxOut[nOutputs]; for (int nCurrentOutput = 0; nCurrentOutput < nOutputs; nCurrentOutput++) @@ -109,7 +109,7 @@ namespace Novacoin vout[nCurrentOutput] = new CTxOut(); vout[nCurrentOutput].nValue = BitConverter.ToInt64(wBytes.Get(8), 0); - int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes); + int nScriptPKLen = (int)wBytes.GetVarInt(); vout[nCurrentOutput].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen)); } @@ -126,7 +126,7 @@ namespace Novacoin CTransaction[] tx; // Read amount of transactions - int nTransactions = (int)VarInt.ReadVarInt(ref wTxBytes); + int nTransactions = (int)wTxBytes.GetVarInt(); tx = new CTransaction[nTransactions]; for (int nTx = 0; nTx < nTransactions; nTx++) diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index 8cff600..967ae0e 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -54,7 +54,7 @@ namespace Novacoin CTxIn[] vin; // Get amount - int nInputs = (int)VarInt.ReadVarInt(ref wBytes); + int nInputs = (int)wBytes.GetVarInt(); vin = new CTxIn[nInputs]; for (int nIndex = 0; nIndex < nInputs; nIndex++) @@ -62,7 +62,7 @@ namespace Novacoin // Fill inputs array vin[nIndex] = new CTxIn(); vin[nIndex].prevout = new COutPoint(wBytes.Get(36)); - vin[nIndex].scriptSig = new CScript(wBytes.Get((int)VarInt.ReadVarInt(ref wBytes))); + vin[nIndex].scriptSig = new CScript(wBytes.Get((int)wBytes.GetVarInt())); vin[nIndex].nSequence = BitConverter.ToUInt32(wBytes.Get(4), 0); } diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index 8acab9b..32fa51b 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -44,7 +44,7 @@ namespace Novacoin /// Outputs array public static CTxOut[] ReadTxOutList(ref ByteQueue wBytes) { - int nOutputs = (int)VarInt.ReadVarInt(ref wBytes); + int nOutputs = (int)wBytes.GetVarInt(); CTxOut[] vout =new CTxOut[nOutputs]; for (int nIndex = 0; nIndex < nOutputs; nIndex++) @@ -53,7 +53,7 @@ namespace Novacoin vout[nIndex] = new CTxOut(); vout[nIndex].nValue = BitConverter.ToUInt32(wBytes.Get(8), 0); - int nScriptPKLen = (int)VarInt.ReadVarInt(ref wBytes); + int nScriptPKLen = (int)wBytes.GetVarInt(); vout[nIndex].scriptPubKey = new CScript(wBytes.Get(nScriptPKLen)); } diff --git a/Novacoin/VarInt.cs b/Novacoin/VarInt.cs index 35e8e8a..ea30a58 100644 --- a/Novacoin/VarInt.cs +++ b/Novacoin/VarInt.cs @@ -94,30 +94,5 @@ namespace Novacoin return prefix; } } - - /// - /// Read and decode variable integer from wrapped list object. - /// - /// Note: Should be used only if there is some variable integer data at current position. Otherwise you will get undefined behavior, so make sure that you know what you are doing. - /// - /// - /// - public static ulong ReadVarInt(ref ByteQueue wBytes) - { - byte prefix = wBytes.Get(); - - switch (prefix) - { - case 0xfd: // ushort - return BitConverter.ToUInt16(wBytes.Get(2), 0); - case 0xfe: // uint - return BitConverter.ToUInt32(wBytes.Get(4), 0); - case 0xff: // ulong - return BitConverter.ToUInt64(wBytes.Get(8), 0); - default: - return prefix; - } - - } } } diff --git a/Novacoin/WrappedList.cs b/Novacoin/WrappedList.cs index ff50096..b8c1656 100644 --- a/Novacoin/WrappedList.cs +++ b/Novacoin/WrappedList.cs @@ -92,5 +92,22 @@ namespace Novacoin return result; } + + public ulong GetVarInt() + { + byte prefix = Get(); + + switch (prefix) + { + case 0xfd: // ushort + return BitConverter.ToUInt16(Get(2), 0); + case 0xfe: // uint + return BitConverter.ToUInt32(Get(4), 0); + case 0xff: // ulong + return BitConverter.ToUInt64(Get(8), 0); + default: + return prefix; + } + } } }