/// <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; }
/// <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(); } }
/// <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(); }