예제 #1
0
        public static void EVAL_SCRIPT(ref ExecutionStack stack)
        {
            Script lockScript   = new Script(stack.Pop());
            Script unlockScript = new Script(stack.Pop());

            unlockScript.InsertScript(lockScript);

            stack.Script.AddRange(unlockScript.Reverse().ToArray());
        }
예제 #2
0
        public static EXECUTION_RESULT?EQUALS(ref ExecutionStack stack)
        {
            if (stack.Count < 2)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }

            stack.Push(System.Linq.Enumerable.SequenceEqual(stack.Pop(), stack.Pop()));
            return(null);
        }
예제 #3
0
        public static EXECUTION_RESULT?CHECKSIG(ref ExecutionStack stack)
        {
            if (stack.Transaction == null)
            {
                return(EXECUTION_RESULT.NO_TRANSACTION_GIVEN);
            }
            if (stack.Count < 2)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }

            //Verify if signature is valid
            stack.Push(new CryptoRSA(stack.Pop()).Verify(stack.Transaction.Hash(), stack.Pop()));
            return(null);
        }
예제 #4
0
        public static EXECUTION_RESULT?DUP(ref ExecutionStack stack)
        {
            if (!stack.Any())
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }
            var item = stack.Pop();

            stack.Push(item, item);
            return(null);
        }
        protected override void Run(CancellationToken cancellationToken)
        {
            IOperation          next;
            OperationCollection coll;
            IAtomicOperation    operation;

            while (ExecutionStack.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();

                next = ExecutionStack.Pop();
                if (next is OperationCollection)
                {
                    coll = (OperationCollection)next;
                    for (int i = coll.Count - 1; i >= 0; i--)
                    {
                        if (coll[i] != null)
                        {
                            ExecutionStack.Push(coll[i]);
                        }
                    }
                }
                else if (next is IAtomicOperation)
                {
                    operation = (IAtomicOperation)next;
                    try {
                        next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
                    }
                    catch (Exception ex) {
                        ExecutionStack.Push(operation);
                        if (ex is OperationCanceledException)
                        {
                            throw ex;
                        }
                        else
                        {
                            throw new OperatorExecutionException(operation.Operator, ex);
                        }
                    }
                    if (next != null)
                    {
                        ExecutionStack.Push(next);
                    }

                    if (operation.Operator.Breakpoint)
                    {
                        Log.LogMessage(string.Format("Breakpoint: {0}", operation.Operator.Name != string.Empty ? operation.Operator.Name : operation.Operator.ItemName));
                        Pause();
                    }
                }
            }
        }
 public void OneStep(ProgramState ps, ExecutionStack es, bool eachExecution)
 {
     try
     {
         IStatement statement = es.Pop();
         statement.Execute(ps);
         if (eachExecution)
         {
             Console.WriteLine(ps.Tostring());
         }
     }
     catch (CustomException exc)
     {
         throw exc;
     }
 }
예제 #7
0
        protected override void Run(CancellationToken cancellationToken)
        {
            IOperation          next;
            OperationCollection coll;
            IAtomicOperation    operation;

            while (ExecutionStack.Count > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();

                next = ExecutionStack.Pop();
                if (next is OperationCollection)
                {
                    coll = (OperationCollection)next;
                    for (int i = coll.Count - 1; i >= 0; i--)
                    {
                        if (coll[i] != null)
                        {
                            ExecutionStack.Push(coll[i]);
                        }
                    }
                }
                else if (next is IAtomicOperation)
                {
                    operation = (IAtomicOperation)next;
                    try {
                        next = operation.Operator.Execute((IExecutionContext)operation, cancellationToken);
                    }
                    catch (Exception ex) {
                        ExecutionStack.Push(operation);
                        if (ex is OperationCanceledException)
                        {
                            throw;
                        }
                        else
                        {
                            throw new OperatorExecutionException(operation.Operator, ex);
                        }
                    }
                    if (next != null)
                    {
                        ExecutionStack.Push(next);
                    }
                }
            }
        }
예제 #8
0
 private IEnumerable <string> CommandProcessor(XmlNode root)
 {
     if (root.HasChildNodes)
     {
         foreach (XmlNode topLevelCommand in root.ChildNodes)
         {
             if (topLevelCommand.LocalName.Equals("Run", StringComparison.InvariantCultureIgnoreCase))
             {
                 string name = "Unnamed Run";
                 SetupRun(topLevelCommand, ref name);
                 yield return(name);
             }
             else
             {
                 if (topLevelCommand.NodeType != XmlNodeType.Comment)
                 {
                     var commandName = topLevelCommand.LocalName;
                     if (!BatchCommands.TryGetValue(commandName.ToLowerInvariant(), out Action <XmlNode> command))
                     {
                         throw new XTMFRuntimeException(this, "We are unable to find a command named '" + commandName
                                                        + "' for batch processing.  Please check your batch file!\r\n" + topLevelCommand.OuterXml);
                     }
                     var initialCount = ExecutionStack.Count;
                     command.Invoke(topLevelCommand);
                     if (initialCount < ExecutionStack.Count)
                     {
                         var current = ExecutionStack.Pop();
                         foreach (var run in CommandProcessor(current))
                         {
                             yield return(run);
                         }
                     }
                 }
             }
         }
     }
 }
예제 #9
0
 public static EXECUTION_RESULT?HASH_160(ref ExecutionStack stack)
 {
     stack.Push(Hash.HASH160(stack.Pop()));
     return(null);
 }
예제 #10
0
 public static EXECUTION_RESULT?RIPEMD_160(ref ExecutionStack stack)
 {
     stack.Push(Hash.RIPEMD160(stack.Pop()));
     return(null);
 }
예제 #11
0
 public static EXECUTION_RESULT?SHA_256(ref ExecutionStack stack)
 {
     stack.Push(Hash.SHA256(stack.Pop()));
     return(null);
 }