編譯后的幾個主要程序
-
bitcoin-qt 客戶端圖形界面版
-
bitcoind /src/bitcoind Bitcoin簡潔命令行版,也是下一步源代碼分析的重點(不能與Bitcoin Core同事運行,如果不小心嘗試同時運行另外一個客戶端,它會提示已經有一個客戶端在運行並且自動退出)
-
bitcoin-cli /src/bitcoin-cli Bitcoind的一個功能完備的RPC客戶端,可以通過它在命令行查詢某個區塊信息,交易信息等
-
bitcoin-tx /src/bitcoind 比特幣交易處理模塊,可以進行交易的查詢和創建
我們現階段主要學習bitcoind這個程序,這個程序的啟動參數大致如下
//bitcoind 命令通用格式 bitcoind [選項] bitcoind [選項] <命令> [參數] 將命令發送到 -server 或 bitcoind bitcoind [選項] help 列出命令 bitcoind [選項] help <命令> 獲取該命令的幫助 //bitcoind常見命令 -conf=<文件名> 指定配置文件(默認:bitcoin.conf) -pid=<文件名> 指定 pid (進程 ID)文件(默認:bitcoind.pid) -gen 生成比特幣 -gen=0 不生成比特幣 -min 啟動時最小化 -splash 啟動時顯示啟動屏幕(默認:1) -datadir=<目錄名> 指定數據目錄 -dbcache=<n style="word-wrap: break-word;"> 設置數據庫緩存大小,單位為兆字節(MB)(默認:25)</n> -dblogsize=<n style="word-wrap: break-word;"> 設置數據庫磁盤日志大小,單位為兆字節(MB)(默認:100)</n> -timeout=<n style="word-wrap: break-word;"> 設置連接超時,單位為毫秒</n> -proxy=<ip:端口 style="word-wrap: break-word;"> 通過 Socks4 代理鏈接</ip:端口> -dns addnode 允許查詢 DNS 並連接 -port=<端口> 監聽 <端口> 上的連接(默認:8333,測試網絡 testnet:18333) -maxconnections=<n style="word-wrap: break-word;"> 最多維護 <n style="word-wrap: break-word;">個節點連接(默認:125)</n></n> -addnode=<ip style="word-wrap: break-word;"> 添加一個節點以供連接,並嘗試保持與該節點的連接</ip> -connect=<ip style="word-wrap: break-word;"> 僅連接到這里指定的節點</ip> -irc 使用 IRC(因特網中繼聊天)查找節點(默認:0) -listen 接受來自外部的連接(默認:1) -dnsseed 使用 DNS 查找節點(默認:1) -banscore=<n style="word-wrap: break-word;"> 與行為異常節點斷開連接的臨界值(默認:100)</n> -bantime=<n style="word-wrap: break-word;"> 重新允許行為異常節點連接所間隔的秒數(默認:86400)</n> -maxreceivebuffer=<n style="word-wrap: break-word;"> 最大每連接接收緩存,<n style="word-wrap: break-word;">*1000 字節(默認:10000)</n></n> -maxsendbuffer=<n style="word-wrap: break-word;"> 最大每連接發送緩存,<n style="word-wrap: break-word;">*1000 字節(默認:10000)</n></n> -upnp 使用全局即插即用(UPNP)映射監聽端口(默認:0) -detachdb 分離貨幣塊和地址數據庫。會增加客戶端關閉時間(默認:0) -paytxfee=<amt style="word-wrap: break-word;"> 您發送的交易每 KB 字節的手續費</amt> -testnet 使用測試網絡 -debug 輸出額外的調試信息 -logtimestamps 調試信息前添加[時間戳](http://8btc.com/article-165-1.html) -printtoconsole 發送跟蹤/調試信息到控制台而不是 debug.log 文件 -printtodebugger 發送跟蹤/調試信息到調試器 -rpcuser=<用戶名> JSON-RPC 連接使用的用戶名 -rpcpassword=<密碼> JSON-RPC 連接使用的密碼 -rpcport=<port style="word-wrap: break-word;"> JSON-RPC 連接所監聽的 <端口>(默認:8332)</port> -rpcallowip=<ip style="word-wrap: break-word;"> 允許來自指定 <ip style="word-wrap: break-word;">地址的 JSON-RPC 連接</ip></ip> -rpcconnect=<ip style="word-wrap: break-word;"> 發送命令到運行在 <ip style="word-wrap: break-word;">地址的節點(默認:127.0.0.1)</ip></ip> -blocknotify=<命令> 當最好的貨幣塊改變時執行命令(命令中的 %s 會被替換為貨幣塊哈希值) -upgradewallet 將錢包升級到最新的格式 -keypool=<n style="word-wrap: break-word;"> 將密匙池的尺寸設置為 <n style="word-wrap: break-word;">(默認:100)</n></n> -rescan 重新掃描貨幣塊鏈以查找錢包丟失的交易 -checkblocks=<n style="word-wrap: break-word;"> 啟動時檢查多少貨幣塊(默認:2500,0 表示全部)</n> -checklevel=<n style="word-wrap: break-word;"> 貨幣塊驗證的級別(0-6,默認:1)</n> **SSL 選項:** -rpcssl 使用 OpenSSL(https)JSON-RPC 連接 -rpcsslcertificatechainfile=<文件.cert> 服務器證書文件(默認:server.cert) -rpcsslprivatekeyfile=<文件.pem> 服務器私匙文件(默認:server.pem) -rpcsslciphers=<密碼> 可接受的密碼(默認:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH)
這里面大部分參數都可以省略,轉而使用配置文件進行配置,因為使用配置文件更方便些,所以這里我們使用配置文件進行配置,在linux下時,bitcoin.conf的默認路徑為$HOME/.bitcoin/bitcoin.conf,我們可以從bitcoin源碼的share/examples找到一份樣本拷貝過去並進行修改,我的配置文件如下:
##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##
# Network-related settings:
# Note that if you use testnet or regtest, particularly with the options
# addnode, connect, port, bind, rpcport, rpcbind or wallet, you will also
# want to read "[Sections]" further down.
# 在測試網絡中運行,而不是在真正的比特幣網絡.
testnet=1
# Run a regression test network
# regtest=1
# 通過一個 Socks5 代理服務器連接
# proxy=127.0.0.1:9050
# Bind to given address and always listen on it. Use [host]:port notation for IPv6
#bind=<addr>
# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6
#whitebind=<addr>
##############################################################
## addnode 與 connect 的區別 ##
## ##
## 假設您使用了 addnode=4.2.2.4 參數,那么 addnode 便會與 ##
## 您的節點連接,並且告知您的節點所有與它相連接的其它節點。 ##
## 另外它還會將您的節點信息告知與其相連接的其它節點,這樣它 ##
## 們也可以連接到您的節點。 ##
## ##
## connect 在您的節點“連接”到它的時候並不會做上述工作。僅 ##
## 它會與您連接,而其它節點不會。 ##
## ##
## 因此如果您位於防火牆后,或者因為其它原因無法找到節點,則 ##
## 使用“addnode”添加一些節點。 ##
## ##
## 如果您想保證隱私,使用“connect”連接到那些您可以“信任” ##
## 的節點。 ##
## ##
## 如果您在一個局域網內運行了多個節點,您不需要讓它們建立許多 ##
## 連接。您只需要使用“connect”讓它們統一連接到一個已端口轉 ##
## 發並擁有多個連接的節點。 ##
##############################################################
# Use as many addnode= settings as you like to connect to specific peers
#addnode=69.164.218.197
#addnode=10.0.0.2:8333
# Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=69.164.218.197
#connect=10.0.0.1:8333
# Listening mode, enabled by default except when 'connect' is being used
#listen=1
# Port on which to listen for connections (default: 8333, testnet: 18333, regtest: 18444)
#port=
# Maximum number of inbound+outbound connections.
#maxconnections=
#
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
#
# server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands
#server=0
# Bind to given address to listen for JSON-RPC connections.
# Refer to the manpage or bitcoind -help for further details.
#rpcbind=<addr>
# If no rpcpassword is set, rpc cookie auth is sought. The default `-rpccookiefile` name
# is .cookie and found in the `-datadir` being used for bitcoind. This option is typically used
# when the server and client are run as the same user.
#
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC API.
#
# The config option `rpcauth` can be added to server startup argument. It is set at initialization time
# using the output from the script in share/rpcauth/rpcauth.py after providing a username:
#
# ./share/rpcauth/rpcauth.py alice
# String to be appended to bitcoin.conf:
# rpcauth=alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc02b724e5d095828e0bc8b2456e9ac8757ae3211a5d9b16a22ae
# Your password:
# DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# On client-side, you add the normal user/password pair to send commands:
#rpcuser=alice
#rpcpassword=DONT_USE_THIS_YOU_WILL_GET_ROBBED_8ak1gI25KFTvjovL3gAM967mies3E=
#
# You can even add multiple entries of these to the server conf file, and client can use any of them:
# rpcauth=bob:b2dd077cb54591a2f3139e69a897ac$4e71f08d48b4347cf8eff3815c0e25ae2e9a4340474079f55705f40574f4ec99
# How many seconds bitcoin will wait for a complete RPC HTTP request.
# after the HTTP connection is established.
#rpcclienttimeout=30
# By default, only RPC connections from localhost are allowed.
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,
# either as a single IPv4/IPv6 or with a subnet specification.
# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
# because the rpcpassword is transmitted over the network unencrypted.
# server=1 tells Bitcoin-Qt to accept JSON-RPC commands.
# it is also read by bitcoind to determine if RPC should be enabled
#rpcallowip=10.1.1.34/255.255.255.0
#rpcallowip=1.2.3.4/24
#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96
# 在如下端口監聽 RPC 連接
# rpcport=8332
# 您可以通過如下設置使用 Bitcoin 或 bitcoind 來發送命令到一個在
# 其它主機遠程運行的 Bitcoin/bitcoind 客戶端
# rpcconnect=127.0.0.1
# Wallet options
# Specify where to find wallet, lockfile and logs. If not present, those files will be
# created as new.
#wallet=</path/to/dir>
# Create transactions that have enough fees so they are likely to begin confirmation within n blocks (default: 6).
# This setting is over-ridden by the -paytxfee option.
#txconfirmtarget=n
# Pay a transaction fee every time you send bitcoins.
#paytxfee=0.000x
# Miscellaneous options
# Pre-generate this many public/private key pairs, so wallet backups will be valid for
# both prior transactions and several dozen future transactions.
#keypool=100
# Enable pruning to reduce storage requirements by deleting old blocks.
# This mode is incompatible with -txindex and -rescan.
# 0 = default (no pruning).
# 1 = allows manual pruning via RPC.
# >=550 = target to stay under in MiB.
#prune=550
# User interface options
# Start Bitcoin minimized
#min=1
# Minimize to the system tray
#minimizetotray=1
# [Sections]
# Most options apply to mainnet, testnet and regtest.
# If you want to confine an option to just one network, you should add it in the
# relevant section below.
# EXCEPTIONS: The options addnode, connect, port, bind, rpcport, rpcbind and wallet
# only apply to mainnet unless they appear in the appropriate section below.
# Options only for mainnet
[main]
# Options only for testnet
[test]
# Options only for regtest
[regtest]
然后我們只要調用bitcoind -datadir=數據目錄,就可以進行bitcoind的啟動了。
我個人的C盤空間吃緊,所以數據目錄我就設成了f盤,啟動命令如下:
bitcoind -datadir='/mnt/f/bitcoin_data/' -conf='/home/lsm/bitcoin/bitcoin.conf'