比特币区块链代码分析

比特币区块链代码分析

1.程序和依赖库
2.代码分析
3.ubuntu编译
4.私链开发
5.区块浏览器
用git clone从github获取代码
https://github.com/bitcoin/bitcoin
https://github.com/bankledger/bitcoin
http://bankledger.com/bitcoin.html

工具准备

sudo apt-get update
sudo apt-get install git autoconf make gcc g++ libdb-dev libdb++-dev libboost-all-dev zlib1g-dev libssl-dev build-essential libminiupnpc-dev libtool pkg-config libevent-dev libzmq3-dev

Ubuntu 编译

•git clone https://github.com/bitcoin/bitcoin
•cd bitcoin
•git branch
•git checkout 0.12
•./autogen.sh
•./configure –with-incompatible-bdb
•make

编译 bitcoin-qt

•sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler gcc-multilib libqrencode-dev
•./configure –with-incompatible-bdb
•make

Bitcoin私链

主链代码修改
Bitcoin/src/chainparams.cpp
(1)出块时间:10 * 60 -> 1 * 60
(2)P2P端口: 8333 -> 58333
(3)节点: 改成VPS地址
(4)检查点: 删除所有检查点
(5)降低难度:powLimit 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
-> 0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
(6)延长合法区块时间:maxTipAge: 24 * 60 * 60 -> 8 * 365 * 24 * 60 * 60;
(7)创世块: 改变nBits, 0x1d00ffff -> 0x1e00ffff
(8)创世块: 重新计算nonce
(9)挖矿: ~/.bitcoin/bitcoin.conf设 gen=1;
(10)开启RPC: bitcoin.conf设 rpcuser=rpcuser, rpcpassword=rpcpass
(11)编译运行:cd src
strip bitcoind
./bitcoind -server -debug –printtoconsole
(bitcoind在src目录下)

bitcoin-cli

./bitcoin-cli -rpcuser=rpcuser -rpcpassword=rpcpass + 命令
命令如下:
(1)getinfo: 查看基本情况
(2)getbalance: 查看余额 (~/.bitcoin/wallet.dat)
(3)sendtoaddress: 跟地址和金额,如sendtoaddress 1CHtexWBwTYuqNokzLXtToqUHz2hkiz2HZ 0.1
(4)getmininginfo: 查看挖矿信息
(5)getaccountaddress “” : 获得当前地址

区块浏览器bitcoin-abe

git clone https://github.com/bitcoin-abe/bitcoin-abe
sudo apt-get install python python-dev python-pip
pip install pycrypto
python setup.py install

配置bitcoin.conf

dbtype = sqlite3
connect-args = abe.sqlite
port 80
host 127.0.0.1
datadir += [{
“dirname”: “~/.bitcoin”,
#”loader”: “rpc”, # See the comments for default-loader below.
“code3”:”MYB”,
“chain”: “MyBitcoin”,
“policy”: “Bitcoin” # … but use the “Bitcoin” loader.
}]

运行

运行:
python -m Abe.abe –config bitcoin.conf$


阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页