小坚的技术博客

比特股BTS和BAR类节点搭建

本文作者:陈进坚
个人博客:https://jian1098.github.io
CSDN博客:https://blog.csdn.net/c_jian
简书:https://www.jianshu.com/u/8ba9ac5706b6
联系方式:jian1098@qq.com

简述

本文教程使用于任何比特股(bitshares)类链的搭建,例如BAR、公信宝以及其他通过比特股源码修改搭建的山寨链的搭建。本文搭建的环境为私有环境,方便测试和开发。系统最好选用Ubuntu,用CentOS可能需要安装其他依赖。

下载程序

github上下载编译好的程序,也可以自己下载源码,根据文档编译,但是需要的配置很高(8G内存)不然会编译失败,而且编译要好几个小时。

BTS:https://github.com/bitshares/bitshares-core/releases

BAR:https://github.com/bar-chain/bar-core

我这里直接下载编译好的二进制程序

1
wget https://github.com/bitshares/bitshares-core/releases/download/3.3.2/bitshares-core-3.3.2-linux-amd64-bin.tar.bz2

解压

1
tar -xjf bitshares-core-3.3.2-linux-amd64-bin.tar.bz2

得到两个应用程序文件

  • witness_node:节点程序
  • cli_wallet:钱包命令行程序

创建创世数据文件

如果是同步公链的数据,直接跳过这一步即可

1
2
3
mkdir genesis
cd genesis
vi genesis.json

将下面的配置信息复制保存

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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
{
"initial_timestamp": "2019-02-14T20:32:55",
"max_core_supply": "1000000000000000",
"initial_parameters": {
"current_fees": {
"parameters": [[
0,{
"fee": 2000000,
"price_per_kbyte": 1000000
}
],[
1,{
"fee": 500000
}
],[
2,{
"fee": 0
}
],[
3,{
"fee": 2000000
}
],[
4,{}
],[
5,{
"basic_fee": 500000,
"premium_fee": 200000000,
"price_per_kbyte": 100000
}
],[
6,{
"fee": 2000000,
"price_per_kbyte": 100000
}
],[
7,{
"fee": 300000
}
],[
8,{
"membership_annual_fee": 200000000,
"membership_lifetime_fee": 1000000000
}
],[
9,{
"fee": 50000000
}
],[
10,{
"symbol3": "50000000000",
"symbol4": "30000000000",
"long_symbol": 500000000,
"price_per_kbyte": 10
}
],[
11,{
"fee": 50000000,
"price_per_kbyte": 10
}
],[
12,{
"fee": 50000000
}
],[
13,{
"fee": 50000000
}
],[
14,{
"fee": 2000000,
"price_per_kbyte": 100000
}
],[
15,{
"fee": 2000000
}
],[
16,{
"fee": 100000
}
],[
17,{
"fee": 10000000
}
],[
18,{
"fee": 50000000
}
],[
19,{
"fee": 100000
}
],[
20,{
"fee": 500000000
}
],[
21,{
"fee": 2000000
}
],[
22,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
23,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
24,{
"fee": 100000
}
],[
25,{
"fee": 100000
}
],[
26,{
"fee": 100000
}
],[
27,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
28,{
"fee": 0
}
],[
29,{
"fee": 500000000
}
],[
30,{
"fee": 2000000
}
],[
31,{
"fee": 100000
}
],[
32,{
"fee": 100000
}
],[
33,{
"fee": 2000000
}
],[
34,{
"fee": 500000000
}
],[
35,{
"fee": 100000,
"price_per_kbyte": 10
}
],[
36,{
"fee": 100000
}
],[
37,{}
],[
38,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
39,{
"fee": 500000,
"price_per_output": 500000
}
],[
40,{
"fee": 500000,
"price_per_output": 500000
}
],[
41,{
"fee": 500000
}
],[
42,{}
],[
43,{
"fee": 2000000
}
],[
44,{}
],[
45,{
"fee": 2000000
}
],[
46,{}
],[
47,{
"fee": 2000000
}
],[
48,{
"fee": 2000000
}
]
],
"scale": 10000
},
"block_interval": 5,
"maintenance_interval": 86400,
"maintenance_skip_slots": 3,
"committee_proposal_review_period": 1209600,
"maximum_transaction_size": 2048,
"maximum_block_size": 2000000,
"maximum_time_until_expiration": 86400,
"maximum_proposal_lifetime": 2419200,
"maximum_asset_whitelist_authorities": 10,
"maximum_asset_feed_publishers": 10,
"maximum_witness_count": 1001,
"maximum_committee_count": 1001,
"maximum_authority_membership": 10,
"reserve_percent_of_fee": 2000,
"network_percent_of_fee": 2000,
"lifetime_referrer_percent_of_fee": 3000,
"cashback_vesting_period_seconds": 31536000,
"cashback_vesting_threshold": 10000000,
"count_non_member_votes": true,
"allow_non_member_whitelists": false,
"witness_pay_per_block": 1000000,
"worker_budget_per_day": "50000000000",
"max_predicate_opcode": 1,
"fee_liquidation_threshold": 10000000,
"accounts_per_fee_scale": 1000,
"account_fee_scale_bitshifts": 4,
"max_authority_depth": 2,
"extensions": []
},
"initial_accounts": [{
"name": "init0",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init1",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init2",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init3",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init4",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init5",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init6",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init7",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init8",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init9",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "init10",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": true
},{
"name": "nathan",
"owner_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"active_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"is_lifetime_member": false
}
],
"initial_assets": [],
"initial_balances": [{
"owner": "BTSFAbAx7yuxt725qSZvfwWqkdCwp9ZnUama",
"asset_symbol": "BTS",
"amount": "1000000000000000"
}
],
"initial_vesting_balances": [],
"initial_active_witnesses": 11,
"initial_witness_candidates": [{
"owner_name": "init0",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init1",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init2",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init3",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init4",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init5",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init6",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init7",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init8",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init9",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
},{
"owner_name": "init10",
"block_signing_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
}
],
"initial_committee_candidates": [{
"owner_name": "init0"
},{
"owner_name": "init1"
},{
"owner_name": "init2"
},{
"owner_name": "init3"
},{
"owner_name": "init4"
},{
"owner_name": "init5"
},{
"owner_name": "init6"
},{
"owner_name": "init7"
},{
"owner_name": "init8"
},{
"owner_name": "init9"
},{
"owner_name": "init10"
}
],
"initial_worker_candidates": [],
"immutable_parameters": {
"min_committee_member_count": 11,
"min_witness_count": 11,
"num_special_accounts": 0,
"num_special_assets": 0
}
}

