Esempio n. 1
0
        ///--------------------------------------------------------------------------------------------------------
        ///
        public bool SetPassword(string pwd)
        {
            string hdmasterkeyid = QtumHandler.GetHDMasterKeyId();

            if (string.IsNullOrEmpty(hdmasterkeyid))
            {
                Logger.Log("퀀텀 지갑의 구동 상태를 확인 해 주세요.");
                return(false);
            }

            try
            {
                byte[] pwdBytes = Encoding.UTF8.GetBytes(Encrypt(pwd, Encrypt(hdmasterkeyid, Config.RPCPassword)));

                using (FileStream fs = File.Open(passwordFile, FileMode.Create))
                {
                    using (GZipOutputStream gzs = new GZipOutputStream(fs))
                    {
                        using (MemoryStream c = new MemoryStream())
                        {
                            gzs.Write(pwdBytes, 0, pwdBytes.Length);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
                return(false);
            }

            return(true);
        }
        public string GetString()
        {
            DateTime txTime = QtumHandler.BlockTimeToUtcTime(time);
            string   str    = string.Format("time : {0:yyyy/MM/dd HH:mm:ss}", DateTimeHandler.ToLocalTime(txTime));

            str += string.Format("\n tx id : {0}", Command.ICommand.GetTxLink(txId));
            str += string.Format("\n address : {0}", Command.ICommand.GetAddressLink(address));
            //notifyStr += string.Format("\n category : {0}", txInfo.category);
            str += string.Format("\n amount : {0}", amount);
            str += string.Format("\n fee : {0}", fee);
            str += string.Format("\n label : {0}", label);
            str += string.Format("\n comment : {0}", comment);
            str += string.Format("\n");

            return(str);
        }
Esempio n. 3
0
        ///--------------------------------------------------------------------------------------------------------
        ///
        public string GetPassword()
        {
            string pwd = null;

            string hdmasterkeyid = QtumHandler.GetHDMasterKeyId();

            if (string.IsNullOrEmpty(hdmasterkeyid))
            {
                Logger.Log("퀀텀 지갑의 구동 상태를 확인 해 주세요.");
                return(pwd);
            }

            try
            {
                if (File.Exists(passwordFile) == false)
                {
                    Logger.Log("파일 없음 : {0}", passwordFile);
                    return(pwd);
                }

                using (FileStream fs = File.Open(passwordFile, FileMode.Open))
                {
                    using (GZipInputStream gzs = new GZipInputStream(fs))
                    {
                        const int count  = 1024 * 1024;
                        byte[]    dest   = new byte[count];
                        int       length = gzs.Read(dest, 0, count);

                        pwd = Decrypt(Encoding.UTF8.GetString(dest, 0, length), Encrypt(hdmasterkeyid, Config.RPCPassword));
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
                return(null);
            }

            return(pwd);
        }
        static public async void RefreshTransactionInfo()
        {
            if (lastTxTime == DateTime.MaxValue)
            {
                return;
            }

            if ((DateTime.Now - lastRefreshTine).Ticks / TimeSpan.TicksPerSecond < 10)
            {
                return;
            }

            lastRefreshTine = DateTime.Now;

            List <QtumTxInfo> list = QtumHandler.GetTransactions(1);

            if (list != null && list.Count > 0)
            {
                QtumTxInfo lastInfo = list[list.Count - 1];

                DateTime newLastTime = QtumHandler.BlockTimeToUtcTime(lastInfo.time);

                if (newLastTime > lastTxTime)
                {
                    list = QtumHandler.GetTransactions(100);

                    DateTime notiyStartTime = lastTxTime;

                    lastTxTime = DateTime.MaxValue;

                    await BroadcastTxNotify(notiyStartTime, SummarizeTxList(list));

                    lastTxTime = newLastTime;

                    SaveLastTime();
                }
            }
        }
        private static async Task BroadcastTxNotify(DateTime startTime, List <QtumTxInfo> txList)
        {
            if (txList == null)
            {
                return;
            }

            if (startTime == DateTime.MinValue)
            {
                return;
            }

            await UserList.ForeachSendMsg("---------------------------------");

            await UserList.ForeachSendMsg("A new transaction has occurred!\n");

            for (int i = txList.Count - 1; i >= 0; --i)
            {
                QtumTxInfo txInfo = txList[i];
                DateTime   txTime = QtumHandler.BlockTimeToUtcTime(txInfo.time);

                if (txTime < startTime)
                {
                    break;
                }

                string notifyStr = txInfo.GetString();

                Logger.Log(notifyStr);
                Logger.Log("");

                await UserList.ForeachSendMsg(notifyStr);
            }

            await UserList.ForeachSendMsg("---------------------------------");
        }
Esempio n. 6
0
        static public void Update()
        {
            if (((DateTime.Now - lastUpdateTime).Ticks / TimeSpan.TicksPerSecond) < 30)
            {
                return;
            }

            lastUpdateTime = DateTime.Now;

            try
            {
                List <QtumPeerInfo> peerList = QtumHandler.GetPeerList();

                for (int i = 0; i < peerList.Count; ++i)
                {
                    QtumPeerInfo info = peerList[i];

                    bool isBad = false;

                    if (info.pingTime >= Config.MiniumPing)
                    {
                        isBad = true;
                    }
                    else if (string.IsNullOrEmpty(info.subVersion) == false)
                    {
                        string subVersion = info.subVersion.Replace("/Satoshi:", "").Replace("/", "");

                        string[] subVersionStrList = subVersion.Split('.');

                        if (subVersionStrList.Length < 3)
                        {
                            isBad = true;
                        }
                        else
                        {
                            for (int n = 0; n < subVersionStrList.Length; ++n)
                            {
                                if (n >= 3)
                                {
                                    break;
                                }

                                int verNum = 0;
                                int.TryParse(subVersionStrList[n], out verNum);

                                if (Config.MiniumVersion[n] > verNum)
                                {
                                    isBad = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (isBad)
                    {
                        QtumHandler.BanPeer(info);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
            }
        }