majestic/php-litecoinrpc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

majestic/php-litecoinrpc

最新稳定版本:v2.0.2

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!

统计信息

  • 总下载量: 8.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 103
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固