初始化节点

进入程序所在目录

1
2
[root@gamesrv bts]# ls
cli_wallet genesis witness_node

执行下面的命令创建创世区块数据

1
2
3
4
5
6
7
8
9
10
11
12
./witness_node --data-dir data --genesis-json genesis/genesis.json --seed-nodes "[]"

430942ms th_a config_util.cpp:247 create_new_config_fi ] Writing new config file at /home/jian/bts/data/config.ini
430942ms th_a config_util.cpp:309 create_logging_confi ] Writing new config file at /home/jian/bts/data/logging.ini
430944ms th_a witness.cpp:121 plugin_initialize ] witness plugin: plugin_initialize() begin
430945ms th_a witness.cpp:114 add_private_key ] Public Key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
430945ms th_a witness.cpp:167 plugin_initialize ] witness plugin: plugin_initialize() end
.........
plugin_startup() end
431033ms th_a application.cpp:1179 startup_plugins ] Plugin witness started
431033ms th_a main.cpp:183 main ] Started BitShares node on a chain with 0 blocks.
431034ms th_a main.cpp:184 main ] Chain ID is ced68e68d7e41258f6a2e71643e41c690edae19dbed8c5f525a0f5c74d322fa9

看到Chain ID就可以按Ctrl+C退出了

配置文件

进行上一步操作之后会在当前目录生成data目录,在该目录下回生成区块和配置文件,我们需要修改一些配置

1
2
cd data
vi config.ini

需要修改的配置如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 找到这一个配置,将值修改为true,这个配置是开启挖矿生成区块,主链的话不需要打开
enable-stale-production = true

