public ProgramState Execute(ProgramState ps)
        {
            ExecutionStack executionStack = ps.GetExecutionStack();

            executionStack.Push(right);
            executionStack.Push(left);
            return(ps);
        }
        public ProgramState Execute(ProgramState ps)
        {
            SymbolTable    symbolTable    = ps.GetSymbolTable();
            ExecutionStack executionStack = ps.GetExecutionStack();
            int            result         = expression.Evaluate(symbolTable);

            if (result == 0)
            {
                executionStack.Push(selse);
            }
            else
            {
                executionStack.Push(sthen);
            }
            return(ps);
        }
Esempio n. 3
0
 public static EXECUTION_RESULT?EQ_VERIFY(ref ExecutionStack stack)
 {
     if (EQUALS(ref stack) != null)
     {
         stack.Push(false);
     }
     return(Verify.VERIFY(ref stack));
 }
Esempio n. 4
0
 public static EXECUTION_RESULT?CHECKLOCKTIME_VERIFY(ref ExecutionStack stack)
 {
     if (CHECKLOCKTIME(ref stack) != null)
     {
         stack.Push(false);
     }
     return(VERIFY(ref stack));
 }
Esempio n. 5
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);
        }
Esempio n. 6
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();
                    }
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
                    }
                }
            }
        }
Esempio n. 10
0
        public static EXECUTION_RESULT?CHECKLOCKTIME(ref ExecutionStack stack)
        {
            if (stack.Transaction == null)
            {
                return(EXECUTION_RESULT.NO_TRANSACTION_GIVEN);
            }
            if (stack.Count() < 1)
            {
                return(EXECUTION_RESULT.INVALID_STACK);
            }
            if (stack.Peek().Length != 4)
            {
                return(EXECUTION_RESULT.INVALID_BYTE_SIZE);
            }

            uint size = stack.PopUInt();

            stack.Push(stack.Transaction.lockTime >= size);
            return(null);
        }
Esempio n. 11
0
 public static void MIN(ref ExecutionStack stack)
 => stack.Push(System.Math.Min(stack.PopShort(), stack.PopShort()));
Esempio n. 12
0
 public static void ABS(ref ExecutionStack stack)
 => stack.Push(System.Math.Abs(stack.PopShort()));
Esempio n. 13
0
 public static void PUBKEY_HASH(ref ExecutionStack stack)
 => stack.Push(stack.Script.DequeueRange(Script.AddressSize));
Esempio n. 14
0
 public static void SIGNATURE(ref ExecutionStack stack)
 => stack.Push(stack.Script.DequeueRange(Script.SignatureSize));
Esempio n. 15
0
 public static void PUBKEY(ref ExecutionStack stack)
 => stack.Push(stack.Script.DequeueRange(Script.PubKeySize));
Esempio n. 16
0
 public static void PUSH_SHORT(ref ExecutionStack stack)
 => stack.Push(System.BitConverter.ToInt16(stack.Script.DequeueRange(2)));
Esempio n. 17
0
 public static void EQ_NUM(ref ExecutionStack stack)
 => stack.Push(stack.PopShort() == stack.PopShort());
Esempio n. 18
0
 public static void GREATERTHAN(ref ExecutionStack stack)
 => stack.Push(stack.PopShort() > stack.PopShort());
Esempio n. 19
0
 public static void LESSTHAN(ref ExecutionStack stack)
 => stack.Push(stack.PopShort() < stack.PopShort());
Esempio n. 20
0
 public static void ADD(ref ExecutionStack stack)
 => stack.Push((short)(stack.PopShort() + stack.PopShort()));
Esempio n. 21
0
 public static EXECUTION_RESULT?HASH_160(ref ExecutionStack stack)
 {
     stack.Push(Hash.HASH160(stack.Pop()));
     return(null);
 }
Esempio n. 22
0
 public static EXECUTION_RESULT?RIPEMD_160(ref ExecutionStack stack)
 {
     stack.Push(Hash.RIPEMD160(stack.Pop()));
     return(null);
 }
Esempio n. 23
0
 public static void SUBSTRACT(ref ExecutionStack stack)
 => stack.Push((short)(stack.PopShort() - stack.PopShort()));
Esempio n. 24
0
 public static void OP_9(ref ExecutionStack stack) => stack.Push((short)9);
Esempio n. 25
0
 public static void LESSOREQUAL(ref ExecutionStack stack)
 => stack.Push(stack.PopShort() <= stack.PopShort());
Esempio n. 26
0
 public static void OP_16(ref ExecutionStack stack) => stack.Push((short)16);
Esempio n. 27
0
 public static void GREATEROREQUAL(ref ExecutionStack stack)
 => stack.Push(stack.PopShort() >= stack.PopShort());
Esempio n. 28
0
 public static void PUSHDATA_1(ref ExecutionStack stack)
 => stack.Push(stack.Script.DequeueRange(stack.Script.Dequeue()));
Esempio n. 29
0
 public static EXECUTION_RESULT?EQ_VERIFY_NUM(ref ExecutionStack stack)
 {
     stack.Push(stack.PopShort() == stack.PopShort());
     return(Verify.VERIFY(ref stack));
 }
Esempio n. 30
0
 public static void PUSH_UINT(ref ExecutionStack stack)
 => stack.Push(System.BitConverter.ToUInt32(stack.Script.DequeueRange(4)));