Module: Lightning

Defined in:
lib/lnd_ruby_sdk.rb,
lib/lightning/node.rb,
lib/lightning/stub.rb,
lib/lightning/version.rb,
lib/lightning/invoices.rb

Overview

Namespace for classes and modules that handle communication with your LND node

Constant Summary collapse

VERSION =

Current SDK version number.

'0.1.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject

Returns the value of attribute config



15
16
17
# File 'lib/lnd_ruby_sdk.rb', line 15

def config
  @config
end

Class Method Details

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

Add a new invoice, expressing intent for a future payment. Invoices without an amount can be created by not supplying any parameters or providing an amount of 0. These invoices allow the payee to specify the amount of satoshis they wish to send.

Examples:

Create a new invoice

Lightning.addinvoice(amt: 500, memo: '1x Cappuccino')

Parameters:

  • args (Hash)

    a customizable set of options

Options Hash (**args):

  • :amt (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)


25
26
27
28
29
30
31
32
33
# File 'lib/lightning/invoices.rb', line 25

def addinvoice(**args)
  amt = args[:amt]
  expiry = args[:expiry]
  memo = args[:memo]

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

.decodepayreq(pay_req) ⇒ Lnrpc::PayReq

DecodePayReq takes an encoded payment request string and attempts to decode it, returning a full description of the conditions encoded within the payment request.

Examples:

Decode a payment request

Lightning.decodepayreq("lnbc5u1pwt0...qxht38d")

Parameters:

  • pay_req (String)

    The payment request string to be decoded

Returns:

  • (Lnrpc::PayReq)


45
46
47
48
# File 'lib/lightning/invoices.rb', line 45

def decodepayreq(pay_req)
  opts = { pay_req: pay_req }
  stub.decode_pay_req(Lnrpc::PayReqString.new(opts))
end

.getinfoLnrpc::GetInfoResponse

Returns general information concerning the lightning node including it's identity pubkey, alias, the chains it is connected to, and information concerning the number of open+pending channels.

Examples:

Receive node info

Lightning.getinfo

Returns:

  • (Lnrpc::GetInfoResponse)


12
13
14
# File 'lib/lightning/node.rb', line 12

def getinfo
  stub.get_info(Lnrpc::GetInfoRequest.new)
end

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

This command enables the retrieval of all invoices currently stored within the database. It has full support for paginationed 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. The reversed flag is set by default in order to paginate backwards. If you wish to paginate forwards, you must explicitly set the flag to false. If none of the parameters are specified, then the last 100 invoices will be returned. For example: if you have 200 invoices, “listinvoices” will return the last 100 created. If you wish to retrieve the previous 100, the first_offset_index of the response can be used as the index_offset of the next listinvoices request.

Examples:

List all invoices

Lightning.listinvoices

Parameters:

  • args (Hash)

    a customizable set of options

Options Hash (**args):

  • :num_max_invoices (Integer) — default: 100

    The max number of invoices to return in the response to this query.

  • :index_offset (Integer) — default: 0

    The index of an invoice that will be used as either the start or end of a query to determine which invoices should be returned in the response.

  • :pending_only (Boolean) — default: false

    If set, only unsettled invoices will be returned in the response.

  • :reversed (Boolean) — default: false

    If set, the invoices returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards.

Returns:

  • (Lnrpc::ListInvoiceResponse)


82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/lightning/invoices.rb', line 82

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

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