Go middleware for monetizing your API on a per-request basis with Bitcoin and Lightning ⚡️
storage.NewBoltClient(...)
contained usage suggestions that would lead to the possibility of clients cheating with reusing preimagesln.Invoice
struct the whole struct was logged instead of just the invoice stringNote: The following breaking changes don't affect normal users of the package, but only those who use their own implementations of our interfaces.
ln.Invoice
now has a field ImplDepID string
which is required by the middlewares. It's an LN node implementation dependent ID (e.g. payment hash for lnd, some random string for Lightning Charge). (Required for issue #28.)wall.LNclient
now requires the method CheckInvoice(string) (bool, error)
to accept the LN node implementation dependent ID instead of the preimage hash as parameter. (Required for issue #28.)pay
(issue #20)
pay.LNclient
- Abstraction of a Lightning Network node client for paying LN invoices. Enables developers to write their own implementations if the provided ones aren't enough.pay.Client
- Replacement for a standard Go http.Client
NewClient(httpClient *http.Client, lnClient LNclient) Client
- httpClient
can be passed as nil
, leading to http.DefaultClient
being usedDo(req *http.Request) (*http.Response, error)
- Meant to be used as equivalent to the same Go http.Client
method, but handles the Lightning Network payment in the background.Get(url string) (*http.Response, error)
- A convenience method for the Do(...)
method, also an equivalent to the same Go http.Client
method (regarding its usage)examples/client/main.go
Note: Currently only
ln.LNDclient
can be used in the client, because Lightning Charge doesn't support sending payments (and maybe never will)
Pay(invoice string) (string, error)
for ln.LNDclient
- Implements the new pay.LNclient
interface, so that the LNDclient
can be used as parameter in the pay.NewClient(...)
function. (Issue #20)stderr
instead of stdout
X-Preimage
header must now be hex encoded instead of Base64 encoded. The hex encoded representation is the typical representation, as used by "lncli listpayments", Eclair on Android and bolt11 payment request decoders like https://lndecode.com. Base64 was used previously because "lncli listinvoices" uses that encoding. (Issue #8)wall.StorageClient
and thus all its implementations in the storage
package were significantly changed. The methods are now completely independent of any ln-paywall specifics, with Set(...)
and Get(...)
just setting and retrieving any arbitrary interface{}
to/from the storage. (Required for issue #16.)GenerateInvoice(int64, string) (string, error)
in the interface wall.LNclient
was changed to return a ln.Invoice
object, which makes it much easier to access the invoice ID (a.k.a. preimage hash, a.k.a. payment hash), instead of having to decode the invoice. (Useful for issue #16, in which the invoice ID is required as key in the storage.)Warning: This release contains a lot of renamings and refactorings, so your code will most definitely break. But it paves the way to upcoming features and makes some things easier, like automated testing.
400 Bad Request
is returned instead of a 500 Internal Server Error
. (Issue #11)pay
to wall
- this enables us to create a package called pay
for client-side payments to the paywall in the futurestorage
LNDoptions
and DefaultLNDoptions
to the from the wall
(former pay
) package to the ln
package
LNclient
as second parameter instead of LNDoptions
pay.NewEchoMiddleware(...)
- A middleware factory function for Echo (issue #2)pay.BoltClient
- Implements the StorageClient
interfaceNewBoltClient(...)
pay.BoltOptions
- Options for the BoltClient
pay.DefaultBoltOptions
- a BoltOptions
object with default valuespay.LNclient
- An abstraction of a client that connects to a Lightning Network node implementation (like lnd, c-lightning and eclair)
ln.LNDclient
- Implements the pay.LNclient
interface (issue #4)
ln.NewLNDclient(...)
pay.GoMap
as storage client, remote lnd, same hardware) it took about 100ms per request before, and takes about 25ms per request now. Measured from the arrival of the initial request until the sending of the response with the Lightning invoice (as logged by Gin).400 Bad Request
instead of 500 Internal Server Error
)Package pay
:
pay.InvoiceOptions.Amount
to pay.InvoiceOptions.Price
to avoid misunderstandingsPackage ln
(none of these changes should affect anyone, because this package is meant to be used only internally):
ln.NewLightningClient(...)
- Not required anymore after adding the much more usable ln.NewLNDclient(...)
.ln.GenerateInvoice(...)
from being a function to being a method of ln.LNDclient
and removed all lnd connection-related parameters which are part of the LNDclient
. (issue #4)ln.CheckInvoice(...)
from being a function to being a method of ln.LNDclient
and removed all lnd connection-related parameters which are part of the LNDclient
. (issue #4)pay.StorageClient
- an abstraction for multiple storage clients, which allows you to write your own storage client for storing the preimages that have already been used as payment proof in a request (issue #1)
WasUsed(string) (bool, error)
and SetUsed(string) error
pay.RedisClient
- implements the StorageClient
interface (issue #1)
NewRedisClient(...)
pay.DefaultRedisOptions
- a RedisOptions
object with default valuespay.GoMap
- implements the StorageClient
interface (issue #1)
NewGoMap()
x-preimage
header are received (invalid because the preimage was already used) - Instead of first getting a corresponding invoice for a preimage from the lnd and then checking if the preimage was used already, the order of these operations was switched, because then, if the preimage was already used, no request to lnd needs to be made anymore.pay.RedisOptions
are now optionalPackage pay
:
pay.NewHandlerFuncMiddleware(...)
, pay.NewHandlerMiddleware(...)
and pay.NewGinMiddleware(...)
now take a ln.StorageClient
instead of a *redis.Client
as parameter (issue #1)Package ln
(none of these changes should affect anyone, because this package is meant to be used only internally):
ln.CheckPreimage(...)
was renamed to ln.CheckInvoice(...)
and doesn't check the storage anymore. The ln
methods are supposed to just handle lightning related things and nothing else.lnrpc
- Instead of using our own generated lnd gRPC Go file, import the one from Lightning Labs.Initial release after working on the project during the "Chainhack 3" Blockchain hackathon.