Bitcoind

將已經執行的 bitcoind 與比特幣資源管理器的 bitcore 連接起來

  • December 9, 2021

我想使用 bitcoind 創建一個比特幣瀏覽器。為此,我正在使用 bitcore 和洞察 API。

我已經在我的本地系統中執行 bitcoind。我想將這個正在執行的 bitcoind 與 bitcore 連接起來,並使用 insight-api 和 UI。

這是我的bitcore-node.json文件:

{
 "network": "testnet",
 "port": 3001,
 "services": [
   "bitcoind",
   "insight-api",
   "insight-ui",
   "web"
 ],
 "servicesConfig": {
   "bitcoind": {
     "spawn": {
       "datadir": "./",
       "exec": "/home/ajit/.nvm/versions/node/v4.8.6/lib/node_modules/bitcore/node_modules/bitcore-node/bin/bitcoind"
     }
   }
 }
}

我已經複製粘貼node_modulebitcore-node.json.bitcoin已經下載比特幣塊並且是最新的文件夾中。

這是我的bitcoin.conf

server=1
testnet=1
whitelist=127.0.0.1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
zmqpubrawtx=tcp://127.0.0.1:28332
zmqpubhashblock=tcp://127.0.0.1:28332
rpcallowip=127.0.0.1
uacomment=bitcore

當我執行 bitcore 時,我得到了這個日誌

ajit@AjitSoman:~/.bitcoin$ bitcored
   [2017-11-17T11:20:14.753Z] info: Using config: /home/ajit/.bitcoin/bitcore-node.json
   [2017-11-17T11:20:14.755Z] info: Using network: testnet
   [2017-11-17T11:20:14.756Z] info: Starting bitcoind
   [2017-11-17T11:20:14.758Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:14.763Z] info: Starting bitcoin process
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:14.796Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:14.797Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:14.853Z] info: Bitcoin Height: 1230668 Percentage: 100.00
   [2017-11-17T11:20:14.862Z] info: Bitcoin Daemon Ready
   [2017-11-17T11:20:14.863Z] info: Starting web
   [2017-11-17T11:20:14.890Z] info: Starting insight-api
   [2017-11-17T11:20:14.891Z] info: Starting insight-ui
   [2017-11-17T11:20:14.892Z] info: Bitcore Node ready
   [2017-11-17T11:20:15.306Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:15.307Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:19.806Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:19.807Z] info: Starting bitcoin process
   [2017-11-17T11:20:19.827Z] warn: Bitcoin process restarted
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:19.848Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:19.848Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:20.326Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:20.326Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:24.848Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:24.849Z] info: Starting bitcoin process
   [2017-11-17T11:20:24.860Z] warn: Bitcoin process restarted
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:24.887Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:24.887Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:25.359Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:25.359Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:29.887Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:29.888Z] info: Starting bitcoin process
   [2017-11-17T11:20:29.906Z] warn: Bitcoin process restarted
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:29.928Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:29.929Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:30.403Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:30.403Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:34.930Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:34.931Z] info: Starting bitcoin process
   [2017-11-17T11:20:34.952Z] warn: Bitcoin process restarted
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:34.971Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:34.971Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:35.450Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:35.451Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:39.972Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
   [2017-11-17T11:20:39.974Z] info: Starting bitcoin process
   [2017-11-17T11:20:39.993Z] warn: Bitcoin process restarted
   Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
   [2017-11-17T11:20:40.008Z] warn: Bitcoin process unexpectedly exited with code: 1
   [2017-11-17T11:20:40.009Z] warn: Restarting bitcoin child process in 5000ms
   [2017-11-17T11:20:40.492Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
   [2017-11-17T11:20:40.492Z] info: ZMQ connected to: tcp://127.0.0.1:28332
   [2017-11-17T11:20:45.010Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf

當我打開 Insight-UI 時。使用者界面打開,我得到了很少的交易,但沒有得到塊列表,並且在 10 秒內比特核停止了這個日誌

[2017-11-17T11:20:50.049Z] info: Starting bitcoin process
[2017-11-17T11:20:50.065Z] warn: Bitcoin process restarted
Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
[2017-11-17T11:20:50.087Z] warn: Bitcoin process unexpectedly exited with code: 1
[2017-11-17T11:20:50.087Z] warn: Restarting bitcoin child process in 5000ms
[2017-11-17T11:20:50.140Z] error: uncaught exception: { Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879
Error
   at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)
   at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)
   at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)
   at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)
   at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)
   at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)
   at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)
   at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)
   at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)
   at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40
 message: 'Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879',
 stack: 'Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879\nError\n    at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)\n    at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)\n    at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)\n    at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)\n    at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)\n    at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)\n    at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)\n    at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)\n    at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)\n    at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40' }
[2017-11-17T11:20:50.144Z] error: Invalid state: Invalid length while reading varlength buffer. Expected to read: 3307054118928383 and read 74879
Error
   at new NodeError (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/errors/index.js:20:41)
   at Object.checkState (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/util/preconditions.js:9:13)
   at BufferReader.readVarLengthBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/encoding/bufferreader.js:141:5)
   at Function.Input.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/input/input.js:95:28)
   at Transaction.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/transaction/transaction.js:307:23)
   at Function._fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:92:42)
   at Function.fromBufferReader (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:103:20)
   at Function.fromBuffer (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:112:16)
   at Function.fromString (/home/ajit/.bitcoin/node_modules/bitcore-lib/lib/block/block.js:121:16)
   at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:1686:40
[2017-11-17T11:20:50.144Z] info: Beginning shutdown
[2017-11-17T11:20:50.145Z] info: Stopping insight-ui
[2017-11-17T11:20:50.145Z] info: Stopping insight-api
[2017-11-17T11:20:50.146Z] info: Stopping web
[2017-11-17T11:20:50.146Z] info: Stopping bitcoind
[2017-11-17T11:20:50.151Z] info: ::1 "GET /insight-api/blocks?limit=5" 400 29 1.819 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36" 
[2017-11-17T11:20:50.564Z] warn: ZMQ connection delay: tcp://127.0.0.1:28332
[2017-11-17T11:20:50.565Z] info: ZMQ connected to: tcp://127.0.0.1:28332
[2017-11-17T11:20:55.087Z] info: Using bitcoin config file: /home/ajit/.bitcoin/bitcoin.conf
[2017-11-17T11:20:55.089Z] info: Starting bitcoin process
[2017-11-17T11:20:55.096Z] error: Error: Stopping while trying to spawn bitcoind.
   at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:905:25
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:676:51
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:726:13
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:52:16
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:264:21
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:44:16
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:723:17
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:167:37
   at /home/ajit/.bitcoin/node_modules/bitcore-node/node_modules/async/lib/async.js:652:25
   at /home/ajit/.bitcoin/node_modules/bitcore-node/lib/services/bitcoind.js:887:16
Error: Cannot obtain a lock on data directory /home/ajit/.bitcoin/testnet3. Bitcoin Core is probably already running.
[2017-11-17T11:21:05.149Z] error: Failed to stop services: Error: bitcoind process did not exit

似乎有一些比特幣程序已經僵死並正在監聽您的埠。嘗試執行此命令以殺死其他程序

killall -9 bitcoind

Bitcore 已經實現了 bitcoind,並將其命名為 bitcored。事實上,您首先執行的是 bitcoind,然後是 bitcored,bitcore 試圖訪問與 bitcoind 相同的埠。鎖定文件也存在於 ~/.bitcoin/testnet3/ 文件夾中。因此衝突。

你不需要執行 bitcoind。

引用自:https://bitcoin.stackexchange.com/questions/62929