tmwclaxton/laravel-bitcoin-module 问题修复 & 功能扩展

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

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

tmwclaxton/laravel-bitcoin-module

最新稳定版本:v1.0.3

Composer 安装命令:

composer require tmwclaxton/laravel-bitcoin-module

包简介

Laravel Bitcoin Module

README 文档

README

Pest Laravel Expectations

Latest Version on Packagist Php Version Php Version Total Downloads

Website Telegram

Laravel Bitcoin Module is a Laravel package for work with cryptocurrency Bitcoin. You can create descriptor wallets, generate addresses, track current balances, collect transaction history, organize payment acceptance on your website, and automate outgoing transfers.

You can contact me for help in integrating payment acceptance into your project.

Examples

Create Descriptor Wallet:

$name = 'my-wallet';
$password = 'password for encrypt wallet files';
$title = 'My First Wallet';

$node = Bitcoin::createNode('localhost', 'LocalHost', '127.0.0.1');
$wallet = Bitcoin::createWallet($node, $name, $password, $title);

Import Descriptor Wallet using descriptors:

$name = 'my-wallet';
$password = 'password for encrypt wallet files';
$descriptions = json_decode('DESCRIPTORS JSON', true);
$title = 'My First Wallet';

$node = Bitcoin::createNode('localhost', 'LocalHost', '127.0.0.1');
$wallet = Bitcoin::importWallet($node, $name, $descriptions, $password, $title);

Create address:

$wallet = BitcoinWallet::firstOrFail();
$title = 'My address title';

$address = Bitcoin::createAddress($wallet, AddressType::BECH32, $title);

Validate address:

$address = '....';

$node = BitcoinNode::firstOrFail();
$addressType = Bitcoin::validateAddress($node, $address);
if( $addressType === null ) {
    die('Address is not valid!');
} 

var_dump($addressType); // Enum value of AddressType

Send all BTC from wallet:

$wallet = BitcoinWallet::firstOrFail();
$address = 'to_address';

$txid = Bitcoin::sendAll($wallet, $address);

echo 'TXID: '.$txid;

Send BTC from wallet:

$wallet = BitcoinWallet::firstOrFail();
$address = 'to_address';
$amount = 0.001;

$txid = Bitcoin::send($wallet, $address, $amount);

echo 'TXID: '.$txid;

Installation

You can install the package via composer:

composer require mollsoft/laravel-bitcoin-module

After you can run installer using command:

php artisan bitcoin:install

And run migrations:

php artisan migrate

Register Service Provider and Facade in app, edit config/app.php:

'providers' => ServiceProvider::defaultProviders()->merge([
    ...,
    \Mollsoft\LaravelBitcoinModule\BitcoinServiceProvider::class,
])->toArray(),

'aliases' => Facade::defaultAliases()->merge([
    ...,
    'Bitcoin' => \Mollsoft\LaravelBitcoinModule\Facades\Bitcoin::class,
])->toArray(),

In file app/Console/Kernel in method schedule(Schedule $schedule) add

$schedule->command('bitcoin:sync')
    ->everyMinute()
    ->runInBackground();

Commands

Scan transactions and update balances:

> php artisan bitcoin:sync

Scan transactions and update balances for wallet:

> php artisan bitcoin:sync-wallet {wallet_id}

WebHook

You can set up a WebHook that will be called when a new incoming BTC deposit is detected.

In file config/bitcoin.php you can set param:

'webhook_handler' => \Mollsoft\LaravelBitcoinModule\WebhookHandlers\EmptyWebhookHandler::class,

Example WebHook handler:

class EmptyWebhookHandler implements WebhookHandlerInterface
{
    public function handle(BitcoinWallet $wallet, BitcoinAddress $address, BitcoinDeposit $transaction): void
    {
        Log::error('Bitcoin Wallet '.$wallet->name.' new transaction '.$transaction->txid.' for address '.$address->address);
    }
}

Requirements

The following versions of PHP are supported by this version.

  • PHP 8.2 and older
  • PHP Extensions: Decimal.

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-24