azartpay/azart-rpc-php
Composer 安装命令:
composer require azartpay/azart-rpc-php
包简介
Azart JSON-RPC client based on GuzzleHttp
README 文档
README
Simple Azart JSON-RPC client based on GuzzleHttp
Installation
Run php composer.phar require azartpay/azart-rpc-php in your project directory or add following lines to composer.json
"require": { "azartpay/azart-rpc-php": "2.0.3" }
and run php composer.phar update.
Requirements
PHP 7.0 or higher (should also work on 5.6, but this is unsupported)
Usage
Create new object with url as parameter
use AzartPay\Azart\Client as AzartClient; $azartd = new AzartClient('http://rpcuser:rpcpassword@localhost:9798/');
or use array to define your azartd settings
use AzartPay\Azart\Client as AzartClient; $azartd = new AzartClient([ 'scheme' => 'http', // optional, default http 'host' => 'localhost', // optional, default localhost 'port' => 9798, // optional, default 9798 'user' => 'rpcuser', // required 'pass' => 'rpcpassword', // required 'ca' => '/etc/ssl/ca-cert.pem' // optional, for use with https scheme ]);
Then call methods defined in Dash Core API Documentation with magic:
/** * Get block info. */ $block = $azartd->getBlock('000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9'); $block('hash')->get(); // 000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9 $block['height']; // 0 (array access) $block->get('tx.0'); // 44701bbc011bdd471b75fa83e42acc8e067759a69cdeef723df57181a33e5467 $block->count('tx'); // 1 $block->has('version'); // key must exist and CAN NOT be null $block->exists('version'); // key must exist and CAN be null $block->contains(0); // check if response contains value $block->values(); // array of values $block->keys(); // array of keys $block->random(1, 'tx'); // random block txid $block('tx')->random(2); // two random block txid's $block('tx')->first(); // txid of first transaction $block('tx')->last(); // txid of last transaction /** * Send transaction. */ $result = $azartd->sendToAddress('AqUM31KtkxgbMwYrrpUi6RVjaftK3Mv5mG', 0.1); $txid = $result->get(); /** * Get transaction amount. */ $result = $azartd->listSinceBlock(); $totalAmount = $result->sum('transactions.*.amount'); $totalSatoshi = AzartClient::toSatoshi($totalAmount);
To send asynchronous request, add Async to method name:
use AzartPay\Azart\AzartdResponse; $promise = $azartd->getBlockAsync( '000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9', function (AzartdResponse $success) { // }, function (\Exception $exception) { // } ); $promise->wait();
You can also send requests using request method:
/** * Get block info. */ $block = $azartd->request('getBlock', '000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9'); $block('hash'); // 000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9 $block['height']; // 0 (array access) $block->get('tx.0'); // 44701bbc011bdd471b75fa83e42acc8e067759a69cdeef723df57181a33e5467 $block->count('tx'); // 1 $block->has('version'); // key must exist and CAN NOT be null $block->exists('version'); // key must exist and CAN be null $block->contains(0); // check if response contains value $block->values(); // get response values $block->keys(); // get response keys $block->first('tx'); // get txid of the first transaction $block->last('tx'); // get txid of the last transaction $block->random(1, 'tx'); // get random txid /** * Send transaction. */ $result = $azartd->request('sendtoaddress', ['AqUM31KtkxgbMwYrrpUi6RVjaftK3Mv5mG', 0.06]); $txid = $result->get();
or requestAsync method for asynchronous calls:
use AzartPay\Azart\AzartdResponse; $promise = $azartd->requestAsync( 'getBlock', '000009b9903dae4466d48db6c264d711ac554492da34cd0bfa4c0b6d230f29c9', function (AzartdResponse $success) { // }, function (\Exception $exception) { // } ); $promise->wait();
License
This product is distributed under MIT license.
azartpay/azart-rpc-php 适用场景与选型建议
azartpay/azart-rpc-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Guzzle」 「jsonrpc」 「azart」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 azartpay/azart-rpc-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 azartpay/azart-rpc-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 azartpay/azart-rpc-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bitcoin JSON-RPC Service Provider for Laravel
A collection of server-side addons that might be of use for development of xml-rpc (and json-rpc) based applications
JsonRpc Client for Laravel
Flexible JSON RPC v2 client for PHP written in object-oriented style
A PSR-7 compatible library for making CRUD API endpoints
Multichain JSON-RPC Client
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-05