vtx = CTransaction.ReadTransactionsList(ref wBytes);
// Read block signature
- signature = wBytes.Get((int)VarInt.ReadVarInt(ref wBytes));
+ signature = wBytes.Get((int)wBytes.GetVarInt());
}
public CBlock()
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++)
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++)
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));
}
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++)
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++)
// 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);
}
/// <returns>Outputs array</returns>
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++)
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));
}
return prefix;
}
}
-
- /// <summary>
- /// 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.
- /// </summary>
- /// <param name="wBytes"></param>
- /// <returns></returns>
- 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;
- }
-
- }
}
}
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;
+ }
+ }
}
}