flavienbwk/blockchain-php
Composer 安装命令:
composer require flavienbwk/blockchain-php
包简介
An object-oriented PHP library for creating a blockchain easily.
关键字:
README 文档
README
An object-oriented PHP library for creating a simple blockchain easily.
Original code (august 2015) by Marty Anstey (https://marty.anstey.ca/), on Github.
The code has been improved and adapted to an object-oriented library.
Characteristics
- SHA256 hash algorithm.
- Record any data.
- File-based (the blockchain lives in two files only).
- PHP >= 7.1 (verified).
Installation
composer require flavienbwk/blockchain-php
Usage
Adding a block.
Our blockchain will be saved in the blockchain.dat file for the example.
require 'vendor/autoload.php'; $Blockchain = new \flavienbwk\BlockchainPHP\Blockchain(); $block = $Blockchain->addBlock("blockchain.dat", "What you want to put in the blockchain");
You can now get the data of your block :
$block->hasError(); // Returns true or false if there was an error while adding the block. $block->getMessage(); // Returns the error message. $block->getHash(); // Returns the hash (SHA256) of the block. $block->getPrevHash(); // Returns the hash (SHA256) of the block added before this one. $block->getData(); // Returns the data stored in the block. $block->getPosition(); // Returns the height/position of the block in the blockchain. $block->getJson(); // Returns a JSON associative array with all the data of the block. // ... // Go to /src/Block.php to see all the getters.
You can get the data of one block by its hash or previous hash block :
$Blockchain->getBlockByHash("blockchain.dat", "INSERT_THE_BLOCK_HASH_HERE"); $Blockchain->getBlockByPrevHash("blockchain.dat", "INSERT_THE_BLOCK_HASH_HERE");
Printing all your blockchain.
$Blockchain = new \flavienbwk\BlockchainPHP\Blockchain(); $all = $Blockchain->getBlockchain("blockchain.dat"); var_dump($all);
As 3 blocks have been added, it will display :
[
{
"position":1,
"header":127,
"magic":"d5e8a97f",
"version":1,
"timestamp":1528658690,
"prevhash":"0000000000000000000000000000000000000000000000000000000000000000",
"hash":"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d",
"datalen":15,
"data":"{\"id\":\"BLABLA\"}"
},
{
"position":2,
"header":127,
"magic":"d5e8a97f",
"version":1,
"timestamp":1528658691,
"prevhash":"ef6ecc71fc1570e7fbebf3d5d24f3d396f71e5588a5a5d930ef6d6118443095d",
"hash":"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710",
"datalen":15,
"data":"{\"id\":\"BLABLA\"}"
},
{
"position":3,
"header":127,
"magic":"d5e8a97f",
"version":1,
"timestamp":1528658692,
"prevhash":"cec0f91c9bdca41d3356508f3eaefdeb302b92e111c889d1743350d9e0912710",
"hash":"555905b331a019bed206b772dd191e6ad2e7cb263e6c9e610222c1afd4c8b0c9",
"datalen":15,
"data":"{\"id\":\"BLABLA\"}"
}
]
flavienbwk/blockchain-php 适用场景与选型建议
flavienbwk/blockchain-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 660 次下载、GitHub Stars 达 35, 最近一次更新时间为 2018 年 06 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「OOP」 「blockchain」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 flavienbwk/blockchain-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 flavienbwk/blockchain-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 flavienbwk/blockchain-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Solana PHP SDK for interacting with the Solana blockchain
A php library to bootstrap the use of Domain Driven Design valueObjects
A fast and dynamic Merkle tree implementation
Multichain JSON-RPC Client
Super simple HTTP client
统计信息
- 总下载量: 660
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 37
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-10