1. 程式人生 > >Ubuntu Server 16.04.1 LTS 64位下編譯並運行bitcoin-v0.15.1

Ubuntu Server 16.04.1 LTS 64位下編譯並運行bitcoin-v0.15.1

core confirm 區別 mon prefix ffi bit ould tco

依賴庫安裝

?

  • 安裝編譯環境
    apt-get -y install build-essential libtool autotools-dev automake autoconf pkg-config bsdmainutils python3
  • 安裝必備依賴庫
    apt-get -y install libssl-dev libboost-all-dev libevent-dev
  • 安裝錢包依賴庫
    apt-get -y install libdb-dev libdb++-dev
  • 安裝其他依賴庫
    apt-get -y install libminiupnpc-dev libzmq3-dev
  • 安裝GUI依賴庫
    apt-get -y install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler libqrencode-dev

    源代碼編譯

    ?

  • 下載源代碼
    git clone https://github.com/bitcoin/bitcoin.git
    cd bitcoin/
    git checkout -b v0.15.1 v0.15.1
  • 編譯源代碼
    ./autogen.sh
    ./configure --with-incompatible-bdb --prefix=/data/install/bitcoin
    #--with-incompatible-bdb為忽略libdb版本差異
    make
    make install
  • 其他編譯選項
    #--disable-wallet不編譯錢包
    #--without-gui不編譯GUI

    編譯完成後,安裝目錄下文件為:

    ls /data/install/bitcoin/bin/
    bench_bitcoin  bitcoin-cli  bitcoind  bitcoin-qt  bitcoin-tx  test_bitcoin  test_bitcoin-qt

    附官方文檔:https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md
    ?
    g++: internal compiler error: Killed (program cc1plus)解決辦法:

    dd if=/dev/zero of=/swapfile bs=64M count=16
    mkswap /swapfile
    swapon /swapfile
  • bitcoin-cli、bitcoind、bitcoin-qt區別
    bitcoin-qt,帶GUI的完整節點。
    bitcoind,無GUI的完整節點。
    bitcoin-cli,使用bitcoin-cli訪問JSON-RPC接口。

    啟動bitcoind並加入比特幣測試網絡

    ?

  • 啟動bitcoind
    cd /data/install/bitcoin/bin/
    ./bitcoind --daemon -testnet
    Bitcoin server starting
  • 錢包及數據目錄
    cd ~/.bitcoin/testnet3/
    ls -l
    banlist.dat  bitcoind.pid  blocks  chainstate  database  db.log  debug.log  peers.dat  wallet.dat
  • 停止bitcoind
    ./bitcoin-cli -testnet stop
    Bitcoin server stopping

    bitcoin-cli訪問JSON-RPC接口

    ?

  • 獲取節點統計信息
    ./bitcoin-cli -testnet getinfo
    {
    "deprecation-warning": "WARNING: getinfo is deprecated and will be fully removed in 0.16. Projects should transition to using getblockchaininfo, getnetworkinfo, and getwalletinfo before upgrading to 0.16",
    "version": 150100,
    "protocolversion": 70015,
    "walletversion": 139900,
    "balance": 0.00000000,
    "blocks": 531765,
    "timeoffset": 0,
    "connections": 0,
    "proxy": "",
    "difficulty": 858629.5213440134,
    "testnet": true,
    "keypoololdest": 1516255482,
    "keypoolsize": 2000,
    "paytxfee": 0.00000000,
    "relayfee": 0.00001000,
    "errors": ""
    }
  • 獲取區塊鏈信息
    ./bitcoin-cli -testnet getblockchaininfo
    {
    "chain": "test",
    "blocks": 721658,
    "headers": 1259495,
    "bestblockhash": "00000000000005c7be6d6a242e281756ea155ab248df12877c579439b3e9fcbe",
    "difficulty": 262144,
    "mediantime": 1456540510,
    "verificationprogress": 0.5614052534742976,
    "chainwork": "000000000000000000000000000000000000000000000007b2d3c70327f81d35",
    "pruned": false,
    "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": true
      }
    }, 
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": true
      }
    }, 
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": true
      }
    }
    ],
    "bip9_softforks": {
    "csv": {
      "status": "defined",
      "startTime": 1456790400,
      "timeout": 1493596800,
      "since": 0
    },
    "segwit": {
      "status": "defined",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 0
    }
    }
    }
  • 獲取挖礦信息
    ./bitcoin-cli -testnet getmininginfo
    {
    "blocks": 721883,
    "currentblockweight": 0,
    "currentblocktx": 0,
    "difficulty": 1,
    "errors": "",
    "networkhashps": 6860463578666.306,
    "pooledtx": 0,
    "chain": "test"
    }
  • 獲取錢包信息
    ./bitcoin-cli -testnet getwalletinfo
    {
    "walletname": "wallet.dat",
    "walletversion": 139900,
    "balance": 0.00000000,
    "unconfirmed_balance": 0.00000000,
    "immature_balance": 0.00000000,
    "txcount": 0,
    "keypoololdest": 1516255482,
    "keypoolsize": 1000,
    "keypoolsize_hd_internal": 1000,
    "paytxfee": 0.00000000,
    "hdmasterkeyid": "1f264d1522573ed5b189940b4b80e60c1d8572e2"
    }
  • 獲取區塊信息
    ./bitcoin-cli -testnet getblock 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
    {
    "hash": "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943",
    "confirmations": 723926,
    "strippedsize": 285,
    "size": 285,
    "weight": 1140,
    "height": 0,
    "version": 1,
    "versionHex": "00000001",
    "merkleroot": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
    "tx": [
    "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"
    ],
    "time": 1296688602,
    "mediantime": 1296688602,
    "nonce": 414098458,
    "bits": "1d00ffff",
    "difficulty": 1,
    "chainwork": "0000000000000000000000000000000000000000000000000000000100010001",
    "nextblockhash": "00000000b873e79784647a6c82962c70d228557d24a747ea4d1b8bbe878e1206"
    }

    更多JSON-RPC接口使用方法見官方文檔:https://bitcoin.org/en/developer-reference#bitcoin-core-apis

Ubuntu Server 16.04.1 LTS 64位下編譯並運行bitcoin-v0.15.1