ln

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2018 License: MPL-2.0 Imports: 16 Imported by: 40

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(id string) (bool, error)

CheckInvoice takes an invoice ID (LN node implementation specific) and checks if the corresponding invoice was settled. An error is returned if the invoice info couldn't be fetched from Lightning Charge or deserialized etc. False is returned if the invoice isn't settled.

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 unique identifier for the invoice in the LN node.
	// The value depends on the LN node implementation.
	//
	// For example, lnd uses the payment hash (a.k.a. preimage hash) as ID.
	// It doesn't use this term ("ID"), but when fetching a single invoice via RPC,
	// the payment hash is used as identifier.
	// Also, Lightning Lab's (creators of lnd) desktop app "Lightning" explicitly shows
	// the payment hash in a field with the title "invoice ID" in the Lightning transaction overview.
	//
	// But Lightning Charge on the other hand generates its own timestamp-based ID for each invoice.
	// They explicitly call that value "invoice ID" and they also require it when fetching a single invoice
	// via Lightning Charge's RESTful API.
	ImplDepID string
	// A.k.a. preimage hash. 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 an invoice.
	PaymentHash string
	// 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
}

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(id string) (bool, error)

CheckInvoice takes an invoice ID (LN node implementation specific) and checks if the corresponding invoice was settled. An error is returned 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