依赖包:
Clang 4.0.0
CMake 3.5.1
Boost 1.64
LLVM 4.0
secp256k1-zkp (Cryptonomex branch)
简介:
Clang: Clang 是 LLVM 的一个编译器前端。
CMake: 跨平台的编译工具,可以用简单的语句来描述所有平台的安装(编译过程)。
Boost: boost是一个准标准库,相当于STL的延续和扩充,它的设计理念和STL比较接近,都是利用泛型让复用达到最大化
LLVM: LLVM最初是Low Level Virtual Machine的缩写,定位是一个虚拟机,但是是比较底层的虚拟机
Clang的优势:
编译速度更快、编译产出更小、出错提示更友好
clang完成词法和语法分析,代码优化和机器代码的生成工作由llvm完成
Clang的缺点:
编译出的可执行文件无法用gdb调试。
1. MAC准备
- 更新XCode, Update XCode
xcode-select --install
- 安装homebrew(包管理器 / package manager)
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.安装依赖包
一次性安装git,automake,libtool,boost,openssl,llvm
brew update
brew install git automake libtool boost openssl llvm
3. 椭圆曲线加密库 secp256k1
- 椭圆曲线ECDSA加密验证,和密钥生成
- 公钥私钥处理
- 非随机数字密钥加密
cd ~
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
4. 安装WASM、WebAssembly
使用WebAssembly,我们可以在浏览器中运行一些高性能、低级别的编程语言,可用它将大型的C和C++代码库比如游戏、物理引擎甚至是桌面应用程序导入Web平台。
用C语言来编写好的WebAssembly模块(.wasm文件)。用JavaScript glue code,用于连接生成的.wasm文件
mkdir ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
把参数WASM_LLVM_CONFIG和LLVM_DIR导入/.bash_profile
(方便未来调取环境变量)
echo "export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config" >> ~/.bash_profile
echo "export LLVM_DIR=/usr/local/Cellar/llvm/4.0.1/lib/cmake/llvm" >> ~/.bash_profile
获取代码:
官网教程中用Terminal去获取代码,但笔者推荐SourceTree,因为能够更轻易的知道代码更新的消息,即使pull,获取最新版本
方法一: 官网
git clone https://github.com/eosio/eos --recursive
recursive的目的是为了获取submodule子模块
方法二:
复制HTTPs链接
使用SourceTree clone还有一个好,就是submodule也一起clone了
cd ~/eos
mkdir build
cd eos/build
cmake ..
make -j4
测试
Test 1: chain_test
chain_test,跑45个test case,去验证EOS是否安装正确
要在构建后运行测试套件,请在root文件夹下面的tests文件夹中运行chain_test可执行文件。
无误标志
Test 2: Creating and launching a single-node testnet
After successfully building the project, the eosd binary should be present in the programs/eosd directory. Go ahead and run eosd -- it will probably exit with an error, but if not, close it immediately with Ctrl-C. Note that eosd will have created a directory named data-dir containing the default configuration (config.ini) and some other internals. This default data storage path can be overridden by passing --data-dir /path/to/data to eosd.
在成功build project之后,eosd 的binary file会出现在 programs/eosd
文件夹下
1. 在Terminal中执行./eosd
,会报错,但这一步骤的目的是为产生data-dir
的文件夹
2. 进入data-dir,打开config.ini
3. 这时候复制下面的code,替换config.ini
的内容,这段内容来自eos Docker
# File to read Genesis State from
# genesis-json =
genesis-json = "/opt/eos/bin/data-dir/genesis.json"
# the location of the block log (absolute path or relative to application data dir)
block-log-dir = "blocks"
# Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.
# checkpoint =
# open the database in read only mode
readonly = 0
# the location of the chain shared memory files (absolute path or relative to application data dir)
shared-file-dir = "blockchain"
# Minimum size MB of database shared memory file
shared-file-size = 8192
# The local IP and port to listen for incoming http connections.
http-server-endpoint = 127.0.0.1:8888
# The local IP address and port to listen for incoming connections.
listen-endpoint = 127.0.0.1:9876
# The IP address and port of a remote peer to sync with.
# remote-endpoint =
# The public IP address and port that should be advertized to peers.
public-endpoint = 0.0.0.0:9876
# Enable block production, even if the chain is stale.
enable-stale-production = true
# Percent of producers (0-99) that must be participating in order to produce blocks
required-participation = false
# ID of producer controlled by this node (e.g. "inita", quotes are required, may specify multiple times)
# producer-name =
producer-name = inita
producer-name = initb
producer-name = initc
producer-name = initd
producer-name = inite
producer-name = initf
producer-name = initg
producer-name = inith
producer-name = initi
producer-name = initj
producer-name = initk
producer-name = initl
producer-name = initm
producer-name = initn
producer-name = inito
producer-name = initp
producer-name = initq
producer-name = initr
producer-name = inits
producer-name = initt
producer-name = initu
# Tuple of [PublicKey, WIF private key] (may specify multiple times)
private-key = ["EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]
# Plugin(s) to enable, may be specified multiple times
# plugin =
plugin = eos::producer_plugin
plugin = eos::chain_api_plugin
plugin = eos::http_plugin
上面的和报错版本的区别在于plugin,
genesis-json,并加上了21个block producer
并
4. 找到genesis-json =
,给它复制为自己的genesis.json
(一般位于eos root文件夹)的地址,比如笔者就替换成genesis.json = "/Users/Sheldon/eos/genesis.json"
5. 删掉data-dir
内产生的blocks和blockchain文件夹
6. 重新测试./eosd
,成功
7. 利用eosc进行确认
cd ..
cd eosc
./eosc get info
正确示例的结果
如果没有开始跑eosd,就会报错
之后的篇章会重点介绍account 和 contract编写
技术爱好者的知识星球会分享最及时的EOS 团队进展以及技术发展
本星球会分享:
- EOS code 基础知识:
- C++: boost, CMake,Clang,
- Linux:OpenSSL,LLVM 4.0,
- 安全加密: secp256k1-zkp, PGP
- 前端: WASM,Javascript
- �筛选并发布Telegram “EOS Developer”优质信息
- EOS 单机节点运行
- EOS 虚拟多节点运行 (pseudo-distributed)
- EOS 多节点运行
- EOS智能合约编写与发布
- 优秀项目架构和设计原理:
- graphene(石墨烯),Steemit,BitShares
- PressOne,BigOne
- OracleChain
- Motion.one
- HMS(Health Mutual Society)