-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclocalsetting.cpp
More file actions
153 lines (137 loc) · 4.84 KB
/
Copy pathclocalsetting.cpp
File metadata and controls
153 lines (137 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include "clocalsetting.h"
#include "common/cregistry.h"
#include "localrpcdialog.h"
#include "cmasternode.h"
#include "cmasternodemodel.h"
#include "common/walletrpc.h"
#include "common/processconfs.h"
#include <QMessageBox>
CLocalSetting::CLocalSetting()
{
M_STATUS["UNLOAD"] = UNLOAD;
M_STATUS["UPLOADED"] = UPLOADED;
M_STATUS["STARTING"] = STARTING;
M_STATUS["STARTED"] = STARTED;
//@todo read rpc from /safe.conf
new_safe_conf_files_path = "./safeconf/";
local_script_path = "./script/";
install_script = "auto_install_safe.py";
start_script = "masternode_start.sh";
restart_script = "masternode_restart.sh";
stop_script = "masternode_stop.sh";
reset_rpc_script = "reset_rpc.py";
if(!CRegistry::readDataDir(safe_conf_path))
{
QMessageBox::warning(NULL,QString("提示"),
QString("未能从注册表中获取钱包路径,请查看是否正确安装钱包。"));
exit(0);
}
QString localSafeConfFile = safe_conf_path + "\\safe.conf";
SafeConfEntity safeEntity;
ProcessSafeConf::read(safeEntity, localSafeConfFile);
local_rpc_user = safeEntity.qsRpcuser;
local_rpc_pwd = safeEntity.qsRpcpassword;
masternode_conf_file = safe_conf_path + "/masternode.conf";
QFile mnfile(masternode_conf_file);
if(mnfile.exists())
{
if(mnfile.open(QIODevice::ReadWrite))
{
CMasternode cmn;
while(true)
{
QByteArray mn_conf_line = mnfile.readLine();
if(mn_conf_line.size()>0)
{
if (mn_conf_line.at(0) == '#')
{
continue;
}
QList<QByteArray> qList = mn_conf_line.split(' ');
if(qList.size() > 4)
{
mn_old_info[qList[3]] = qList[4]; // 保存hash与索引
mn_alias<<qList[0]; // 保存别名
cmn.m_alias = qList[0];
QList<QByteArray> qIpAndPort = qList[1].split(':');
if (qIpAndPort.size() > 1)
{
cmn.m_ip = qIpAndPort[0];
cmn.m_port = qIpAndPort[1].toInt();
}
else
{
cmn.m_ip = "0.0.0.0";
cmn.m_port = 5555;
}
cmn.m_mn_key = qList[2];
cmn.m_mn_hash = qList[3];
cmn.m_index = qList[4].toInt();
cmn.m_config_status = 2;
pMnDb->insertMasternode(cmn);
}
}
else
{
break;
}
}
mnfile.close();
}
else
{
/*
QMessageBox::information(this,tr("提示"),
tr("打开masternode.conf配置文件失败,请检查改文件是否被占用。"));
*/
}
}
else
{
/*
QMessageBox::information(this,tr("提示"),
tr("未找到masternode.conf文件。"));
*/
}
// 获取Masternode outputs的输出
WalletRPC walletRpc("127.0.0.1", local_rpc_user, local_rpc_pwd);
QJsonObject qjsonOutput = walletRpc.masternodeOutputs();
for (QJsonObject::Iterator it = qjsonOutput.begin();
it!=qjsonOutput.end(); it++)
{
qDebug()<<"key:"<<it.key();
qDebug()<<"value:"<<it.value().toString();
if (it.value().toString()!="0"
&& it.value().toString()!="1")
{
continue;
}
if (mn_old_info.find(it.key()) == mn_old_info.end())
{
qDebug()<<"not in mn.conf"<<it.key();
if (pMnDb->selectMasternode(it.key()).m_mn_hash != "")
{
// masternode.conf没有,DB里面有,以前配置过,被用户删了
// 怎么处理?
// 1 提示用户是否恢复,如果恢复,从数据库读取数据写入masternode.conf
}
else
{
CMasternode cmn;
cmn.m_mn_hash = it.key();
cmn.m_config_status = 1;
pMnDb->insertMasternode(cmn);
}
}
}
}
CLocalSetting* CLocalSetting::initance()
{
static CLocalSetting p;
return &p;
}
CLocalSetting *local_setting;
QString g_current_ip;
QString g_current_tx_hash;
QString MNSTATUS[] = {"UNLOAD","UPLOADED","STARTING","STARTED"};
QMap<QString, E_STATUS> M_STATUS;