Exemplo n.º 1
0
        public string CreatUTPoolFromDB(string strDBpath)
        {
            try
            {
                string strRet = LeveldbOperator.OpenDB(strDBpath);
                if (strRet != ConstHelper.BC_OK)
                {
                    return("open db fail");
                }
                strRet = LeveldbOperator.GetfirstKey();
                if (string.IsNullOrEmpty(strRet))
                {
                    return("empty DB");
                }
                string blockValue = LeveldbOperator.GetValue(strRet);
                Block  tempBlock  = JsonHelper.Deserialize <Block>(blockValue);
                this.BlockData2UTXOPool(true, tempBlock);

                while (true)
                {
                    strRet = LeveldbOperator.GetNextKey();
                    if (string.IsNullOrEmpty(strRet))
                    {
                        break;
                    }
                    blockValue = LeveldbOperator.GetValue(strRet);
                    tempBlock  = JsonHelper.Deserialize <Block>(blockValue);
                    this.BlockData2UTXOPool(true, tempBlock);
                }

                if (this.tempUTXOList.Count != 0)
                {
                    foreach (UTXO utxo in this.tempUTXOList)
                    {
                        if (this.CommitedUtxoPool.contains(utxo))
                        {
                            this.CommitedUtxoPool.removeUTXO(utxo);
                        }
                    }
                }

                return(ConstHelper.BC_OK);
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.Message);
                return("exception");
            }
            finally
            {
                LeveldbOperator.CloseDB();
            }
        }
Exemplo n.º 2
0
        public static string PrintAlldb()
        {
            try
            {
                string strRet = LeveldbOperator.OpenDB(AppSettings.XXPDBFolder);
                if (strRet != ConstHelper.BC_OK)
                {
                    return("open db fail");
                }
                strRet = LeveldbOperator.GetfirstKey();
                if (string.IsNullOrEmpty(strRet))
                {
                    return("empty DB");
                }
                string blockValue = LeveldbOperator.GetValue(strRet);
                string lastblock  = string.Empty;
                LogHelper.WriteInfoLog(blockValue);


                while (true)
                {
                    strRet = LeveldbOperator.GetNextKey();
                    if (string.IsNullOrEmpty(strRet))
                    {
                        break;
                    }
                    else if (strRet == ConstHelper.BC_LastKey)
                    {
                        lastblock = LeveldbOperator.GetValue(strRet);
                    }
                    else
                    {
                        blockValue = LeveldbOperator.GetValue(strRet);
                        LogHelper.WriteInfoLog(blockValue);
                    }
                }
                LogHelper.WriteInfoLog("LashBlock: " + lastblock);
                return(ConstHelper.BC_OK);
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.Message);
                return("exception");
            }
            finally
            {
                LeveldbOperator.CloseDB();
            }
        }