让 EOS 跑起来-EOS 编译、测试指南(一)

EOS 团队于 2017 年 月 28 日推出了单机测试版,基于此单机版开发者可以 完成用户注册、转账等简单功能。OracleChain 团队在第一时间对代码进行了编译 和测试,以下将详细介绍如何让 EOS 在自己的本地跑起来。OracleChain 团队使 用 Mac 系统进行开发,并使用 Homebrew 进行软件管理。

该指南将从环境准备、获取 EOS 代码、编译 EOS 代码和运行 EOS 四个方面 对 EOS的开发进行讲解,帮助开发者进入 EOS 世界。

EOS 文档:https://eosio.github.io/eos/ EOS 代码:https://github.com/EOSIO/eos


第一步:环境准备

EOS 是基于 C++ 14 进行开发并使用 CMake 进行编译管理,据 git 上的信息, EOS开发者使用 clang 4.0.0 和 CMake 3.8.0 进行开发编译。

EOS 使用 WebAssembly 对编译和运行智能合约,因此需要使用 WASM 编译 器。

除此之外 EOS 还依赖:Boost 1.64OpenSSL, LLVM 4.0 和 secp256k1-zkp 


基本环境安装
Mac 系统下需先安装 xcode,然后运行:

brew install automake autoconf libtool cmake。 Boost 安装

brew install boost

OpenSSL 安装 brew install openssl

在 Mac 系统已经移除了 openssl,需要手动配置环境变量: 在~/.bash_profile 内添加:

export OPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n
export OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2l/includes

其中 1.0.2n 为 openssl 版本号。 随后更新配置文件:

source ~/.bash_profile

安装 secp256k1-zkp

  1. git clone https://github.com/cryptonomex/secp256k1-zkp.git

  2. cd secp256k1-zkp

  3. ./autogen.sh

  4. ./configure

  5. make

  6. sudo make install

安装 LLVM

brew install llvm 随后添加环境变量,在~/.bash_profile 内添加:


编译 WASM 编译环境

  1. mkdir ~/wasm-compiler

  2. cd ~/wasm-compiler

  3. git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-

    mirror/llvm.git

  4. cd llvm/tools

  5. git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm- mirror/clang.git

  6. cd ..

  7. mkdir build

  8. cd build

  9. cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=..

    -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../

  10. make -j4 install

  至此,准备工作已经完成。 


第二步,获取 EOS 代码

EOS 代码使用了三个子模块,包括两个 EOS 自己维护的插件管理模块 AppBase 和区块链结构模块 ChainBase,以及 WASM 模块。

开发者可以通过 git clone https://github.com/eosio/eos --recursive 获取全部代 码,或者在获取 EOS 代码后通过 git submodule update --init –recursive 补全子模 块。 

第三步,编译 EOS 代码

建议使用前面准备的 WASM 编译器对 EOS 进行完整编译。

1. cd eos

  1. mkdir build && cd build

  2. export WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config

  3. cmake ..

  4. cd ..

  5. make -j4

其中~/wasm-compiler/llvm/bin/llvm-config 为之前编译的 WASM 编译器地址。 开发者可以将 WASM_LLVM_CONFIG=~/wasm-compiler/llvm/bin/llvm-config 添加 到.bash_profile 中去。

至此,eos 已经编译完成。 

第四步,运行 EOS

在 eos/programs 文件加下,eosd 是单机版的 EOS 节点,会模拟多个账号轮 流出块。eosc 通过 REST 访问 eosd,并提供命令行工具。

运行 eosd

首次运行 eosd 下的 eosd 将会报错,并会在 eosd 文件夹下生成 data-dir 文 件夹,此时需要对文件夹下的 config.ini 文件进行修改然后再重新运行 eosd

注释掉原文中的 enable-stale-production = false。 在 config.ini 文件末尾添加

# Load the testnet genesis state, which creates some initial block producers with the default key

genesis-json = /path/to/eos/genesis.json

# Enable production on a stale chain, since a single-node test chain is pretty much always stale

enable-stale-production = true
# Enable block production with the testnet producers 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
# Load the block producer plugin, so we can produce blocks plugin = eos::producer_plugin

plugin = eos::chain_api_plugin
其中/path/to/eos/genesis.json 是 genesis.json 文件的全地址,在 eos 文件夹

下。
随后再次运行 
eosd,将启动 EOS。 

猜你喜欢

转载自blog.csdn.net/qq_35624642/article/details/79744784
eos