From be834adfb84c418d7915a186ee13651312eab1d1 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Thu, 20 Aug 2015 21:44:14 +0300 Subject: [PATCH] Use getters instead of Satoshi-style access methods --- Novacoin/CBlock.cs | 25 +++++---- Novacoin/CBlockHeader.cs | 21 ++++--- Novacoin/CKey.cs | 8 +- Novacoin/CKeyPair.cs | 12 ++-- Novacoin/CNovacoinAddress.cs | 45 ++++++++------- Novacoin/CPubKey.cs | 4 +- Novacoin/CScript.cs | 44 ++++++++------ Novacoin/CTransaction.cs | 131 +++++++++++++++++++++-------------------- Novacoin/CTxIn.cs | 25 +++++---- Novacoin/CTxOut.cs | 15 +++-- Novacoin/Hash.cs | 4 +- Novacoin/ScriptCode.cs | 4 +- NovacoinTest/Program.cs | 26 ++++---- 13 files changed, 194 insertions(+), 170 deletions(-) diff --git a/Novacoin/CBlock.cs b/Novacoin/CBlock.cs index 68e813a..46ca9d5 100644 --- a/Novacoin/CBlock.cs +++ b/Novacoin/CBlock.cs @@ -53,22 +53,25 @@ namespace Novacoin /// Convert current instance into sequence of bytes /// /// Byte sequence - public IList ToBytes() + public IList Bytes { - List r = new List(); + get + { + List r = new List(); - r.AddRange(header.ToBytes()); - r.AddRange(VarInt.EncodeVarInt(vtx.LongLength)); // transactions count + r.AddRange(header.Bytes); + r.AddRange(VarInt.EncodeVarInt(vtx.LongLength)); // transactions count - foreach (CTransaction tx in vtx) - { - r.AddRange(tx.ToBytes()); - } + foreach (CTransaction tx in vtx) + { + r.AddRange(tx.Bytes); + } - r.AddRange(VarInt.EncodeVarInt(signature.LongLength)); - r.AddRange(signature); + r.AddRange(VarInt.EncodeVarInt(signature.LongLength)); + r.AddRange(signature); - return r; + return r; + } } public override string ToString() diff --git a/Novacoin/CBlockHeader.cs b/Novacoin/CBlockHeader.cs index 1eb4885..d85f34f 100644 --- a/Novacoin/CBlockHeader.cs +++ b/Novacoin/CBlockHeader.cs @@ -50,18 +50,21 @@ namespace Novacoin /// Convert current block header instance into sequence of bytes /// /// Byte sequence - public IList ToBytes() + public IList Bytes { - List r = new List(); + get + { + List 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)); + 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; + return r; + } } public override string ToString() diff --git a/Novacoin/CKey.cs b/Novacoin/CKey.cs index 3fe695e..46b1387 100644 --- a/Novacoin/CKey.cs +++ b/Novacoin/CKey.cs @@ -81,15 +81,15 @@ namespace Novacoin /// Calculate Hash160 and create new CKeyID instance. /// /// New key ID - public CKeyID GetKeyID() + public CKeyID KeyID { - return new CKeyID(Hash160.Compute160(Public)); + get { return new CKeyID(Hash160.Compute160(PublicBytes)); } } /// - /// Public part of key pair + /// PublicBytes part of key pair /// - public IEnumerable Public + public IEnumerable PublicBytes { get { return _Public.Q.GetEncoded(); } } diff --git a/Novacoin/CKeyPair.cs b/Novacoin/CKeyPair.cs index f59f45f..a729d50 100644 --- a/Novacoin/CKeyPair.cs +++ b/Novacoin/CKeyPair.cs @@ -129,15 +129,15 @@ namespace Novacoin return signer.GenerateSignature(); } - public CPubKey GetPubKey() + public CPubKey PubKey { - return new CPubKey(Public); + get { return new CPubKey(PublicBytes); } } /// - /// Secret part of key pair + /// SecretBytes part of key pair /// - public IEnumerable Secret + public IEnumerable SecretBytes { get { @@ -161,7 +161,7 @@ namespace Novacoin public string ToHex() { - return Interop.ToHex(Secret); + return Interop.ToHex(SecretBytes); } public override string ToString() @@ -169,7 +169,7 @@ namespace Novacoin List r = new List(); r.Add((byte)(128 + AddrType.PUBKEY_ADDRESS)); // Key version - r.AddRange(Secret); // Key data + r.AddRange(SecretBytes); // Key data return AddressTools.Base58EncodeCheck(r); } diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index 7165a33..410de44 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -68,30 +68,33 @@ namespace Novacoin /// Basic sanity checking /// /// - public bool IsValid() + public bool IsValid { - // Address data is normally generated by RIPEMD-160 hash function - int nExpectedSize = 20; - - switch ((AddrType) nVersion) + get { - case AddrType.PUBKEY_ADDRESS: - nExpectedSize = 20; // Hash of public key - break; - case AddrType.SCRIPT_ADDRESS: - nExpectedSize = 20; // Hash of CScript - break; - case AddrType.PUBKEY_ADDRESS_TEST: - nExpectedSize = 20; - break; - case AddrType.SCRIPT_ADDRESS_TEST: - nExpectedSize = 20; - break; - default: - return false; - } + // Address data is normally generated by RIPEMD-160 hash function + int nExpectedSize = 20; - return addrData.Count == nExpectedSize; + switch ((AddrType)nVersion) + { + case AddrType.PUBKEY_ADDRESS: + nExpectedSize = 20; // Hash of public key + break; + case AddrType.SCRIPT_ADDRESS: + nExpectedSize = 20; // Hash of CScript + break; + case AddrType.PUBKEY_ADDRESS_TEST: + nExpectedSize = 20; + break; + case AddrType.SCRIPT_ADDRESS_TEST: + nExpectedSize = 20; + break; + default: + return false; + } + + return addrData.Count == nExpectedSize; + } } /// diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs index fa4c052..0294f1d 100644 --- a/Novacoin/CPubKey.cs +++ b/Novacoin/CPubKey.cs @@ -50,7 +50,7 @@ namespace Novacoin public string ToHex() { - return Interop.ToHex(Public); + return Interop.ToHex(PublicBytes); } public override string ToString() @@ -59,7 +59,7 @@ namespace Novacoin r.Add((byte)(AddrType.PUBKEY_ADDRESS)); - r.AddRange(Public); + r.AddRange(PublicBytes); return AddressTools.Base58EncodeCheck(r); } diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs index d9938fd..565b6a2 100644 --- a/Novacoin/CScript.cs +++ b/Novacoin/CScript.cs @@ -240,31 +240,37 @@ namespace Novacoin /// Quick test for pay-to-script-hash CScripts /// /// Checking result - public bool IsPayToScriptHash() + public bool IsPayToScriptHash { - // Sender provides redeem script hash, receiver provides signature list and redeem script - // OP_HASH160 20 [20 byte hash] OP_EQUAL - return (codeBytes.Count() == 23 && - codeBytes[0] == (byte)opcodetype.OP_HASH160 && - codeBytes[1] == 0x14 && // 20 bytes hash length prefix - codeBytes[22] == (byte)opcodetype.OP_EQUAL); + get + { + // Sender provides redeem script hash, receiver provides signature list and redeem script + // OP_HASH160 20 [20 byte hash] OP_EQUAL + return (codeBytes.Count() == 23 && + codeBytes[0] == (byte)opcodetype.OP_HASH160 && + codeBytes[1] == 0x14 && // 20 bytes hash length prefix + codeBytes[22] == (byte)opcodetype.OP_EQUAL); + } } /// /// Quick test for pay-to-pubkeyhash CScripts /// /// Checking result - public bool IsPayToPubKeyHash() + public bool IsPayToPubKeyHash { - // Sender provides hash of pubkey, receiver provides signature and pubkey - // OP_DUP OP_HASH160 20 [20 byte hash] OP_EQUALVERIFY OP_CHECKSIG - - return (codeBytes.Count == 25 && - codeBytes[0] == (byte) opcodetype.OP_DUP && - codeBytes[1] == (byte)opcodetype.OP_HASH160 && - codeBytes[2] == 0x14 && // 20 bytes hash length prefix - codeBytes[23] == (byte)opcodetype.OP_EQUALVERIFY && - codeBytes[24] == (byte)opcodetype.OP_CHECKSIG); + get + { + // Sender provides hash of pubkey, receiver provides signature and pubkey + // OP_DUP OP_HASH160 20 [20 byte hash] OP_EQUALVERIFY OP_CHECKSIG + + return (codeBytes.Count == 25 && + codeBytes[0] == (byte)opcodetype.OP_DUP && + codeBytes[1] == (byte)opcodetype.OP_HASH160 && + codeBytes[2] == 0x14 && // 20 bytes hash length prefix + codeBytes[23] == (byte)opcodetype.OP_EQUALVERIFY && + codeBytes[24] == (byte)opcodetype.OP_CHECKSIG); + } } /// @@ -317,7 +323,7 @@ namespace Novacoin /// SigOps count public int GetSigOpCount(CScript scriptSig) { - if (!IsPayToScriptHash()) + if (!IsPayToScriptHash) { return GetSigOpCount(true); } @@ -369,7 +375,7 @@ namespace Novacoin foreach (CPubKey key in keys) { - PushData(key.Public.ToList()); + PushData(key.PublicBytes.ToList()); } AddOp(ScriptCode.EncodeOP_N(keys.Count())); AddOp(opcodetype.OP_CHECKMULTISIG); diff --git a/Novacoin/CTransaction.cs b/Novacoin/CTransaction.cs index 6647c11..1fa5bf5 100644 --- a/Novacoin/CTransaction.cs +++ b/Novacoin/CTransaction.cs @@ -113,73 +113,76 @@ namespace Novacoin return tx; } - public IList ToBytes() + public IList Bytes { - List resultBytes = new List(); - - // Typical transaction example: - // - // 01000000 -- version - // 78b4c953 -- timestamp - // 06 -- amount of txins - // 340d96b77ec4ee9d42b31cadc2fab911e48d48c36274d516f226d5e85bbc512c -- txin hash - // 01000000 -- txin outnumber - // 6b -- txin scriptSig length - // 483045022100c8df1fc17b6ea1355a39b92146ec67b3b53565e636e028010d3a8a87f6f805f202203888b9b74df03c3960773f2a81b2dfd1efb08bb036a8f3600bd24d5ed694cd5a0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // 364c640420de8fa77313475970bf09ce4d0b1f8eabb8f1d6ea49d90c85b202ee -- txin hash - // 01000000 -- txin outnumber - // 6b -- txin scriptSig length - // 483045022100b651bf3a6835d714d2c990c742136d769258d0170c9aac24803b986050a8655b0220623651077ff14b0a9d61e30e30f2c15352f70491096f0ec655ae1c79a44e53aa0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // 7adbd5f2e521f567bfea2cb63e65d55e66c83563fe253464b75184a5e462043d -- txin hash - // 00000000 -- txin outnumber - // 6a -- txin scriptSig length - // 4730440220183609f2b995993acc9df241aff722d48b9a731b0cd376212934565723ed81f00220737e7ce75ef39bdc061d0dcdba3ee24e43b899696a7c96803cee0a79e1f78ecb0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // 999eb03e00a41c2f9fde8865a554ceebbc48d30f4c8ba22dd88da8c9b46fa920 -- txin hash - // 03000000 -- txin outnumber - // 6b -- txin scriptSig length - // 483045022100ec1ab104ef086ba79b0f2611ebf1bfdd22a7a1020f6630fa1c6707546626e0db022056093d4048a999392185ccc735ef736a5497bd68f60b42e6c0c93ba770b54d010121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // c0543b86be257ddd85b014a76718a70fab9eaa3c477460e4ca187094d86f369c -- txin hash - // 05000000 -- txin outnumber - // 69 -- txin scriptSig length - // 463043021f24275c72f952043174daf01d7f713f878625f0522124a3cab48a0a2e12604202201b47742e6697b0ebdd1e4ba49c74baf142a0228ad0e0ee847488994c9dce78470121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // e1793d4519147782293dd1db6d90e461265d91db2cc6889c37209394d42ad10d -- txin hash - // 05000000 -- txin outnumber - // 6a -- txin scriptSig length - // 473044022018a0c3d73b2765d75380614ab36ee8e3c937080894a19166128b1e3357b208fb0220233c9609985f535547381431526867ad0255ec4969afe5c360544992ed6b3ed60121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig - // ffffffff -- txin nSequence - // 02 -- amount of txouts - // e542000000000000 -- txout value - // 19 -- scriptPubKey length - // 76a91457d84c814b14bd86bf32f106b733baa693db7dc788ac -- scriptPubKey - // 409c000000000000 -- txout value - // 19 -- scriptPubKey length - // 76a91408c8768d5d6bf7c1d9609da4e766c3f1752247b188ac -- scriptPubKey - // 00000000 -- lock time - - resultBytes.AddRange(BitConverter.GetBytes(nVersion)); - resultBytes.AddRange(BitConverter.GetBytes(nTime)); - resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength)); - - foreach(CTxIn input in vin) + get { - resultBytes.AddRange(input.ToBytes()); + List resultBytes = new List(); + + // Typical transaction example: + // + // 01000000 -- version + // 78b4c953 -- timestamp + // 06 -- amount of txins + // 340d96b77ec4ee9d42b31cadc2fab911e48d48c36274d516f226d5e85bbc512c -- txin hash + // 01000000 -- txin outnumber + // 6b -- txin scriptSig length + // 483045022100c8df1fc17b6ea1355a39b92146ec67b3b53565e636e028010d3a8a87f6f805f202203888b9b74df03c3960773f2a81b2dfd1efb08bb036a8f3600bd24d5ed694cd5a0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // 364c640420de8fa77313475970bf09ce4d0b1f8eabb8f1d6ea49d90c85b202ee -- txin hash + // 01000000 -- txin outnumber + // 6b -- txin scriptSig length + // 483045022100b651bf3a6835d714d2c990c742136d769258d0170c9aac24803b986050a8655b0220623651077ff14b0a9d61e30e30f2c15352f70491096f0ec655ae1c79a44e53aa0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // 7adbd5f2e521f567bfea2cb63e65d55e66c83563fe253464b75184a5e462043d -- txin hash + // 00000000 -- txin outnumber + // 6a -- txin scriptSig length + // 4730440220183609f2b995993acc9df241aff722d48b9a731b0cd376212934565723ed81f00220737e7ce75ef39bdc061d0dcdba3ee24e43b899696a7c96803cee0a79e1f78ecb0121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // 999eb03e00a41c2f9fde8865a554ceebbc48d30f4c8ba22dd88da8c9b46fa920 -- txin hash + // 03000000 -- txin outnumber + // 6b -- txin scriptSig length + // 483045022100ec1ab104ef086ba79b0f2611ebf1bfdd22a7a1020f6630fa1c6707546626e0db022056093d4048a999392185ccc735ef736a5497bd68f60b42e6c0c93ba770b54d010121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // c0543b86be257ddd85b014a76718a70fab9eaa3c477460e4ca187094d86f369c -- txin hash + // 05000000 -- txin outnumber + // 69 -- txin scriptSig length + // 463043021f24275c72f952043174daf01d7f713f878625f0522124a3cab48a0a2e12604202201b47742e6697b0ebdd1e4ba49c74baf142a0228ad0e0ee847488994c9dce78470121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // e1793d4519147782293dd1db6d90e461265d91db2cc6889c37209394d42ad10d -- txin hash + // 05000000 -- txin outnumber + // 6a -- txin scriptSig length + // 473044022018a0c3d73b2765d75380614ab36ee8e3c937080894a19166128b1e3357b208fb0220233c9609985f535547381431526867ad0255ec4969afe5c360544992ed6b3ed60121030dd13e6d3c63fa10cc0b6bf968fbbfcb9a988b333813b1f22d04fa60e344bc4c -- txin scriptSig + // ffffffff -- txin nSequence + // 02 -- amount of txouts + // e542000000000000 -- txout value + // 19 -- scriptPubKey length + // 76a91457d84c814b14bd86bf32f106b733baa693db7dc788ac -- scriptPubKey + // 409c000000000000 -- txout value + // 19 -- scriptPubKey length + // 76a91408c8768d5d6bf7c1d9609da4e766c3f1752247b188ac -- scriptPubKey + // 00000000 -- lock time + + resultBytes.AddRange(BitConverter.GetBytes(nVersion)); + resultBytes.AddRange(BitConverter.GetBytes(nTime)); + resultBytes.AddRange(VarInt.EncodeVarInt(vin.LongLength)); + + foreach (CTxIn input in vin) + { + resultBytes.AddRange(input.Bytes); + } + + resultBytes.AddRange(VarInt.EncodeVarInt(vout.LongLength)); + + foreach (CTxOut output in vout) + { + resultBytes.AddRange(output.Bytes); + } + + resultBytes.AddRange(BitConverter.GetBytes(nLockTime)); + + return resultBytes; } - - resultBytes.AddRange(VarInt.EncodeVarInt(vout.LongLength)); - - foreach(CTxOut output in vout) - { - resultBytes.AddRange(output.ToBytes()); - } - - resultBytes.AddRange(BitConverter.GetBytes(nLockTime)); - - return resultBytes; } public override string ToString() diff --git a/Novacoin/CTxIn.cs b/Novacoin/CTxIn.cs index f5fbc77..7f6aeee 100644 --- a/Novacoin/CTxIn.cs +++ b/Novacoin/CTxIn.cs @@ -80,29 +80,32 @@ namespace Novacoin /// Get raw bytes representation of our input. /// /// Byte sequence. - public IList ToBytes() + public IList Bytes { - List inputBytes = new List(); + get + { + List inputBytes = new List(); - inputBytes.AddRange(txID.hashBytes); // Input transaction id - inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number - inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length - inputBytes.AddRange(scriptSig); // scriptSig - inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence + inputBytes.AddRange(txID.hashBytes); // Input transaction id + inputBytes.AddRange(BitConverter.GetBytes(n)); // Output number + inputBytes.AddRange(VarInt.EncodeVarInt(scriptSig.LongLength)); // scriptSig length + inputBytes.AddRange(scriptSig); // scriptSig + inputBytes.AddRange(BitConverter.GetBytes(nSequence)); // Sequence - return inputBytes; + return inputBytes; + } } - public bool IsCoinBase() + public bool IsCoinBase { - return txID.IsZero(); + get { return txID.IsZero; } } public override string ToString () { StringBuilder sb = new StringBuilder (); - if (IsCoinBase()) + if (IsCoinBase) { sb.AppendFormat("CTxIn(txId={0}, coinbase={2}, nSequence={3})", txID.ToString(), n, Interop.ToHex(scriptSig), nSequence); } diff --git a/Novacoin/CTxOut.cs b/Novacoin/CTxOut.cs index 94a853c..9b40a8f 100644 --- a/Novacoin/CTxOut.cs +++ b/Novacoin/CTxOut.cs @@ -61,15 +61,18 @@ namespace Novacoin /// Get raw bytes representation of our output. /// /// Byte sequence. - public IList ToBytes() + public IList Bytes { - List resultBytes = new List(); + get + { + List resultBytes = new List(); - resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value - resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length - resultBytes.AddRange(scriptPubKey); // scriptPubKey + resultBytes.AddRange(BitConverter.GetBytes(nValue)); // txout value + resultBytes.AddRange(VarInt.EncodeVarInt(scriptPubKey.LongLength)); // scriptPubKey length + resultBytes.AddRange(scriptPubKey); // scriptPubKey - return resultBytes; + return resultBytes; + } } public override string ToString () diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index 4944b30..34632f1 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -51,9 +51,9 @@ namespace Novacoin _hashBytes = bytes; } - public bool IsZero() + public bool IsZero { - return !_hashBytes.Any(b => b != 0); + get { return !_hashBytes.Any(b => b != 0); } } public override string ToString() diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index c6da9c5..6d69349 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -656,7 +656,7 @@ namespace Novacoin // There are shortcuts for pay-to-script-hash and pay-to-pubkey-hash, which are more constrained than the other types: // It is always OP_HASH160 20 [20 byte hash] OP_EQUAL - if (scriptPubKey.IsPayToScriptHash()) + if (scriptPubKey.IsPayToScriptHash) { typeRet = txnouttype.TX_SCRIPTHASH; @@ -668,7 +668,7 @@ namespace Novacoin } // It is always OP_DUP OP_HASH160 20 [20 byte hash] OP_EQUALVERIFY OP_CHECKSIG - if (scriptPubKey.IsPayToPubKeyHash()) + if (scriptPubKey.IsPayToPubKeyHash) { typeRet = txnouttype.TX_PUBKEYHASH; diff --git a/NovacoinTest/Program.cs b/NovacoinTest/Program.cs index d48bc74..71c7741 100644 --- a/NovacoinTest/Program.cs +++ b/NovacoinTest/Program.cs @@ -27,12 +27,12 @@ namespace NovacoinTest string strBlock1 = "0600000086e539d77573abc0d81feb7896e1aef41a866001bc78bd24f5fe1a0000000000f5822cea59d999f37d896f66899c86e01e764ed6014706f3ceb58281ed55d0e55ab7d155ada3001d0000000005010000005ab7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0363ff02026d05062f503253482fffffffff0100000000000000000000000000010000005ab7d15501a768f8ed022f4080e3c8866bbe8292c7610b826cd467c49a06a1d0ff2ef7cdd6000000006b483045022100dce689d8cda64ebaffd6b96321952f16df34494256c58d2fd83069db7bce40e5022016020f55dc747d845d2057547c650412aa27d7d628e72238579f72e572dafdfe012102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ffffffff03000000000000000000d0f1440300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093acc23f450300000000232102916e12c72a41913a5307bf7477db80dd499ea20f1a6bd99a2bdae6229f5aa093ac000000000100000091b4d15502c252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d010000004847304402204bee0faac004364cdf6483d492333d00ad6f7c925faa3750fef2c79a9065a28102204a5e2b970f776ea1af2c2c03e36e6381d3d69b529d90b512363ae44815a321c601ffffffffc252c9130b1fd1dc8ef59cdb550ed398c4fe12c7ebf3eb917076bbda039b769d02000000494830450221008bf152a838f6f14f0ed1b2afc27821717e43a528e27aec3569ab42fc82f468aa02202cf6c962ef97db6e5ba32ccdd235afdc9a3cbb7907bfe879f8109446485d66dc01ffffffff0116467210000000001976a914edbf189bece45d4afa9848276e949183936bf6a488ac000000000100000017b5d1550229c74fb0004d45fba5baaefed1d9c229a8f1c85c36590cedf3ce6635335963d5000000006a4730440220319a4dfcf1607682d493c6d90087dc35d778a8bfcebe3549bae0af69e8daecb902206e6622367be30d9ccd4fdd27ed09c2fbcc9e5c858b26dfcdd927a8aba637b327012103b103f5d7e9717bc37cc99984b23babc3fff4677728be6b9c1847f6ce78e557f5ffffffff24b91fa6e9c160cc8da306e485942ee76137117aa8adecf531f6af1aef4e9b680000000049483045022100c9b311b7a7f5adeb0e72f962fb81b4cc1d105e32cfd7b1a7641a0fcc014d67c50220527161371a17301448bae87a26df201598b46d00ff452893177e9aed665c357c01ffffffff028e380000000000001976a91400afc350f81916a642a88b5ce8f73508663b531188ac67f46b00000000001976a91420c10f267f55ff4e05a083a8e1f4e882fbca1f4988ac0000000001000000efb6d15501626835db281e1fe6271620b8f67999f2174bb96df0eb3935fc99771e4ff45acf000000006a47304402206c34deb9c07c5477c47d398eaf91dbdf74aff5229c448e82ed0c1d8e2ee30e2d02203fe609434844b3eee21e747e313bcbf98efa4326727db6d2efba7bb627d2e0ce0121030c86c72f59c66824297aa78e433fe7057fd064e03e44c62ec49201ee0184149bffffffff028be30300000000001976a91481fc5cfb7f41afb3baf4138626022b3081b84e1788ac6abd0000000000001976a91499346dcd8ddfa10326697d5387b7df765004f4e388ac0000000046304402205189911c97354edb2965b4a119e6d76281f4c5da8fcead19c97bf6bcc9990fe102200f56d9dd967b036627b32b1e3ef2f819deaaafcc3244332472df7acfe19f1aa5"; CBlock b1 = new CBlock(Interop.ParseHex(strBlock1).ToList()); - string strBlock1Bytes = Interop.ToHex(b1.ToBytes()); + string strBlock1Bytes = Interop.ToHex(b1.Bytes); string strBlock2 = "06000000eb5ab262c7382e7e009ad0b65c707131b8b6b846f8920a1a6697d929203a22f70e8cbd6bee1c0519a9d06b749b5eb6e599c154b12b732170807e603b6c326abbe0b7d15560e2211b15085b8f0101000000e0b7d155010000000000000000000000000000000000000000000000000000000000000000ffffffff270364ff02062f503253482f04c7b7d15508300000032b0000000d2f6e6f64655374726174756d2f0000000002f87d6b000000000023210287753c456abfc248d1bd155f44742d2ea72a2f29a5290c815fea0e9c55c4e2d0ac488a0000000000001976a914276cdbe21aaab75d58e151e01efea2860d3ef3d088ac0000000000"; CBlock b2 = new CBlock(Interop.ParseHex(strBlock2).ToList()); - string strBlock2Bytes = Interop.ToHex(b2.ToBytes()); + string strBlock2Bytes = Interop.ToHex(b2.Bytes); Console.WriteLine(b1.ToString()); Console.WriteLine("OK: {0}\n", strBlock1 == strBlock1Bytes); @@ -43,8 +43,8 @@ namespace NovacoinTest /// ECDSA keypair generation test CKeyPair keyPair1 = new CKeyPair(); - CKeyPair keyPair2 = new CKeyPair(keyPair1.Secret); - CPubKey pubKey = keyPair2.GetPubKey(); + CKeyPair keyPair2 = new CKeyPair(keyPair1.SecretBytes); + CPubKey pubKey = keyPair2.PubKey; string strPrivKeyBase58 = keyPair1.ToString(); @@ -52,7 +52,7 @@ namespace NovacoinTest Console.WriteLine("Privkey in Hex: {0}", keyPair1.ToHex()); CKeyPair keyPair3 = new CKeyPair(strPrivKeyBase58); - Console.WriteLine("Privkey base58 deserialization is OK: {0}", keyPair3.GetKeyID().ToString() == keyPair1.GetKeyID().ToString()); + Console.WriteLine("Privkey base58 deserialization is OK: {0}", keyPair3.KeyID.ToString() == keyPair1.KeyID.ToString()); Console.WriteLine("Pubkey in Base58: {0}", pubKey.ToString()); Console.WriteLine("Pubkey in Hex: {0}", pubKey.ToHex()); @@ -61,20 +61,20 @@ namespace NovacoinTest /// Address generation test - CKeyID keyID = keyPair1.GetKeyID(); + CKeyID 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"); Console.WriteLine("\nHard-coded privkey in Hex: {0}", keyPair4.ToHex()); - Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.GetKeyID().ToString()); + Console.WriteLine("Hard-Coded privkey address: {0}", keyPair4.KeyID.ToString()); Console.WriteLine("Hard-Coded privkey: {0}\n", keyPair4.ToString()); // Privkey hex deserialization test - CKeyPair keyPair5 = new CKeyPair(keyPair4.Secret.ToArray()); + CKeyPair keyPair5 = new CKeyPair(keyPair4.SecretBytes.ToArray()); Console.WriteLine("Decoded privkey in Hex: {0}", keyPair5.ToHex()); - Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.GetKeyID().ToString()); + Console.WriteLine("Decoded privkey address: {0}\n", keyPair5.KeyID.ToString()); /// ECDSA keypair signing test @@ -90,17 +90,17 @@ namespace NovacoinTest string strPubKeyTest = "029780fac8b85b4a47a616acb4e19d7958eaf02acc5123f65e7824ce720b1ae788"; CPubKey pubKeyTest = new CPubKey(Interop.ParseHex(strPubKeyTest)); - string strDonationAddress = pubKeyTest.GetKeyID().ToString(); + 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); - Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.GetKeyID().ToString()); + Console.WriteLine("Address reserialization is OK: {0}", donationAddress.ToString() == pubKeyTest.KeyID.ToString()); /// Block header hashing test - IEnumerable dataBytesForScrypt = b1.header.ToBytes(); + IEnumerable dataBytesForScrypt = b1.header.Bytes; ScryptHash256 scryptHash = ScryptHash256.Compute256(dataBytesForScrypt); Console.WriteLine("\nblock1 header hash: {0}", scryptHash.ToString()); @@ -113,7 +113,7 @@ namespace NovacoinTest IList> solutions; Console.WriteLine("scriptPubKey solved: {0}", ScriptCode.Solver(scriptPubKey, out typeRet, out solutions)); - Console.WriteLine("scriptPubKey address: {0}", new CPubKey(solutions.First()).GetKeyID().ToString()); + Console.WriteLine("scriptPubKey address: {0}", new CPubKey(solutions.First()).KeyID.ToString()); Console.WriteLine("scriptPubKeyHash solved: {0}", ScriptCode.Solver(scriptPubKeyHash, out typeRet, out solutions)); Console.WriteLine("scriptPubKeyHash address: {0}", new CKeyID(new Hash160(solutions.First())).ToString()); -- 1.7.1