Ejemplo n.º 1
0
        //public bool InsertBasecoin(Transaction basecoinTrans)
        //{
        //    try
        //    {   // one block only has one basecoin
        //        if(!this.lstPoolTx.Contains(basecoinTrans))
        //        {
        //            this.lstPoolTx.Insert(0, basecoinTrans);
        //            return true;

        //        }
        //        else
        //        {
        //            return false;
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        LogHelper.WriteErrorLog(ex.Message);
        //        return false;
        //    }
        //}

        public string WriteLastblock(Block block)
        {
            if (block == null)
            {
                return("Invalid block");
            }
            string jsonblock = JsonHelper.Serializer <Block>(block);

            LogHelper.WriteInfoLog(jsonblock);
            string strRet = LeveldbOperator.OpenDB(AppSettings.XXPDBFolder);

            if (strRet != ConstHelper.BC_OK)
            {
                return("Open DB fail");

                LogHelper.WriteInfoLog("Open DB fail");
            }
            strRet = LeveldbOperator.PutKeyValue(block.Hash, jsonblock);
            strRet = LeveldbOperator.PutKeyValue(ConstHelper.BC_LastKey, jsonblock);
            LeveldbOperator.CloseDB();
            if (strRet != ConstHelper.BC_OK)
            {
                return("Write KeyValue fail");

                LogHelper.WriteInfoLog("Write KeyValue fail");
            }

            return(ConstHelper.BC_OK);
        }
Ejemplo n.º 2
0
        public bool CreatBaseCoin(string sBaseCoinScript)
        {
            Block block = new Block();

            // mutex todo 181215
            Transaction basecoinTrans = this.CreatCoinBaseTX(sBaseCoinScript);

            this.AddTx2hsPool(basecoinTrans);
            //this.HashsetPool2list();
            block.listTransactions = this.GetlstPoolTx();
            this.ClearTxPool();
            block.SetTransInfo();

            block.SetBlockHeader("0000000000000000000000000000000000000000000000000000000000000000", -1);

            block.SetNonce("");
            //add by fdp 190114 set hash all 0 temporary for computing block size,
            block.Hash = ConstHelper.BC_BaseCoinInputTxHash;
            string jsonBlock = JsonHelper.Serializer <Block>(block);

            block.SetBlockSize(jsonBlock.Length);

            block.SetBlockHash();

            string jsonblock = JsonHelper.Serializer <Block>(block);

            LogHelper.WriteInfoLog(jsonblock);

            string strRet = LeveldbOperator.OpenDB(AppSettings.XXPDBFolder);

            strRet = LeveldbOperator.PutKeyValue(block.Hash, jsonblock);
            strRet = LeveldbOperator.PutKeyValue(ConstHelper.BC_LastKey, jsonblock);
            bool   breadOK = false;
            string readout = LeveldbOperator.GetValue(block.Hash);

            LogHelper.WriteInfoLog(readout);
            LeveldbOperator.CloseDB();

            if (!string.IsNullOrEmpty(readout))
            {
                breadOK = true;
            }
            return(breadOK);
        }