pay

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2018 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultBoltOptions = BoltOptions{
	Path: "ln-paywall.db",
}

DefaultBoltOptions is a BoltOptions object with default values. Path: "ln-paywall.db"

View Source
var DefaultInvoiceOptions = InvoiceOptions{
	Price: 1,
	Memo:  "API call",
}

DefaultInvoiceOptions provides default values for InvoiceOptions.

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

DefaultLNDoptions provides default values for LNDoptions.

View Source
var DefaultRedisOptions = RedisOptions{
	Address: "localhost:6379",
}

DefaultRedisOptions is a RedisOptions object with default values. Address: "localhost:6379", Password: "", DB: 0

Functions

func NewEchoMiddleware added in v0.3.0

func NewEchoMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient, skipper middleware.Skipper) echo.MiddlewareFunc

NewEchoMiddleware returns an Echo middleware in the form of an echo.MiddlewareFunc.

func NewGinMiddleware

func NewGinMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) gin.HandlerFunc

NewGinMiddleware returns a Gin middleware in the form of a gin.HandlerFunc.

func NewHandlerFuncMiddleware

func NewHandlerFuncMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) func(http.HandlerFunc) http.HandlerFunc

NewHandlerFuncMiddleware returns a function which you can use within an http.HandlerFunc chain.

func NewHandlerMiddleware

func NewHandlerMiddleware(invoiceOptions InvoiceOptions, lndOptions LNDoptions, storageClient StorageClient) func(http.Handler) http.Handler

NewHandlerMiddleware returns a function which you can use within an http.Handler chain.

Types

type BoltClient added in v0.3.0

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

BoltClient is a StorageClient implementation for bbolt (formerly known as Bolt / Bolt DB).

func NewBoltClient added in v0.3.0

func NewBoltClient(boltOptions BoltOptions) (BoltClient, error)

NewBoltClient creates a new BoltClient. Note: Bolt uses an exclusive write lock on the database file so it cannot be shared by multiple processes. This shouldn't be a problem when you use one file for one middleware, like this:

// ...
boltClient, err := pay.NewBoltClient(pay.DefaultBoltOptions) // Uses file "ln-paywall.db"
if err != nil {
    panic(err)
}
defer boltClient.Close()
r.Use(pay.NewGinMiddleware(invoiceOptions, lndOptions, boltClient))
// ...

Also don't worry about closing the Bolt DB, the middleware opens it once and uses it for the duration of its lifetime. When the web service is stopped, the DB file lock is released automatically.

func (BoltClient) SetUsed added in v0.3.0

func (c BoltClient) SetUsed(preimage string) error

SetUsed stores the information that a preimage has been used for a payment.

func (BoltClient) WasUsed added in v0.3.0

func (c BoltClient) WasUsed(preimage string) (bool, error)

WasUsed checks if the preimage was used for a previous payment already.

type BoltOptions added in v0.3.0

type BoltOptions struct {
	// Path of the DB file.
	// Optional ("ln-paywall.db" by default).
	Path string
}

BoltOptions are the options for the BoltClient.

type GoMap added in v0.2.0

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

GoMap is a StorageClient implementation for a simple Go sync.Map.

func NewGoMap added in v0.2.0

func NewGoMap() GoMap

NewGoMap creates a new GoMap.

func (GoMap) SetUsed added in v0.2.0

func (m GoMap) SetUsed(preimage string) error

SetUsed stores the information that a preimage has been used for a payment.

func (GoMap) WasUsed added in v0.2.0

func (m GoMap) WasUsed(preimage string) (bool, error)

WasUsed checks if the preimage was used for a previous payment already.

type InvoiceOptions

type InvoiceOptions struct {
	// Amount of Satoshis you want to have paid for one API call.
	// Values below 1 are automatically changed to the default value.
	// Optional (1 by default).
	Price int64
	// Note to be shown on the invoice,
	// for example: "API call to api.example.com".
	// Optional ("" by default).
	Memo string
}

InvoiceOptions are the options for an invoice.

type LNDoptions

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 "invoice.macaroon" file that your LND node uses.
	// Optional ("invoice.macaroon" by default).
	MacaroonFile string
}

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

type LNclient added in v0.3.0

type LNclient interface {
	GenerateInvoice(int64, string) (string, error)
	CheckInvoice(string) (bool, error)
}

LNclient is an abstraction of a client that connects to a Lightning Network node implementation (like lnd, c-lightning and eclair) and provides the methods required by the paywall.

type RedisClient added in v0.2.0

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

RedisClient is a StorageClient implementation for Redis.

func NewRedisClient added in v0.2.0

func NewRedisClient(redisOptions RedisOptions) RedisClient

NewRedisClient creates a new RedisClient.

func (RedisClient) SetUsed added in v0.2.0

func (c RedisClient) SetUsed(preimage string) error

SetUsed stores the information that a preimage has been used for a payment.

func (RedisClient) WasUsed added in v0.2.0

func (c RedisClient) WasUsed(preimage string) (bool, error)

WasUsed checks if the preimage was used for a previous payment already.

type RedisOptions

type RedisOptions struct {
	// Address of the Redis server, including the port.
	// Optional ("localhost:6379" by default).
	Address string
	// Password for the Redis server.
	// Optional ("" by default).
	Password string
	// DB to use.
	// Optional (0 by default).
	DB int
}

RedisOptions are the options for the Redis DB.

type StorageClient added in v0.2.0

type StorageClient interface {
	WasUsed(string) (bool, error)
	SetUsed(string) error
}

StorageClient is an abstraction for different storage client implementations. A storage client must only be able to check if a preimage was already used for a payment bofore and to store a preimage that was used before.

Jump to

Keyboard shortcuts

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