ln

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2018 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package ln contains the Lightning Network-related code.

There should be no need to use this package when implementing a web service that uses ln-paywall.

Index

Constants

This section is empty.

Variables

View Source
var DefaultChargeOptions = ChargeOptions{
	Address: "http://localhost:9112",
}

DefaultChargeOptions provides default values for ChargeOptions.

View Source
var DefaultLNDoptions = LNDoptions{
	Address:      "localhost:10009",
	CertFile:     "tls.cert",
	MacaroonFile: "invoice.macaroon",
}

DefaultLNDoptions provides default values for LNDoptions.

Functions

func HashPreimage

func HashPreimage(preimageHex string) (string, error)

HashPreimage turns a hex encoded preimage into a hex encoded preimage hash. It's the same format that's being used by "lncli listpayments", Eclair on Android and bolt11 payment request decoders like https://lndecode.com. Only "lncli listinvoices" uses Base64.

Types

type ChargeClient added in v0.5.0

type ChargeClient struct {
	// contains filtered or unexported fields
}

ChargeClient is an implementation of the wall.LNclient interface for "Lightning Charge" running on top of the c-lightning Lightning Network node implementation.

func NewChargeClient added in v0.5.0

func NewChargeClient(chargeOptions ChargeOptions) (ChargeClient, error)

NewChargeClient creates a new ChargeClient instance.

func (ChargeClient) CheckInvoice added in v0.5.0

func (c ChargeClient) CheckInvoice(preimageHex string) (bool, error)

CheckInvoice takes a hex encoded preimage and checks if the corresponding invoice was settled. This is done by fetching ALL invoices (for reasons outlined below) and looking for a matching preimage hash, then checking if the found invoice was settled. An error is returned if the preimage isn't properly encoded or if no corresponding invoice was found. False is returned if the invoice isn't settled.

Implementation notes: Lightning Charge doesn't allow to fetch an invoice via a preimage or preimage hash, which is fine by itself, but doesn't fit our implementation, which was focused on lnd at first (which allows to fetch invoices via preimage hash). In the future, for multiple reasons (for example GitHub issue #16), the client won't send the preimage anymore but just a token, similar to or the same as with ElementProject's paypercall.

func (ChargeClient) GenerateInvoice added in v0.5.0

func (c ChargeClient) GenerateInvoice(amount int64, memo string) (Invoice, error)

GenerateInvoice generates an invoice with the given price and memo.

type ChargeOptions added in v0.5.0

type ChargeOptions struct {
	// Address of your Lightning Charge server, including the protocol (e.g. "https://") and port.
	// Optional ("http://localhost:9112" by default).
	Address string
	// APItoken for authenticating the request to Lightning Charge.
	// The token is configured when Lightning Charge is started.
	APItoken string
}

ChargeOptions are the options for the connection to Lightning Charge.

type Invoice added in v0.5.0

type Invoice struct {
	// The actual invoice string required by the payer in Bech32 encoding,
	// see https://github.com/lightningnetwork/lightning-rfc/blob/master/11-payment-encoding.md
	PaymentRequest string
	// A.k.a. preimage hash, a.k.a. invoice ID. Hex encoded.
	// Could be extracted from the PaymentRequest, but that would require additional
	// dependencies during build time and additional computation during runtime,
	// while all Lightning Node implementation clients already return the value directly
	// when generating a new invoice.
	PaymentHash string
}

Invoice is a Lightning Network invoice and contains the typical invoice string and the payment hash.

type LNDclient added in v0.3.0

type LNDclient struct {
	// contains filtered or unexported fields
}

LNDclient is an implementation of the wall.LNClient and pay.LNClient interface for the lnd Lightning Network node implementation.

func NewLNDclient added in v0.3.0

func NewLNDclient(lndOptions LNDoptions) (LNDclient, error)

NewLNDclient creates a new LNDclient instance.

func (LNDclient) CheckInvoice added in v0.3.0

func (c LNDclient) CheckInvoice(preimageHex string) (bool, error)

CheckInvoice takes a hex encoded preimage and checks if the corresponding invoice was settled. An error is returned if the preimage isn't properly encoded or if no corresponding invoice was found. False is returned if the invoice isn't settled.

func (LNDclient) GenerateInvoice added in v0.3.0

func (c LNDclient) GenerateInvoice(amount int64, memo string) (Invoice, error)

GenerateInvoice generates an invoice with the given price and memo.

func (LNDclient) Pay added in v0.5.0

func (c LNDclient) Pay(invoice string) (string, error)

Pay pays the invoice and returns the preimage (hex encoded) on success, or an error on failure.

type LNDoptions added in v0.4.0

type LNDoptions struct {
	// Address of your LND node, including the port.
	// Optional ("localhost:10009" by default).
	Address string
	// Path to the "tls.cert" file that your LND node uses.
	// Optional ("tls.cert" by default).
	CertFile string
	// Path to the macaroon file that your LND node uses.
	// "invoice.macaroon" if you only use the GenerateInvoice() and CheckInvoice() methods
	// (required by the middleware in the package "wall").
	// "admin.macaroon" if you use the Pay() method (required by the client in the package "pay").
	// Optional ("invoice.macaroon" by default).
	MacaroonFile string
}

LNDoptions are the options for the connection to the lnd node.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL