EOS大神,C++写的高发并行区块链

xiaoxiao2021-02-28  50

EOS大神,C++写的高发并行区块链

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.2nexport OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2l/includes

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

source ~/.bash_profile

安装 secp256k1-zkp

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

cd secp256k1-zkp

./autogen.sh

./configure

make

sudo make install

安装 LLVM

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

编译 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

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

第二步,获取 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

mkdir build && cd build

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

cmake ..

cd ..

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 = initaproducer-name = initbproducer-name = initcproducer-name = initd 

producer-name = initeproducer-name = initfproducer-name = initgproducer-name = inithproducer-name = initiproducer-name = initjproducer-name = initkproducer-name = initlproducer-name = initmproducer-name = initnproducer-name = initoproducer-name = initpproducer-name = initqproducer-name = initrproducer-name = initsproducer-name = inittproducer-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。 

转载请注明原文地址: https://www.6miu.com/read-2627866.html

最新回复(0)