Пример #1
0
        public static double getBalance(string pubkey)
        {
            double balance = 0.0;

            string[] files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + "\\Chain\\");
            int      count = 0;

            foreach (string file in files)
            {
                string index = count.ToString("0000000000");
                Block  b     = Serialize.ReadBlock(index);
                Ledger l     = b.GetData();
                balance += l.getBalance(pubkey);
                count++;
            }

            return(balance);
        }
Пример #2
0
        public async Task <bool> LoadBlockchain()
        {
            // TODO: When loading chain confirm integrity against peers

            string[] files = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory() + "\\Chain\\");

            await Task.Run(() =>
            {
                foreach (string file in files)
                {
                    string index = ConvertToChainString(blockHeight);
                    Block b      = Serialize.ReadBlock(index);
                    if (blockHeight > 0)
                    {
                        // Testing: Compare hashes
                        // MessageBox.Show(chain.ElementAt(blockHeight - 1).HashBlock() + "\n\n" + b.previousHash);

                        // Check to see if blockchain was tampered with
                        if (b.previousHash != chain.ElementAt(blockHeight - 1).HashBlock())
                        {
                            //MessageBox.Show("Chain has been modified. Exiting...");
                            //break;
                        }
                    }

                    chain.Add(b);
                    blockHeight++;
                    network.blockheight = blockHeight;
                }

                // Start timer to keep chain in sync
                timer.Enabled = true;

                previousBlock = chain.ElementAt(blockHeight - 1);
                currentBlock  = new Block();
                currentBlock.NewBlock(blockHeight, previousBlock.HashBlock());
            });

            return(true);
        }
Пример #3
0
 private Block LoadGenesisBlock()
 {
     return(Serialize.ReadBlock("0000000000"));
 }