X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=Novacoin%2FCScript.cs;h=abdad9c238b64cfd219295ebe5e86e01e3f9ea15;hb=6dfa6de57c6493b76856acc9ab510ac31962c327;hp=cd6d27ab85f98b0b1e0561e3495973ef5bbe026f;hpb=241856f1328f7d900260976c18c29f67c7cebc80;p=NovacoinLibrary.git
diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs
index cd6d27a..abdad9c 100644
--- a/Novacoin/CScript.cs
+++ b/Novacoin/CScript.cs
@@ -21,6 +21,7 @@ using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
+using System.Numerics;
namespace Novacoin
{
@@ -58,9 +59,26 @@ namespace Novacoin
}
///
+ /// Add serialized number to instructions list.
+ ///
+ /// Number to add.
+ public void AddNumber(int n)
+ {
+ if (n == -1 || (n >= 1 && n <= 16))
+ {
+ codeBytes.Add((byte)ScriptCode.EncodeOP_N(n, true));
+ }
+ else
+ {
+ BigInteger bn = n;
+ PushData(bn.ToByteArray());
+ }
+ }
+
+ ///
/// Adds specified operation to instruction list
///
- ///
+ /// Instruction to add.
public void AddInstruction(instruction opcode)
{
Contract.Requires(opcode >= instruction.OP_0 && opcode <= instruction.OP_INVALIDOPCODE, "Invalid instruction.");
@@ -73,7 +91,7 @@ namespace Novacoin
/// New items are added in this format:
/// hash_length_byte hash_bytes
///
- /// Hash160 instance
+ /// uint160 instance
public void AddHash(uint160 hash)
{
codeBytes.Add((byte)hash.Size);
@@ -85,7 +103,7 @@ namespace Novacoin
/// New items are added in this format:
/// hash_length_byte hash_bytes
///
- /// Hash256 instance
+ /// uint256 instance
public void AddHash(uint256 hash)
{
codeBytes.Add((byte)hash.Size);
@@ -402,7 +420,7 @@ namespace Novacoin
// get the last item that the scriptSig
// pushes onto the stack:
InstructionQueue wScriptSig = scriptSig.GetInstructionQueue();
- int nScriptSigSize = scriptSig.Size;
+ uint nScriptSigSize = scriptSig.Size;
instruction opcode; // Current instruction
byte[] pushArgs = new byte[0]; // OP_PUSHDATAn argument
@@ -501,16 +519,25 @@ namespace Novacoin
}
///
+ /// Implicit cast of byte array to CScript.
+ ///
+ ///
+ public static implicit operator CScript(byte[] scriptBytes)
+ {
+ return new CScript(scriptBytes);
+ }
+
+ ///
/// Script size
///
- public int Size
+ public uint Size
{
- get { return codeBytes.Count; }
+ get { return (uint) codeBytes.Count; }
}
public CScriptID ScriptID
{
- get { return new CScriptID(Hash160.Compute160(codeBytes.ToArray())); }
+ get { return new CScriptID(CryptoUtils.ComputeHash160(codeBytes.ToArray())); }
}
///