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