# 在文件最后加入下面的配置
p2p-endpoint = 0.0.0.0:11010
checkpoint = []
rpc-endpoint = 127.0.0.1:11011
witness-id = "1.6.1"
witness-id = "1.6.2"
witness-id = "1.6.3"
witness-id = "1.6.4"
witness-id = "1.6.5"
witness-id = "1.6.6"
witness-id = "1.6.7"
witness-id = "1.6.8"
witness-id = "1.6.9"
witness-id = "1.6.10"
witness-id = "1.6.11"

改完保存

启动和停止节点

启动命令有点长,为了方便启动和停止我们制作好启动和停止脚本

1
2
3
4
5
6
vi start_witness.sh

# 将下面的脚本保存

#!/bin/bash
nohup ./witness_node --data-dir data --seed-nodes "[]" >> witness.log 2>&1 &
1
2
3
4
5
6
7
8
9
10
11
vi stop_witness.sh

# 将下面的脚本保存

#!/bin/bash
PIDS=`ps -ef |grep witness_node |grep -v grep | awk '{print $2}'`
if [ "$PIDS" != "" ]; then
kill -9 $PIDS
else
echo `date +%F" "%H:%M:%S` "witness_node is NOT runing!"
fi

添加执行权限

1
chmod u+x *.sh

启动节点

1
./start_witness.sh

查看日志,可以看到已经在生成区块了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tail -f witness.log

1770002ms th_a db_maint.cpp:952 process_hf_1465 ] Processing hard fork core-1465 at block 1
1770002ms th_a db_maint.cpp:854 update_call_orders_h ] Updating all call orders for hardfork core-343 at block 1
1770002ms th_a db_maint.cpp:872 update_call_orders_h ] Done updating all call orders for hardfork core-343 at block 1
1770002ms th_a db_maint.cpp:895 match_call_orders ] Matching call orders at block 1
1770002ms th_a db_maint.cpp:905 match_call_orders ] Done matching call orders at block 1
1770002ms th_a db_maint.cpp:880 update_call_orders_h ] Updating all call orders for hardfork core-1270 at block 1
1770002ms th_a db_maint.cpp:888 update_call_orders_h ] Done updating all call orders for hardfork core-1270 at block 1
1770003ms th_a db_maint.cpp:895 match_call_orders ] Matching call orders at block 1
1770003ms th_a db_maint.cpp:905 match_call_orders ] Done matching call orders at block 1
1770003ms th_a witness.cpp:277 block_production_loo ] Generated block #1 with 0 transaction(s) and timestamp 2019-10-18T07:29:30 at time 2019-10-18T07:29:30
1790000ms th_a witness.cpp:277 block_production_loo ] Generated block #2 with 0 transaction(s) and timestamp 2019-10-18T07:29:50 at time 2019-10-18T07:29:50
1795000ms th_a witness.cpp:277 block_production_loo ] Generated block #3 with 0 transaction(s) and timestamp 2019-10-18T07:29:55 at time 2019-10-18T07:29:55
1800001ms th_a witness.cpp:277 block_production_loo ] Generated block #4 with 0 transaction(s) and timestamp 2019-10-18T07:30:00 at time 2019-10-18T07:30:00

执行停止脚本即可停止节点

1
./stop_witness.sh

停止和启动钱包

启动钱包,需要指定RPChttp端口和websocket端口、链ID、钱包文件,需要注意的是必须先启动节点才能启动,不然会报错

1
./cli_wallet --wallet-file my-wallet.json --chain-id ced68e68d7e41258f6a2e71643e41c690edae19dbed8c5f525a0f5c74d322fa9 --server-rpc-endpoint ws://127.0.0.1:11011 -H 127.0.0.1:11012

执行结果

1
2
3
4
5
6
7
8
9
2094762ms th_a       main.cpp:229                  main                 ] wdata.ws_server: ws://127.0.0.1:11011 
2094819ms th_a main.cpp:234 main ] wdata.ws_user: wdata.ws_password:
2094867ms th_a main.cpp:281 main ] Listening for incoming HTTP and WS RPC requests on 127.0.0.1:11012

Type "help" for a list of available commands.
Type "gethelp <command>" for info about individual commands.

Please use the "set_password" method to initialize a new wallet before continuing
new >>>

