从零开始架设属于自己的去中心化交易所 比特股私链 Bitshares Private Testnet building tutorial -2019.7 NEW


参考文献 References:
https://dev.bitshares.works/en/master/development/installation/build_ubuntu.html
https://github.com/bitshares/bitshares-core/wiki/private-testnet
https://dev.bitshares.works/en/master/development/testnets/private_testnet.html

本教程采用配置:GCP VM Instance with Ubuntu 16.04.6 LTS (50G SSD, 15G RAM, 4v CPU)
需要相关知识:服务器租用与设置, 基础Linux操作, etc.

1、安装运行环境Install Dependencies

sudo apt-get update
sudo apt-get install autoconf cmake make automake libtool git libboost-all-dev libssl-dev g++ libcurl4-openssl-dev
sudo apt-get install doxygen

2、安装并编译比特股核心 Build BitShares Core:

git clone https://github.com/bitshares/bitshares-core.git
cd bitshares-core
git submodule update --init --recursive
cmake -DCMAKE_BUILD_TYPE=Release  .
make

make 操作视系统状况大致需要半小时时间

3、编写与导入 genesis 文件 Embedding genesis

  • 创建 genesis 文件夹
    make之后,bitshares-core 文件夹结构是这样的
    
    ../[bitshares-core]
    ├── CMakeCache.txt
    ├── libraries
    ├── programs
    ……

* 我们直接在 `bitshares-core` 文件夹创建子文件夹 genesis,运行

mkdir -p genesis


此时的文件夹结构是这样的:

../[bitshares-core]
├── CMakeCache.txt
├── genesis
├── libraries
├── programs
……

* 进入 genesis 文件夹

cd genesis


* 创建my-genesis.json

vim my-genesis.json


my-genesis.json 文件内容在官方github里面有
https://github.com/bitshares/bitshares-core/blob/master/libraries/egenesis/genesis-dev.json
请复制一下粘到窗口保存
复制后,
```esc```退出
```:wq```保存
* *注意*  有时会复制不全,请手动保存

* 回到/bitshares-core#文件夹:

cd ..


* cmake

cmake -DGRAPHENE_EGENESIS_JSON="$(pwd)/genesis/my-genesis.json"


4、创建数据目录Creating data directory

* 第一次运行节点:

programs/witness_node/witness_node --data-dir data/my-blockprod --genesis-json genesis/my-genesis.json --seed-nodes "[]"


处理约1秒,窗口显示大致如下的信息即正常



* 键盘Ctrl+C 停止运行节点

* 编辑 config.ini

vim data/my-blockprod/config.ini


复制如下信息,粘贴于任意一行

p2p-endpoint = 0.0.0.0:11012
rpc-endpoint = 127.0.0.1:11011

seed_node = // add a seed node of your own

This value set needs to overwrite default checkpoint.

checkpoint = []

genesis-json = genesis/my-genesis.json

private-key = ["BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

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"

按esc键,输入 ```:wq``` 以保存退出

5、运行节点

* 由于后续工作我们需要新的窗口,运行该命令打开新窗口

screen -S n

* 在新的窗口运行

programs/witness_node/witness_node --data-dir data/my-blockprod --enable-stale-production --seed-nodes "[]"


显示类似如下信息即正常,你可以观察到区块不断被产出



6、接入钱包
* 使用 Ctrl+C+A 打开新窗口
* 观察链的ID Obtaining the chain ID

curl --data '{"jsonrpc": "2.0", "method": "get_chain_properties", "params": [], "id": 1}' http://127.0.0.1:11011/rpc && echo


显示大致如下信息,请保存在某处供后续备用

{"id":1,"jsonrpc":"2.0","result":{"id":"2.11.0","chain_id":"8bf0971bdf6d484670424a954bf5678a9af9a7ba17d3a3ddf3a590f7b1b9cfc3","immutable
_parameters":{"min_committee_member_count":11,"min_witness_count":11
,"num_special_accounts":0,"num_special_assets":0}}}


* 创建钱包 Creating a wallet

请替换为你产出的chain ID

programs/cli_wallet/cli_wallet --wallet-file my-wallet.json --chain-id 8bf0971bdf6d484670424a954bf5678a9af9a7ba17d3a3ddf3a590f7b1b9cfc3 --server-rpc-endpoint ws://127.0.0.1:11011 -u '' -p ''

或有警告,无视即可

分别依次输入如下操作

set_password supersecret
unlock supersecret
import_key nathan "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
import_balance nathan ["5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"] true

现在可以查看你的账户nathan拥有的余额

get_account nathan
list_account_balances nathan


7、创建其他账户

upgrade_account nathan true
get_account nathan

创建新的key

suggest_brain_key

有如下类似key产出

{
"brain_priv_key": "MOMBLE DOWED PERMIT SOOKY BIPARTY IMMANE EVOKER
HASK TEBBET STIGME VACUITY SPROAT WINDILY ESS HEPTAL CHILDE",
"wif_priv_key": "5Hxc1aZpwW8HjaB4SsUYgEAH4xnGJkJRJYHhD7XcZPgYDsJWZT6",
"pub_key": "BTS8iZutNnWWvaqjJiPeqtsJ8GwehTNXVGUhEHLoFoszU1nACqXEM"
}

