static private List <QtumTxInfo> SummarizeTxList(List <QtumTxInfo> orgList)
        {
            if (orgList == null)
            {
                return(null);
            }

            if (orgList.Count == 0)
            {
                return(orgList);
            }

            List <QtumTxInfo> newList = new List <QtumTxInfo>();

            Dictionary <string, QtumTxInfo> infoByTxId = new Dictionary <string, QtumTxInfo>();

            foreach (var txInfo in orgList)
            {
                QtumTxInfo beforeInfo = null;
                if (infoByTxId.TryGetValue(txInfo.txId, out beforeInfo) == false)
                {
                    beforeInfo = txInfo;
                    infoByTxId.Add(txInfo.txId, beforeInfo);
                    continue;
                }

                beforeInfo.amount += txInfo.amount;
                beforeInfo.fee    += txInfo.fee;
                beforeInfo.comment = txInfo.comment;
                beforeInfo.label   = txInfo.label;
            }

            foreach (var txInfo in infoByTxId.Values)
            {
                newList.Add(txInfo);
            }

            newList.Sort((left, right) =>
            {
                int cmp = left.time.CompareTo(right.time);
                if (cmp == 0)
                {
                    cmp = left.txId.CompareTo(right.txId);
                    if (cmp == 0)
                    {
                        cmp = left.address.CompareTo(right.address);
                    }
                }

                return(cmp);
            }
                         );

            return(newList);
        }
        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("---------------------------------");
        }
        ///--------------------------------------------------------------------------------------------------------
        ///
        static public List <QtumTxInfo> GetTransactions(uint count = 1)
        {
            JObject json   = null;
            JToken  txJson = null;
            int     i      = 0;

            try
            {
                string resultStr = "{\n TxList : " + commandline.Process("listtransactions \"*\" " + count) + "\n}";


                if (TryParseJson(resultStr, out json))
                {
                    List <QtumTxInfo> list = new List <QtumTxInfo>();

                    JToken txListJson = json["TxList"];

                    for (i = 0; i < txListJson.Count(); ++i)
                    {
                        txJson = txListJson[i];

                        if (txJson == null)
                        {
                            continue;
                        }

                        QtumTxInfo newInfo = new QtumTxInfo();

                        if (txJson["address"] != null)
                        {
                            newInfo.address = txJson["address"].ToString();
                        }

                        newInfo.category = txJson["category"].ToString();
                        newInfo.amount   = Convert.ToDouble(txJson["amount"].ToString());

                        //if (txJson["blockhash"] == null)
                        //    continue;
                        //
                        //JObject blockInfoJson = GetBlockInfo(txJson["blockhash"].ToString());
                        //
                        //if (blockInfoJson == null || blockInfoJson["time"] == null)
                        //    continue;
                        //
                        //newInfo.time = Convert.ToInt64(blockInfoJson["time"].ToString());

                        newInfo.time = Convert.ToInt64(txJson["time"].ToString());

                        newInfo.txId = txJson["txid"].ToString();

                        if (txJson["fee"] != null)
                        {
                            newInfo.fee = Convert.ToDouble(txJson["fee"].ToString());
                        }

                        if (txJson["label"] != null)
                        {
                            newInfo.label = txJson["label"].ToString();
                        }

                        if (txJson["comment"] != null)
                        {
                            newInfo.label = txJson["comment"].ToString();
                        }

                        list.Add(newInfo);
                    }

                    return(list);
                }
            }
            catch (Exception e)
            {
                if (txJson != null)
                {
                    Logger.Log("faild parse txList {0}, {1}\n{2}", i, txJson.ToString(), e.ToString());
                }
            }

            return(null);
        }