blockavel/lara-block-io

Block.io API PHP 封装的一个 Laravel 包/外观。

0.0.4 2017-03-18 03:42 UTC

This package is not auto-updated.

Last update: 2024-09-29 00:48:44 UTC


README

GitHub license Build Status StyleCI

Block.io API PHP 封装的一个 Laravel 包/外观。

此仓库实现了一个简单的 Block.io 客户端服务提供者,并使其通过 Laravel >= 5 的外观轻松访问。

有关 Block.io API 的 PHP 封装及其接口的更多信息,请参阅 @BlockIo/block_io-phpBlockIo PHP API 文档

要求

Block.io 创建一个账户,并在“账户”>“仪表板”下记录您的 API 密钥。

BlockIo 库需要 PHP 的 'mcrypt'(请注意,mcrypt 已在 php7.1 中弃用)、'gmp' 和 'cURL' 扩展以及 'bcmath' 库。要启用这些,请参阅

-mCrypt 安装指南

-GMP 安装指南

-cURL 安装指南

-bcmath 安装指南

使用 Composer 安装

在您的终端应用程序中使用 cd 命令移动到您的 laravel 项目的根目录,然后使用 composer 将项目作为依赖项添加。

composer require blockavel/lara-block-io

这将在您的 composer.json 中添加以下行,并将项目及其依赖项下载到您的项目 ./vendor 目录

// 

./composer.json
{
    "name": "blockavel/lara-block-io",
    "description": "A dummy project used to test the Laravel Block.io Facade.",

    // ...

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.*",
        "blockavel/lara-block-io": "1.0.*",
        // ...
    },

    //...
}

用法

为了使用静态接口,我们必须自定义应用程序配置,告诉系统在哪里可以找到新的服务。打开文件 config/app.php,并添加以下行 ([a],[b])

// config/app.php

return [

    // ...

    'providers' => [

        // ...

        /*
         * Package Service Providers...
         */
        Blockavel\LaraBlockIo\LaraBlockIoServiceProvider::class, // [a]

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    // ...

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,

        // ...

        'LaraBlockIo' => 'Blockavel\LaraBlockIo\LaraBlockIoFacade', // [b]
        'Hash' => Illuminate\Support\Facades\Hash::class,

        // ...
    ],

];

发布供应商

lara-block-io 需要一个连接配置。要开始,您需要运行以下命令发布所有供应商资产

php artisan vendor:publish

这将创建一个 config/larablockio.php 文件在您的应用程序中,您可以修改它来设置您的配置。请确保在升级后检查与原始配置文件相比是否有变化。

现在您应该可以在您的应用程序中使用外观。例如

namespace App;

use Illuminate\Database\Eloquent\Model;

class BlockIoTest extends Model
{
    /**
     * Get the balance information associated with a Bitcoin Dogecoin,
     * or Litecoin account.
     *
     * @return object Contains balance information
     */
     
    public function test()
    {
        return LaraBlockIo::getBalanceInfo();
    }
}

可用方法列表

余额和网络信息

// BlockIo getter method, returns a BlockIo object.
LaraBlockIo::getBlockIo();
// Get the balance information associated with a Bitcoin Dogecoin, or Litecoin account.
LaraBlockIo::getBalanceInfo();
// Get the Network associated with your API KEY.
LaraBlockIo::getNetwork();  
// Get the balance associated with all your addresses in the selected network.
LaraBlockIo::getAvailableBalance();
// Get the the balance that's pending confirmation in the selected network.
LaraBlockIo::getPendingReceivedBalance();
// Get address(es) balance by specified address(es).
LaraBlockIo::getAddressesBalanceByAddress($addresses);
// Get address(es) balance by specified label(s).
LaraBlockIo::getAddressesBalanceByLabels($labels);
// Get user(s) balance.
LaraBlockIo::getUsersBalance($userIds);
// Get network fee estimate for transacting (withdrawing, sending).
LaraBlockIo::getNetworkFeeEstimate($amounts, $addresses);

地址

// Create new address.
LaraBlockIo::createAddress($label); 
// Get all the (unarchived) addresses information.
LaraBlockIo::getAddressesInfo();
// Get all the (unarchived) addresses information without balance.
LaraBlockIo::getAddressesInfoWithoutBalances(); 
// Get the (unarchived) addresses associated with your account.
LaraBlockIo::getAddresses(); 
// Get the (unarchived) addresses associated with your account without balance.
LaraBlockIo::getAddressesWithoutBalances();
// Get address by label.
LaraBlockIo::getAddressByLabel($label);
// Get all the users associated with your account in a given network.
LaraBlockIo::getUsers()
// Get a user's address.
LaraBlockIo::getUserAddress($userId);