替换一下公钥后输入

register_account alpha BTS8iZutNnWWvaqjJiPeqtsJ8GwehTNXVGUhEHLoFoszU1nACqXEM BTS8iZutNnWWvaqjJiPeqtsJ8GwehTNXVGUhEHLoFoszU1nACqXEM nathan nathan 0 true


转账

transfer nathan alpha 100000 BTS "here is the cash" true
list_account_balances alpha

为alpha打开新钱包

import_key alpha 5Hxc1aZpwW8HjaB4SsUYgEAH4xnGJkJRJYHhD7XcZPgYDsJWZT6
upgrade_account alpha true
create_witness alpha "http://www.alpha" true

校验一下公钥

get_private_key BTS8iZutNnWWvaqjJiPeqtsJ8GwehTNXVGUhEHLoFoszU1nACqXEM


会显示你的私钥
```"5Hxc1aZpwW8HjaB4SsUYgEAH4xnGJkJRJYHhD7XcZPgYDsJWZT6"```

8、创建委员会用户 Create Committee Members

* 创建用户

create_account_with_brain_key com0 com0 nathan nathan true
create_account_with_brain_key com1 com1 nathan nathan true
create_account_with_brain_key com2 com2 nathan nathan true
create_account_with_brain_key com3 com3 nathan nathan true
create_account_with_brain_key com4 com4 nathan nathan true
create_account_with_brain_key com5 com5 nathan nathan true
create_account_with_brain_key com6 com6 nathan nathan true


* 升级用户

transfer nathan com0 100000 BTS "some cash" true
transfer nathan com1 100000 BTS "some cash" true
transfer nathan com2 100000 BTS "some cash" true
transfer nathan com3 100000 BTS "some cash" true
transfer nathan com4 100000 BTS "some cash" true
transfer nathan com5 100000 BTS "some cash" true
transfer nathan com6 100000 BTS "some cash" true

upgrade_account com0 true
upgrade_account com1 true
upgrade_account com2 true
upgrade_account com3 true
upgrade_account com4 true
upgrade_account com5 true
upgrade_account com6 true

* 注册为委员会成员

create_committee_member com0 "http://www.com0" true
create_committee_member com1 "http://www.com1" true
create_committee_member com2 "http://www.com2" true
create_committee_member com3 "http://www.com3" true
create_committee_member com4 "http://www.com4" true
create_committee_member com5 "http://www.com5" true
create_committee_member com6 "http://www.com6" true


* 投票

vote_for_committee_member nathan com0 true true
vote_for_committee_member nathan com1 true true
vote_for_committee_member nathan com2 true true
vote_for_committee_member nathan com3 true true
vote_for_committee_member nathan com4 true true
vote_for_committee_member nathan com5 true true
vote_for_committee_member nathan com6 true true


9、(可选optional)设置第二个节点

* 与第一个节点类似,首先安装环境,参考上述步骤1~3,在第二台服务器完成1~3步之后进入下一步。

* 创建数据目录Creating data directory

* 初始化节点

programs/witness_node/witness_node --data-dir data/my-blockprod --genesis-json genesis/my-genesis.json --seed-nodes "[]"

处理约1秒,窗口显示大致如下的信息即正常



* 键盘Ctrl+C 停止运行节点

* 编辑 config.ini

vim data/my-blockprod/config.ini

复制如下信息,粘贴于任意一行

p2p-endpoint = 0.0.0.0:11015
seed-node = you.ser.ver.ip:11012
rpc-endpoint = 127.0.0.1:11020
checkpoint = []
genesis-json = genesis/my-genesis.json
private-key = ["BTS8DcLrqhnWMz5Nagfr7rkyVwr2umDbWAXhhBWFVENUxLXe71rKu","5HrRyonxQCsK5ks4ghqLDnMA7Ez5nErRCF9fu3FFrnyfnoHZxom"]
witness-id = "1.6.7"


按esc键,输入 ```:wq``` 以保存退出

* 运行节点,在新的窗口运行

programs/witness_node/witness_node --data-dir data/my-blockprod


如观察到两个节点同步出块,则第二个节点成功设置。

10、设置可以外部访问的交易网站Bitshares-ui

https://github.com/bitshares/bitshares-ui

参考官方教程

https://github.com/bitshares/bitshares-ui/blob/develop/README_zh.md

* 注意,请在非root用户模式操作

BitShares-UI 依赖于 Node.js v9 以上版本。

在 Linux 和 macOS 上,安装 Node 最简单的方式是用 NVM。

将以下命令复制到终端中执行即可安装 NVM。

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
nvm install v10
nvm use v10


Node 安装完成后,获取项目的源代码:

git clone https://github.com/bitshares/bitshares-ui.git
cd bitshares-ui


在启动之前,需要先安装 npm 软件包:

npm install

运行开发服务器
开发服务器使用 Express 和 Webpack。

所有软件包安装好后,可以使用以下命令启动开发服务器:

npm start


编译完成后,即可通过浏览器访问 localhost:8080 或 127.0.0.1:8080 打开钱包。服务器启用了热加载功能,在编辑源文件后,浏览器中的内容会实时更新。

Comments 0