目录

Bitcoin源码编译及修改(定制虚拟币FantasyCoin)

准备

  1. 下载安装VMware Workstation 16 Pro(激活密钥ZF3R0-FHED2-M80TY-8QYGC-NPKYF
  2. 下载安装虚拟机镜像Ubuntu 20.04.1
  3. 设置ubuntu软件源为阿里源
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091224363.png
    设置阿里源
  4. 打开ubuntu命令行并运行sudo apt update && sudo apt upgrade更新软件
  5. 安装环境依赖1sudo apt install -y git autoconf make --without-bdb libdb++-dev libtool g++ libqt4-dev libzmq-dev libevent-dev

编译Bitcoin

  1. 通过git clone命令下载Bitcoin源码
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091301371.png
    Bitcoin源码
  2. 在源码根目录下执行sudo ./autogen.sh
  3. 在源码根目录下执行sudo ./configure,常见错误及处理方法:
    • 执行sudo ./configure --with-incompatible-bdb若出现:
    1
    
    configure: error: Found Berkeley DB other than 4.8, required for portable BDB wallets (--with-incompatible-bdb to ignore or --without-bdb to disable BDB wallet support)
    
    • 执行sudo ./configure --with-incompatible-bdb --disable-dependency-tracking若出现:
    1
    
    config.status: error: Something went wrong bootstrapping makefile fragments for automatic dependency tracking.  Try re-running configure with the '--disable-dependency-tracking' option to at least be able to build the package (albeit without support for automatic dependency tracking).
    

    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091336059.png
    configure成功

  4. 在源码根目录下执行sudo make(可能要几十分钟)
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091413765.png
    sudo make
  5. 在源码根目录下执行sudo make install
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091418559.png
    sudo make install
  6. 安装完成后使用bitcoin-cli -h命令测试
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091415465.png
    bitcoin-cli -h

定制FantasyCoin

  1. 重新通过git clone命令下载Bitcoin源码
  2. mv bitcoin fantasycoin修改目录名为fantasycoin
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091439186.png
    mv bitcoin fantasycoin
  3. 修改文件名
1
2
3
4
5
6
7
find . -type f -print0 | xargs -0 sed -i 's/bitcoin/fantasycoin/g'
find . -type f -print0 | xargs -0 sed -i 's/Bitcoin/Fantasycoin/g' 
find . -type f -print0 | xargs -0 sed -i 's/BitCoin/FantasyCoin/g' 
find . -type f -print0 | xargs -0 sed -i 's/BITCOIN/FANTASYCOIN/g' 
find . -type f -print0 | xargs -0 sed -i 's/BTC/FC/g' 
find . -type f -print0 | xargs -0 sed -i 's/btc/FC/g' 
find . -type f -print0 | xargs -0 sed -i 's/Btc/FC/g'

https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091444364.png
修改文件名
4. 修改文件夹名

1
2
find . -exec rename 's/bitcoin/fantasycoin/' {} ";" 
find . -exec rename 's/btc/FC/' {} ";"
  1. 修改运行端口
1
2
find . -type f -print0 | xargs -0 sed -i 's/8332/7272/' {} ";" 
find . -type f -print0 | xargs -0 sed -i 's/8333/7273/' {} ";" 
  1. 修改检查点
    比特币客户端初始化时会检查特定的几个区块的hash值是否符合要求,这几个特定区块的高度就是比特币的检查点。由于我们自定义的虚拟币并没有已存在的链,所以需要将检查点删除修改为创世区块。使用vim命令打开src目录下的chainparams.cpp文件,搜索checkpointData关键字可在第146行找到比特币默认的几个检查点区块:
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091508011.png
    原始检查点
    数据类似于一个数组,每个元素的第一个元素为块高度、第二个元素为块的hash值。在这里我们将其改为(0, uint256("0x001"))
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091513682.png
    修改后检查点
  2. 在源码根目录下执行sudo ./autogen.sh
  3. 在源码根目录下执行sudo ./configure
  4. 在源码根目录下执行sudo make(可能要几十分钟)
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091618428.png
    sudo make
  5. 在源码根目录下执行sudo make install
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091621402.png
    sudo make instal2l2
  6. 安装完成后使用bitcoin-cli -h命令测试
    https://cdn.jsdelivr.net/gh/wefantasy/FileCloud/img/202108091622970.png
    bitcoin-cli -h

参考


  1. malajisi01. Ubuntu编译运行bitcoin运行全节点. CSDN. [2017-10-26] ↩︎