8

Ethereum以太坊源码分析(一)前言与环境搭建

 2 years ago
source link: https://dinghaoli.github.io/2018/11/ETH_code_1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ethereum以太坊源码分析(一)前言与环境搭建

calendar.png2018-11-03 | 阅读:次

本文参考:

Github - go-ethereum-code-analysis


之前在Github看到一个很棒的Ethereum源码分析笔记,所以想跟着这个笔记把Ethereum的代码过一遍,希望通过这个已有的笔记和自己的分析,能总结出一些自己的东西,并以此方式记录下来,用输出来激励自己的输入。

因为之前有过fabric的开发经历,所以,我选择了go-ethereum这个项目来对ethereum的框架和模块进行研究。


环境搭建(MacOS)

首先得配置好golang的环境:

GOPATH=/Users/dinghao/go
go get github.com/ethereum/go-ethereum

#cd  $GOPATH; mkdir -p src/github.com/ethereum; cd src/github.com/ethereum  
#git clone https://github.com/ethereum/go-ethereum

总之,请确定go-ethereum是在GOPATH路径下

/Users/dinghao/go/src/github.com/ethereum/go-ethereum

使用vim或其他IDE打开go-ethereum即可,我使用的IDE是GoLand。

进入go-ethereum/rlp的文件夹,运行go test确定环境搭建完成。

#go test
PASS
ok      github.com/ethereum/go-ethereum/rlp 0.011s

go-ethereum 目录大概介绍

go-ethereum项目的组织结构基本上是按照功能模块划分的目录,下面简单介绍一下各个目录的结构,每个目录在GO语言里面又被成为一个Package,我理解跟Java里面的Package应该是差不多的意思。

accounts        实现了一个高等级的以太坊账户管理
bmt             二进制的默克尔树的实现
build           主要是编译和构建的一些脚本和配置
cmd             命令行工具,又分了很多的命令行工具,下面一个一个介绍
    /abigen     Source code generator to convert Ethereum contract definitions into easy to use, compile-time type-safe Go packages
    /bootnode   启动一个仅仅实现网络发现的节点
    /evm        以太坊虚拟机的开发工具, 用来提供一个可配置的,受隔离的代码调试环境
    /faucet     
    /geth       以太坊命令行客户端,最重要的一个工具
    /p2psim     提供了一个工具来模拟http的API
    /puppeth    创建一个新的以太坊网络的向导
    /rlpdump    提供了一个RLP数据的格式化输出
    /swarm      swarm网络的接入点
    /util       提供了一些公共的工具
    /wnode      这是一个简单的Whisper节点。 它可以用作独立的引导节点。此外,可以用于不同的测试和诊断目的。
common          提供了一些公共的工具类
compression     Package rle implements the run-length encoding used for Ethereum data.
consensus       提供了以太坊的一些共识算法,比如ethhash, clique(proof-of-authority)
console         console类
contracts   
core            以太坊的核心数据结构和算法(虚拟机,状态,区块链,布隆过滤器)
crypto          加密和hash算法,
eth             实现了以太坊的协议
ethclient       提供了以太坊的RPC客户端
ethdb           eth的数据库(包括实际使用的leveldb和供测试使用的内存数据库)
ethstats        提供网络状态的报告
event           处理实时的事件
les             实现了以太坊的轻量级协议子集
light           实现为以太坊轻量级客户端提供按需检索的功能
log             提供对人机都友好的日志信息
metrics         提供磁盘计数器
miner           提供以太坊的区块创建和挖矿
mobile          移动端使用的一些warpper
node            以太坊的多种类型的节点
p2p             以太坊p2p网络协议
rlp             以太坊序列化处理
rpc             远程方法调用
swarm           swarm网络处理
tests           测试
trie            以太坊重要的数据结构Package trie implements Merkle Patricia Tries.
whisper         提供了whisper节点的协议。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK