EOS大神,C++写的高发并行区块链
EOS大神,C++寫的高發并行區塊鏈
EOS?團隊于?2017?年?7?月?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.64,OpenSSL,?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
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 = 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。?
總結
以上是生活随笔為你收集整理的EOS大神,C++写的高发并行区块链的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 教程 | 以太坊智能合约编程之菜鸟教程
- 下一篇: Starzhou:EOSIO1.0 版本