Esempio n. 1
0
        public void run()
        {
            blocks.Add(Block.makeGenesis());
            //TODO CONNECT
            int      index     = 0;
            Random   r         = new Random();
            DateTime nextTime  = DateTime.Now.AddMilliseconds(r.Next() % MAX_TIME);
            bool     keepGoing = true;

            while (keepGoing)//Change to connection has next?
            {
                if (!done)
                {
                    done = readTransaction(ref blocks, ref r, ref nextTime);
                }
                if (index != inputs.Count())
                {
                    String input = inputs.ElementAt(index);//Read from scanner
                    if (input == null)
                    {
                        continue;
                    }
                    if (input.StartsWith("Transaction"))
                    {
                        verifyTransaction(ref blocks, input);
                    }
                    else if (input.StartsWith("Block"))
                    {
                        addBlock(ref blocks, Int32.Parse(input.Split(' ').Last()));
                    }
                    else if (input.StartsWith("Request Chain"))
                    {
                        PseudoNetwork.setChain(ref blocks);
                        outputs.Add("Response Chain " + number);
                    }
                    else if (requested && input.StartsWith("Response Chain"))
                    {
                        int num = Int32.Parse(input.Split(' ').Last());
                        blocks    = confirmChain(blocks, ChainStarter.members[num].getChain(), ref transactions, num);
                        requested = false;
                    }
                    else if (input.StartsWith("End"))
                    {
                        keepGoing = false;
                    }
                    index++;
                }
            }
        }
Esempio n. 2
0
        private void makeBlock(ref List <Block> blocks)
        {
            String data = "";

            for (int i = transactions.Count() - 1; i >= 0; i--)
            {
                data += transactions.ElementAt(i) + "\n";
                transactions.RemoveAt(i);
            }
            Block b     = blocks.ElementAt(blocks.Count - 1);
            Block block = b.generateNextBlock(data);

            blocks.Add(block);
            PseudoNetwork.setBlock(b);//Send block
            outputs.Add("Block " + number);
        }