From: CryptoManiac Date: Thu, 20 Aug 2015 19:16:25 +0000 (+0300) Subject: Use getters instead of Satoshi-style access methods X-Git-Url: https://git.novaco.in/?p=NovacoinLibrary.git;a=commitdiff_plain;h=a56e5293ec49be8fd7fd0962837a1a5a38e244f3 Use getters instead of Satoshi-style access methods --- diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs index 565b6a2..c4f7f91 100644 --- a/Novacoin/CScript.cs +++ b/Novacoin/CScript.cs @@ -175,65 +175,71 @@ namespace Novacoin /// Is it true that script doesn't contain anything except push value operations? /// /// Checking result - public bool IsPushonly() + public bool IsPushonly { - WrappedList wCodeBytes = new WrappedList(codeBytes); - - opcodetype opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument - - // Scan opcodes sequence - while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) + get { - if (opcode > opcodetype.OP_16) + WrappedList wCodeBytes = new WrappedList(codeBytes); + + opcodetype opcode; // Current opcode + IEnumerable pushArgs; // OP_PUSHDATAn argument + + // Scan opcodes sequence + while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) { - // We don't allow control opcodes here - return false; + if (opcode > opcodetype.OP_16) + { + // We don't allow control opcodes here + return false; + } } - } - return true; + return true; + } } /// /// Is it true that script doesn't contain non-canonical push operations? /// /// Checking result - public bool HashOnlyCanonicalPushes() + public bool HasOnlyCanonicalPushes { - WrappedList wCodeBytes = new WrappedList(codeBytes); - - opcodetype opcode; // Current opcode - IEnumerable pushArgs; // OP_PUSHDATAn argument - - // Scan opcodes sequence - while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) + get { - byte[] data = pushArgs.ToArray(); + WrappedList wCodeBytes = new WrappedList(codeBytes); - if (opcode < opcodetype.OP_PUSHDATA1 && opcode > opcodetype.OP_0 && (data.Length == 1 && data[0] <= 16)) - { - // Could have used an OP_n code, rather than a 1-byte push. - return false; - } - if (opcode == opcodetype.OP_PUSHDATA1 && data.Length < (int)opcodetype.OP_PUSHDATA1) - { - // Could have used a normal n-byte push, rather than OP_PUSHDATA1. - return false; - } - if (opcode == opcodetype.OP_PUSHDATA2 && data.Length <= 0xFF) - { - // Could have used an OP_PUSHDATA1. - return false; - } - if (opcode == opcodetype.OP_PUSHDATA4 && data.LongLength <= 0xFFFF) + opcodetype opcode; // Current opcode + IEnumerable pushArgs; // OP_PUSHDATAn argument + + // Scan opcodes sequence + while (ScriptCode.GetOp(ref wCodeBytes, out opcode, out pushArgs)) { - // Could have used an OP_PUSHDATA2. - return false; + byte[] data = pushArgs.ToArray(); + + if (opcode < opcodetype.OP_PUSHDATA1 && opcode > opcodetype.OP_0 && (data.Length == 1 && data[0] <= 16)) + { + // Could have used an OP_n code, rather than a 1-byte push. + return false; + } + if (opcode == opcodetype.OP_PUSHDATA1 && data.Length < (int)opcodetype.OP_PUSHDATA1) + { + // Could have used a normal n-byte push, rather than OP_PUSHDATA1. + return false; + } + if (opcode == opcodetype.OP_PUSHDATA2 && data.Length <= 0xFF) + { + // Could have used an OP_PUSHDATA1. + return false; + } + if (opcode == opcodetype.OP_PUSHDATA4 && data.LongLength <= 0xFFFF) + { + // Could have used an OP_PUSHDATA2. + return false; + } } - } - return true; + return true; + } } /// @@ -263,7 +269,6 @@ namespace Novacoin { // 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 && @@ -384,7 +389,7 @@ namespace Novacoin /// /// Access to script code. /// - public IEnumerable Enumerable + public IEnumerable Bytes { get { return codeBytes; } } diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index 6d69349..2326c01 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -661,7 +661,7 @@ namespace Novacoin typeRet = txnouttype.TX_SCRIPTHASH; // Take 20 bytes with offset of 2 bytes - IEnumerable hashBytes = scriptPubKey.Enumerable.Skip(2).Take(20); + IEnumerable hashBytes = scriptPubKey.Bytes.Skip(2).Take(20); solutions.Add(hashBytes); return true; @@ -673,7 +673,7 @@ namespace Novacoin typeRet = txnouttype.TX_PUBKEYHASH; // Take 20 bytes with offset of 3 bytes - IEnumerable hashBytes = scriptPubKey.Enumerable.Skip(3).Take(20); + IEnumerable hashBytes = scriptPubKey.Bytes.Skip(3).Take(20); solutions.Add(hashBytes); return true; @@ -722,8 +722,8 @@ namespace Novacoin IEnumerable args1, args2; - byte last1 = script1.Enumerable.Last(); - byte last2 = script2.Enumerable.Last(); + byte last1 = script1.Bytes.Last(); + byte last2 = script2.Bytes.Last(); while (true) {