6
6

More than 5 years have passed since last update.

Bitcoin環境

Posted at

Bitcoin Core

Install

ソースコード

$ ghq get https://github.com/bitcoin/bitcoin.git
$ git checkout -b v0.9.5

依存パッケージ

$ brew install automake berkeley-db4 libtool boost --c++11 miniupnpc openssl pkg-config homebrew/versions/protobuf260 --c++11 qt5 libevent

コンパイル

$ ./autogen.sh
$ ./configure
$ make
$ make install
$ which bitcoind
/usr/local/bin/bitcoind
$ which bitcoin-cli
/usr/local/bin/bitcoin-cli

ビットコイン・ネットワーク

環境 内容
mainnet 実際に送金を行うことができる。取引されるビットコインには実際の価値がある。
testnet 開発・実験用。
regtest testnetと同じルールで動作するプライベートブロックチェーンを新規に作成できる。任意のタイミングで新しいブロックを追加することができる。

bitcoind

GUI

$ bitcoin-qt

デーモン

$ bitcoind daemon

testnetモード

$ bitcoind -testnet -daemon

停止

$ bitcoin-cli stop

ディレクトリ・ファイル

ディレクトリ

$ ll ~/Library/Application\ Support/Bitcoin/
.lock
banlist.dat
blocks
chainstate
db.log
debug.log
fee_estimates.dat
mempool.dat
peers.dat
wallet.dat
名称 内容
banlist.dat 禁止ノードのIPアドレス・サブネットのリスト
bitcoin.conf Bitcoin Coreの設定ファイル
blocks/blk000??.dat ブロックの生データ。ウォレット内の欠落しているトランザクションを再スキャンする際や、同期中の他のノードにブロックデータを提供する際などに利用される。
blocks/rev000??.dat blocksディレクトリ内に格納されているundoデータ。
blocks/index/* 既知のブロックのメタデータやその格納場所の情報が格納されたLevelDBのDB。
chainstate 現在未使用のトランザクションアウトプット(UTXO)とそのトランザクションのメタデータをコンパクトにしたLevelDBのDB。受信したブロックやトランザクションを検証するために利用される。
database Berkeley DBのジャーナリングファイルが格納されるディレクトリ。
db.log ワレットデータベースのログファイル
debug.log Bitcoinの詳細なログ
fee_estimates.dat 手数料と優先順位を予測するための統計。プログラムのシャットダウン時に保存され、起動時に読み込まれる。
mempool.dat メモリプール内のトランザクションのダンプ
peers.dat 再接続を容易にするためのピア情報用のストレージ。ビットコイン専用のフォーマットを使用している
wallet.dat 鍵やトランザクション、メタデータ、オプション情報が保存されるBerkelayDBのデータベースファイル
.cookie セッションRPC認証クッキー。クッキー認証が使用されているときに書き込まれ、シャットダウン時に削除される
onionprivatekey キャッシュされたTor匿名通信サービスの秘密鍵
testnet3 testnetモードでbitcoindを起動した際のデータ
regtest regtestモードでbitcoindを起動した際のデータ。regtestディレクトリを削除してBitcoin Coreを再起動すると、新しいregtest環境になる
.lock Berkelay DBのロックファイル

bitcoin.conf

testnetへ接続する場合

testnet=3     # testnetを利用する
txindex=1     # indexを作成してすべてのトランザクションIDを参照可能にする
server=1      # JSON RPCサーバとしてコマンドを受け付ける
rest=1        # RESTインターフェースを有効にする
rpcuser=      # JSON RPCのユーザー名
rpcpassword=  # JSON RPCのパスワード
rpcport=18332 # JSON RPC用ポート番号

mainnetへ接続する場合

testnet=3     # mainnetを利用する
txindex=1
server=1
rest=1
rpcuser=
rpcpassword=
rpcport=8332

RESTインターフェース

$ curl localhost:18332/rest/chaininfo.json | jq
{
  "chain": "test",
  "blocks": 196914,
  "headers": 1209418,
  "bestblockhash": "00000000045e8dfee8e0d4fd93a5e9cbcaf713376b1402661d71d5fcc4eb027e",
  "difficulty": 10.64796144714119,
  "mediantime": 1393592557,
  "verificationprogress": 0.07445246717676264,
  "chainwork": "000000000000000000000000000000000000000000000000044de604b0f5e566",
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": true
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": false
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "defined",
      "startTime": 1456790400,
      "timeout": 1493596800,
      "since": 0
    },
    "segwit": {
      "status": "defined",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 0
    }
  },
  "warnings": "This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
}

bitcoin-cli

$ bitcoin-cli getconnectioncount
2
$ bitcoin-cli getconnectioncount
8
$ bitcoin-cli getpeerinfo
[
  {
    "id": 2,
    "addr": "176.9.121.46:18333",
    "addrlocal": "160.13.221.92:56210",
    "addrbind": "192.168.10.102:56210",
    "services": "000000000000000d",
    "relaytxes": true,
    "lastsend": 1507338137,
    "lastrecv": 1507338137,
    "bytessent": 263814,
    "bytesrecv": 38348312,
    "conntime": 1507338048,
    "timeoffset": 0,
    "pingtime": 0.243435,
    "minping": 0.243435,
    "version": 70015,
    "subver": "/Satoshi:0.14.2/",
    "inbound": false,
    "addnode": false,
    "startingheight": 1209429,
    "banscore": 0,
    "synced_headers": 1209432,
    "synced_blocks": 311488,
    "inflight": [
      311622,
      311625,
      311631,
      311633,
      311634,
      311727,
      311772,
      311774,
      311778,
      311782,
      311786,
      311790,
      311797,
      311803,
      311810,
      311815
    ],
    "whitelisted": false,
    "bytessent_per_msg": {
      "addr": 140,
      "feefilter": 32,
      "getaddr": 24,
      "getdata": 262228,
      "getheaders": 1085,
      "ping": 32,
      "pong": 32,
      "sendcmpct": 66,
      "sendheaders": 24,
      "verack": 24,
      "version": 127
    },
    "bytesrecv_per_msg": {
      "addr": 30052,
      "block": 38315063,
      "feefilter": 32,
      "getheaders": 1085,
      "headers": 424,
      "inv": 1352,
      "ping": 32,
      "pong": 32,
      "sendcmpct": 66,
      "sendheaders": 24,
      "verack": 24,
      "version": 126
    }
  },

bitcoin-ruby

$ ruby -v
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
$ gem install bitcoin-ruby

openassets-ruby

$ gem install openassets-ruby
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6