module Lightning
Namespace for classes and modules that handle communication with your LND node
Namespace for classes and modules that handle communication with your LND node
Namespace for classes and modules that handle communication with your LND node
Namespace for classes and modules that handle communication with your LND node
Namespace for classes and modules that handle communication with your LND node
Constants
- VERSION
Current SDK version number.
Attributes
Public Class Methods
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.
@option args [Integer] :amt (0)
Amount in satoshis
@option args [Integer] :expiry (3600)
Payment request expiry time in seconds.
@option args [String] :memo ('')
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.
@example Create a new invoice
Lightning.addinvoice(amt: 500, memo: '1x Cappuccino')
@return [Lnrpc::AddInvoiceResponse]
# 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 takes an encoded payment request string and attempts to decode it, returning a full description of the conditions encoded within the payment request.
@param [String] pay_req The payment request string to be decoded
@example Decode a payment request
Lightning.decodepayreq("lnbc5u1pwt0...qxht38d")
@return [Lnrpc::PayReq]
# 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
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.
@example Receive node info
Lightning.getinfo
@return [Lnrpc::GetInfoResponse]
# File lib/lightning/node.rb, line 12 def getinfo stub.get_info(Lnrpc::GetInfoRequest.new) end
Listinvoices 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.
@option args [Integer] :num_max_invoices (100)
The max number of invoices to return in the response to this query.
@option args [Integer] :index_offset (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.
@option args [Boolean] :pending_only (false)
If set, only unsettled invoices will be returned in the response.
@option args [Boolean] :reversed (false)
If set, the invoices returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards.
@example List all invoices
Lightning.listinvoices
@return [Lnrpc::ListInvoiceResponse]
# 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
Private Class Methods
Get SSL credentials from the tls.cert file generated by LND. This file is normally generated by LND and will be created by default at ~/.lnd/tls.cert on the server running your LND node. We will use it to establish a secured connection between your app and the node/server. @since 0.1.0 @return [GRPC::Core::ChannelCredentials]
# File lib/lightning/stub.rb, line 54 def credentials ENV['GRPC_SSL_CIPHER_SUITES'] = ENV['GRPC_SSL_CIPHER_SUITES'] || 'HIGH+ECDSA' certificate = File.read(File.expand_path(config[:certificate_path])) GRPC::Core::ChannelCredentials.new(certificate) end
Macaroon files works like cookies and are used to authenticate with LND gRPC. By default, when lnd starts, it creates three files which contain macaroons: a file called admin.macaroon, which contains a macaroon with no caveats, a file called readonly.macaroon, which is the same macaroon but with an additional caveat, that permits only methods that don't change the state of lnd, and invoice.macaroon, which only has access to invoice related methods. You can learn more about LND macaroons at: tiny.cc/1nuc5y @since 0.1.0 @return [Binary]
# File lib/lightning/stub.rb, line 39 def macaroon macaroon_binary = File.read( File.expand_path(config[:macaroon_path]) ) macaroon_binary.each_byte.map { |b| b.to_s(16).rjust(2, '0') }.join end
On the client side, the client has a local object known as stub (for other languages, the preferred term is client) that implements the same methods as the service. The client can then just call those methods on the local object, wrapping the parameters for the call in the appropriate protocol buffer message type - gRPC looks after sending the request(s) to the server and returning the server's protocol buffer response(s). Read more about stubs at: tiny.cc/nwuc5y. We're using a pre-generated stub created with inspiration from the tutorial at: github.com/lightningnetwork/lnd/blob/master/docs/grpc/ruby.md @since 0.1.0 @return [Lnrpc::Lightning::Stub]
# File lib/lightning/stub.rb, line 21 def stub Lnrpc::Lightning::Stub.new( '127.0.0.1:10009', credentials, interceptors: [MacaroonInterceptor.new(macaroon)] ) end