本文作者:陳進堅
個人博客:https://jian1098.github.io
CSDN博客:https://blog.csdn.net/c_jian
簡書:https://www.jianshu.com/u/8ba9ac5706b6
聯繫方式:[email protected]
簡述
本文教程使用於任何比特股(bitshares
)類鏈的搭建,例如BAR、公信寶以及其他通過比特股源碼修改搭建的山寨鏈的搭建。本文搭建的環境爲私有環境,方便測試和開發。系統最好選用Ubuntu
,用CentOS
可能需要安裝其他依賴。
下載程序
到github
上下載編譯好的程序,也可以自己下載源碼,根據文檔編譯,但是需要的配置很高(8G內存)不然會編譯失敗,而且編譯要好幾個小時。
BTS:https://github.com/bitshares/bitshares-core/releases
BAR:https://github.com/bar-chain/bar-core
我這裏直接下載編譯好的二進制程序
wget https://github.com/bitshares/bitshares-core/releases/download/3.3.2/bitshares-core-3.3.2-linux-amd64-bin.tar.bz2
解壓
tar -xjf bitshares-core-3.3.2-linux-amd64-bin.tar.bz2
得到兩個應用程序文件
- witness_node:節點程序
- cli_wallet:錢包命令行程序
創建創世數據文件
如果是同步公鏈的數據,直接跳過這一步即可
mkdir genesis
cd genesis
vi genesis.json
將下面的配置信息複製保存
{
"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
}
}
初始化節點
進入程序所在目錄
[root@gamesrv bts]# ls
cli_wallet genesis witness_node
執行下面的命令創建創世區塊數據
./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
目錄,在該目錄下回生成區塊和配置文件,我們需要修改一些配置
cd data
vi config.ini
需要修改的配置如下
# 找到這一個配置,將值修改爲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"
改完保存
啓動和停止節點
啓動命令有點長,爲了方便啓動和停止我們製作好啓動和停止腳本
vi start_witness.sh
# 將下面的腳本保存
#!/bin/bash
nohup ./witness_node --data-dir data --seed-nodes "[]" >> witness.log 2>&1 &
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
添加執行權限
chmod u+x *.sh
啓動節點
./start_witness.sh
查看日誌,可以看到已經在生成區塊了
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
執行停止腳本即可停止節點
./stop_witness.sh
停止和啓動錢包
啓動錢包,需要指定RPC
的http
端口和websocket
端口、鏈ID、錢包文件,需要注意的是必須先啓動節點才能啓動,不然會報錯
./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
執行結果
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
可以退出
爲了方便啓動和停止,我們也可以製作啓動和停止錢包的腳本
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 &
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
添加執行權限
chmod u+x *.sh
啓動錢包
./start_wallet.sh
查看日誌
tail -f wallet.log
停止錢包
./stop_wallet.sh
錢包相關命令
創建錢包
第一次使用錢包會讓你設置默認錢包的密碼,這裏設置爲123456
please use the set_password method to initialize a new wallet before continuing
new >>> set_password 123456
null
解鎖錢包
下面很多命令都需要先解鎖錢包,解鎖命令如下
locked >>> unlock 123456
null
導入nathan賬號
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
導入初始餘額給這個帳號
unlocked >>> import_balance nathan ["5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"] true
null
餘額查詢
unlocked >>> list_account_balances nathan
10000000000 BTS
創建賬號
首先升級賬號,要不然沒有權限
unlocked >>> upgrade_account nathan true
獲取助記詞
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
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
轉賬
unlocked >>> transfer nathan account1 1000 BTS "first transfer" true
再查看餘額
unlocked >>> list_account_balances account1
1000 BTS
更多的RPC
命令會在下一篇文章中詳細列舉。
參考文章
https://bitsharescn.github.io/bts-cn-docs/bts-exchange-single/