可以看到会进入钱包的命令行,这命令行可以进行创建钱包、转账等操作,按Ctrl+C可以退出

为了方便启动和停止,我们也可以制作启动和停止钱包的脚本

1
2
3
4
5
6
7
vi start_wallet.sh

# 将下面的脚本保存

#!/bin/bash

nohup ./cli_wallet --wallet-file my-wallet.json --chain-id ced68e68d7e41258f6a2e71643e41c690edae19dbed8c5f525a0f5c74d322fa9 --server-rpc-endpoint ws://127.0.0.1:11011 -H 127.0.0.1:11012 -d >> wallet.log 2>&1 &
1
2
3
4
5
6
7
8
9
10
11
vi stop_wallet.sh

# 将下面的脚本保存

#!/bin/bash
PIDS=`ps -ef |grep cli_wallet |grep -v grep | awk '{print $2}'`
if [ "$PIDS" != "" ]; then
kill -9 $PIDS
else
echo `date +%F" "%H:%M:%S` "cli_wallet is NOT runing!"
fi

添加执行权限

1
chmod u+x *.sh

启动钱包

1
./start_wallet.sh

查看日志

1
tail -f wallet.log

停止钱包

1
./stop_wallet.sh

钱包相关命令

创建钱包

第一次使用钱包会让你设置默认钱包的密码,这里设置为123456

1
2
3
please use the set_password method to initialize a new wallet before continuing
new >>> set_password 123456
null

解锁钱包

下面很多命令都需要先解锁钱包,解锁命令如下

1
2
locked >>> unlock 123456
null

导入nathan账号

1
2
3
4
5
6
7
8
9
10
unlocked >>> import_key nathan "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"

2768812ms th_a wallet.cpp:565 copy_wallet_file ] backing up wallet my-wallet.json to before-import-key-9407629b.wallet
2768826ms th_a wallet.cpp:983 save_wallet_file ] saving wallet to file my-wallet.json
2768828ms th_a wallet.cpp:1002 save_wallet_file ] saved successfully wallet to tmp file my-wallet.json.tmp
2768828ms th_a wallet.cpp:1008 save_wallet_file ] validated successfully tmp wallet file my-wallet.json.tmp
2768829ms th_a wallet.cpp:1012 save_wallet_file ] renamed successfully tmp wallet file my-wallet.json.tmp
2768829ms th_a wallet.cpp:1019 save_wallet_file ] successfully saved wallet to file my-wallet.json
2768829ms th_a wallet.cpp:565 copy_wallet_file ] backing up wallet my-wallet.json to after-import-key-9407629b.wallet
true

导入初始余额给这个帐号

1
2
unlocked >>> import_balance nathan ["5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"] true
null

余额查询

1
2
unlocked >>> list_account_balances nathan
10000000000 BTS

创建账号

首先升级账号,要不然没有权限

1
unlocked >>> upgrade_account nathan true

获取助记词

1
2
3
4
5
6
unlocked >>> suggest_brain_key
{
"brain_priv_key": "CHOW CAWQUAW SADE JILT VELUM WAYLAY SMITE FARAD CHASE YAWN BALL DECODE PHORIA PIKI JUNGLY MINGLER",
"wif_priv_key": "5J61N7xP7Y7zYgk1msafaYsRW1gAZ77SZdN3oxEX1Dxja4ZGFej",
"pub_key": "BTS6pbt37VPfBZcYtXpNk8iTwgDZhuw9ikteBudiX5BWXbGdxJcNf"
}

用助记词创建账号account1

1
unlocked >>> create_account_with_brain_key "ETCH ZAYAT LARKY TRANSOM EOSIN ETHANE BRAVE RELATED COPIST SHRIVEN LIMPKIN STARE FOHAT SUCCENT MOUSY REEVE" account1 nathan nathan true

转账

1
unlocked >>> transfer nathan account1 1000 BTS "first transfer" true

再查看余额

1
2
unlocked >>> list_account_balances account1
1000 BTS

更多的RPC命令会在下一篇文章中详细列举。

参考文章

https://bitsharescn.github.io/bts-cn-docs/bts-exchange-single/

-------------本文结束感谢您的阅读-------------
🐶 您的支持将鼓励我继续创作 🐶