From: CryptoManiac Date: Sun, 23 Aug 2015 06:32:13 +0000 (+0300) Subject: Use byte[] instead of IEnumerable if possible X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=0aa2d5cb7cdb5813440e7afcdbe6014e9b8deeee Use byte[] instead of IEnumerable if possible --- diff --git a/Novacoin/AddressTools.cs b/Novacoin/AddressTools.cs index 1bf7e2a..1f72cea 100644 --- a/Novacoin/AddressTools.cs +++ b/Novacoin/AddressTools.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Text; @@ -63,13 +62,11 @@ namespace Novacoin /// /// Byte sequence /// Base58(data+checksum) - public static string Base58EncodeCheck(IEnumerable bytes) + public static string Base58EncodeCheck(byte[] bytes) { - byte[] dataBytes = bytes.ToArray(); - Array.Resize(ref dataBytes, dataBytes.Length + 4); - - byte[] checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray(); - + var dataBytes = new byte[bytes.Length + 4]; + bytes.CopyTo(dataBytes, 0); + var checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray(); checkSum.CopyTo(dataBytes, dataBytes.Length - 4); // add 4-byte hash check to the end return Base58Encode(dataBytes); @@ -115,22 +112,22 @@ namespace Novacoin return bi; } - public static IEnumerable Base58DecodeCheck(string strBase58Check) + public static byte[] Base58DecodeCheck(string strBase58Check) { - byte[] rawData = Base58Decode(strBase58Check).ToArray(); + var rawData = Base58Decode(strBase58Check).ToArray(); if (rawData.Length < 4) { throw new Base58Exception("Data is too short."); } - byte[] result = new byte[rawData.Length - 4]; - byte[] resultCheckSum = new byte[4]; + var result = new byte[rawData.Length - 4]; + var resultCheckSum = new byte[4]; Array.Copy(rawData, result, result.Length); Array.Copy(rawData, result.Length, resultCheckSum, 0, 4); - byte[] checkSum = Hash256.Compute256(result).hashBytes.Take(4).ToArray(); + var checkSum = Hash256.Compute256(result).hashBytes.Take(4).ToArray(); if (!checkSum.SequenceEqual(resultCheckSum)) { diff --git a/Novacoin/ByteQueue.cs b/Novacoin/ByteQueue.cs index 1b32adf..813d187 100644 --- a/Novacoin/ByteQueue.cs +++ b/Novacoin/ByteQueue.cs @@ -104,19 +104,6 @@ namespace Novacoin get { return Index; } } - public IEnumerable GetEnumerable(int Count) - { - if (Elements.Count - Index < Count) - { - throw new ByteQueueException("Unable to read requested amount of data."); - } - - IEnumerable result = Elements.Skip(Index).Take(Count); - Index += Count; - - return result; - } - public ulong GetVarInt() { byte prefix = Get(); diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index 5cc3977..3a5a36d 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -106,7 +106,7 @@ namespace Novacoin } txnouttype whichType; - IList> solutions; + IList solutions; if (!ScriptCode.Solver(vtx[1].vout[1].scriptPubKey, out whichType, out solutions)) { @@ -148,12 +148,12 @@ namespace Novacoin { get { - List r = new List(); + var r = new List(); r.AddRange(header.Bytes); r.AddRange(VarInt.EncodeVarInt(vtx.LongLength)); // transactions count - foreach (CTransaction tx in vtx) + foreach (var tx in vtx) { r.AddRange(tx.Bytes); } @@ -167,11 +167,11 @@ namespace Novacoin public override string ToString() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.AppendFormat("CBlock(\n header={0},\n", header.ToString()); - foreach(CTransaction tx in vtx) + foreach(var tx in vtx) { sb.AppendFormat("{0}", tx.ToString()); } @@ -182,8 +182,7 @@ namespace Novacoin } sb.Append(")"); - - // TODO + return sb.ToString(); } } diff --git a/Novacoin/CBlockHeader.cs b/Novacoin/CBlockHeader.cs index 1612ee1..cc753c4 100644 --- a/Novacoin/CBlockHeader.cs +++ b/Novacoin/CBlockHeader.cs @@ -93,7 +93,7 @@ namespace Novacoin { get { - List r = new List(); + var r = new List(); r.AddRange(BitConverter.GetBytes(nVersion)); r.AddRange(prevHash.hashBytes); @@ -115,7 +115,7 @@ namespace Novacoin public override string ToString() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.AppendFormat("CBlockHeader(nVersion={0}, prevHash={1}, merkleRoot={2}, nTime={3}, nBits={4}, nNonce={5})", nVersion, prevHash.ToString(), merkleRoot.ToString(), nTime, nBits, nNonce); return sb.ToString(); } diff --git a/Novacoin/CKey.cs b/Novacoin/CKey.cs index a24d6c8..2769de5 100644 --- a/Novacoin/CKey.cs +++ b/Novacoin/CKey.cs @@ -71,7 +71,7 @@ namespace Novacoin return pubKeyParams; } - ECPoint q = new FpPoint(curve.Curve, pubKeyParams.Q.X, pubKeyParams.Q.Y, false); + var q = new FpPoint(curve.Curve, pubKeyParams.Q.X, pubKeyParams.Q.Y, false); return new ECPublicKeyParameters(q, domain); } @@ -82,13 +82,13 @@ namespace Novacoin /// Data hash /// Signature bytes /// Checking result - public bool VerifySignature(Hash sigHash, IEnumerable signature) + public bool VerifySignature(Hash sigHash, byte[] signature) { - ISigner signer = SignerUtilities.GetSigner("NONEwithECDSA"); + var signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(false, _Public); signer.BlockUpdate(sigHash.hashBytes, 0, sigHash.hashSize); - return signer.VerifySignature(signature.ToArray()); + return signer.VerifySignature(signature); } /// @@ -101,9 +101,9 @@ namespace Novacoin } /// - /// PublicBytes part of key pair + /// Public part of key pair /// - public IEnumerable PublicBytes + public byte[] PublicBytes { get { return _Public.Q.GetEncoded(); } } diff --git a/Novacoin/CKeyPair.cs b/Novacoin/CKeyPair.cs index 6c7243c..f5deeed 100644 --- a/Novacoin/CKeyPair.cs +++ b/Novacoin/CKeyPair.cs @@ -20,9 +20,7 @@ using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Generators; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math; -using Org.BouncyCastle.Math.EC; using Org.BouncyCastle.Security; -using System; using System.Collections.Generic; using System.Linq; @@ -38,10 +36,10 @@ namespace Novacoin /// public CKeyPair(bool Compressed=true) { - ECKeyGenerationParameters genParams = new ECKeyGenerationParameters(domain, new SecureRandom()); - ECKeyPairGenerator generator = new ECKeyPairGenerator("ECDSA"); + var genParams = new ECKeyGenerationParameters(domain, new SecureRandom()); + var generator = new ECKeyPairGenerator("ECDSA"); generator.Init(genParams); - AsymmetricCipherKeyPair ecKeyPair = generator.GenerateKeyPair(); + var ecKeyPair = generator.GenerateKeyPair(); _Private = (ECPrivateKeyParameters)ecKeyPair.Private; _Public = (ECPublicKeyParameters)ecKeyPair.Public; @@ -57,21 +55,21 @@ namespace Novacoin /// /// Byte sequence /// Compression flag - public CKeyPair(IEnumerable secretBytes, bool Compressed=true) + public CKeyPair(byte[] secretBytes, bool Compressed=true) { // Deserialize secret value - BigInteger D = new BigInteger(secretBytes.Take(32).ToArray()); + var D = new BigInteger(secretBytes.Take(32).ToArray()); if (D.SignValue == -1) { - List fixedKeyBytes = secretBytes.Take(32).ToList(); + var fixedKeyBytes = secretBytes.Take(32).ToList(); fixedKeyBytes.Insert(0, 0x00); // prepend with sign byte D = new BigInteger(fixedKeyBytes.ToArray()); } // Calculate public key - ECPoint Q = curve.G.Multiply(D); + var Q = curve.G.Multiply(D); _Private = new ECPrivateKeyParameters(D, domain); _Public = new ECPublicKeyParameters(Q, domain); @@ -86,29 +84,29 @@ namespace Novacoin /// Init key pair using secret sequence of bytes /// /// Byte sequence - public CKeyPair(IEnumerable secretBytes) : - this (secretBytes.Take(32), (secretBytes.Count() == 33 && secretBytes.Last() == 0x01)) + public CKeyPair(byte[] secretBytes) : + this (secretBytes.Take(32).ToArray(), (secretBytes.Count() == 33 && secretBytes.Last() == 0x01)) { } public CKeyPair(string strBase58) { - List rawBytes = AddressTools.Base58DecodeCheck(strBase58).ToList(); + var rawBytes = AddressTools.Base58DecodeCheck(strBase58).ToList(); rawBytes.RemoveAt(0); // Remove key version byte // Deserialize secret value - BigInteger D = new BigInteger(rawBytes.Take(32).ToArray()); + var D = new BigInteger(rawBytes.Take(32).ToArray()); if (D.SignValue == -1) { - List secretbytes = rawBytes.Take(32).ToList(); // Copy secret + var secretbytes = rawBytes.Take(32).ToList(); // Copy secret secretbytes.Insert(0, 0x00); // Prepend with sign byte D = new BigInteger(secretbytes.ToArray()); // Try decoding again } // Calculate public key - ECPoint Q = curve.G.Multiply(D); + var Q = curve.G.Multiply(D); _Private = new ECPrivateKeyParameters(D, domain); _Public = new ECPublicKeyParameters(Q, domain); @@ -134,9 +132,9 @@ namespace Novacoin /// /// Hash to sigh /// Signature bytes sequence - public IEnumerable Sign(Hash sigHash) + public byte[] Sign(Hash sigHash) { - ISigner signer = SignerUtilities.GetSigner("NONEwithECDSA"); + var signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(true, _Private); signer.BlockUpdate(sigHash.hashBytes, 0, sigHash.hashSize); @@ -151,11 +149,11 @@ namespace Novacoin /// /// SecretBytes part of key pair /// - public IEnumerable SecretBytes + public byte[] SecretBytes { get { - List secretBytes = new List(_Private.D.ToByteArray()); + var secretBytes = new List(_Private.D.ToByteArray()); if (secretBytes[0] == 0x00) { @@ -169,7 +167,7 @@ namespace Novacoin secretBytes.Add(0x01); } - return secretBytes; + return secretBytes.ToArray(); } } @@ -180,12 +178,12 @@ namespace Novacoin public override string ToString() { - List r = new List(); + var r = new List(); r.Add((byte)(128 + AddrType.PUBKEY_ADDRESS)); // Key version r.AddRange(SecretBytes); // Key data - return AddressTools.Base58EncodeCheck(r); + return AddressTools.Base58EncodeCheck(r.ToArray()); } } } diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index 1becaf4..22e94ae 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -45,10 +45,10 @@ namespace Novacoin /// /// /// - public CNovacoinAddress(byte nVersionIn, IEnumerable addrDataIn) + public CNovacoinAddress(byte nVersionIn, byte[] addrDataIn) { nVersion = nVersionIn; - addrData = addrDataIn.ToList(); + addrData = new List(addrDataIn); } /// @@ -117,12 +117,12 @@ namespace Novacoin /// Base58(data + checksum) public override string ToString() { - List r = new List(); + var r = new List(); r.Add(nVersion); r.AddRange(addrData); - return AddressTools.Base58EncodeCheck(r); + return AddressTools.Base58EncodeCheck(r.ToArray()); } } } diff --git a/Novacoin/COutPoint.cs b/Novacoin/COutPoint.cs index ae6c14b..be3017f 100644 --- a/Novacoin/COutPoint.cs +++ b/Novacoin/COutPoint.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; namespace Novacoin @@ -53,10 +52,10 @@ namespace Novacoin n = o.n; } - public COutPoint(IEnumerable bytes) + public COutPoint(byte[] bytes) { hash = new Hash256(bytes); - n = BitConverter.ToUInt32(bytes.ToArray(), 32); + n = BitConverter.ToUInt32(bytes, 32); } public bool IsNull @@ -68,7 +67,7 @@ namespace Novacoin { get { - List r = new List(); + var r = new List(); r.AddRange(hash.hashBytes); r.AddRange(BitConverter.GetBytes(n)); @@ -78,7 +77,7 @@ namespace Novacoin public override string ToString() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.AppendFormat("COutPoint({0}, {1})", hash.ToString(), n); return sb.ToString(); diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs index ff84c78..264ca78 100644 --- a/Novacoin/CPubKey.cs +++ b/Novacoin/CPubKey.cs @@ -18,7 +18,6 @@ using System.Collections.Generic; using System.Linq; -using Org.BouncyCastle.Math.EC; using Org.BouncyCastle.Crypto.Parameters; namespace Novacoin @@ -43,7 +42,7 @@ namespace Novacoin /// Byte sequence public CPubKey(IEnumerable bytes) { - ECPoint pQ = curve.Curve.DecodePoint(bytes.ToArray()); + var pQ = curve.Curve.DecodePoint(bytes.ToArray()); _Public = new ECPublicKeyParameters(pQ, domain); } @@ -53,7 +52,7 @@ namespace Novacoin /// public CPubKey(string strBase58) { - ECPoint pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray()); + var pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray()); _Public = new ECPublicKeyParameters(pQ, domain); } @@ -73,12 +72,12 @@ namespace Novacoin public override string ToString() { - List r = new List(); + var r = new List(); r.Add((byte)(AddrType.PUBKEY_ADDRESS)); r.AddRange(PublicBytes); - return AddressTools.Base58EncodeCheck(r); + return AddressTools.Base58EncodeCheck(r.ToArray()); } } } diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs index 9e65e38..1bc347a 100644 --- a/Novacoin/CScript.cs +++ b/Novacoin/CScript.cs @@ -115,9 +115,9 @@ namespace Novacoin /// Create new OP_PUSHDATAn operator and add it to opcode bytes list /// /// Set of data bytes - public void PushData(IEnumerable dataBytes) + public void PushData(byte[] dataBytes) { - long nCount = dataBytes.LongCount(); + var nCount = dataBytes.LongLength; if (nCount < (int)instruction.OP_PUSHDATA1) { @@ -156,11 +156,11 @@ namespace Novacoin /// /// Pattern sequence /// Matches enumerator - private IEnumerable FindPattern(IList pattern) + private IEnumerable FindPattern(byte[] pattern) { for (int i = 0; i < codeBytes.Count; i++) { - if (codeBytes.Skip(i).Take(pattern.Count).SequenceEqual(pattern)) + if (codeBytes.Skip(i).Take(pattern.Length).SequenceEqual(pattern)) { yield return i; } @@ -172,15 +172,14 @@ namespace Novacoin /// /// Pattern sequence /// Matches number - public int RemovePattern(IList pattern) + public int RemovePattern(byte[] pattern) { - List resultBytes = new List(codeBytes); + var resultBytes = new List(codeBytes); int count = 0; - int patternLen = pattern.Count; foreach (int i in FindPattern(pattern)) { - resultBytes.RemoveRange(i - count * patternLen, patternLen); + resultBytes.RemoveRange(i - count * pattern.Length, pattern.Length); count++; } @@ -196,10 +195,10 @@ namespace Novacoin { get { - ByteQueue wCodeBytes = new ByteQueue(codeBytes); + var wCodeBytes = new ByteQueue(codeBytes); instruction opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument + byte[] pushArgs; // OP_PUSHDATAn argument // Scan opcodes sequence while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) @@ -222,15 +221,15 @@ namespace Novacoin { get { - ByteQueue wCodeBytes = new ByteQueue(codeBytes); + var wCodeBytes = new ByteQueue(codeBytes); + byte[] pushArgs; // OP_PUSHDATAn argument instruction opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument // Scan opcodes sequence while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) { - byte[] data = pushArgs.ToArray(); + var data = pushArgs; if (opcode < instruction.OP_PUSHDATA1 && opcode > instruction.OP_0 && (data.Length == 1 && data[0] <= 16)) { @@ -311,13 +310,13 @@ namespace Novacoin /// Amount of sigops public int GetSigOpCount(bool fAccurate) { - ByteQueue wCodeBytes = new ByteQueue(codeBytes); + var wCodeBytes = new ByteQueue(codeBytes); instruction opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument + byte[] pushArgs; // OP_PUSHDATAn argument int nCount = 0; - instruction lastOpcode = instruction.OP_INVALIDOPCODE; + var lastOpcode = instruction.OP_INVALIDOPCODE; // Scan opcodes sequence while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) @@ -361,7 +360,7 @@ namespace Novacoin ByteQueue wScriptSig = scriptSig.GetByteQUeue(); instruction opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument + byte[] pushArgs; // OP_PUSHDATAn argument while (ScriptCode.GetOp(ref wScriptSig, out opcode, out pushArgs)) { @@ -372,7 +371,7 @@ namespace Novacoin } /// ... and return its opcount: - CScript subScript = new CScript(pushArgs); + var subScript = new CScript(pushArgs); return subScript.GetSigOpCount(true); @@ -428,26 +427,26 @@ namespace Novacoin /// /// Amount of required signatures. /// Set of public keys. - public void SetMultiSig(int nRequired, IEnumerable keys) + public void SetMultiSig(int nRequired, CPubKey[] keys) { codeBytes.Clear(); AddOp(ScriptCode.EncodeOP_N(nRequired)); - foreach (CPubKey key in keys) + foreach (var key in keys) { - PushData(key.PublicBytes.ToList()); + PushData(key.PublicBytes); } - AddOp(ScriptCode.EncodeOP_N(keys.Count())); + AddOp(ScriptCode.EncodeOP_N(keys.Length)); AddOp(instruction.OP_CHECKMULTISIG); } /// /// Access to script code. /// - public IEnumerable Bytes + public byte[] Bytes { - get { return codeBytes; } + get { return codeBytes.ToArray(); } } public CScriptID ScriptID @@ -461,11 +460,11 @@ namespace Novacoin /// Code listing public override string ToString() { - StringBuilder sb = new StringBuilder(); - ByteQueue wCodeBytes = new ByteQueue(codeBytes); + var sb = new StringBuilder(); + var wCodeBytes = new ByteQueue(codeBytes); instruction opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument + byte[] pushArgs; // OP_PUSHDATAn argument while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) { if (sb.Length != 0) @@ -487,4 +486,3 @@ namespace Novacoin } } } - diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index 08495af..3557398 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -97,7 +97,7 @@ namespace Novacoin /// Byte sequence public CTransaction(IList 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); @@ -141,11 +141,9 @@ namespace Novacoin /// Transactions array 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++) { @@ -195,7 +193,7 @@ namespace Novacoin { get { - List resultBytes = new List(); + var resultBytes = new List(); // Typical transaction example: // @@ -245,14 +243,14 @@ namespace Novacoin 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); } @@ -265,16 +263,16 @@ namespace Novacoin 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()); } diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index a4660b8..4b88d15 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -69,11 +69,9 @@ namespace Novacoin /// Inputs array public static CTxIn[] ReadTxInList(ref ByteQueue wBytes) { - CTxIn[] vin; - // Get amount int nInputs = (int)wBytes.GetVarInt(); - vin = new CTxIn[nInputs]; + var vin = new CTxIn[nInputs]; for (int nIndex = 0; nIndex < nInputs; nIndex++) { @@ -96,13 +94,12 @@ namespace Novacoin { get { - List inputBytes = new List(); + var inputBytes = new List(); inputBytes.AddRange(prevout.Bytes); // prevout - List s = new List(scriptSig.Bytes); - - inputBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptSig length + var s = scriptSig.Bytes; + inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length inputBytes.AddRange(s); // scriptSig inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index 2d4d756..e75579a 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -63,7 +63,7 @@ namespace Novacoin public static CTxOut[] ReadTxOutList(ref ByteQueue wBytes) { int nOutputs = (int)wBytes.GetVarInt(); - CTxOut[] vout =new CTxOut[nOutputs]; + var vout =new CTxOut[nOutputs]; for (int nIndex = 0; nIndex < nOutputs; nIndex++) { @@ -86,13 +86,12 @@ namespace Novacoin { get { - List resultBytes = new List(); + var resultBytes = new List(); resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value - List s = new List(scriptPubKey.Bytes); - - resultBytes.AddRange(VarInt.EncodeVarInt(s.Count)); // scriptPubKey length + var s = scriptPubKey.Bytes; + resultBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptPubKey length resultBytes.AddRange(s); // scriptPubKey return resultBytes; @@ -129,7 +128,7 @@ namespace Novacoin public override string ToString () { - StringBuilder sb = new StringBuilder (); + var sb = new StringBuilder (); sb.AppendFormat ("CTxOut(nValue={0}, scriptPubKey={1})", nValue, scriptPubKey.ToString()); return sb.ToString (); diff --git a/Novacoin/CryptoUtils.cs b/Novacoin/CryptoUtils.cs index 7c456d7..4ba7ee0 100644 --- a/Novacoin/CryptoUtils.cs +++ b/Novacoin/CryptoUtils.cs @@ -34,7 +34,7 @@ namespace Novacoin hashLength++; } int keyLength = dklen / hashLength; - if ((long)dklen > (0xFFFFFFFFL * hashLength) || dklen < 0) + if (dklen > (0xFFFFFFFFL * hashLength) || dklen < 0) { throw new ArgumentOutOfRangeException("dklen"); } @@ -42,7 +42,7 @@ namespace Novacoin { keyLength++; } - byte[] extendedkey = new byte[salt.Length + 4]; + var extendedkey = new byte[salt.Length + 4]; Buffer.BlockCopy(salt, 0, extendedkey, 0, salt.Length); using (var ms = new System.IO.MemoryStream()) { @@ -56,11 +56,11 @@ namespace Novacoin extendedkey[salt.Length + 3] = (byte)(((i + 1)) & 0xFF); /* Compute U_1 = PRF(P, S || INT(i)). */ - byte[] u = hmac.ComputeHash(extendedkey); + var u = hmac.ComputeHash(extendedkey); Array.Clear(extendedkey, salt.Length, 4); /* T_i = U_1 ... */ - byte[] f = u; + var f = u; for (int j = 1; j < iterationCount; j++) { /* Compute U_j. */ @@ -80,7 +80,7 @@ namespace Novacoin ms.Position = 0; /* Initialize result array. */ - byte[] dk = new byte[dklen]; + var dk = new byte[dklen]; /* Read key from memory stream. */ ms.Read(dk, 0, dklen); diff --git a/Novacoin/Hash160.cs b/Novacoin/Hash160.cs index 61eb5d8..272527b 100644 --- a/Novacoin/Hash160.cs +++ b/Novacoin/Hash160.cs @@ -45,9 +45,9 @@ namespace Novacoin public static Hash160 Compute160(IEnumerable inputBytes) { - byte[] dataBytes = inputBytes.ToArray(); - byte[] digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); - byte[] digest2 = _hasher160.ComputeHash(digest1, 0, digest1.Length); + var dataBytes = inputBytes.ToArray(); + var digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); + var digest2 = _hasher160.ComputeHash(digest1, 0, digest1.Length); return new Hash160(digest2); } diff --git a/Novacoin/Hash256.cs b/Novacoin/Hash256.cs index 3d98837..2615855 100644 --- a/Novacoin/Hash256.cs +++ b/Novacoin/Hash256.cs @@ -41,9 +41,9 @@ namespace Novacoin public static Hash256 Compute256(IEnumerable inputBytes) { - byte[] dataBytes = inputBytes.ToArray(); - byte[] digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); - byte[] digest2 = _hasher256.ComputeHash(digest1, 0, digest1.Length); + var dataBytes = inputBytes.ToArray(); + var digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); + var digest2 = _hasher256.ComputeHash(digest1, 0, digest1.Length); return new Hash256(digest2); } diff --git a/Novacoin/Interop.cs b/Novacoin/Interop.cs index f0b2c93..de2ba75 100644 --- a/Novacoin/Interop.cs +++ b/Novacoin/Interop.cs @@ -44,7 +44,7 @@ namespace Novacoin { public static byte[] ReverseBytes(byte[] source) { - byte[] b = new byte[source.Length]; + var b = new byte[source.Length]; source.CopyTo(b, 0); @@ -55,7 +55,7 @@ namespace Novacoin public static byte[] LEBytes(uint[] values) { - byte[] result = new byte[values.Length * sizeof(uint)]; + var result = new byte[values.Length * sizeof(uint)]; Buffer.BlockCopy(values, 0, result, 0, result.Length); return result; @@ -63,7 +63,7 @@ namespace Novacoin public static uint[] ToUInt32Array(byte[] bytes) { - uint[] result = new uint[bytes.Length / sizeof(uint)]; + var result = new uint[bytes.Length / sizeof(uint)]; Buffer.BlockCopy(bytes, 0, result, 0, bytes.Length); return result; @@ -71,7 +71,7 @@ namespace Novacoin public static byte[] BEBytes(ushort n) { - byte[] resultBytes = BitConverter.GetBytes(n); + var resultBytes = BitConverter.GetBytes(n); Array.Reverse(resultBytes); @@ -80,7 +80,7 @@ namespace Novacoin public static byte[] BEBytes(uint n) { - byte[] resultBytes = BitConverter.GetBytes(n); + var resultBytes = BitConverter.GetBytes(n); Array.Reverse(resultBytes); @@ -89,7 +89,7 @@ namespace Novacoin public static byte[] BEBytes(ulong n) { - byte[] resultBytes = BitConverter.GetBytes(n); + var resultBytes = BitConverter.GetBytes(n); Array.Reverse(resultBytes); @@ -145,10 +145,15 @@ namespace Novacoin return HexToEnumerable(hex).ToList(); } + public static byte[] HexToArray(string hex) + { + return HexToEnumerable(hex).ToArray(); + } + public static string ToHex(IEnumerable bytes) { - StringBuilder sb = new StringBuilder(); - foreach (byte b in bytes) + var sb = new StringBuilder(); + foreach (var b in bytes) { sb.AppendFormat("{0:x2}", b); } diff --git a/Novacoin/RIPEMD160.cs b/Novacoin/RIPEMD160.cs index 7185101..74e25b8 100644 --- a/Novacoin/RIPEMD160.cs +++ b/Novacoin/RIPEMD160.cs @@ -44,8 +44,8 @@ namespace Novacoin public static RIPEMD160 Compute160(IEnumerable inputBytes) { - byte[] dataBytes = inputBytes.ToArray(); - byte[] digest1 = _hasher160.ComputeHash(dataBytes, 0, dataBytes.Length); + var dataBytes = inputBytes.ToArray(); + var digest1 = _hasher160.ComputeHash(dataBytes, 0, dataBytes.Length); return new RIPEMD160(digest1); } diff --git a/Novacoin/SHA1.cs b/Novacoin/SHA1.cs index 4de79ee..9d31cfa 100644 --- a/Novacoin/SHA1.cs +++ b/Novacoin/SHA1.cs @@ -45,8 +45,8 @@ namespace Novacoin public static SHA1 Compute1(IEnumerable inputBytes) { - byte[] dataBytes = inputBytes.ToArray(); - byte[] digest1 = _hasher1.ComputeHash(dataBytes, 0, dataBytes.Length); + var dataBytes = inputBytes.ToArray(); + var digest1 = _hasher1.ComputeHash(dataBytes, 0, dataBytes.Length); return new SHA1(digest1); } diff --git a/Novacoin/SHA256.cs b/Novacoin/SHA256.cs index 68cc8b5..953eaf4 100644 --- a/Novacoin/SHA256.cs +++ b/Novacoin/SHA256.cs @@ -40,8 +40,8 @@ namespace Novacoin public static SHA256 Compute256(IEnumerable inputBytes) { - byte[] dataBytes = inputBytes.ToArray(); - byte[] digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); + var dataBytes = inputBytes.ToArray(); + var digest1 = _hasher256.ComputeHash(dataBytes, 0, dataBytes.Length); return new SHA256(digest1); } diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index f6f43d6..658a74c 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -244,9 +244,9 @@ namespace Novacoin /// Found opcode. /// IEnumerable out param which is used to get the push arguments. /// Result of operation - public static bool GetOp(ref ByteQueue codeBytes, out instruction opcodeRet, out IEnumerable bytesRet) + public static bool GetOp(ref ByteQueue codeBytes, out instruction opcodeRet, out byte[] bytesRet) { - bytesRet = new List(); + bytesRet = new byte[0]; opcodeRet = instruction.OP_INVALIDOPCODE; instruction opcode; @@ -307,7 +307,7 @@ namespace Novacoin try { // Read found number of bytes into list of OP_PUSHDATAn arguments. - bytesRet = codeBytes.GetEnumerable(nSize); + bytesRet = codeBytes.Get(nSize); } catch (ByteQueueException) { @@ -329,16 +329,13 @@ namespace Novacoin /// /// Collection of value bytes. /// Formatted value. - public static string ValueString(IEnumerable bytes) + public static string ValueString(byte[] bytes) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); - if (bytes.Count() <= 4) + if (bytes.Length <= 4) { - byte[] valueBytes = new byte[4] { 0, 0, 0, 0 }; - bytes.ToArray().CopyTo(valueBytes, valueBytes.Length - bytes.Count()); - - sb.Append(Interop.BEBytesToUInt32(valueBytes)); + sb.Append(Interop.BEBytesToUInt32(bytes)); } else { @@ -353,12 +350,12 @@ namespace Novacoin /// /// List of stack items. /// Formatted value. - public static string StackString(IList> stackList) + public static string StackString(IList stackList) { - StringBuilder sb = new StringBuilder(); - foreach (IList bytesList in stackList) + var sb = new StringBuilder(); + foreach (var bytes in stackList) { - sb.Append(ValueString(bytesList)); + sb.Append(ValueString(bytes)); } return sb.ToString(); @@ -413,7 +410,7 @@ namespace Novacoin return (instruction.OP_1 + n - 1); } - public static int ScriptSigArgsExpected(txnouttype t, IList> solutions) + public static int ScriptSigArgsExpected(txnouttype t, IList solutions) { switch (t) { @@ -426,9 +423,9 @@ namespace Novacoin case txnouttype.TX_PUBKEYHASH: return 2; case txnouttype.TX_MULTISIG: - if (solutions.Count() < 1 || solutions.First().Count() < 1) + if (solutions.Count < 1 || solutions.First().Length < 1) return -1; - return solutions.First().First() + 1; + return solutions.First()[0] + 1; case txnouttype.TX_SCRIPTHASH: return 1; // doesn't include args needed by the script } @@ -443,7 +440,7 @@ namespace Novacoin /// Checking result public static bool IsStandard(CScript scriptPubKey, out txnouttype whichType) { - IList> solutions = new List>(); + IList solutions; if (!Solver(scriptPubKey, out whichType, out solutions)) { @@ -454,8 +451,8 @@ namespace Novacoin if (whichType == txnouttype.TX_MULTISIG) { // Additional verification of OP_CHECKMULTISIG arguments - byte m = solutions.First().First(); - byte n = solutions.Last().First(); + var m = solutions.First()[0]; + var n = solutions.Last()[0]; // Support up to x-of-3 multisig txns as standard if (n < 1 || n > 3) @@ -478,9 +475,9 @@ namespace Novacoin /// Output type /// Set of solutions /// Result - public static bool Solver(CScript scriptPubKey, out txnouttype typeRet, out IList> solutions) + public static bool Solver(CScript scriptPubKey, out txnouttype typeRet, out IList solutions) { - solutions = new List>(); + solutions = new List(); // There are shortcuts for pay-to-script-hash and pay-to-pubkey-hash, which are more constrained than the other types. @@ -490,8 +487,8 @@ namespace Novacoin typeRet = txnouttype.TX_SCRIPTHASH; // Take 20 bytes with offset of 2 bytes - IEnumerable hashBytes = scriptPubKey.Bytes.Skip(2).Take(20); - solutions.Add(hashBytes); + var hashBytes = scriptPubKey.Bytes.Skip(2).Take(20); + solutions.Add(hashBytes.ToArray()); return true; } @@ -502,18 +499,18 @@ namespace Novacoin typeRet = txnouttype.TX_PUBKEYHASH; // Take 20 bytes with offset of 3 bytes - IEnumerable hashBytes = scriptPubKey.Bytes.Skip(3).Take(20); - solutions.Add(hashBytes); + var hashBytes = scriptPubKey.Bytes.Skip(3).Take(20); + solutions.Add(hashBytes.ToArray()); return true; } - List>> templateTuples = new List>>(); + var templateTuples = new List>(); // Sender provides pubkey, receiver adds signature // [ECDSA public key] OP_CHECKSIG templateTuples.Add( - new Tuple>( + new Tuple( txnouttype.TX_PUBKEY, new byte[] { (byte)instruction.OP_PUBKEY, @@ -525,7 +522,7 @@ namespace Novacoin // N [pubkey1] [pubkey2] ... [pubkeyN] M OP_CHECKMULTISIG // Where N and M are small integer opcodes (OP1 ... OP_16) templateTuples.Add( - new Tuple>( + new Tuple( txnouttype.TX_MULTISIG, new byte[] { (byte)instruction.OP_SMALLINTEGER, @@ -538,7 +535,7 @@ namespace Novacoin // Data-carrying output // OP_RETURN [up to 80 bytes of data] templateTuples.Add( - new Tuple>( + new Tuple( txnouttype.TX_NULL_DATA, new byte[] { (byte)instruction.OP_RETURN, @@ -549,18 +546,18 @@ namespace Novacoin // Nonstandard tx output typeRet = txnouttype.TX_NONSTANDARD; - foreach (Tuple> templateTuple in templateTuples) + foreach (var templateTuple in templateTuples) { - CScript script1 = scriptPubKey; - CScript script2 = new CScript(templateTuple.Item2); + var script1 = scriptPubKey; + var script2 = new CScript(templateTuple.Item2); instruction opcode1, opcode2; // Compare - ByteQueue bq1 = script1.GetByteQUeue(); - ByteQueue bq2 = script2.GetByteQUeue(); + var bq1 = script1.GetByteQUeue(); + var bq2 = script2.GetByteQUeue(); - IEnumerable args1, args2; + byte[] args1, args2; int last1 = script1.Bytes.Count() -1; int last2 = script2.Bytes.Count() - 1; @@ -574,8 +571,8 @@ namespace Novacoin if (typeRet == txnouttype.TX_MULTISIG) { // Additional checks for TX_MULTISIG: - byte m = solutions.First().First(); - byte n = solutions.Last().First(); + var m = solutions.First().First(); + var n = solutions.Last().First(); if (m < 1 || n < 1 || m > n || solutions.Count - 2 != n) { @@ -634,7 +631,7 @@ namespace Novacoin // Single-byte small integer pushed onto solutions try { - byte n = (byte)DecodeOP_N(opcode1); + var n = (byte)DecodeOP_N(opcode1); solutions.Add(new byte[] { n }); } catch (Exception) @@ -645,7 +642,7 @@ namespace Novacoin else if (opcode2 == instruction.OP_SMALLDATA) { // small pushdata, <= 80 bytes - if (args1.Count() > 80) + if (args1.Length > 80) { break; } @@ -676,13 +673,13 @@ namespace Novacoin { if (nIn >= txTo.vin.Length) { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); sb.AppendFormat("ERROR: SignatureHash() : nIn={0} out of range\n", nIn); throw new ArgumentOutOfRangeException("nIn", sb.ToString()); } // Init a copy of transaction - CTransaction txTmp = new CTransaction(txTo); + var txTmp = new CTransaction(txTo); // In case concatenating two scripts ends up with two codeseparators, // or an extra one at the end, this prevents all those possible incompatibilities. @@ -745,7 +742,7 @@ namespace Novacoin } // Serialize and hash - List b = new List(); + var b = new List(); b.AddRange(txTmp.Bytes); b.AddRange(BitConverter.GetBytes(nHashType)); @@ -781,7 +778,7 @@ namespace Novacoin /// Remove last element from stack /// /// Stack reference - private static void popstack(ref List> stack) + private static void popstack(ref List stack) { int nCount = stack.Count; if (nCount == 0) @@ -795,7 +792,7 @@ namespace Novacoin /// Stack reference /// Depth /// Byte sequence - private static IEnumerable stacktop(ref List> stack, int nDepth) + private static byte[] stacktop(ref List stack, int nDepth) { int nStackElement = stack.Count + nDepth; @@ -823,16 +820,14 @@ namespace Novacoin /// /// Some byte sequence /// - private static bool CastToBool(IEnumerable arg) + private static bool CastToBool(byte[] arg) { - byte[] value = arg.ToArray(); - - for (var i = 0; i < value.Length; i++) + for (var i = 0; i < arg.Length; i++) { - if (value[i] != 0) + if (arg[i] != 0) { // Can be negative zero - if (i == value.Length - 1 && value[i] == 0x80) + if (i == arg.Length - 1 && arg[i] == 0x80) { return false; } @@ -849,14 +844,14 @@ namespace Novacoin /// /// /// - private static BigInteger CastToBigInteger(IEnumerable value) + private static BigInteger CastToBigInteger(byte[] value) { - if (value.Count() > 4) + if (value.Length > 4) { throw new StackMachineException("CastToBigInteger() : overflow"); } - return new BigInteger(value.ToArray()); + return new BigInteger(value); } /// @@ -869,34 +864,34 @@ namespace Novacoin /// Signature checking flags /// Hash type flag /// - public static bool EvalScript(ref List> stack, CScript script, CTransaction txTo, int nIn, int flags, int nHashType) + public static bool EvalScript(ref List stack, CScript script, CTransaction txTo, int nIn, int flags, int nHashType) { if (script.Bytes.Count() > 10000) { return false; // Size limit failed } - List vfExec = new List(); + var vfExec = new List(); int nOpCount = 0; int nCodeHashBegin = 0; - byte[] falseBytes = new byte[0]; - byte[] trueBytes = new byte[] { 0x01 }; + var falseBytes = new byte[0]; + var trueBytes = new byte[] { 0x01 }; - ByteQueue CodeQueue = script.GetByteQUeue(); - List> altStack = new List>(); + var CodeQueue = script.GetByteQUeue(); + var altStack = new List(); try { instruction opcode; - IEnumerable pushArg; + byte[] pushArg; while (GetOp(ref CodeQueue, out opcode, out pushArg)) // Read instructions { bool fExec = vfExec.IndexOf(false) == -1; - if (pushArg.Count() > 520) + if (pushArg.Length > 520) { return false; // Script element size limit failed } @@ -986,14 +981,14 @@ namespace Novacoin case instruction.OP_NOTIF: { // if [statements] [else [statements]] endif - bool fValue = false; + var fValue = false; if (fExec) { if (stack.Count() < 1) { return false; } - IEnumerable vch = stacktop(ref stack, -1); + var vch = stacktop(ref stack, -1); fValue = CastToBool(vch); if (opcode == instruction.OP_NOTIF) { @@ -1097,8 +1092,8 @@ namespace Novacoin { return false; } - IEnumerable vch1 = stacktop(ref stack, -2); - IEnumerable vch2 = stacktop(ref stack, -1); + var vch1 = stacktop(ref stack, -2); + var vch2 = stacktop(ref stack, -1); stack.Add(vch1); stack.Add(vch2); } @@ -1111,9 +1106,9 @@ namespace Novacoin { return false; } - IEnumerable vch1 = stacktop(ref stack, -3); - IEnumerable vch2 = stacktop(ref stack, -2); - IEnumerable vch3 = stacktop(ref stack, -1); + var vch1 = stacktop(ref stack, -3); + var vch2 = stacktop(ref stack, -2); + var vch3 = stacktop(ref stack, -1); stack.Add(vch1); stack.Add(vch2); stack.Add(vch3); @@ -1127,8 +1122,8 @@ namespace Novacoin { return false; } - IEnumerable vch1 = stacktop(ref stack, -4); - IEnumerable vch2 = stacktop(ref stack, -3); + var vch1 = stacktop(ref stack, -4); + var vch2 = stacktop(ref stack, -3); stack.Add(vch1); stack.Add(vch2); } @@ -1142,8 +1137,8 @@ namespace Novacoin { return false; } - IEnumerable vch1 = stacktop(ref stack, -6); - IEnumerable vch2 = stacktop(ref stack, -5); + var vch1 = stacktop(ref stack, -6); + var vch2 = stacktop(ref stack, -5); stack.RemoveRange(nStackDepth - 6, 2); stack.Add(vch1); stack.Add(vch2); @@ -1153,7 +1148,7 @@ namespace Novacoin case instruction.OP_2SWAP: { // (x1 x2 x3 x4 -- x3 x4 x1 x2) - int nStackDepth = stack.Count(); + int nStackDepth = stack.Count; if (nStackDepth < 4) { return false; @@ -1171,7 +1166,7 @@ namespace Novacoin return false; } - IEnumerable vch = stacktop(ref stack, -1); + var vch = stacktop(ref stack, -1); if (CastToBool(vch)) { @@ -1208,7 +1203,7 @@ namespace Novacoin return false; } - IEnumerable vch = stacktop(ref stack, -1); + var vch = stacktop(ref stack, -1); stack.Add(vch); } break; @@ -1234,7 +1229,7 @@ namespace Novacoin return false; } - IEnumerable vch = stacktop(ref stack, -2); + var vch = stacktop(ref stack, -2); stack.Add(vch); } break; @@ -1259,7 +1254,7 @@ namespace Novacoin return false; } - IEnumerable vch = stacktop(ref stack, -n - 1); + var vch = stacktop(ref stack, -n - 1); if (opcode == instruction.OP_ROLL) { stack.RemoveAt(nStackDepth - n - 1); @@ -1305,7 +1300,7 @@ namespace Novacoin { return false; } - IEnumerable vch = stacktop(ref stack, -1); + var vch = stacktop(ref stack, -1); stack.Insert(nStackDepth - 2, vch); } break; @@ -1319,7 +1314,7 @@ namespace Novacoin return false; } - BigInteger bnSize = new BigInteger((ushort)stacktop(ref stack, -1).Count()); + var bnSize = new BigInteger((ushort)stacktop(ref stack, -1).Count()); stack.Add(bnSize.ToByteArray()); } break; @@ -1338,8 +1333,8 @@ namespace Novacoin return false; } - IEnumerable vch1 = stacktop(ref stack, -2); - IEnumerable vch2 = stacktop(ref stack, -1); + var vch1 = stacktop(ref stack, -2); + var vch2 = stacktop(ref stack, -1); bool fEqual = (vch1.SequenceEqual(vch2)); // OP_NOTEQUAL is disabled because it would be too easy to say // something like n != 1 and have some wiseguy pass in 1 with extra @@ -1381,7 +1376,7 @@ namespace Novacoin return false; } - BigInteger bn = CastToBigInteger(stacktop(ref stack, -1)); + var bn = CastToBigInteger(stacktop(ref stack, -1)); switch (opcode) { case instruction.OP_1ADD: @@ -1429,8 +1424,8 @@ namespace Novacoin return false; } - BigInteger bn1 = CastToBigInteger(stacktop(ref stack, -2)); - BigInteger bn2 = CastToBigInteger(stacktop(ref stack, -1)); + var bn1 = CastToBigInteger(stacktop(ref stack, -2)); + var bn2 = CastToBigInteger(stacktop(ref stack, -1)); BigInteger bn = 0; switch (opcode) @@ -1502,9 +1497,9 @@ namespace Novacoin return false; } - BigInteger bn1 = CastToBigInteger(stacktop(ref stack, -3)); - BigInteger bn2 = CastToBigInteger(stacktop(ref stack, -2)); - BigInteger bn3 = CastToBigInteger(stacktop(ref stack, -1)); + var bn1 = CastToBigInteger(stacktop(ref stack, -3)); + var bn2 = CastToBigInteger(stacktop(ref stack, -2)); + var bn3 = CastToBigInteger(stacktop(ref stack, -1)); bool fValue = (bn2 <= bn1 && bn1 < bn3); @@ -1531,7 +1526,7 @@ namespace Novacoin return false; } Hash hash = null; - IEnumerable data = stacktop(ref stack, -1); + var data = stacktop(ref stack, -1); switch (opcode) { @@ -1572,8 +1567,8 @@ namespace Novacoin return false; } - IList sigBytes = stacktop(ref stack, -2).ToList(); - IList pubkeyBytes = stacktop(ref stack, -1).ToList(); + byte[] sigBytes = stacktop(ref stack, -2); + byte[] pubkeyBytes = stacktop(ref stack, -1); // Subset of script starting at the most recent codeseparator CScript scriptCode = new CScript(script.Bytes.Skip(nCodeHashBegin)); @@ -1581,7 +1576,7 @@ namespace Novacoin // There's no way for a signature to sign itself scriptCode.RemovePattern(sigBytes); - bool fSuccess = IsCanonicalSignature(sigBytes, flags) && IsCanonicalPubKey(pubkeyBytes.ToList(), flags) && CheckSig(sigBytes, pubkeyBytes, scriptCode, txTo, nIn, nHashType, flags); + bool fSuccess = IsCanonicalSignature(sigBytes, flags) && IsCanonicalPubKey(pubkeyBytes, flags) && CheckSig(sigBytes, pubkeyBytes, scriptCode, txTo, nIn, nHashType, flags); popstack(ref stack); popstack(ref stack); @@ -1648,18 +1643,18 @@ namespace Novacoin // There is no way for a signature to sign itself, so we need to drop the signatures for (int k = 0; k < nSigsCount; k++) { - IEnumerable vchSig = stacktop(ref stack, -isig - k); - scriptCode.RemovePattern(vchSig.ToList()); + var vchSig = stacktop(ref stack, -isig - k); + scriptCode.RemovePattern(vchSig); } bool fSuccess = true; while (fSuccess && nSigsCount > 0) { - IList sigBytes = stacktop(ref stack, -isig).ToList(); - IList pubKeyBytes = stacktop(ref stack, -ikey).ToList(); + var sigBytes = stacktop(ref stack, -isig); + var pubKeyBytes = stacktop(ref stack, -ikey); // Check signature - bool fOk = IsCanonicalSignature(sigBytes, flags) && IsCanonicalPubKey(pubKeyBytes.ToList(), flags) && CheckSig(sigBytes, pubKeyBytes, scriptCode, txTo, nIn, nHashType, flags); + bool fOk = IsCanonicalSignature(sigBytes, flags) && IsCanonicalPubKey(pubKeyBytes, flags) && CheckSig(sigBytes, pubKeyBytes, scriptCode, txTo, nIn, nHashType, flags); if (fOk) { @@ -1741,21 +1736,21 @@ namespace Novacoin } - public static bool IsCanonicalPubKey(IList pubKeyBytes, int flags) + public static bool IsCanonicalPubKey(byte[] pubKeyBytes, int flags) { if ((flags & (int)scriptflag.SCRIPT_VERIFY_STRICTENC) == 0) return true; - if (pubKeyBytes.Count < 33) + if (pubKeyBytes.Length < 33) return false; // Non-canonical public key: too short if (pubKeyBytes[0] == 0x04) { - if (pubKeyBytes.Count != 65) + if (pubKeyBytes.Length != 65) return false; // Non-canonical public key: invalid length for uncompressed key } else if (pubKeyBytes[0] == 0x02 || pubKeyBytes[0] == 0x03) { - if (pubKeyBytes.Count != 33) + if (pubKeyBytes.Length != 33) return false; // Non-canonical public key: invalid length for compressed key } else @@ -1765,7 +1760,7 @@ namespace Novacoin return true; } - public static bool IsCanonicalSignature(IList sigBytes, int flags) + public static bool IsCanonicalSignature(byte[] sigBytes, int flags) { // STUB @@ -1783,7 +1778,7 @@ namespace Novacoin /// Hashing type flag /// Signature checking flags /// Checking result - public static bool CheckSig(IList sigBytes, IList pubkeyBytes, CScript script, CTransaction txTo, int nIn, int nHashType, int flags) + public static bool CheckSig(byte[] sigBytes, byte[] pubkeyBytes, CScript script, CTransaction txTo, int nIn, int nHashType, int flags) { CPubKey pubkey; @@ -1805,7 +1800,7 @@ namespace Novacoin return false; } - if (sigBytes.Count == 0) + if (sigBytes.Length == 0) { return false; } @@ -1821,9 +1816,9 @@ namespace Novacoin } // Remove hash type - sigBytes.RemoveAt(sigBytes.Count - 1); + Array.Resize(ref sigBytes, sigBytes.Length - 1); - Hash256 sighash = SignatureHash(script, txTo, nIn, nHashType); + var sighash = SignatureHash(script, txTo, nIn, nHashType); if (!pubkey.VerifySignature(sighash, sigBytes)) { @@ -1845,8 +1840,8 @@ namespace Novacoin /// public static bool VerifyScript(CScript scriptSig, CScript scriptPubKey, CTransaction txTo, int nIn, int flags, int nHashType) { - List> stack = new List>(); - List> stackCopy = null; + var stack = new List(); + List stackCopy = null; if (!EvalScript(ref stack, scriptSig, txTo, nIn, flags, nHashType)) { @@ -1855,7 +1850,7 @@ namespace Novacoin if ((flags & (int)scriptflag.SCRIPT_VERIFY_P2SH) != 0) { - stackCopy = new List> (stack); + stackCopy = new List(stack); } if (!EvalScript(ref stack, scriptPubKey, txTo, nIn, flags, nHashType)) @@ -1885,7 +1880,7 @@ namespace Novacoin throw new StackMachineException("Fatal script validation error."); } - CScript pubKey2 = new CScript(stackCopy.Last()); + var pubKey2 = new CScript(stackCopy.Last()); popstack(ref stackCopy); if (!EvalScript(ref stackCopy, pubKey2, txTo, nIn, flags, nHashType)) diff --git a/Novacoin/ScryptHash256.cs b/Novacoin/ScryptHash256.cs index da6c9cc..162ec99 100644 --- a/Novacoin/ScryptHash256.cs +++ b/Novacoin/ScryptHash256.cs @@ -43,11 +43,11 @@ namespace Novacoin /// Hashing result instance public static ScryptHash256 Compute256(IEnumerable inputBytes) { - uint[] V = new uint[(131072 + 63) / sizeof(uint)]; + var V = new uint[(131072 + 63) / sizeof(uint)]; - byte[] dataBytes = inputBytes.ToArray(); - byte[] keyBytes1 = CryptoUtils.PBKDF2_Sha256(128, dataBytes, dataBytes, 1); - uint[] X = Interop.ToUInt32Array(keyBytes1); + var dataBytes = inputBytes.ToArray(); + var keyBytes1 = CryptoUtils.PBKDF2_Sha256(128, dataBytes, dataBytes, 1); + var X = Interop.ToUInt32Array(keyBytes1); uint i, j, k; for (i = 0; i < 1024; i++) @@ -66,8 +66,8 @@ namespace Novacoin xor_salsa8(ref X, 16, ref X, 0); } - byte[] xBytes = Interop.LEBytes(X); - byte[] keyBytes2 = CryptoUtils.PBKDF2_Sha256(32, dataBytes, xBytes, 1); + var xBytes = Interop.LEBytes(X); + var keyBytes2 = CryptoUtils.PBKDF2_Sha256(32, dataBytes, xBytes, 1); return new ScryptHash256(keyBytes2); } diff --git a/Novacoin/VarInt.cs b/Novacoin/VarInt.cs index edca418..4ebab9d 100644 --- a/Novacoin/VarInt.cs +++ b/Novacoin/VarInt.cs @@ -31,9 +31,9 @@ namespace Novacoin /// /// Unsigned integer value /// Byte sequence - public static IList EncodeVarInt(ulong n) + public static byte[] EncodeVarInt(ulong n) { - List resultBytes = new List(); + var resultBytes = new List(); if (n <= 0xfc) { @@ -68,7 +68,7 @@ namespace Novacoin resultBytes.AddRange(valueBytes); } - return resultBytes; + return resultBytes.ToArray(); } /// @@ -78,7 +78,7 @@ namespace Novacoin /// /// Integer value /// Byte sequence - public static IList EncodeVarInt(long n) + public static byte[] EncodeVarInt(long n) { return EncodeVarInt((ulong)n); } @@ -90,13 +90,12 @@ namespace Novacoin /// /// Byte sequence /// Integer value - public static ulong DecodeVarInt(IList bytes) + public static ulong DecodeVarInt(byte[] bytes) { - byte prefix = bytes[0]; + var prefix = bytes[0]; + var bytesArray = new byte[bytes.Length - 1]; - bytes.RemoveAt(0); // Remove prefix - - byte[] bytesArray = bytes.ToArray(); + bytes.CopyTo(bytesArray, 1); // Get rid of prefix switch (prefix) { diff --git a/NovacoinTest/Program.cs b/NovacoinTest/Program.cs index 8bd9342..8b30486 100644 --- a/NovacoinTest/Program.cs +++ b/NovacoinTest/Program.cs @@ -17,20 +17,20 @@ namespace NovacoinTest string strCoinbaseTx = "010000002926d155010000000000000000000000000000000000000000000000000000000000000000ffffffff27030cff02062f503253482f042926d155081ffffffdf60100000d2f6e6f64655374726174756d2f0000000003c04d6a00000000002321021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749acd89e0100000000001976a914ecf809f1ec0ba4faa909d5175e405902a21282be88aca81b0000000000001976a91422851477d63a085dbc2398c8430af1c09e7343f688ac00000000"; - CTransaction tx = new CTransaction(Interop.HexToList(strUserTx)); - CTransaction txCoinbase = new CTransaction(Interop.HexToList(strCoinbaseTx)); + var tx = new CTransaction(Interop.HexToList(strUserTx)); + var txCoinbase = new CTransaction(Interop.HexToList(strCoinbaseTx)); Console.WriteLine("User TX:{0}\n", tx.ToString()); Console.WriteLine("Coinbase TX: {0}\n", txCoinbase.ToString()); /// Block encoding/decoding tests string strBlock1 = "0600000086e539d77573abc0d81feb7896e1aef41a866001bc78bd24f5fe1a0000000000f5822cea59d999f37d896f66899c86e01e764ed6014706f3ceb58281ed55d0e55ab7d155ada3001d0000000005010000005ab7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0363ff02026d05062f503253482fffffffff0100000000000000000000000000010000005ab7d15501a768f8ed022f4080e3c8866bbe8292c7610b826cd467c49a06a1d0ff2ef7cdd6000000006b483045022100dce689d8cda64ebaffd6b96321952f16df34494256c58d2fd83069db7bce40e5022016020f55dc747d845d2057547c650412aa27d7d628e72238579f72e572dafdfe012102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ffffffff03000000000000000000d0f1440300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093acc23f450300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ac000000000100000091b4d15502c252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d010000004847304402204bee0faac004364cdf6483d492333d00ad6f7c925faa3750fef2c79a9065a28102204a5e2b970f776ea1af2c2c03e36e6381d3d69b529d90b512363ae44815a321c601ffffffffc252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d02000000494830450221008bf152a838f6f14f0ed1b2afc27821717e43a528e27aec3569ab42fc82f468aa02202cf6c962ef97db6e5ba32ccdd235afdc9a3cbb7907bfe879f8109446485d66dc01ffffffff0116467210000000001976a914edbf189bece45d4afa9848276e949183936bf6a488ac000000000100000017b5d1550229c74fb0004d45fba5baaefed1d9c229a8f1c85c36590cedf3ce6635335963d5000000006a4730440220319a4dfcf1607682d493c6d90087dc35d778a8bfcebe3549bae0af69e8daecb902206e6622367be30d9ccd4fdd27ed09c2fbcc9e5c858b26dfcdd927a8aba637b327012103b103f5d7e9717bc37cc99984b23babc3fff4677728be6b9c1847f6ce78e557f5ffffffff24b91fa6e9c160cc8da306e485942ee76137117aa8adecf531f6af1aef4e9b680000000049483045022100c9b311b7a7f5adeb0e72f962fb81b4cc1d105e32cfd7b1a7641a0fcc014d67c50220527161371a17301448bae87a26df201598b46d00ff452893177e9aed665c357c01ffffffff028e380000000000001976a91400afc350f81916a642a88b5ce8f73508663b531188ac67f46b00000000001976a91420c10f267f55ff4e05a083a8e1f4e882fbca1f4988ac0000000001000000efb6d15501626835db281e1fe6271620b8f67999f2174bb96df0eb3935fc99771e4ff45acf000000006a47304402206c34deb9c07c5477c47d398eaf91dbdf74aff5229c448e82ed0c1d8e2ee30e2d02203fe609434844b3eee21e747e313bcbf98efa4326727db6d2efba7bb627d2e0ce0121030c86c72f59c66824297aa78e433fe7057fd064e03e44c62ec49201ee0184149bffffffff028be30300000000001976a91481fc5cfb7f41afb3baf4138626022b3081b84e1788ac6abd0000000000001976a91499346dcd8ddfa10326697d5387b7df765004f4e388ac0000000046304402205189911c97354edb2965b4a119e6d76281f4c5da8fcead19c97bf6bcc9990fe102200f56d9dd967b036627b32b1e3ef2f819deaaafcc3244332472df7acfe19f1aa5"; - CBlock b1 = new CBlock(Interop.HexToList(strBlock1)); + var b1 = new CBlock(Interop.HexToList(strBlock1)); string strBlock1Bytes = Interop.ToHex(b1.Bytes); string strBlock2 = "06000000eb5ab262c7382e7e009ad0b65c707131b8b6b846f8920a1a6697d929203a22f70e8cbd6bee1c0519a9d06b749b5eb6e599c154b12b732170807e603b6c326abbe0b7d15560e2211b15085b8f0101000000e0b7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff270364ff02062f503253482f04c7b7d15508300000032b0000000d2f6e6f64655374726174756d2f0000000002f87d6b000000000023210287753c456abfc248d1bd155f44742d2ea72a2f29a5290c815fea0e9c55c4e2d0ac488a0000000000001976a914276cdbe21aaab75d58e151e01efea2860d3ef3d088ac0000000000"; - CBlock b2 = new CBlock(Interop.HexToList(strBlock2)); + var b2 = new CBlock(Interop.HexToList(strBlock2)); string strBlock2Bytes = Interop.ToHex(b2.Bytes); @@ -42,16 +42,16 @@ namespace NovacoinTest /// ECDSA keypair generation test - CKeyPair keyPair1 = new CKeyPair(); - CKeyPair keyPair2 = new CKeyPair(keyPair1.SecretBytes); - CPubKey pubKey = keyPair2.PubKey; + var keyPair1 = new CKeyPair(); + var keyPair2 = new CKeyPair(keyPair1.SecretBytes); + var pubKey = keyPair2.PubKey; string strPrivKeyBase58 = keyPair1.ToString(); Console.WriteLine("Privkey in Base58: {0}", strPrivKeyBase58); Console.WriteLine("Privkey in Hex: {0}", keyPair1.ToHex()); - CKeyPair keyPair3 = new CKeyPair(strPrivKeyBase58); + var keyPair3 = new CKeyPair(strPrivKeyBase58); Console.WriteLine("Privkey base58 deserialization is OK: {0}", keyPair3.KeyID.ToString() == keyPair1.KeyID.ToString()); Console.WriteLine("Pubkey in Base58: {0}", pubKey.ToString()); @@ -61,12 +61,12 @@ namespace NovacoinTest /// Address generation test - CKeyID keyID = keyPair1.KeyID; + var keyID = keyPair1.KeyID; Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes)); Console.WriteLine("Novacoin address: {0}\n", keyID.ToString()); /// Privkey deserialization test - CKeyPair keyPair4 = new CKeyPair("MEP3qCtFGmWo3Gurf8fMnUNaDHGNf637DqjoeG8rKium2jSj51sf"); + var keyPair4 = new CKeyPair("MEP3qCtFGmWo3Gurf8fMnUNaDHGNf637DqjoeG8rKium2jSj51sf"); Console.WriteLine("\nHard-coded privkey in Hex: {0}", keyPair4.ToHex()); Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.KeyID.ToString()); Console.WriteLine("Hard-Coded privkey: {0}\n", keyPair4.ToString()); @@ -78,9 +78,9 @@ namespace NovacoinTest /// ECDSA keypair signing test - string data = "Превед!"; - Hash256 sigHash = Hash256.Compute256(Encoding.UTF8.GetBytes(data)); - byte[] signature = keyPair1.Sign(sigHash).ToArray(); + var data = "Превед!"; + var sigHash = Hash256.Compute256(Encoding.UTF8.GetBytes(data)); + var signature = keyPair1.Sign(sigHash); Console.WriteLine("Signature: {0}", Interop.ToHex(signature)); Console.WriteLine("Signature is OK: {0} (CKeyPair)", keyPair1.VerifySignature(sigHash, signature)); @@ -89,28 +89,29 @@ namespace NovacoinTest /// Donation address string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788"; - CPubKey pubKeyTest = new CPubKey(Interop.HexToEnumerable(strPubKeyTest)); + var pubKeyTest = new CPubKey(Interop.HexToEnumerable(strPubKeyTest)); string strDonationAddress = pubKeyTest.KeyID.ToString(); + Console.WriteLine("\nDonations may be sent to: {0}", strDonationAddress); Console.WriteLine("Address generation is OK: {0}", strDonationAddress == "4T2t8uiDtyHceMwMjMHPn88TyJB3trCg3o"); /// Address deserialization test - CNovacoinAddress donationAddress = new CNovacoinAddress(strDonationAddress); + var donationAddress = new CNovacoinAddress(strDonationAddress); Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.KeyID.ToString()); /// Block header hashing test - IEnumerable dataBytesForScrypt = b1.header.Bytes; - ScryptHash256 scryptHash = ScryptHash256.Compute256(dataBytesForScrypt); + var dataBytesForScrypt = b1.header.Bytes; + var scryptHash = ScryptHash256.Compute256(dataBytesForScrypt); Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString()); /// Solver tests - CScript scriptPubKey = new CScript(Interop.HexToEnumerable("21021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749ac")); - CScript scriptPubKeyHash = new CScript(Interop.HexToEnumerable("76a914edbf189bece45d4afa9848276e949183936bf6a488ac")); + var scriptPubKey = new CScript(Interop.HexToEnumerable("21021ad6ae76a602310e86957d4ca752c81a8725f142fd2fc40f6a7fc2310bb2c749ac")); + var scriptPubKeyHash = new CScript(Interop.HexToEnumerable("76a914edbf189bece45d4afa9848276e949183936bf6a488ac")); txnouttype typeRet; - IList> solutions; + IList solutions; Console.WriteLine("\nscriptPubKey solved: {0}", ScriptCode.Solver(scriptPubKey, out typeRet, out solutions)); Console.WriteLine("scriptPubKey address: {0}\n", new CPubKey(solutions.First()).KeyID.ToString()); @@ -119,7 +120,7 @@ namespace NovacoinTest Console.WriteLine("scriptPubKeyHash address: {0}\n", new CKeyID(new Hash160(solutions.First())).ToString()); /// Some SetDestination tests - CScript scriptDestinationTest = new CScript(); + var scriptDestinationTest = new CScript(); Console.WriteLine("Creating and decoding new destination with {0} as public key.\n", keyPair1.PubKey.ToString()); @@ -150,7 +151,7 @@ namespace NovacoinTest int nRequired = solutions.First().First(); int nKeys = solutions.Last().First(); - foreach (IEnumerable keyBytes in solutions.Skip(1).Take(nKeys)) + foreach (var keyBytes in solutions.Skip(1).Take(nKeys)) { Console.WriteLine("\t{0}", (new CPubKey(keyBytes)).KeyID.ToString()); } @@ -168,7 +169,7 @@ namespace NovacoinTest Console.WriteLine("\tscriptP2SHTest address: {0}\n", new CScriptID(new Hash160(solutions.First())).ToString()); // SignatureHash tests - CTransaction txS = new CTransaction(Interop.HexToEnumerable("01000000ccfe9e550d083902781746c80954e3af56e930235befb798f987667021a2f32dc0099499cd010000006b483045022100b5f6783af4f7f60866c889fd668c93ee110ecc3751208fe0b49cc7ace47e52e8022075652e1e960a50b27436ab04f2728b3bba09d07a858691559d99c1ac5dd74f16012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff2c6009a7494f38f7797bb9ef2aeafb093ae433208171a504367373df4164399d010000004847304402205f1b74bbc37219918f3de13ff645ecc7093512fecda4fcbcac2174c44144361102202149f1adcfcd473ec8a662b5b166b600208d92596e30b33fb402b4720bac3da101ffffffffbf1dd11394d2c0d3cbd4e0b56c74e7463ed5a19f22fe219ee700c61f834b3948010000006a473044022004824a9e071c40707e5309e510fd2cc105fd430504ceefce48aeed1c8fcf3bd7022023f4a43c58e4012284d8df25b55940199d19d4ca664053e2d5c1cc93ef441c3c012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffffea06d18d8034a3645a8d5da75ed5c5f68a9dd09a798a876bef5d2cc9db8819390100000048473044022018e016973d87a53d6f14ae9929aa3c426d3d3a76eb81b3f1e996f0ec24ebacb302203668f165e6e9d5818eb3d108d23e2390213a6921ddfd51dbfca4ffebad73029601ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc0100000049483045022100c4d210a6cd3edc6bc9cbfee1a8506ff239ef60baf7ebd46ffefb43e20a575d6c022019ea10cf480dadbb6332a03a404a3991437ffc9fef044c07112e2d15f3de74de01ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc020000004948304502210084f5781ff88c201caca29b724f89fad5d72320a578239a3a2834ba669ea92b7e02207651ef9f7c60c2cc4fe187c98587252f3196fb1c31ed8f6c1f1f41e9a90d75ff01ffffffff61a9d75745092786bcbd48cc5860845beea607b8994790e9734f9fa68951bb66010000006b483045022100d2d3f925472970b9a0d365a120a9a6c9b7b0b3b3aacedaa40532397c6252da2f02206939d3cade4bada339799a4d651a7a33cb381640f6acef5fbecbe55ae1fa2364012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff635c711ba32bd587d349521475d2bd133a402c178543183c027cc1414a7837500100000049483045022100aece1ca9d902eaece08ec9704005196046f3a0b6f561cd17e9b09c01fed1447602207e68e21be4fcb895f045337741b42f43d218bb5c681f8e2eac5f9f3ffc8caf8301ffffffff7ddd7385fd7b81f19ccaa6ccd629bd2ab2a0af7ca69831c6dbb3b02c31de95db0100000049483045022100b260f2065dea407006e424d3cbb20009c807f422cee4ac8fb3553e4a81d62a7702204c67c99e792542cfe19a6956b101b4fd754a01fb1538b54e5f2141210729f09b01ffffffff8faebe377bc4211e41bd7e4a551e1de530040f8a55797f82e12d4d3c6a0b9fff010000004847304402204637911286c073fa0a8211e8427a6c63201bdac73e7b2760d3d9c7d748c9267c02205df709fdd06e3fb600ab81a17a1becc829769f1cb117b1520755d4f2a38429f001fffffffff1be969005bfcab4bcdaf835470680e2a309290b97d79fe63f7cbe904560b2d601000000484730440220352ad1a1ea5d92ddc13b7507a05180574c7309822f684ecf7321b7e925e5104302201e6a06e2f2d05a3d665cc6180fafacb658514a2f1bb632de99e88e4c26149e2501fffffffffa2019204a766fb4614be3d12bfb1ab35ad756e144193249e83660ca78898b3b0200000048473044022024f21eaf955291a9aec2cd45f42add62d8a30626aa9246664226fb3b56bf632f02205a3b46ec2857fec2fcb73663a57f99e4fcda328e8f1283198e8e9c5b4a2a3e0f01ffffffffd25e023fbdcd571ae346bf7aa142f5e32ca1aec23adae314ee209af22572cf1f000000006a4730440220551627592cbb7d970222a4d57a32aed50f1e93e81ae69958f26e56ca3b561715022019b12e560ff31013d0941ca2100ecdf9a3c3602b5c76b83d3b3c87d723d32ce3012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff02402d0000000000001976a91479f1d300be0da277e7ae217e99c6cc8a4f8717fe88ac00943577000000001976a914cbc5a055ae068d34b4a93e4c9adb9cb10262ae4f88ac00000000").ToList()); + var txS = new CTransaction(Interop.HexToEnumerable("01000000ccfe9e550d083902781746c80954e3af56e930235befb798f987667021a2f32dc0099499cd010000006b483045022100b5f6783af4f7f60866c889fd668c93ee110ecc3751208fe0b49cc7ace47e52e8022075652e1e960a50b27436ab04f2728b3bba09d07a858691559d99c1ac5dd74f16012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff2c6009a7494f38f7797bb9ef2aeafb093ae433208171a504367373df4164399d010000004847304402205f1b74bbc37219918f3de13ff645ecc7093512fecda4fcbcac2174c44144361102202149f1adcfcd473ec8a662b5b166b600208d92596e30b33fb402b4720bac3da101ffffffffbf1dd11394d2c0d3cbd4e0b56c74e7463ed5a19f22fe219ee700c61f834b3948010000006a473044022004824a9e071c40707e5309e510fd2cc105fd430504ceefce48aeed1c8fcf3bd7022023f4a43c58e4012284d8df25b55940199d19d4ca664053e2d5c1cc93ef441c3c012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffffea06d18d8034a3645a8d5da75ed5c5f68a9dd09a798a876bef5d2cc9db8819390100000048473044022018e016973d87a53d6f14ae9929aa3c426d3d3a76eb81b3f1e996f0ec24ebacb302203668f165e6e9d5818eb3d108d23e2390213a6921ddfd51dbfca4ffebad73029601ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc0100000049483045022100c4d210a6cd3edc6bc9cbfee1a8506ff239ef60baf7ebd46ffefb43e20a575d6c022019ea10cf480dadbb6332a03a404a3991437ffc9fef044c07112e2d15f3de74de01ffffffff5bda9a2a98debbda4ddad400a340190fcba4f4b3268f0a9d88eb5541bd7dadfc020000004948304502210084f5781ff88c201caca29b724f89fad5d72320a578239a3a2834ba669ea92b7e02207651ef9f7c60c2cc4fe187c98587252f3196fb1c31ed8f6c1f1f41e9a90d75ff01ffffffff61a9d75745092786bcbd48cc5860845beea607b8994790e9734f9fa68951bb66010000006b483045022100d2d3f925472970b9a0d365a120a9a6c9b7b0b3b3aacedaa40532397c6252da2f02206939d3cade4bada339799a4d651a7a33cb381640f6acef5fbecbe55ae1fa2364012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff635c711ba32bd587d349521475d2bd133a402c178543183c027cc1414a7837500100000049483045022100aece1ca9d902eaece08ec9704005196046f3a0b6f561cd17e9b09c01fed1447602207e68e21be4fcb895f045337741b42f43d218bb5c681f8e2eac5f9f3ffc8caf8301ffffffff7ddd7385fd7b81f19ccaa6ccd629bd2ab2a0af7ca69831c6dbb3b02c31de95db0100000049483045022100b260f2065dea407006e424d3cbb20009c807f422cee4ac8fb3553e4a81d62a7702204c67c99e792542cfe19a6956b101b4fd754a01fb1538b54e5f2141210729f09b01ffffffff8faebe377bc4211e41bd7e4a551e1de530040f8a55797f82e12d4d3c6a0b9fff010000004847304402204637911286c073fa0a8211e8427a6c63201bdac73e7b2760d3d9c7d748c9267c02205df709fdd06e3fb600ab81a17a1becc829769f1cb117b1520755d4f2a38429f001fffffffff1be969005bfcab4bcdaf835470680e2a309290b97d79fe63f7cbe904560b2d601000000484730440220352ad1a1ea5d92ddc13b7507a05180574c7309822f684ecf7321b7e925e5104302201e6a06e2f2d05a3d665cc6180fafacb658514a2f1bb632de99e88e4c26149e2501fffffffffa2019204a766fb4614be3d12bfb1ab35ad756e144193249e83660ca78898b3b0200000048473044022024f21eaf955291a9aec2cd45f42add62d8a30626aa9246664226fb3b56bf632f02205a3b46ec2857fec2fcb73663a57f99e4fcda328e8f1283198e8e9c5b4a2a3e0f01ffffffffd25e023fbdcd571ae346bf7aa142f5e32ca1aec23adae314ee209af22572cf1f000000006a4730440220551627592cbb7d970222a4d57a32aed50f1e93e81ae69958f26e56ca3b561715022019b12e560ff31013d0941ca2100ecdf9a3c3602b5c76b83d3b3c87d723d32ce3012103fe065856d7fa8cd41d0047600af2ec1ebe8c6198c1a889e90d8ce6b2f1f8afd7ffffffff02402d0000000000001976a91479f1d300be0da277e7ae217e99c6cc8a4f8717fe88ac00943577000000001976a914cbc5a055ae068d34b4a93e4c9adb9cb10262ae4f88ac00000000").ToList()); Hash256 sigHashAll = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_ALL); Hash256 sigHashNone = ScriptCode.SignatureHash(txS.vout[0].scriptPubKey, txS, 1, (int)sigflag.SIGHASH_NONE);