예제 #1
0
        /// <summary>
        /// Initializes a new instance of <see cref="PushDataOp"/> using one of the number OP codes.
        /// </summary>
        /// <exception cref="ArgumentException"/>
        /// <param name="numOp">A number OP code (OP_0, OP_1, ..., OP_16, OP_Negative1</param>
        public PushDataOp(OP numOp)
        {
            if (!OpHelper.IsNumberOp(numOp))
            {
                throw new ArgumentException("OP is not a numbered one.");
            }

            data    = null;
            OpValue = numOp;
        }
예제 #2
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();
     }
 }
예제 #3
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();
        }