/// <summary>
        /// Removes top three stack items and converts them to <see cref="long"/>s: value, Min, Max.
        /// Pushes 1 if value was in range, otherwise 0.
        /// 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 < 3)
            {
                error = "Invalid number of elements in stack.";
                return(false);
            }

            // Stack is: x then min then max so we pop max first
            if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long max, true))
            {
                error = "Couldn't convert to number.";
                return(false);
            }
            if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long min, true))
            {
                error = "Couldn't convert to number.";
                return(false);
            }
            if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out long x, true))
            {
                error = "Couldn't convert to number.";
                return(false);
            }

            int c = (x >= min && x < max) ? 1 : 0;

            opData.Push(OpHelper.IntToByteArray(c));

            error = null;
            return(true);
        }
        protected bool TrySetLockTime(IOpData opData, out string error)
        {
            if (opData.ItemCount < 1)
            {
                error = "Not enough items left in the stack.";
                return(false);
            }

            // The two locktime OPs (CheckLocktimeVerify and CheckSequenceVerify) used to be NOPs. NOPs don't do anything.
            // For backward compatibility of the softfork, Run Peeks at the top item of the stack instead of Poping it.
            byte[] data = opData.Peek();

            // TODO: move this check to OpHelper
            // (for locktimes max length is 5 for others it is 4)
            if (data.Length > 5)
            {
                error = "Data length for locktimes can not be bigger than 5.";
                return(false);
            }

            if (!OpHelper.TryConvertByteArrayToInt(data, out lt, true))
            {
                error = "Invalid number format.";
                return(false);
            }

            if (lt < 0)
            {
                error = "Locktime can not be negative.";
                return(false);
            }

            error = null;
            return(true);
        }
예제 #3
0
 public SysController(IAppSettingService appSettingService, ISession session, OpHelper opHelper, ILogger logger)
 {
     _appSettingService = appSettingService;
     _session           = session;
     _opHelper          = opHelper;
     _logger            = logger;
 }
예제 #4
0
파일: TskController.cs 프로젝트: lpyqyc/swm
 public TskController(ISession session, TaskHelper taskHelper, OpHelper opHelper, ILogger logger)
 {
     _logger     = logger;
     _taskHelper = taskHelper;
     _opHelper   = opHelper;
     _session    = session;
 }
예제 #5
0
        /// <summary>
        /// Pushes the number of stack items onto the stack. 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)
        {
            opData.Push(OpHelper.IntToByteArray(opData.ItemCount));

            error = null;
            return(true);
        }
예제 #6
0
 /// <summary>
 /// 初始化新实例。
 /// </summary>
 /// <param name="session"></param>
 /// <param name="appSeqService"></param>
 /// <param name="opHelper"></param>
 /// <param name="simpleEventBus"></param>
 /// <param name="logger"></param>
 public InboundOrdersController(ISession session, IAppSeqService appSeqService, OpHelper opHelper, SimpleEventBus simpleEventBus, ILogger logger)
 {
     _session        = session;
     _appSeqService  = appSeqService;
     _opHelper       = opHelper;
     _simpleEventBus = simpleEventBus;
     _logger         = logger;
 }
예제 #7
0
 /// <summary>
 /// 初始化新实例。
 /// </summary>
 /// <param name="session"></param>
 /// <param name="outboundOrderAllocator">出库单库存分配程序</param>
 /// <param name="appSeqService"></param>
 /// <param name="opHelper"></param>
 /// <param name="simpleEventBus"></param>
 /// <param name="logger"></param>
 public WioController(ISession session, IOutboundOrderAllocator outboundOrderAllocator, IAppSeqService appSeqService, OpHelper opHelper, SimpleEventBus simpleEventBus, ILogger logger)
 {
     _session = session;
     _outboundOrderAllocator = outboundOrderAllocator;
     _appSeqService          = appSeqService;
     _opHelper       = opHelper;
     _simpleEventBus = simpleEventBus;
     _logger         = logger;
 }
예제 #8
0
파일: LocController.cs 프로젝트: lpyqyc/swm
 public LocController(ISession session, LocationHelper locHelper, ILocationFactory locFactory, OpHelper opHelper, SimpleEventBus eventBus, ILogger logger)
 {
     _session    = session;
     _locHelper  = locHelper;
     _locFactory = locFactory;
     _opHelper   = opHelper;
     _eventBus   = eventBus;
     _logger     = logger;
 }
