示例#1
0
        private bool ChainGetTx()
        {
            if (stack.Count < 1)
            {
                return(false);
            }
            StackItem x = stack.Pop();

            Transaction[] r = x.GetArray <UInt256>().Select(p => Blockchain.Default?.GetTransaction(p)).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#2
0
        private bool BlockGetTx()
        {
            if (stack.Count < 1 || altStack.Count < 1)
            {
                return(false);
            }
            StackItem block_item = altStack.Peek();

            Block[] blocks = block_item.GetArray <Block>();
            if (blocks.Any(p => p == null || p.IsHeader))
            {
                return(false);
            }
            StackItem index_item = stack.Pop();

            BigInteger[] indexes = index_item.GetIntArray();
            if (block_item.IsArray && index_item.IsArray && blocks.Length != indexes.Length)
            {
                return(false);
            }
            if (blocks.Length == 1)
            {
                blocks = Enumerable.Repeat(blocks[0], indexes.Length).ToArray();
            }
            else if (indexes.Length == 1)
            {
                indexes = Enumerable.Repeat(indexes[0], blocks.Length).ToArray();
            }
            Transaction[] tx = blocks.Zip(indexes, (b, i) => i >= b.Transactions.Length ? null : b.Transactions[(int)i]).ToArray();
            if (block_item.IsArray || index_item.IsArray)
            {
                stack.Push(new StackItem(tx));
            }
            else
            {
                stack.Push(new StackItem(tx[0]));
            }
            return(true);
        }
示例#3
0
        private bool BlockTxCount()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            Block[] blocks = x.GetArray <Block>();
            if (blocks.Any(p => p == null || p.IsHeader))
            {
                return(false);
            }
            int[] r = blocks.Select(p => p.Transactions.Length).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#4
0
        private bool HeaderNextMiner(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            BlockBase[] headers = x.GetArray <BlockBase>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            UInt160[] r = headers.Select(p => p.NextMiner).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(new StackItem(r));
            }
            else
            {
                engine.Stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#5
0
        private bool TxOutValue()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            TransactionOutput[] outputs = x.GetArray <TransactionOutput>();
            if (outputs.Any(p => p == null))
            {
                return(false);
            }
            long[] r = outputs.Select(p => p.Value.GetData()).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#6
0
        private bool TxInHash()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            TransactionInput[] inputs = x.GetArray <TransactionInput>();
            if (inputs.Any(p => p == null))
            {
                return(false);
            }
            UInt256[] r = inputs.Select(p => p.PrevHash).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#7
0
        private bool EnrollPubkey()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            EnrollmentTransaction[] tx = x.GetArray <EnrollmentTransaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            ECPoint[] r = tx.Select(p => p.PublicKey).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#8
0
        private bool AssetAmount()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            RegisterTransaction[] tx = x.GetArray <RegisterTransaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            long[] r = tx.Select(p => p.Amount.GetData()).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#9
0
        private bool AssetIssuer(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            RegisterTransaction[] tx = x.GetArray <RegisterTransaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            ECPoint[] r = tx.Select(p => p.Issuer).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(new StackItem(r));
            }
            else
            {
                engine.Stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#10
0
        private bool TxType(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            Transaction[] tx = x.GetArray <Transaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            byte[][] r = tx.Select(p => new[] { (byte)p.Type }).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(r);
            }
            else
            {
                engine.Stack.Push(r[0]);
            }
            return(true);
        }
示例#11
0
        private bool BlockTxCount(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            Block[] blocks = x.GetArray <Block>();
            if (blocks.Any(p => p == null))
            {
                return(false);
            }
            int[] r = blocks.Select(p => p.Transactions.Length).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(r);
            }
            else
            {
                engine.Stack.Push(r[0]);
            }
            return(true);
        }
示例#12
0
        private bool HeaderTimestamp(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            Block[] headers = x.GetArray <Block>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            uint[] r = headers.Select(p => p.Timestamp).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(r);
            }
            else
            {
                engine.Stack.Push(r[0]);
            }
            return(true);
        }
