Ejemplo n.º 1
0
        public ActionResult Block(int id = 0)
        {
            DataChainStats stats = null;
            Client         client;

            try
            {
                client = new Client(blockchain.Epicoin.host, blockchain.Epicoin.port);
                stats  = client.GetChainStats();
                if (stats == null)
                {
                    return(View("~/Views/BlockChain/BlockNotFound.cshtml"));
                }

                if (id >= stats.Lenght)
                {
                    return(View("~/Views/BlockChain/BlockNotFound.cshtml"));
                }
            }
            catch (Exception)
            {
                return(View("~/Views/BlockChain/BlockNotFound.cshtml"));
            }

            try
            {
                blockchain.blockchain.Block block = client.GetBlockNumber(id);
                ViewData["Index"]        = block.Index.ToString();
                ViewData["HashBlock"]    = block.Hashblock;
                ViewData["Date"]         = DateTime.FromBinary(block.Timestamp);
                ViewData["PreviousHash"] = block.PreviousHash;
                ViewData["Nonce"]        = block.nonce.ToString();
                ViewData["Trans1"]       = "";
                ViewData["Trans2"]       = "";
                ViewData["Trans3"]       = "";

                List <blockchain.blockchain.Transaction> trans = block.Data;
                for (int i = 0; i < trans.Count; i++)
                {
                    ViewData["Trans" + (i + 1).ToString()] = trans[i].ToString();
                }


                return(View());
            }
            catch (Exception)
            {
                return(View("~/Views/BlockChain/BlockNotFound.cshtml"));
            }
        }
Ejemplo n.º 2
0
        public static Protocol AskChainStats(Protocol prot)
        {
            DataChainStats stats = new DataChainStats();

            stats.Valid         = DataServer.Chain.IsvalidChain();
            stats.LastBlockHash = DataServer.Chain.GetLatestBlock().Hashblock;
            stats.LastIndex     = DataServer.Chain.GetLatestIndex();
            stats.Lenght        = DataServer.Chain.Chainlist.Count;
            stats.Pending       = DataServer.Chain.Pending.Count + (DataServer.Chain.BlockToMines.Count * Block.nb_trans);
            stats.Difficulty    = DataServer.Chain.Difficulty;
            stats.Name          = Blockchain.Blockchain.Name;
            return(new Protocol(MessageType.Response)
            {
                Stats = stats
            });
        }
Ejemplo n.º 3
0
        // GET: Blockchain
        public ActionResult Index()
        {
            DataChainStats stats = null;

            try
            {
                Client c = new Client(blockchain.Epicoin.host, blockchain.Epicoin.port);
                stats = c.GetChainStats();
            }
            catch (Exception)
            {
                stats = null;
            }

            if (stats != null)
            {
                ViewData["Difficulty"]    = stats.Difficulty.ToString();
                ViewData["valid"]         = stats.Valid.ToString();
                ViewData["Name"]          = stats.Name;
                ViewData["Lenght"]        = stats.Lenght.ToString() + " Blocks";
                ViewData["LastIndex"]     = stats.LastIndex.ToString();
                ViewData["LastBlockHash"] = stats.LastBlockHash;
                ViewData["TotalEpicoin"]  = (((stats.Lenght - 1) * 10) + 542).ToString();
                ViewData["Pending"]       = stats.Pending;
            }
            else
            {
                ViewData["Difficulty"]    = "Offline";
                ViewData["valid"]         = "Offline";
                ViewData["Name"]          = "Offline";
                ViewData["Lenght"]        = "Offline";
                ViewData["LastIndex"]     = "Offline";
                ViewData["LastBlockHash"] = "Offline";
                ViewData["TotalEpicoin"]  = "Offline";
                ViewData["Pending"]       = "Pending";
            }

            return(View());
        }
