比特股BTS和BAR类节点搭建

本文作者:陈进坚
个人博客: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

停止和启动钱包

启动钱包,需要指定RPChttp端口和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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章