forked from bcosorg/bcos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.js
303 lines (237 loc) · 8.92 KB
/
tool.js
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
var Web3= require('web3');
var config=require('./config');
var fs=require('fs');
var BigNumber = require('bignumber.js');
var web3sync = require('./web3sync');
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider(config.HttpProvider));
}
console.log(config);
function getAbi(file){
var abi=JSON.parse(fs.readFileSync(config.Ouputpath+"./"+file+".abi",'utf-8'));
return abi;
}
function getAddress(file){
return (fs.readFileSync(config.Ouputpath+"./"+file+".address",'utf-8'));
}
var options = process.argv;
if( options.length < 3 )
{
console.log('Usage: node tool.js SystemProxy');
console.log('Usage: node tool.js AuthorityFilter ');
console.log('Usage: node tool.js NodeAction all|registerNode|cancelNode ');
console.log('Usage: node tool.js CAAction all|update|updateStatus ');
console.log('Usage: node tool.js ConfigAction get|set ');
}
var filename=options[2];
var func=options[3];
console.log('Soc File :'+options[2]);
console.log('Func :'+options[3]);
console.log("系统合约地址"+getAddress("SystemProxy"));
var initializer = {from: config.account,randomid:Math.ceil(Math.random()*100000000)};
var SystemProxy=web3.eth.contract(getAbi("SystemProxy")).at(getAddress("SystemProxy"));
function getAction(filename){
var address=SystemProxy.getRoute(filename)[0].toString();
console.log(filename+"合约地址"+address);
var contract = web3.eth.contract(getAbi(filename));
return contract.at(address);
}
switch (filename){
case "ConfigAction":
{
switch(func){
case "get":
{
if( options.length< 5 ){
console.log("请输入key");
break;
}
var key=options[4];
var instance=getAction("ConfigAction");
var value=instance.get(key, initializer);
console.log(key+"="+value[0].toString()+","+value[1].toString());
break;
}
case "set":
{
if( options.length< 6 ){
console.log("请输入key,value");
break;
}
var key=options[4];
var value=options[5];
var instance=getAction("ConfigAction");
var func = "set(string,string)";
var params = [key,value];
var receipt = web3sync.sendRawTransaction(config.account, config.privKey, instance.address, func, params);
console.log("配置项:"+key+","+value);
break;
}
default:
console.log("Mod Error");
break;
}
break;
}
case "SystemProxy":
{
console.log("-----------------系统路由表----------------------")
var routelength=SystemProxy.getRouteSize();
for( var i=0;i<routelength;i++){
var key=SystemProxy.getRouteNameByIndex(i).toString();
var route=SystemProxy.getRoute(key);
console.log(i+" )"+ key+"=>"+route[0].toString()+","+route[1].toString()+","+route[2].toString());
if( "TransactionFilterChain" == key ){
var contract = web3.eth.contract(getAbi("TransactionFilterChain"));
var instance = contract.at(route[0]);
var filterlength=instance.getFiltersLength();
for( var j=0;j<filterlength;j++){
var filter=instance.getFilter(j);
contract = web3.eth.contract(getAbi("TransactionFilterBase"));
instance = contract.at(filter);
var name= instance.name();
var version=instance.version();
console.log(" "+name+"=>"+version+","+filter);
}
}
}
break;
}
case "AuthorityFilter":
{
if( options.length< 6 ){
console.log("请输入账号、合约地址、函数名");
break;
}
console.log("origin :"+options[3]);
console.log("to :"+options[4]);
console.log("func :"+options[5]);
var AuthorityFilter=getAction("AuthorityFilter");
//process(address origin, address from, address to, string func, string input)
console.log("权限校验结果:"+AuthorityFilter.process(options[3],"",options[4],options[5],""));
break;
}
case "NodeAction":
{
switch(func){
case "all":
{
var instance=getAction("NodeAction");
var len=instance.getNodeIdsLength(initializer);
console.log("NodeIdsLength= "+len);
for( var i=0;i<len;i++){
console.log("----------node "+i+"---------");
var id=instance.getNodeId(i);
console.log("id="+id);
var node=instance.getNode(id);
console.log("ip="+node[0].toString());
console.log("port="+node[1].toString());
console.log("category="+node[2].toString());
console.log("desc="+node[3].toString());
console.log("CAhash="+node[4].toString());
console.log("agencyinfo="+node[5].toString());
console.log("blocknumber="+node[6].toString());
console.log("Idx="+instance.getNodeIdx(id));
}
break;
}
case "cancelNode":
{
if( options.length< 5 ){
console.log("请输入node.json");
break;
}
console.log("node.json="+options[4]);
var node=JSON.parse(fs.readFileSync(options[4],'utf-8'));
var instance=getAction("NodeAction");
var func = "cancelNode(string)";
var params = [node.id];
var receipt = web3sync.sendRawTransaction(config.account, config.privKey, instance.address, func, params);
break;
}
case "registerNode":
{
if( options.length< 5 ){
console.log("请输入node.json");
break;
}
console.log("node.json="+options[4]);
var node=JSON.parse(fs.readFileSync(options[4],'utf-8'));
var instance=getAction("NodeAction");
var func = "registerNode(string,string,uint256,uint8,string,string,string,uint256)";
var params = [node.id,node.ip,node.port,node.category,node.desc,node.CAhash,node.agencyinfo,node.idx];
var receipt = web3sync.sendRawTransaction(config.account, config.privKey, instance.address, func, params);
//console.log(receipt);
break;
}
default:
console.log("Func Error");
break;
}
break;
}
case "CAAction":
{
switch(func){
case "all":
{
var instance=getAction("CAAction");
var len=instance.getHashsLength(initializer);
console.log("HashsLength= "+len);
for( var i=0;i<len;i++){
console.log("----------CA "+i+"---------");
var hash=instance.getHash(i);
console.log("hash="+hash);
var ca=instance.get(hash);
console.log("pubkey="+ca[1].toString());
console.log("orgname="+ca[2].toString());
console.log("notbefore="+ca[3].toString());
console.log("notafter="+ca[4].toString());
console.log("status="+ca[5].toString());
console.log("blocknumber="+ca[6].toString());
var iplist=instance.getIp(hash);
console.log("whitelist="+iplist[0].toString());
console.log("blacklist="+iplist[1].toString());
}
break;
}
case "update":
{
if( options.length< 5 ){
console.log("ca.json");
break;
}
console.log("ca.json="+options[4]);
var ca=JSON.parse(fs.readFileSync(options[4],'utf-8'));
var instance=getAction("CAAction");
var func = "update(string,string,string,uint256,uint256,uint8,string,string)";
var params = [ca.hash,ca.pubkey,ca.orgname,ca.notbefore,ca.notafter,ca.status,ca.whitelist,ca.blacklist];
var receipt = web3sync.sendRawTransaction(config.account, config.privKey, instance.address, func, params);
break;
}
case "updateStatus":
{
if( options.length< 5 ){
console.log("清输入路径 ca.json");
break;
}
console.log("ca.json="+options[4]);
var ca=JSON.parse(fs.readFileSync(options[4],'utf-8'));
var instance=getAction("CAAction");
var func = "updateStatus(string,uint8)";
var params = [ca.hash,ca.status];
var receipt = web3sync.sendRawTransaction(config.account, config.privKey, instance.address, func, params);
break;
}
default:
console.log("Func Error");
break;
}
break;
}
default:
console.log("Mod Error");
break;
}