Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="ReturnOp"/> using the given <see cref="IScript"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        /// <param name="scr">Script to use</param>
        /// <param name="usePushOp">
        /// [Default value = true]
        /// If true, the data will be included after <see cref="OP.RETURN"/> using <see cref="PushDataOp"/> scheme.
        /// </param>
        public ReturnOp(IScript scr, bool usePushOp = true)
        {
            if (scr == null)
            {
                throw new ArgumentNullException(nameof(scr), "Script can not be null.");
            }

            byte[] temp = scr.ToByteArray();

            if (usePushOp)
            {
                StackInt size = new StackInt(temp.Length);
                Data = ByteArray.ConcatArrays(
                    new byte[1] {
                    (byte)OP.RETURN
                },
                    size.ToByteArray(),
                    temp);
            }
            else
            {
                Data    = new byte[temp.Length + 1];
                Data[0] = (byte)OP.RETURN;
                Buffer.BlockCopy(temp, 0, Data, 1, temp.Length);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of <see cref="ReturnOp"/> using the given data.
 /// </summary>
 /// <param name="ba">Data to use (can be null)</param>
 /// <param name="usePushOp">
 /// [Default value = true]
 /// If true, the data will be included after <see cref="OP.RETURN"/> using <see cref="PushDataOp"/> scheme.
 /// </param>
 public ReturnOp(byte[] ba, bool usePushOp = true)
 {
     if (ba == null || ba.Length == 0)
     {
         Data = new byte[1] {
             (byte)OP.RETURN
         };
     }
     else if (usePushOp)
     {
         StackInt size = new StackInt(ba.Length);
         Data = ByteArray.ConcatArrays(
             new byte[1] {
             (byte)OP.RETURN
         },
             size.ToByteArray(),
             ba);
     }
     else
     {
         Data    = new byte[ba.Length + 1];
         Data[0] = (byte)OP.RETURN;
         Buffer.BlockCopy(ba, 0, Data, 1, ba.Length);
     }
 }