Ejemplo n.º 4
0
        protected void RefreshChain()
        {
            DataChainStats stats = Epicoin.Library.Epicoin.Client.GetChainStats();

            if (stats != null)
            {
                this.ChainLenght.Text = stats.Lenght.ToString();
                this.ChainLenght.Refresh();
                this.ChainLastIndex.Text = stats.LastIndex.ToString();
                this.ChainLastIndex.Refresh();
                this.ChainLastHash.Text = stats.LastBlockHash;
                this.ChainLastHash.Refresh();
                this.ChainDifficulty.Text = stats.Difficulty.ToString();
                this.ChainDifficulty.Refresh();

                this.EpicoinAmount.Text = Epicoin.Library.Epicoin.Wallet.TotalAmount().ToString();
                this.EpicoinAmount.Refresh();
            }
            else
            {
                Console.WriteLine("Error");
            }
        }
Ejemplo n.º 5
0
        public static void User(string namearg = null)
        {
            Console.WriteLine("\n\n        Blochain Epicoin Client \n\n");

            Console.WriteLine("Host: [Default: " + host + "]\nChoice: ");
            host = ReadLine();
            Console.WriteLine("\n");

            ImportWallet();
            if (Wallet == null)
            {
                string name = "";
                if (namearg == null)
                {
                    Console.Write("Your name : ");
                    name = ReadLine();
                }
                else
                {
                    name = namearg;
                }

                CreateWallet(name);
                ExportWallet();
            }

            client = new Client(host, port);

            Console.WriteLine("\nYour epicoin address : " + Wallet.Address[0] + "\n\n");

            while (Continue)
            {
                Console.WriteLine("\n      MENU Client");
                Console.WriteLine();
                Console.WriteLine("1 : exit");
                Console.WriteLine("2 : Export wallet");
                Console.WriteLine("3 : Get Chain Stats");
                Console.WriteLine("4 : Get Wallet Stats");
                Console.WriteLine("5 : Generate a new address");
                Console.WriteLine("6 : Create Transaction");
                Console.WriteLine();

                Console.Write("action : ");
                string action = ReadLine();

                Console.WriteLine();

                if (action == "1")
                {
                    Continue            = false;
                    DataClient.Continue = false;
                    DataServer.Continue = false;
                    ExportWallet();
                    break;
                }
                else if (action == "2")
                {
                    ExportWallet();
                    Console.WriteLine("Wallet exported in " + Epicoin.walletfile);
                }
                else if (action == "3")
                {
                    DataChainStats stats = client.GetChainStats();
                    if (stats != null)
                    {
                        Console.WriteLine("     Chain " + Blockchain.Blockchain.Name);
                        Console.WriteLine("Chain is valid : " + stats.Valid);
                        Console.WriteLine("Chain lenght : " + stats.Lenght);
                        Console.WriteLine("Chain difficulty : " + stats.Difficulty);
                        Console.WriteLine("Last Block " + stats.LastIndex + " : " + stats.LastBlockHash);
                        Console.WriteLine("pending Transaction : " + stats.Pending);
                    }
                    else
                    {
                        Console.WriteLine("Error");
                    }
                }
                else if (action == "5")
                {
                    string newaddress = Wallet.GenNewAddress();
                    ExportWallet();
                    Console.WriteLine("New Epicoin Address : " + newaddress);
                }
                else if (action == "4")
                {
                    Console.WriteLine("     Wallet : " + Wallet.Name);
                    Console.WriteLine("Your epicoin address : ");
                    foreach (var address in Wallet.Address)
                    {
                        Console.WriteLine(address);
                    }
                    Console.WriteLine("Epicoin amount : " + Wallet.TotalAmount());
                }
                else if (action == "6")
                {
                    Console.Write("ToAddress : ");
                    string ToAddress = ReadLine();
                    Console.Write("\nAmount : ");
                    string Samount = ReadLine();
                    int    amount  = 0;
                    try
                    {
                        amount = int.Parse(Samount);
                        if (amount <= 0)
                        {
                            throw new Exception();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Invalid amount");
                        continue;
                    }

                    List <DataTransaction> ltrans = Wallet.GenTransactions(amount, ToAddress);
                    string display = "";
                    foreach (var trans in ltrans)
                    {
                        display += client.SendTransaction(trans) + "\n";
                    }
                    Console.WriteLine(display);
                }
                else
                {
                    Console.WriteLine("Entrée incorrect");
                }
                action = "";
            }
            Console.WriteLine("\nbye!");
        }