项目作者: andkom

项目描述 :
A simple PHP library for reading Bitcoin blockchain database.
高级语言: PHP
项目地址: git://github.com/andkom/php-bitcoin-blockchain.git
创建时间: 2018-09-09T18:55:13Z
项目社区:https://github.com/andkom/php-bitcoin-blockchain

开源协议:MIT License

下载


PHP Bitcoin Blockchain Parser

A PHP implementation of Bitcoin blockchain database parser.

Features:

  • Parse unordered block data
  • Parse ordered block data
  • Parse block index
  • Parse chain state (UTXO database)

Requirements

  • PHP >= 7.1
  • Bitcoin Core >= 0.15.1
  • leveldb >= 1.20
  • php-leveldb >= 0.2.1
  • php-gmp >= 7.1

Installation

  1. composer require andkom/php-bitcoin-blockchain

Examples

  1. $databaseReader = new DatabaseReader('/path/to/bitcoin');
  2. // read ordered blocks
  3. foreach ($databaseReader->readBlocks() as $block) {
  4. }
  5. // read unordered blocks
  6. foreach ($databaseReader->readBlocksUnordered() as $block) {
  7. }
  8. // read UTXO
  9. foreach ($databaseReader->getChainstate()->read() as $utxo) {
  10. }
  11. // get block by hash
  12. $block = $databaseReader->getBlockByHash('binary hash in little endian');
  13. // get block by height
  14. $block = $databaseReader->getBlockByHeight(12345);
  15. // get best block hash
  16. $hash = $databaseReader->getChainstate()->getBestBlock();

See more examples in the examples dir.

LevelDB installation

Ubuntu/Debian:

  1. apt-get install libleveldb-dev
  2. pecl install leveldb-0.2.1

Mac OS:

  1. brew install leveldb
  2. pecl install leveldb-0.2.1

Or compile from source:

  1. git clone https://github.com/google/leveldb.git
  2. cd leveldb
  3. mkdir -p build && cd build
  4. cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
  5. make install
  6. cd ../../
  7. git clone https://github.com/reeze/php-leveldb.git
  8. cd php-leveldb
  9. phpize
  10. ./configure --with-leveldb
  11. make
  12. make install

Make sure you’ve enabled leveldb.so extension in your php.ini.