majestic/php-litecoinrpc
Composer 安装命令:
composer require majestic/php-litecoinrpc
包简介
Litecoin JSON-RPC client based on GuzzleHttp
README 文档
README
About
This project is based on php-bitcoinrpc project - fully unit-tested Litecoin JSON-RPC client powered by GuzzleHttp.
Installation
Run php composer.phar require majestic/php-litecoinrpc in your project directory or add following lines to composer.json
"require": { "majestic/php-litecoinrpc": "^2.0" }
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 Majestic\Litecoin\Client as LitecoinClient; $litecoind = new LitecoinClient('http://rpcuser:rpcpassword@localhost:9332/');
or use array to define your litecoind settings
use Majestic\Litecoin\Client as LitecoinClient; $litecoind = new LitecoinClient([ 'scheme' => 'http', // optional, default http 'host' => 'localhost', // optional, default localhost 'port' => 9332, // optional, default 9332 'user' => 'rpcuser', // required 'pass' => 'rpcpassword', // required 'ca' => '/etc/ssl/ca-cert.pem' // optional, for use with https scheme ]);
Then call methods defined in Litecoin Core API Documentation with magic:
/** * Get block info. */ $block = $litecoind->getBlock('9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8'); $block('hash')->get(); // 9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8 $block['height']; // 1298009 (array access) $block->get('tx.0'); // a8971eaf8dfda3ee5dd20b3de3fb6c22e936339bbb53f8fa0f2379941ac5ff3f $block->count('tx'); // 26 $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 = $litecoind->sendToAddress('LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY', 0.1); $txid = $result->get(); /** * Get transaction amount. */ $result = $litecoind->listSinceBlock(); $totalAmount = $result->sum('transactions.*.amount'); $totalSatoshi = LitecoinClient::toSatoshi($totalAmount);
To send asynchronous request, add Async to method name:
use Majestic\Litecoin\LitecoindResponse; $promise = $litecoind->getBlockAsync( '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8', function (LitecoindResponse $success) { // }, function (\Exception $exception) { // } ); $promise->wait();
You can also send requests using request method:
/** * Get block info. */ $block = $litecoind->request('getBlock', '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8'); $block('hash'); // 9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8 $block['height']; // 1298009 (array access) $block->get('tx.0'); // a8971eaf8dfda3ee5dd20b3de3fb6c22e936339bbb53f8fa0f2379941ac5ff3f $block->count('tx'); // 26 $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->random(1, 'tx'); // get random txid /** * Send transaction. */ $result = $BTC->request('sendtoaddress', ['LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY', 0.06]); $txid = $result->get();
or requestAsync method for asynchronous calls:
use Majestic\Litecoin\LitecoindResponse; $promise = $litecoind->requestAsync( 'getBlock', '9d4d9fd2f4dee46d5918861b7bbff81f52c581c3b935ad186fe4c5b6dc58d2f8', function (LitecoindResponse $success) { // }, function (\Exception $exception) { // } ); $promise->wait();
Multi-Wallet RPC
You can use wallet($name) function to do a Multi-Wallet RPC call:
/** * Get wallet2.dat balance. */ $balance = $litecoind->wallet('wallet2.dat')->getbalance(); $balance->get(); // 0.10000000
License
This product is distributed under MIT license.
Donations
If you like this project, you can donate Litecoins to LKdsQGCwBbgJNdXSQtAvVbFMpwgwThtsSY.
Thanks for your support!
majestic/php-litecoinrpc 适用场景与选型建议
majestic/php-litecoinrpc 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.32k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「Guzzle」 「jsonrpc」 「litecoin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 majestic/php-litecoinrpc 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 majestic/php-litecoinrpc 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 majestic/php-litecoinrpc 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 8.32k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 16
- 依赖项目数: 5
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-19