Esempio n. 1
0
        private bool ChainGetBlock()
        {
            if (stack.Count < 1)
            {
                return(false);
            }
            StackItem x = stack.Pop();

            byte[][]     data = x.GetBytesArray();
            List <Block> r    = new List <Block>();

            foreach (byte[] d in data)
            {
                switch (d.Length)
                {
                case sizeof(uint):
                    uint height = BitConverter.ToUInt32(d, 0);
                    if (Blockchain.Default != null)
                    {
                        r.Add(Blockchain.Default.GetBlock(height));
                    }
                    else if (height == 0)
                    {
                        r.Add(Blockchain.GenesisBlock);
                    }
                    else
                    {
                        r.Add(null);
                    }
                    break;

                case 32:
                    UInt256 hash = new UInt256(d);
                    if (Blockchain.Default != null)
                    {
                        r.Add(Blockchain.Default.GetBlock(hash));
                    }
                    else if (hash == Blockchain.GenesisBlock.Hash)
                    {
                        r.Add(Blockchain.GenesisBlock);
                    }
                    else
                    {
                        r.Add(null);
                    }
                    break;

                default:
                    return(false);
                }
            }
            if (x.IsArray)
            {
                stack.Push(new StackItem(r.ToArray()));
            }
            else
            {
                stack.Push(new StackItem(r[0]));
            }
            return(true);
        }