Exemplo n.º 1
0
        public void GetOpCodeTest(uint val, OP expected)
        {
            StackInt si     = new StackInt(val);
            OP       actual = si.GetOpCode();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of <see cref="PushDataOp"/> using the given <see cref="IScript"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <param name="script">
        /// Script to use (will be converted to byte array using the <see cref="IScript.ToByteArray"/> function)
        /// </param>
        public PushDataOp(IScript script)
        {
            if (script == null)
            {
                throw new ArgumentNullException(nameof(script), "Script can not be null.");
            }

            data = script.ToByteArray();
            StackInt size = new StackInt(data.Length);

            OpValue = size.GetOpCode();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of <see cref="PushDataOp"/> using the given integer.
 /// </summary>
 /// <param name="num">Integer value to use</param>
 public PushDataOp(long num)
 {
     if (num >= -1 && num <= 16) // We have OP for these
     {
         _    = TryConvertToOp((int)num, out _opVal);
         data = null;
     }
     else // There is no OP code, we have to use regular push
     {
         data = IntToByteArray(num);
         StackInt size = new StackInt(data.Length);
         _opVal = size.GetOpCode();
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of <see cref="PushDataOp"/> using the given integer.
 /// </summary>
 /// <param name="num">Integer value to use</param>
 public PushDataOp(int num)
 {
     if (num >= -1 && num <= 16) // We have OP for these
     {
         OpValue = OpHelper.IntToOp(num);
         data    = null;
     }
     else // There is no OP, we have to use regular push
     {
         // TODO: this is wrong!!!
         data = OpHelper.IntToByteArray(num);
         StackInt size = new StackInt(data.Length);
         OpValue = size.GetOpCode();
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of <see cref="PushDataOp"/> using the given byte array.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentException"/>
        /// <param name="ba">Byte array to use</param>
        public PushDataOp(byte[] ba)
        {
            if (ba == null)
            {
                throw new ArgumentNullException(nameof(ba), "Byte array can not be null.");
            }
            if (OpHelper.HasOpNum(ba)) // TODO: add isStrict field for this check.
            {
                throw new ArgumentException("Short form of data exists which should be used instead.");
            }

            data = ba.CloneByteArray();
            StackInt size = new StackInt(ba.Length);

            OpValue = size.GetOpCode();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of <see cref="PushDataOp"/> using the given <see cref="IScript"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <param name="script">Script to use</param>
        public PushDataOp(IScript script)
        {
            if (script == null)
            {
                throw new ArgumentNullException(nameof(script), "Script can not be null.");
            }
            if (script.Data.Length > Constants.MaxScriptItemLength)
            {
                throw new ArgumentOutOfRangeException(nameof(script),
                                                      $"Script byte size to be pushed to the stack can not be bigger than {Constants.MaxScriptItemLength} bytes.");
            }

            data = script.Data.CloneByteArray();
            StackInt size = new StackInt(data.Length);

            _opVal = size.GetOpCode();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of <see cref="PushDataOp"/> using the given byte array.
        /// Throws an <see cref="ArgumentException"/> if there is an OP_number available equal to the value of the byte array.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentException"/>
        /// <param name="ba">Byte array to use</param>
        public PushDataOp(byte[] ba)
        {
            if (ba == null)
            {
                throw new ArgumentNullException(nameof(ba), "Byte array can not be null.");
            }
            if (HasNumOp(ba))
            {
                throw new ArgumentException("Short form of data exists with OP codes which should be used instead.");
            }
            if (ba.Length > Constants.MaxScriptItemLength)
            {
                throw new ArgumentOutOfRangeException(nameof(ba),
                                                      $"Data to be pushed to the stack can not be bigger than {Constants.MaxScriptItemLength} bytes.");
            }

            data = ba.CloneByteArray();
            StackInt size = new StackInt(ba.Length);

            _opVal = size.GetOpCode();
        }