Class: Lightning::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/lightning/invoice.rb

Class Method Summary collapse

Class Method Details

.add(**args) ⇒ Lnrpc::AddInvoiceResponse

Attempts to add a new invoice to the invoice database and returns a payment request.

Examples:

Create a new invoice

Lightning::Invoice.add(value: 500, memo: '1x Cappuccino')

Parameters:

  • args (Hash)

    a customizable set of options

Options Hash (**args):

  • :value (Integer) — default: 0

    Amount in satoshis

  • :expiry (Integer) — default: 3600

    Payment request expiry time in seconds.

  • :memo (String) — default: ''

    An optional memo to attach along with the invoice. Used for record keeping purposes for the invoices creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used.

Returns:

  • (Lnrpc::AddInvoiceResponse)

    response



23
24
25
26
27
28
29
30
31
# File 'lib/lightning/invoice.rb', line 23

def add(**args)
  value = args[:value]
  expiry = args[:expiry]
  memo = args[:memo]

  return_res stub.add_invoice(
    Lnrpc::Invoice.new(value: value, expiry: expiry, memo: memo)
  )
end

.list(**args) ⇒ Lnrpc::ListInvoiceResponse

Returns a list of all the invoices currently stored within the database. Any active debug invoices are ignored. It has full support for paginated responses, allowing users to query for specific invoices through their add_index. This can be done by using either the first_index_offset or last_index_offset fields included in the response as the index_offset of the next request. By default, the first 100 invoices created will be returned. Backwards pagination is also supported through the Reversed flag.

Examples:

List all invoices

Lightning::Invoice.list

Returns:

  • (Lnrpc::ListInvoiceResponse)

    response



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/lightning/invoice.rb', line 46

def list(**args)
  num_max_invoices = args[:num_max_invoices]
  index_offset = args[:index_offset]
  pending_only = args[:pending_only]
  reversed = args[:reversed]

  return_res stub.list_invoices(
    Lnrpc::ListInvoiceRequest.new(
      num_max_invoices: num_max_invoices, index_offset: index_offset,
      pending_only: pending_only, reversed: reversed
    )
  )
end