示例#1
0
        public static void Export2CSV_Block(string[] args)
        {
            var randName = "LevelDB";

            if (args[2] != null)
            {
                randName = args[2];
            }
            var          tempPath     = System.IO.Directory.GetCurrentDirectory();
            var          DatabasePath = System.IO.Path.Combine(tempPath, randName);
            LevelDBStore dbstore      = new LevelDBStore().Init(DatabasePath);

            // file open
            string   fullPath = "C:\\blocks.csv";
            FileInfo fi       = new FileInfo(args[0]);

            if (!fi.Directory.Exists)
            {
                fi.Directory.Create();
            }
            FileStream   fs   = new FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            StreamWriter sw   = new StreamWriter(fs, System.Text.Encoding.UTF8);
            string       data = $"height;hash;diff;prehash;prehashmkl;Address;timestamp;random;sign;linksblk;linkstran";

            sw.WriteLine(data);

            long.TryParse(dbstore.Get("UndoHeight"), out long curHeight);
            for (long ii = 1; ii < curHeight + 10000; ii++)
            {
                List <string> list = dbstore.Heights.Get(ii.ToString());
                if (list != null)
                {
                    foreach (string hash in list)
                    {
                        Block blk = dbstore.Blocks.Get(hash);
                        if (blk != null)
                        {
                            string str_linksblk  = "";
                            string str_linkstran = "";

                            foreach (string value in blk.linksblk.Values)
                            {
                                str_linksblk = $"{str_linksblk}#{value}";
                            }

                            foreach (Transfer value in blk.linkstran.Values)
                            {
                                str_linkstran = $"{str_linkstran}#{value.ToString()}";
                            }

                            string temp = $"{blk.height};{blk.hash};#{blk.GetDiff()};{blk.prehash};{blk.prehashmkl};{blk.Address};{blk.timestamp};{blk.random};{blk.sign};{str_linksblk};{str_linkstran}";
                            sw.WriteLine(temp);
                        }
                    }
                }
                else
                {
                    //break;
                }
            }
            sw.Close();
            fs.Close();
            dbstore.Dispose();
        }