ftab/php-dogecoinrpc

基于php-bitcoinrpc的Dogecoin JSON-RPC客户端

v3.0.2 2020-03-01 17:11 UTC

README

安装

在您的项目目录中运行 php composer.phar require ftab/php-dogecoinrpc,或者在composer.json中添加以下行

"require": {
    "ftab/php-dogecoinrpc": "^3.0"
}

然后运行 php composer.phar install

需求

PHP 7.1或更高版本

用法

使用url作为参数创建新对象

/**
 * Don't forget to include composer autoloader by uncommenting line below
 * if you're not already done it anywhere else in your project.
 **/
// require 'vendor/autoload.php';

use ftab\Dogecoin\Client as DogecoinClient;

$dogecoind = new DogecoinClient('http://rpcuser:rpcpassword@localhost:22555/');

或者使用数组定义您的dogecoind设置

/**
 * Don't forget to include composer autoloader by uncommenting line below
 * if you're not already done it anywhere else in your project.
 **/
// require 'vendor/autoload.php';

use ftab\Dogecoin\Client as DogecoinClient;

$dogecoind = new DogecoinClient([
    'scheme'        => 'http',                 // optional, default http
    'host'          => 'localhost',            // optional, default localhost
    'port'          => 22555,                  // optional, default 22555
    'user'          => 'rpcuser',              // required
    'password'      => 'rpcpassword',          // required
    'ca'            => '/etc/ssl/ca-cert.pem',  // optional, for use with https scheme
    'preserve_case' => false,                  // optional, send method names as defined instead of lowercasing them
]);

然后使用魔术方式调用在Dogecoin Core API中定义的方法

/**
 * Get block info.
 */
$block = $dogecoind->getBlock('1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691');

$block('hash')->get();     // 1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691
$block['height'];          // 0 (array access)
$block->get('tx.0');       // 5b2a3f53f605d62c53e62932dac6925e3d74afa5a4b459745c36d42d0ed26a69
$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 = $dogecoind->sendToAddress('DATfurydmRTZ6vJnBtaibHJYMdx9JYjL4n', 100);
$txid = $result->get();

/**
 * Get transaction amount.
 */
$result = $dogecoind->listSinceBlock();
$dogecoin = $result->sum('transactions.*.amount');
$dogetoshi = \ftab\Dogecoin\to_dogetoshi($dogecoin);

要发送异步请求,请将Async添加到方法名中

$dogecoind->getBlockAsync(
    '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691',
    function ($response) {
        // success
    },
    function ($exception) {
        // error
    }
);

您还可以使用请求方法发送请求

/**
 * Get block info.
 */
$block = $dogecoind->request('getBlock', '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691');

$block('hash');            // 1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691
$block['height'];          // 0 (array access)
$block->get('tx.0');       // 5b2a3f53f605d62c53e62932dac6925e3d74afa5a4b459745c36d42d0ed26a69
$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 = $dogecoind->request('sendtoaddress', 'DATfurydmRTZ6vJnBtaibHJYMdx9JYjL4n', 60);
$txid = $result->get();

或requestAsync方法进行异步调用

$dogecoind->requestAsync(
    'getBlock',
    '1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691',
    function ($response) {
        // success
    },
    function ($exception) {
        // error
    }
);

异常

  • ftab\Dogecoin\Exceptions\BadConfigurationException - 在客户端配置错误时抛出。
  • ftab\Dogecoin\Exceptions\BadRemoteCallException - 在从守护进程获取错误消息时抛出。
  • ftab\Dogecoin\Exceptions\ConnectionException - 在守护进程连接错误(例如超时)时抛出。

辅助工具

该包提供以下辅助工具以协助处理值。

to_dogecoin()

将dogetoshi中的值转换为dogecoin。

echo ftab\Dogecoin\to_dogecoin('100000'); // '0.00100000'

to_dogetoshi()

将dogecoin中的值转换为dogetoshi。

echo ftab\Dogecoin\to_dogetoshi('0.001'); // '100000'

to_fixed()

裁剪值到精度,不进行四舍五入。

echo ftab\Dogecoin\to_fixed('0.1236', 3); // '0.123'

许可证

本产品在MIT许可证下分发。

捐赠

让我们给Denpa一些爱

如果您喜欢这个项目,请考虑捐赠给php-bitcoinrpc的原作者,因为他们做了所有的工作
BTC: 3L6dqSBNgdpZan78KJtzoXEk9DN3sgEQJu
Bech32: bc1qyj8v6l70c4mjgq7hujywlg6le09kx09nq8d350

❤感谢您的支持!❤

dogecoin分支

我想我可以为制作这个分支收取一些doge?不知道。只做差异和编辑的时候感觉有点奇怪。

  • DOGE: DATfurydmRTZ6vJnBtaibHJYMdx9JYjL4n

或者看看我将它放入的游戏,并在游戏内的一些物品上扔一些doge!