提款

// Withdraws amount of coins from any addresses in your account.
LaraBlockIo::withdraw($amounts, $toAddresses, $nonce = null);
// Withdraws amount of coins from specific addresses in your account.
LaraBlockIo::withdrawFromAddressesToAddresses($amounts, $fromAddresses, $toAddresses, $nonce = null);
LaraBlockIo::withdrawFromLabelsToLabels($amounts, $fromLabels, $toLabels, $nonce = null);
LaraBlockIo::withdrawFromLabelsToAddresses($amounts, $fromLabels, $toAddresses, $nonce = null);

存档

// Archive adress(es).
LaraBlockIo::archiveAddressesByAddress($addresses);
LaraBlockIo::archiveAddressesByLabels($labels);
// Unarchive address(es)
LaraBlockIo::unarchiveAddressesByAddress($addresses);
LaraBlockIo::unarchiveAddressesByLabels($labels);
// Returns all the archived addresses.
LaraBlockIo::getArchivedAddresses();

交易

// Returns various data for transactions spent or received.
LaraBlockIo::getTransactionsByAddresses($type, $addresses, $beforeTx = null);
LaraBlockIo::getTransactionsByLabels($type, $labels, $beforeTx = null);
LaraBlockIo::getTransactionsByUserIds($type, $userIds, $beforeTx = null);
LaraBlockIo::getReceivedTransactions($beforeTx = null);
LaraBlockIo::getSentTransactions($beforeTx = null);
// Returns the prices from the largest exchanges for the given network.
LaraBlockIo::getCurrentPrice($baseCurrency = null);
// Returns an array of transactions that were sent by Block.io Green Addresses.
LaraBlockIo::isGreenTransaction($txIds);
// Get pending transactions.
LaraBlockIo::getNotConfirmedTxs($toAddress, $confidenceThreshold);

DTrust

// Get all dtrust addresses.
LaraBlockIo::getDTrustAddresses();
// Create a MultiSig address.
LaraBlockIo::createMultiSigAddress($label, $reqSigs, $s1, $s2, $s3 = null, $s4 = null);
// Get details of a dtrust address associated with a given label.
LaraBlockIo::getDTrustInfoByLabel($label);
// Perform a MultiSig withdraw.
LaraBlockIo::multiSigWithdraw($label, $toAddresses, $amount);
// Returns a MultiSig withdraw object for signing.
LaraBlockIo::getMultiSigWithdraw($referenceId);
// Sign MultiSig withdraw.
LaraBlockIo::signMultiSigWithdraw($reference_id, $passphrase);
// Returns sent dtrust transactions.
LaraBlockIo::getSentDTrustTransactions($beforeTx = null);
// Returns received dtrust transactions.
LaraBlockIo::getReceivedDTrustTransactions($beforeTx = null);
// Returns information associated with dtrust transactions.
LaraBlockIo::getDtrustTransactionsByAddresses($type, $addresses, $beforeTx = null);
LaraBlockIo::getDtrustTransactionsByLabels($type, $labels, $beforeTx = null);
LaraBlockIo::getDTrustTransactionsByUserIds($type, $userIds, $beforeTx = null);
// Get balance associated with dtrust addresses.
LaraBlockIo::getDTrustAddressBalance($addresses);
// Archive dtrust addresses.
LaraBlockIo::archiveDTrustAddress($addresses);
// Unarchive dtrust addresses.
LaraBlockIo::unarchiveDTrustAddress($addresses);
// Get archived addresses.
LaraBlockIo::getArchivedDTrustAddresses();
// Get estimated network fee for dtrust transactions.
LaraBlockIo::getNetworkDTrustFeeEstimate($amounts, $fromAddress, $toAddress);

撤资资金

// Sweep funds from external address to a BlockIo address.
LaraBlockIo::sweepFromAddress($fromAddress, $toAddress, $privateKey);

测试

单元测试使用 PHPunit 和 orchestra/testbench 创建,可以使用 ./vendor/bin/phpunit 运行。

贡献

找到您可以帮忙的领域并去做。开源是关于协作和开放参与的。尽量使您的代码看起来像已经存在的代码或更好,并提交拉取请求。此外,如果您有任何改进代码或改进范围和功能的想法,请联系任何贡献者。

许可

MIT 许可证。