示例#13
0
        private bool HeaderMerkleRoot(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            Block[] headers = x.GetArray <Block>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            UInt256[] r = headers.Select(p => p.MerkleRoot).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(new StackItem(r));
            }
            else
            {
                engine.Stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#14
0
        private bool HeaderVersion()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            Block[] headers = x.GetArray <Block>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            uint[] r = headers.Select(p => Block.Version).ToArray(); //header.Version
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#15
0
        private bool TxHash()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            Transaction[] tx = x.GetArray <Transaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            UInt256[] r = tx.Select(p => p.Hash).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#16
0
        private bool AssetType()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            RegisterTransaction[] tx = x.GetArray <RegisterTransaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            byte[][] r = tx.Select(p => new[] { (byte)p.AssetType }).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#17
0
        private bool AttrUsage(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            TransactionAttribute[] attr = x.GetArray <TransactionAttribute>();
            if (attr.Any(p => p == null))
            {
                return(false);
            }
            byte[][] r = attr.Select(p => new[] { (byte)p.Usage }).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(r);
            }
            else
            {
                engine.Stack.Push(r[0]);
            }
            return(true);
        }
示例#18
0
        private bool AssetAdmin()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            RegisterTransaction[] tx = x.GetArray <RegisterTransaction>();
            if (tx.Any(p => p == null))
            {
                return(false);
            }
            UInt160[] r = tx.Select(p => p.Admin).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#19
0
        private bool TxOutAsset(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            TransactionOutput[] outputs = x.GetArray <TransactionOutput>();
            if (outputs.Any(p => p == null))
            {
                return(false);
            }
            UInt256[] r = outputs.Select(p => p.AssetId).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(new StackItem(r));
            }
            else
            {
                engine.Stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#20
0
        private bool AttrData()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            TransactionAttribute[] attr = x.GetArray <TransactionAttribute>();
            if (attr.Any(p => p == null))
            {
                return(false);
            }
            byte[][] r = attr.Select(p => p.Data).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#21
0
        private bool HeaderNonce()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            Block[] headers = x.GetArray <Block>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            ulong[] r = headers.Select(p => p.Nonce).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#22
0
        private bool TxInIndex()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            TransactionInput[] inputs = x.GetArray <TransactionInput>();
            if (inputs.Any(p => p == null))
            {
                return(false);
            }
            uint[] r = inputs.Select(p => (uint)p.PrevIndex).ToArray();
            if (x.IsArray)
            {
                stack.Push(r);
            }
            else
            {
                stack.Push(r[0]);
            }
            return(true);
        }
示例#23
0
        private bool HeaderNextMiner()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            Block[] headers = x.GetArray <Block>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            UInt160[] r = headers.Select(p => p.NextMiner).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#24
0
        private bool TxOutScriptHash()
        {
            if (altStack.Count < 1)
            {
                return(false);
            }
            StackItem x = altStack.Peek();

            TransactionOutput[] outputs = x.GetArray <TransactionOutput>();
            if (outputs.Any(p => p == null))
            {
                return(false);
            }
            UInt160[] r = outputs.Select(p => p.ScriptHash).ToArray();
            if (x.IsArray)
            {
                stack.Push(new StackItem(r));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }
示例#25
0
        private bool HeaderNonce(ScriptEngine engine)
        {
            if (engine.AltStack.Count < 1)
            {
                return(false);
            }
            StackItem x = engine.AltStack.Peek();

            BlockBase[] headers = x.GetArray <BlockBase>();
            if (headers.Any(p => p == null))
            {
                return(false);
            }
            ulong[] r = headers.Select(p => p.Nonce).ToArray();
            if (x.IsArray)
            {
                engine.Stack.Push(r);
            }
            else
            {
                engine.Stack.Push(r[0]);
            }
            return(true);
        }