/// <summary>
        /// Copies 2 items from stack to top of the stack like this: x1 x2 x3 x4 -> x1 x2 x3 x4 x1 x2
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 4)
            {
                error = Err.OpNotEnoughItems;
                return(false);
            }

            byte[] data1 = opData.PeekAtIndex(3);
            byte[] data2 = opData.PeekAtIndex(2);

            opData.Push(new byte[2][] { data1, data2 });
            return(CheckItemCount(opData, out error));
        }
예제 #2
0
        /// <summary>
        /// Copies 2 items from stack to top of the stack like this: x1 x2 x3 x4 -> x1 x2 x3 x4 x1 x2
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 4)
            {
                error = "There was not enough items left in the stack to copy over.";
                return(false);
            }

            byte[] data1 = opData.PeekAtIndex(3);
            byte[] data2 = opData.PeekAtIndex(2);

            opData.Push(new byte[2][] { data1, data2 });

            error = null;
            return(true);
        }
        /// <summary>
        /// Copies the second item from top of the stack to the top. Return value indicates success.
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 2)
            {
                error = Err.OpNotEnoughItems;
                return(false);
            }

            byte[] data = opData.PeekAtIndex(1);
            opData.Push(data);

            return(CheckItemCount(opData, out error));
        }
예제 #4
0
        /// <summary>
        /// Copies the second item from top of the stack to the top. Return value indicates success.
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 2)
            {
                error = "There was not enough items left in the stack to copy over.";
                return(false);
            }

            byte[] data = opData.PeekAtIndex(1);
            opData.Push(data);

            error = null;
            return(true);
        }
        /// <summary>
        /// Copies the nth item from top of the stack to the top. Return value indicates success.
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            // At least 2 items is needed. 1 telling us the index and the other is the item to copy
            if (opData.ItemCount < 2)
            {
                error = Err.OpNotEnoughItems;
                return(false);
            }

            byte[] data = opData.Pop();
            // Initial test to reject any huge numbers
            if (data.Length > 4)
            {
                error = "'n' is too big.";
                return(false);
            }

            if (!TryConvertToLong(data, out long n, true)) // TODO: set isStrict field based on BIP62
            {
                error = "Invalid number format.";
                return(false);
            }

            if (n < 0)
            {
                error = "'n' can not be negative.";
                return(false);
            }
            // 'n' is index so it can't be equal to ItemCount
            if (opData.ItemCount <= n)
            {
                error = Err.OpNotEnoughItems;
                return(false);
            }

            opData.Push(opData.PeekAtIndex((int)n));

            error = null;
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Copies the nth item from top of the stack to the top. Return value indicates success.
        /// </summary>
        /// <param name="opData">Data to use</param>
        /// <param name="error">Error message (null if sucessful, otherwise will contain information about the failure)</param>
        /// <returns>True if operation was successful, false if otherwise</returns>
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 2) // At least 2 items is needed. 1 telling us the index and the other to copy
            {
                error = "There was not enough items left in the stack to copy to top.";
                return(false);
            }

            byte[] data = opData.Pop();
            if (data.Length > 4) // Initial test to reject any huge numbers
            {
                error = "'n' is too big.";
                return(false);
            }

            if (!OpHelper.TryConvertByteArrayToInt(data, out long n, true)) // TODO: set isStrict field base don BIP62
            {
                error = "Invalid number format.";
                return(false);
            }

            if (n < 0)
            {
                error = "'n' can not be negative.";
                return(false);
            }
            if (opData.ItemCount <= n) // 'n' is index so it can't be equal to ItemCount
            {
                error = "There was not enough items left in the stack to copy to top.";
                return(false);
            }

            opData.Push(opData.PeekAtIndex((int)n));

            error = null;
            return(true);
        }