appino / blockchain
区块链API客户端库
v1.4.1
2020-11-20 10:54 UTC
Requires
- php: ^7.1
- guzzlehttp/guzzle: *
- illuminate/support: *
README
一个非官方的PHP库,用于与blockchain.info API交互。
安装
为了使用此包,您必须提供一个指向service-my-wallet-v3实例的URL。在使用这些功能之前,请参考service-my-wallet-v3。
您可以通过composer安装此包
composer require appino/blockchain
添加提供者到应用配置
Appino\Blockchain\BlockchainServiceProvider::class
发布配置文件
php artisan vendor:publish --provider="Appino\blockchain\BlockchainServiceProvider"
在env文件中添加2行
blockchain_api_code=123456789abcdefghijklmnop //you must get api code from blockchain.info blockchain_base_url=https://:3000
使用方法
创建
$blocchain = Blockchain::Create();
1. 创建钱包
/** * @param string $password * @param string|null $email * @param string|null $label * @return WalletResponse * @throws ParameterError */ $blockchain->create($password, $email, $label);
2. 使用特定私钥创建钱包
/** * @param string $password * @param string $privKey * @param string|null $email * @param string|null $label * @return WalletResponse * @throws ParameterError */ $blockchain->createWithKey($password, $privKey, $email, $label);
钱包
$blockchain = Blockchain::Wallet(); $blockchain->credentials($guid, $password);
1. 创建新地址
/** * @param null|string $label * @return AccountResponse */ $blockchain->CreateAddress($label));
2. 余额
/** * @return int in satoshi */ $blockchain->balnce();
3. 地址余额
/** * @param int|string $param can be index of address in wallet or address * @return int in satoshi */ $blockchain->AddressBallance($param);
4. 激活地址
返回钱包的地址列表
/** * @return array<AccountResponse> */ $blockchain->ActiveAddresses();
5. Xpub列表
返回xpub列表
/** * @return array<string> */ $blockchain->XpubList();
6. 单个地址数据
返回单个地址数据
/** * @param int|string $param can be index of address in wallet or address * @return AccountResponse */ $blockchain->SingleAddress($param);
7. 获取接收地址
返回接收地址
/** * @param int|string $param can be index of address in wallet or address * @return string */ $blockchain->ReceivingAddress($param);
8. 归档地址
/** * @param int|string $param can be index of address in wallet or address * @return AccountResponse */ $blockchain->ArchiveAddress($param);
9. 解档地址
/** * @param int|string $param can be index of address in wallet or address * @return AccountResponse */ $blockchain->UnArchiveAddress($param);
10. 发送支付
/** * @param string $to bitcoin address that you want to send payment to * @param integer $amount amount of payment you want to send in satoshi * @param integer|string|null $from xpub address or index of account that you want to send payment from * @param int|null $fee * @param int|null $fee_per_byte * @return PaymentResponse * @throws ParameterError */ $blockchain->SendPayment($to, $amount, $from, $fee, $fee_per_byte);
11. 发送多笔支付
/** * @param array<string,integer> $recipients recipients must be an array of address as key and satoshi as integer * @param integer|string|null $from xpub address or index of account that you want to send payment from * @param integer|null $fee must be in satoshi (better to set null or use fee_per_byte) * @param integer|null $fee_per_byte must be in satoshi * @return PaymentResponse * @throws ParameterError */ $blockchain->SendManyPayment($recipients, $from=null, $fee=null, $fee_per_byte = null);
接收
$blocchain = Blockchain::Receive();
1. 生成接收地址
/** * @param string $xpub The public key. * @param string $callback The callback URL. * @param int $gap_limit How many unused addresses are allowed. * @return ReceiveResponse */ $blockchain->Generate($xpub, $callback, $gap_limit = 20);
2. 获取地址间隔
/** * @param $xpub string * @return int * @throws \GuzzleHttp\Exception\GuzzleException */ $blockchain->AddressGap($xpub);
3. 余额通知
/** * @param string $address * @param string $callback callback url * @param Notification|string $on what to do after notification called * @param int $confs how many confiramtion need to send notification * @param Operation|string $op on Receive/Send/All notification will send * @return NotificationResponse */ $blockchain->BalanceNotification($address, $callback, $on, $confs, $op);
使用以下命令删除通知
/** * @param $id int * @return bool * @throws \GuzzleHttp\Exception\GuzzleException */ $blockchain->DeleteBalanceNotification($id);
4. 区块通知
/** * @param string $callback callback url * @param Notification|string $on what to do after notification called * @param int $confs how many confiramtion need to send notification * @param int|null $height height of block default(currentblock height plus 1) * @return NotificationResponse * @throws \GuzzleHttp\Exception\GuzzleException */ $blockchain->BlockNotification($callback, $on, $confs, $height);
使用以下命令删除通知
/** * @param int $id * @return bool * @throws \GuzzleHttp\Exception\GuzzleException */ $blockchain->DeleteBlockNotification($id);
5. 获取回调日志
/** * @param string $callback callback url * @return array<LogResponse> * @throws \GuzzleHttp\Exception\GuzzleException */ $blockchain->CallbackLogs($callback);
更新日志
请参阅更新日志以获取更多最近更改的信息。
贡献
请参阅贡献指南以获取详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件cyberman9000@gmail.com报告,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。请参阅许可证文件以获取更多信息。