项目作者: Jorijn

项目描述 :
A PHP library for decoding lightning network payment requests as defined in BOLT #11.
高级语言: PHP
项目地址: git://github.com/Jorijn/bitcoin-bolt11.git
创建时间: 2021-01-10T17:33:48Z
项目社区:https://github.com/Jorijn/bitcoin-bolt11

开源协议:MIT License

下载


A PHP library for BOLT #11: Invoice Protocol for Lightning Payments

Latest Stable Version
Total Downloads
License
PHPUnit Tests

This library aims to be a tool to decode BOLT #11 Payment Requests into usable PHP objects. Currently, only decoding is supported.

BOLT #11 is a simple, extendable, QR-code-ready protocol for requesting payments over Lightning.

Installation

  1. $ composer require jorijn/bitcoin-bolt11

Usage

  1. $invoice = 'lnbc9678785340p1pwmna7lpp5gc3xfm08u9qy06djf8dfflhugl6p7lgza6dsjxq454gxhj9t7a0sd8dgfkx7cmtwd68yetpd5s9xar0wfjn5gpc8qhrsdfq24f5ggrxdaezqsnvda3kkum5wfjkzmfqf3jkgem9wgsyuctwdus9xgrcyqcjcgpzgfskx6eqf9hzqnteypzxz7fzypfhg6trddjhygrcyqezcgpzfysywmm5ypxxjemgw3hxjmn8yptk7untd9hxwg3q2d6xjcmtv4ezq7pqxgsxzmnyyqcjqmt0wfjjq6t5v4khxxqyjw5qcqp2rzjq0gxwkzc8w6323m55m4jyxcjwmy7stt9hwkwe2qxmy8zpsgg7jcuwz87fcqqeuqqqyqqqqlgqqqqn3qq9qn07ytgrxxzad9hc4xt3mawjjt8znfv8xzscs7007v9gh9j569lencxa8xeujzkxs0uamak9aln6ez02uunw6rd2ht2sqe4hz8thcdagpleym0j';
  2. $decoder = new \Jorijn\Bitcoin\Bolt11\Encoder\PaymentRequestDecoder();
  3. $denormalizer = new \Jorijn\Bitcoin\Bolt11\Normalizer\PaymentRequestDenormalizer();
  4. $paymentRequest = $denormalizer->denormalize($decoder->decode($invoice));
  5. // satoshis: 967878
  6. echo 'satoshis: ' . $paymentRequest->getSatoshis();
  7. // description: Blockstream Store: 88.85 USD for Blockstream Ledger Nano S x 1, "Back In My Day" Sticker x 2, "I Got Lightning Working" Sticker x 2 and 1 more items
  8. echo 'description: ' . $paymentRequest->findTagByName(\Jorijn\Bitcoin\Bolt11\Model\Tag::DESCRIPTION)->getData();
  9. // timestamp: DateTime Object
  10. // (
  11. // [date] => 2019-10-30 20:51:43.000000
  12. // [timezone_type] => 1
  13. // [timezone] => +00:00
  14. // )
  15. echo 'timestamp: ' . print_r($paymentRequest->getTimestampDateTime(), true);
  16. // hop: 0
  17. // public key: 029e03a901b85534ff1e92c43c74431f7ce72046060fcf7a95c37e148f78c77255
  18. // short channel id: 0102030405060708
  19. // fee base msat: 1
  20. // fee proportional millionths 20
  21. // cltv expiry delta: 3
  22. foreach ($paymentRequest->findTagByName(\Jorijn\Bitcoin\Bolt11\Model\Tag::ROUTING_INFO)->getData() as $hop => $routingInfo) {
  23. echo 'hop: ' . $hop;
  24. echo 'public key: ' . $routingInfo->getPubKey();
  25. echo 'short channel id: ' . $routingInfo->getShortChannelId();
  26. echo 'fee base msat: ' . $routingInfo->getFeeBaseMsat();
  27. echo 'fee proportional millionths ' . $routingInfo->getFeeProportionalMillionths();
  28. echo 'cltv expiry delta: ' . $routingInfo->getCltvExpiryDelta();
  29. }

More examples are available in the examples directory.

Warning

The ->getSatoshis() method will only return a valid number if the invoice is for a whole number of satoshis. If it is in a fractional number of satoshis, and the method returns NULL, the ->getMilliSatoshis() method must be used. 1000 millisatoshis is 1 satoshi.

Thanks

This library is based on other BOLT #11 libraries from other programming languages. Special thanks to:

CLI tool

There is a CLI tool based on this library. It allows for easy decoding and converting of payment requests into JSON, XML, YAML & CSV. Download and usage here: https://github.com/Jorijn/bitcoin-bolt11-cli