예제 #9
0
 public MatlController(NHibernate.ISession session, IMaterialFactory materialFactory, FlowHelper flowHelper, PalletizationHelper palletizationHelper, OpHelper opHelper, ILogger logger)
 {
     _logger              = logger;
     _materialFactory     = materialFactory;
     _opHelper            = opHelper;
     _flowHelper          = flowHelper;
     _palletizationHelper = palletizationHelper;
     _session             = session;
 }
        /// <summary>
        /// Replaces top two stack items interpreted as <see cref="long"/>s with their subtract result. 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 (!TrySetValues(opData, out error))
            {
                return(false);
            }

            opData.Push(OpHelper.IntToByteArray(a - b));

            error = null;
            return(true);
        }
        /// <summary>
        /// Replaces top two stack items interpreted as <see cref="long"/>s with 1 if either one is not 0, otherwise with 0.
        /// 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 (!TrySetValues(opData, out error))
            {
                return(false);
            }

            int c = (a != 0 || b != 0) ? 1 : 0;

            opData.Push(OpHelper.IntToByteArray(c));

            error = null;
            return(true);
        }
예제 #12
0
        /// <summary>
        /// Pushes the size of the top stack item to the stack. 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 bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 1)
            {
                error = "There was not enough items left in the stack.";
                return(false);
            }

            byte[] temp = opData.Peek();
            opData.Push(OpHelper.IntToByteArray(temp.Length));

            error = null;
            return(true);
        }
예제 #13
0
        /// <summary>
        /// Duplicates top stack item if its value is not 0. 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 < 1)
            {
                error = "There was no item left in the stack to check and duplicate.";
                return(false);
            }

            byte[] data = opData.Peek();
            if (OpHelper.IsNotZero(data))
            {
                opData.Push(data);
            }

            error = null;
            return(true);
        }
        protected bool TrySetValue(IOpData opData, out string error)
        {
            if (opData.ItemCount < 1)
            {
                error = "Not enough items left in the stack.";
                return(false);
            }

            if (!OpHelper.TryConvertByteArrayToInt(opData.Pop(), out a, true))
            {
                error = "Invalid number format.";
                return(false);
            }

            error = null;
            return(true);
        }
예제 #15
0
        /// <summary>
        /// Removes top stack item only passes if it is true. 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 < 1)
            {
                error = "There was not enough items left in the stack.";
                return(false);
            }
            // Check the top stack value, only fail if False
            bool b = OpHelper.IsNotZero(opData.Pop());

            if (!b)
            {
                error = "Top stack item value was 'false'.";
                return(false);
            }

            error = null;
            return(true);
        }
        public override bool Run(IOpData opData, out string error)
        {
            if (opData.ItemCount < 1)
            {
                error = "Invalid number of elements in stack.";
                return(false);
            }

            // TODO: check what this part is
            // https://github.com/bitcoin/bitcoin/blob/a822a0e4f6317f98cde6f0d5abe952b4e8992ac9/src/script/interpreter.cpp#L478-L483
            // probably have to include it in whever we run these operations.

            // Remove top stack item and interpret it as bool
            // OP_IF: runs for True
            // OP_NOTIF: runs for false
            bool isRunnable = OpHelper.IsNotZero(opData.Pop()) & ShouldRunIfTopItemIs; // Note: this is a bitwise operation not logical

            if (isRunnable)
            {
                foreach (var op in mainOps)
                {
                    if (!op.Run(opData, out error))
                    {
                        return(false);
                    }
                }
            }
            else if (elseOps != null && elseOps.Length != 0)
            {
                foreach (var op in elseOps)
                {
                    if (!op.Run(opData, out error))
                    {
                        return(false);
                    }
                }
            }

            error = null;
            return(true);
        }
예제 #17
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);
        }
예제 #18
0
 /// <summary>
 /// 初始化新实例。
 /// </summary>
 /// <param name="eventBus"></param>
 /// <param name="opHelper"></param>
 /// <param name="logger"></param>
 public DebugController(SimpleEventBus eventBus, OpHelper opHelper, ILogger logger)
 {
     _opHelper = opHelper;
     _logger   = logger;
     _eventBus = eventBus;
 }