From: CryptoManiac Date: Thu, 27 Aug 2015 15:07:42 +0000 (+0300) Subject: Use implicit type casting operator for serialization. X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=0279648337efe9bbe32b5204e247529243805484 Use implicit type casting operator for serialization. --- diff --git a/Novacoin/AddressTools.cs b/Novacoin/AddressTools.cs index 1f72cea..c0073fe 100644 --- a/Novacoin/AddressTools.cs +++ b/Novacoin/AddressTools.cs @@ -66,7 +66,7 @@ namespace Novacoin { var dataBytes = new byte[bytes.Length + 4]; bytes.CopyTo(dataBytes, 0); - var checkSum = Hash256.Compute256(bytes).hashBytes.Take(4).ToArray(); + var checkSum = Hash256.ComputeRaw256(bytes).Take(4).ToArray(); checkSum.CopyTo(dataBytes, dataBytes.Length - 4); // add 4-byte hash check to the end return Base58Encode(dataBytes); @@ -127,7 +127,7 @@ namespace Novacoin Array.Copy(rawData, result, result.Length); Array.Copy(rawData, result.Length, resultCheckSum, 0, 4); - var checkSum = Hash256.Compute256(result).hashBytes.Take(4).ToArray(); + var checkSum = Hash256.ComputeRaw256(result).Take(4).ToArray(); if (!checkSum.SequenceEqual(resultCheckSum)) { diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index fc3d32d..20f462c 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -143,28 +143,25 @@ namespace Novacoin } /// - /// Get current instance as sequence of bytes + /// Get instance as sequence of bytes /// /// Byte sequence - public IList Bytes + public static implicit operator byte[] (CBlock b) { - get - { - var r = new List(); + var r = new List(); - r.AddRange(header.Bytes); - r.AddRange(VarInt.EncodeVarInt(vtx.LongLength)); // transactions count + r.AddRange((byte[])b.header); + r.AddRange(VarInt.EncodeVarInt(b.vtx.LongLength)); // transactions count - foreach (var tx in vtx) - { - r.AddRange(tx.Bytes); - } + foreach (var tx in b.vtx) + { + r.AddRange((byte[])tx); + } - r.AddRange(VarInt.EncodeVarInt(signature.LongLength)); - r.AddRange(signature); + r.AddRange(VarInt.EncodeVarInt(b.signature.LongLength)); + r.AddRange(b.signature); - return r; - } + return r.ToArray(); } /// @@ -178,7 +175,7 @@ namespace Novacoin foreach (var tx in vtx) { - merkleTree.AddRange(Hash256.ComputeRaw256(tx.Bytes)); + merkleTree.AddRange(Hash256.ComputeRaw256(tx)); } int levelOffset = 0; diff --git a/Novacoin/CBlockHeader.cs b/Novacoin/CBlockHeader.cs index 129be06..d7c1dc6 100644 --- a/Novacoin/CBlockHeader.cs +++ b/Novacoin/CBlockHeader.cs @@ -88,27 +88,24 @@ namespace Novacoin /// Convert current block header instance into sequence of bytes /// /// Byte sequence - public byte[] Bytes + public static implicit operator byte[] (CBlockHeader h) { - get - { - var r = new List(); - - r.AddRange(BitConverter.GetBytes(nVersion)); - r.AddRange(prevHash.hashBytes); - r.AddRange(merkleRoot.hashBytes); - r.AddRange(BitConverter.GetBytes(nTime)); - r.AddRange(BitConverter.GetBytes(nBits)); - r.AddRange(BitConverter.GetBytes(nNonce)); - - return r.ToArray(); - } + var r = new List(); + + r.AddRange(BitConverter.GetBytes(h.nVersion)); + r.AddRange((byte[])h.prevHash); + r.AddRange((byte[])h.merkleRoot); + r.AddRange(BitConverter.GetBytes(h.nTime)); + r.AddRange(BitConverter.GetBytes(h.nBits)); + r.AddRange(BitConverter.GetBytes(h.nNonce)); + + return r.ToArray(); } public ScryptHash256 Hash { get { - return ScryptHash256.Compute256(Bytes); + return ScryptHash256.Compute256(this); } } diff --git a/Novacoin/CKey.cs b/Novacoin/CKey.cs index 2769de5..355c66e 100644 --- a/Novacoin/CKey.cs +++ b/Novacoin/CKey.cs @@ -86,7 +86,7 @@ namespace Novacoin { var signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(false, _Public); - signer.BlockUpdate(sigHash.hashBytes, 0, sigHash.hashSize); + signer.BlockUpdate(sigHash, 0, sigHash.hashSize); return signer.VerifySignature(signature); } @@ -97,15 +97,7 @@ namespace Novacoin /// New key ID public CKeyID KeyID { - get { return new CKeyID(Hash160.Compute160(PublicBytes)); } - } - - /// - /// Public part of key pair - /// - public byte[] PublicBytes - { - get { return _Public.Q.GetEncoded(); } + get { return new CKeyID(Hash160.Compute160(_Public.Q.GetEncoded())); } } /// diff --git a/Novacoin/CKeyID.cs b/Novacoin/CKeyID.cs index 12b2b97..ea8e561 100644 --- a/Novacoin/CKeyID.cs +++ b/Novacoin/CKeyID.cs @@ -22,7 +22,7 @@ namespace Novacoin { public CKeyID(Hash160 pubKeyHash) { - _hashBytes = pubKeyHash.hashBytes; + _hashBytes = pubKeyHash; } internal CKeyID(byte[] hashBytes) diff --git a/Novacoin/CKeyPair.cs b/Novacoin/CKeyPair.cs index 6f6cbe1..adecb9b 100644 --- a/Novacoin/CKeyPair.cs +++ b/Novacoin/CKeyPair.cs @@ -174,44 +174,41 @@ namespace Novacoin { var signer = SignerUtilities.GetSigner("NONEwithECDSA"); signer.Init(true, _Private); - signer.BlockUpdate(sigHash.hashBytes, 0, sigHash.hashSize); + signer.BlockUpdate(sigHash, 0, sigHash.hashSize); return signer.GenerateSignature(); } public CPubKey PubKey { - get { return new CPubKey(PublicBytes); } + get { return new CPubKey(_Public.Q.GetEncoded()); } } /// /// SecretBytes part of key pair /// - public byte[] SecretBytes + public static implicit operator byte[] (CKeyPair kp) { - get - { - var secretBytes = new List(_Private.D.ToByteArray()); - - if (secretBytes.Count == 33 && secretBytes[0] == 0x00) - { - // Remove sign - secretBytes.RemoveAt(0); - } + var secretBytes = new List(kp._Private.D.ToByteArray()); - if (IsCompressed) - { - // Set compression flag - secretBytes.Add(0x01); - } + if (secretBytes.Count == 33 && secretBytes[0] == 0x00) + { + // Remove sign + secretBytes.RemoveAt(0); + } - return secretBytes.ToArray(); + if (kp.IsCompressed) + { + // Set compression flag + secretBytes.Add(0x01); } + + return secretBytes.ToArray(); } public string ToHex() { - return Interop.ToHex(SecretBytes); + return Interop.ToHex((byte[])this); } /// @@ -223,7 +220,7 @@ namespace Novacoin var r = new List(); r.Add((byte)(128 + AddrType.PUBKEY_ADDRESS)); // Key version - r.AddRange(SecretBytes); // Key data + r.AddRange((byte[])this); // Key data return AddressTools.Base58EncodeCheck(r.ToArray()); } diff --git a/Novacoin/CKeyStore.cs b/Novacoin/CKeyStore.cs index 5d8f8ff..8d6ab98 100644 --- a/Novacoin/CKeyStore.cs +++ b/Novacoin/CKeyStore.cs @@ -163,9 +163,9 @@ namespace Novacoin var res = dbConn.Insert(new KeyStorageItem() { - KeyID = keyPair.KeyID.hashBytes, - PublicKey = keyPair.PublicBytes, - PrivateKey = keyPair.SecretBytes, + KeyID = keyPair.KeyID, + PublicKey = keyPair.PubKey, + PrivateKey = keyPair, IsCompressed = keyPair.IsCompressed, IsUsed = false, nTime = Interop.GetTime() @@ -189,9 +189,9 @@ namespace Novacoin { var res = dbConn.Insert(new KeyStorageItem() { - KeyID = keyPair.KeyID.hashBytes, - PublicKey = keyPair.PublicBytes, - PrivateKey = keyPair.SecretBytes, + KeyID = keyPair.KeyID, + PublicKey = keyPair.PubKey, + PrivateKey = keyPair, IsCompressed = keyPair.IsCompressed, IsUsed = true, nTime = Interop.GetTime() @@ -213,7 +213,7 @@ namespace Novacoin /// Checking result public bool HaveKey(CKeyID keyID) { - var QueryCount = dbConn.Query("select count([ItemID]) from [KeyStorage] where [KeyID] = ?", keyID.hashBytes); + var QueryCount = dbConn.Query("select count([ItemID]) from [KeyStorage] where [KeyID] = ?", (byte[])keyID); return QueryCount.First().Num == 1; } @@ -226,7 +226,7 @@ namespace Novacoin /// Result public bool GetKey(CKeyID keyID, out CKeyPair keyPair) { - var QueryGet = dbConn.Query("select * from [KeyStorage] where [KeyID] = ?", keyID.hashBytes); + var QueryGet = dbConn.Query("select * from [KeyStorage] where [KeyID] = ?", (byte[])keyID); if (QueryGet.Count() == 1) { @@ -249,8 +249,8 @@ namespace Novacoin { var res = dbConn.Insert(new ScriptStorageItem() { - ScriptID = script.ScriptID.hashBytes, - ScriptCode = script.Bytes + ScriptID = script.ScriptID, + ScriptCode = script }); if (res == 0) @@ -269,7 +269,7 @@ namespace Novacoin /// Checking result public bool HaveScript(CScriptID scriptID) { - var QueryGet = dbConn.Query("select count([ItemID]) from [ScriptStorage] where [ScriptID] = ?", scriptID.hashBytes); + var QueryGet = dbConn.Query("select count([ItemID]) from [ScriptStorage] where [ScriptID] = ?", (byte[])scriptID); return QueryGet.First().Num == 1; } @@ -282,7 +282,7 @@ namespace Novacoin /// Result public bool GetScript(CScriptID scriptID, out CScript script) { - var QueryGet = dbConn.Query("select * from [ScriptStorage] where [ScriptID] = ?", scriptID.hashBytes); + var QueryGet = dbConn.Query("select * from [ScriptStorage] where [ScriptID] = ?", (byte[])scriptID); if (QueryGet.Count() == 1) { diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index c2dd81c..bf5321a 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -58,7 +58,7 @@ namespace Novacoin public CNovacoinAddress(CKeyID keyID) { nVersion = (byte)AddrType.PUBKEY_ADDRESS; - addrData = new List(keyID.hashBytes); + addrData = new List((byte[])keyID); } public CNovacoinAddress(string strNovacoinAddress) @@ -76,7 +76,7 @@ namespace Novacoin public CNovacoinAddress(CScriptID scriptID) { nVersion = (byte)AddrType.SCRIPT_ADDRESS; - addrData = new List(scriptID.hashBytes); + addrData = new List((byte[])scriptID); } /// diff --git a/Novacoin/COutPoint.cs b/Novacoin/COutPoint.cs index be3017f..a8db03d 100644 --- a/Novacoin/COutPoint.cs +++ b/Novacoin/COutPoint.cs @@ -63,16 +63,13 @@ namespace Novacoin get { return hash.IsZero && n == uint.MaxValue; } } - public IList Bytes + public static implicit operator byte[] (COutPoint o) { - get - { - var r = new List(); - r.AddRange(hash.hashBytes); - r.AddRange(BitConverter.GetBytes(n)); - - return r; - } + var r = new List(); + r.AddRange((byte[])o.hash); + r.AddRange(BitConverter.GetBytes(o.n)); + + return r.ToArray(); } public override string ToString() diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs index 64cc1ba..543a261 100644 --- a/Novacoin/CPubKey.cs +++ b/Novacoin/CPubKey.cs @@ -67,7 +67,15 @@ namespace Novacoin public string ToHex() { - return Interop.ToHex(PublicBytes); + return Interop.ToHex((byte[])this); + } + + /// + /// Public part of key pair + /// + public static implicit operator byte[] (CPubKey p) + { + return p._Public.Q.GetEncoded(); } public override string ToString() @@ -75,7 +83,7 @@ namespace Novacoin var r = new List(); r.Add((byte)(AddrType.PUBKEY_ADDRESS)); - r.AddRange(PublicBytes); + r.AddRange((byte[])this); return AddressTools.Base58EncodeCheck(r.ToArray()); } diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs index 13386a1..a9ca8ef 100644 --- a/Novacoin/CScript.cs +++ b/Novacoin/CScript.cs @@ -96,7 +96,7 @@ namespace Novacoin public void AddHash(Hash160 hash) { codeBytes.Add((byte)hash.hashSize); - codeBytes.AddRange(hash.hashBytes); + codeBytes.AddRange((byte[])hash); } /// @@ -108,7 +108,7 @@ namespace Novacoin public void AddHash(Hash256 hash) { codeBytes.Add((byte)hash.hashSize); - codeBytes.AddRange(hash.hashBytes); + codeBytes.AddRange((byte[])hash); } /// @@ -447,7 +447,7 @@ namespace Novacoin public void SetDestination(CPubKey pubKey) { codeBytes.Clear(); - PushData(pubKey.PublicBytes); + PushData(pubKey); AddInstruction(instruction.OP_CHECKSIG); } @@ -497,7 +497,7 @@ namespace Novacoin foreach (var key in keys) { - PushData(key.PublicBytes); + PushData(key); } AddInstruction(ScriptCode.EncodeOP_N(keys.Length)); @@ -507,9 +507,9 @@ namespace Novacoin /// /// Access to script code. /// - public byte[] Bytes + public static implicit operator byte[] (CScript script) { - get { return codeBytes.ToArray(); } + return script.codeBytes.ToArray(); } public CScriptID ScriptID diff --git a/Novacoin/CScriptID.cs b/Novacoin/CScriptID.cs index c252f56..c2cbc1f 100644 --- a/Novacoin/CScriptID.cs +++ b/Novacoin/CScriptID.cs @@ -22,7 +22,7 @@ namespace Novacoin { public CScriptID(Hash160 scriptHash) { - _hashBytes = scriptHash.hashBytes; + _hashBytes = scriptHash; } public override string ToString() diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index 13ce0c7..d8572eb 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -183,38 +183,35 @@ namespace Novacoin /// public Hash256 Hash { - get { return Hash256.Compute256(Bytes); } + get { return Hash256.Compute256(this); } } /// /// A sequence of bytes, which corresponds to the current state of CTransaction. /// - public byte[] Bytes + public static implicit operator byte[] (CTransaction tx) { - get - { - var resultBytes = new List(); + var resultBytes = new List(); - resultBytes.AddRange(BitConverter.GetBytes(nVersion)); - resultBytes.AddRange(BitConverter.GetBytes(nTime)); - resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength)); + resultBytes.AddRange(BitConverter.GetBytes(tx.nVersion)); + resultBytes.AddRange(BitConverter.GetBytes(tx.nTime)); + resultBytes.AddRange(VarInt.EncodeVarInt(tx.vin.LongLength)); - foreach (var input in vin) - { - resultBytes.AddRange(input.Bytes); - } + foreach (var input in tx.vin) + { + resultBytes.AddRange((byte[])input); + } - resultBytes.AddRange(VarInt.EncodeVarInt(vout.LongLength)); + resultBytes.AddRange(VarInt.EncodeVarInt(tx.vout.LongLength)); - foreach (var output in vout) - { - resultBytes.AddRange(output.Bytes); - } + foreach (var output in tx.vout) + { + resultBytes.AddRange((byte[])output); + } - resultBytes.AddRange(BitConverter.GetBytes(nLockTime)); + resultBytes.AddRange(BitConverter.GetBytes(tx.nLockTime)); - return resultBytes.ToArray(); - } + return resultBytes.ToArray(); } public override string ToString() diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index 4b88d15..a33606a 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -90,23 +90,21 @@ namespace Novacoin /// Get raw bytes representation of our input. /// /// Byte sequence. - public IList Bytes + public static implicit operator byte[] (CTxIn input) { - get - { - var inputBytes = new List(); + var inputBytes = new List(); - inputBytes.AddRange(prevout.Bytes); // prevout + inputBytes.AddRange((byte[])input.prevout); // prevout - var s = scriptSig.Bytes; - inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length - inputBytes.AddRange(s); // scriptSig - inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence + var s = (byte[])input.scriptSig; + inputBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptSig length + inputBytes.AddRange(s); // scriptSig + inputBytes.AddRange(BitConverter.GetBytes(input.nSequence)); // Sequence - return inputBytes; - } + return inputBytes.ToArray(); } + public bool IsFinal { get { return (nSequence == uint.MaxValue); } @@ -120,7 +118,7 @@ namespace Novacoin if(prevout.IsNull) { - sb.AppendFormat(", coinbase={0}", Interop.ToHex(scriptSig.Bytes)); + sb.AppendFormat(", coinbase={0}", Interop.ToHex((byte[])scriptSig)); } else { diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index e75579a..c5adf1c 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -82,20 +82,17 @@ namespace Novacoin /// Get raw bytes representation of our output. /// /// Byte sequence. - public IList Bytes + public static implicit operator byte[] (CTxOut output) { - get - { var resultBytes = new List(); - resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value + resultBytes.AddRange(BitConverter.GetBytes(output.nValue)); // txout value - var s = scriptPubKey.Bytes; + var s = (byte[])output.scriptPubKey; resultBytes.AddRange(VarInt.EncodeVarInt(s.Length)); // scriptPubKey length resultBytes.AddRange(s); // scriptPubKey - return resultBytes; - } + return resultBytes.ToArray(); } /// diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index b9e6d0c..d11f0b0 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -36,11 +36,6 @@ namespace Novacoin get; } - public byte[] hashBytes - { - get { return _hashBytes; } - } - /// /// Initializes an empty instance of the Hash class. /// @@ -74,10 +69,10 @@ namespace Novacoin get { return !_hashBytes.Any(b => b != 0); } } - /*public static implicit operator BigInteger(Hash h) + public static implicit operator byte[](Hash h) { - return new BigInteger(h._hashBytes); - }*/ + return h._hashBytes; + } public override string ToString() { diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index e1964b3..52c36f7 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -478,6 +478,8 @@ namespace Novacoin /// Result public static bool Solver(CScript scriptPubKey, out txnouttype typeRet, out IList solutions) { + var scriptBytes = ((byte[])scriptPubKey); + solutions = new List(); // There are shortcuts for pay-to-script-hash and pay-to-pubkey-hash, which are more constrained than the other types. @@ -488,7 +490,7 @@ namespace Novacoin typeRet = txnouttype.TX_SCRIPTHASH; // Take 20 bytes with offset of 2 bytes - var hashBytes = scriptPubKey.Bytes.Skip(2).Take(20); + var hashBytes = scriptBytes.Skip(2).Take(20); solutions.Add(hashBytes.ToArray()); return true; @@ -500,7 +502,7 @@ namespace Novacoin typeRet = txnouttype.TX_PUBKEYHASH; // Take 20 bytes with offset of 3 bytes - var hashBytes = scriptPubKey.Bytes.Skip(3).Take(20); + var hashBytes = scriptBytes.Skip(3).Take(20); solutions.Add(hashBytes.ToArray()); return true; @@ -560,8 +562,8 @@ namespace Novacoin byte[] args1, args2; - int last1 = script1.Bytes.Count() -1; - int last2 = script2.Bytes.Count() - 1; + int last1 = ((byte[])script1).Length -1; + int last2 = ((byte[])script2).Length - 1; while (true) { @@ -743,7 +745,7 @@ namespace Novacoin } // Concatenate and hash - var txBytes = txTmp.Bytes; + var txBytes = (byte[])txTmp; var nHashTypeBytes = BitConverter.GetBytes(nHashType); return Hash256.Compute256(ref txBytes, ref nHashTypeBytes); @@ -866,7 +868,9 @@ namespace Novacoin /// public static bool EvalScript(ref List stack, CScript script, CTransaction txTo, int nIn, int flags, int nHashType) { - if (script.Bytes.Count() > 10000) + var scriptBytes = ((byte[])script); + + if (scriptBytes.Length > 10000) { return false; // Size limit failed } @@ -1547,7 +1551,7 @@ namespace Novacoin break; } popstack(ref stack); - stack.Add(hash.hashBytes); + stack.Add(hash); } break; @@ -1571,7 +1575,7 @@ namespace Novacoin var pubkeyBytes = stacktop(ref stack, -1); // Subset of script starting at the most recent codeseparator - var scriptCode = new CScript(script.Bytes.Skip(nCodeHashBegin).ToArray()); + var scriptCode = new CScript(scriptBytes.Skip(nCodeHashBegin).ToArray()); // There's no way for a signature to sign itself scriptCode.RemovePattern(sigBytes); @@ -1638,7 +1642,7 @@ namespace Novacoin } // Subset of script starting at the most recent codeseparator - var scriptCode = new CScript(script.Bytes.Skip(nCodeHashBegin).ToArray()); + var scriptCode = new CScript(scriptBytes.Skip(nCodeHashBegin).ToArray()); // There is no way for a signature to sign itself, so we need to drop the signatures for (int k = 0; k < nSigsCount; k++) diff --git a/NovacoinTest/Program.cs b/NovacoinTest/Program.cs index 5b1c51e..f9b5128 100644 --- a/NovacoinTest/Program.cs +++ b/NovacoinTest/Program.cs @@ -27,12 +27,12 @@ namespace NovacoinTest string strBlock1 = "0600000086e539d77573abc0d81feb7896e1aef41a866001bc78bd24f5fe1a0000000000f5822cea59d999f37d896f66899c86e01e764ed6014706f3ceb58281ed55d0e55ab7d155ada3001d0000000005010000005ab7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0363ff02026d05062f503253482fffffffff0100000000000000000000000000010000005ab7d15501a768f8ed022f4080e3c8866bbe8292c7610b826cd467c49a06a1d0ff2ef7cdd6000000006b483045022100dce689d8cda64ebaffd6b96321952f16df34494256c58d2fd83069db7bce40e5022016020f55dc747d845d2057547c650412aa27d7d628e72238579f72e572dafdfe012102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ffffffff03000000000000000000d0f1440300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093acc23f450300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ac000000000100000091b4d15502c252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d010000004847304402204bee0faac004364cdf6483d492333d00ad6f7c925faa3750fef2c79a9065a28102204a5e2b970f776ea1af2c2c03e36e6381d3d69b529d90b512363ae44815a321c601ffffffffc252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d02000000494830450221008bf152a838f6f14f0ed1b2afc27821717e43a528e27aec3569ab42fc82f468aa02202cf6c962ef97db6e5ba32ccdd235afdc9a3cbb7907bfe879f8109446485d66dc01ffffffff0116467210000000001976a914edbf189bece45d4afa9848276e949183936bf6a488ac000000000100000017b5d1550229c74fb0004d45fba5baaefed1d9c229a8f1c85c36590cedf3ce6635335963d5000000006a4730440220319a4dfcf1607682d493c6d90087dc35d778a8bfcebe3549bae0af69e8daecb902206e6622367be30d9ccd4fdd27ed09c2fbcc9e5c858b26dfcdd927a8aba637b327012103b103f5d7e9717bc37cc99984b23babc3fff4677728be6b9c1847f6ce78e557f5ffffffff24b91fa6e9c160cc8da306e485942ee76137117aa8adecf531f6af1aef4e9b680000000049483045022100c9b311b7a7f5adeb0e72f962fb81b4cc1d105e32cfd7b1a7641a0fcc014d67c50220527161371a17301448bae87a26df201598b46d00ff452893177e9aed665c357c01ffffffff028e380000000000001976a91400afc350f81916a642a88b5ce8f73508663b531188ac67f46b00000000001976a91420c10f267f55ff4e05a083a8e1f4e882fbca1f4988ac0000000001000000efb6d15501626835db281e1fe6271620b8f67999f2174bb96df0eb3935fc99771e4ff45acf000000006a47304402206c34deb9c07c5477c47d398eaf91dbdf74aff5229c448e82ed0c1d8e2ee30e2d02203fe609434844b3eee21e747e313bcbf98efa4326727db6d2efba7bb627d2e0ce0121030c86c72f59c66824297aa78e433fe7057fd064e03e44c62ec49201ee0184149bffffffff028be30300000000001976a91481fc5cfb7f41afb3baf4138626022b3081b84e1788ac6abd0000000000001976a91499346dcd8ddfa10326697d5387b7df765004f4e388ac0000000046304402205189911c97354edb2965b4a119e6d76281f4c5da8fcead19c97bf6bcc9990fe102200f56d9dd967b036627b32b1e3ef2f819deaaafcc3244332472df7acfe19f1aa5"; var b1 = new CBlock(Interop.HexToArray(strBlock1)); - string strBlock1Bytes = Interop.ToHex(b1.Bytes); + string strBlock1Bytes = Interop.ToHex((byte[])b1); string strBlock2 = "06000000eb5ab262c7382e7e009ad0b65c707131b8b6b846f8920a1a6697d929203a22f70e8cbd6bee1c0519a9d06b749b5eb6e599c154b12b732170807e603b6c326abbe0b7d15560e2211b15085b8f0101000000e0b7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff270364ff02062f503253482f04c7b7d15508300000032b0000000d2f6e6f64655374726174756d2f0000000002f87d6b000000000023210287753c456abfc248d1bd155f44742d2ea72a2f29a5290c815fea0e9c55c4e2d0ac488a0000000000001976a914276cdbe21aaab75d58e151e01efea2860d3ef3d088ac0000000000"; var b2 = new CBlock(Interop.HexToArray(strBlock2)); - string strBlock2Bytes = Interop.ToHex(b2.Bytes); + string strBlock2Bytes = Interop.ToHex((byte[])b2); Console.WriteLine(b1.ToString()); Console.WriteLine("OK: {0}\n", strBlock1 == strBlock1Bytes); @@ -43,7 +43,7 @@ namespace NovacoinTest /// ECDSA keypair generation test var keyPair1 = new CKeyPair(); - var keyPair2 = new CKeyPair(keyPair1.SecretBytes); + var keyPair2 = new CKeyPair((byte[])keyPair1); var pubKey = keyPair2.PubKey; string strPrivKeyBase58 = keyPair1.ToString(); @@ -62,7 +62,7 @@ namespace NovacoinTest /// Address generation test var keyID = keyPair1.KeyID; - Console.WriteLine("Key ID: {0}", Interop.ToHex(keyID.hashBytes)); + Console.WriteLine("Key ID: {0}", Interop.ToHex((byte[])keyID)); Console.WriteLine("Novacoin address: {0}\n", keyID.ToString()); /// Privkey deserialization test @@ -72,7 +72,7 @@ namespace NovacoinTest Console.WriteLine("Hard-Coded privkey: {0}\n", keyPair4.ToString()); // Privkey hex deserialization test - CKeyPair keyPair5 = new CKeyPair(keyPair4.SecretBytes.ToArray()); + CKeyPair keyPair5 = new CKeyPair((byte[])keyPair4); Console.WriteLine("Decoded privkey in Hex: {0}", keyPair5.ToHex()); Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.KeyID.ToString()); @@ -101,7 +101,7 @@ namespace NovacoinTest Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.KeyID.ToString()); /// Block header hashing test - var dataBytesForScrypt = b1.header.Bytes; + byte[] dataBytesForScrypt = b1.header; var scryptHash = ScryptHash256.Compute256(dataBytesForScrypt); Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString()); @@ -244,7 +244,7 @@ namespace NovacoinTest watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine("Calculation time: {0} ms\n", elapsedMs); - Console.WriteLine("Merkle tree is OK: {0}", merkleroot.hashBytes.SequenceEqual(veryBigBlock.header.merkleRoot.hashBytes)); + Console.WriteLine("Merkle tree is OK: {0}", ((byte[])merkleroot).SequenceEqual((byte[])veryBigBlock.header.merkleRoot)); // Initialization of key store @@ -256,7 +256,6 @@ namespace NovacoinTest var kp1 = new CKeyPair(); keyStore.AddKey(kp1); - CKeyPair kp2; var queryRes = keyStore.GetKey(kp1.KeyID, out kp2); Console.WriteLine("KeyID={0} exists in database: {1}", kp1.KeyID.ToString(), queryRes);