Module: Hodl::Server::Services

Included in:
Lightning::Server
Defined in:
lib/hodl/server/services.rb

Instance Method Summary collapse

Instance Method Details

#abandon_channel(channel_point:) ⇒ Object

Parameters: channel_point ChannelPoint



200
201
202
# File 'lib/hodl/server/services.rb', line 200

def abandon_channel(channel_point:)
  stub.abandon_channel(Lnrpc::AbandonChannelRequest.new(channel_point: channel_point))
end

#add_invoice(memo: nil, r_preimage: nil, r_hash: nil, value: nil, settled: nil, creation_date: nil, settle_date: nil, payment_request: nil, description_hash: nil, expiry: nil, fallback_addr: nil, cltv_expiry: nil, route_hints: nil, private_invoice: nil, add_index: nil, settle_index: nil, amt_paid_sat: nil, amt_paid_msat: nil, state: nil) ⇒ Object

Parameters: memo string An optional memo to attach along with the invoice. Used for record keeping purposes for the invoice’s creator, and will also be set in the description field of the encoded payment request if the description_hash field is not being used. r_preimage bytes The hex-encoded preimage (32 byte) which will allow settling an incoming HTLC payable to this preimage r_hash bytes The hash of the preimage value int64 The value of this invoice in satoshis settled bool Whether this invoice has been fulfilled creation_date int64 When this invoice was created settle_date int64 When this invoice was settled payment_request string A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. description_hash bytes Hash (SHA-256) of a description of the payment. Used if the description of payment (memo) is too long to naturally fit within the description field of an encoded payment request. expiry int64 Payment request expiry time in seconds. Default is 3600 (1 hour). fallback_addr string Fallback on-chain address. cltv_expiry uint64 Delta to use for the time-lock of the CLTV extended to the final hop. route_hints array RouteHint Route hints that can each be individually used to assist in reaching the invoice’s destination. private bool Whether this invoice should include routing hints for private channels. add_index uint64 The “add” index of this invoice. Each newly created invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all added invoices with an add_index greater than this one. settle_index uint64 The “settle” index of this invoice. Each newly settled invoice will increment this index making it monotonically increasing. Callers to the SubscribeInvoices call can use this to instantly get notified of all settled invoices with an settle_index greater than this one. amt_paid_sat int64 The amount that was accepted for this invoice, in satoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it’s possible that the sender paid MORE that was specified in the original invoice. So we’ll record that here as well. amt_paid_msat int64 The amount that was accepted for this invoice, in millisatoshis. This will ONLY be set if this invoice has been settled. We provide this field as if the invoice was created with a zero value, then we need to record what amount was ultimately accepted. Additionally, it’s possible that the sender paid MORE that was specified in the original invoice. So we’ll record that here as well. state InvoiceState



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/hodl/server/services.rb', line 254

def add_invoice(memo:nil, r_preimage:nil, r_hash:nil, value:nil, settled:nil, creation_date:nil, settle_date:nil, payment_request:nil, description_hash:nil, expiry:nil,
                   fallback_addr:nil, cltv_expiry:nil, route_hints:nil, private_invoice:nil, add_index:nil, settle_index:nil, amt_paid_sat:nil, amt_paid_msat:nil, state:nil)
	stub.add_invoice(Lnrpc::Invoice.new(memo: memo,
                                         r_preimage: r_preimage,
                                         r_hash: r_hash,
                                         value: value,
                                         settled: settled,
                                         creation_date: creation_date,
                                         settle_date: settle_date,
                                         payment_request: payment_request,
                                         description_hash: description_hash,
                                         expiry: expiry,
                                         fallback_addr: fallback_addr,
                                         cltv_expiry: cltv_expiry,
                                         route_hints: route_hints,
                                         private: private_invoice,
                                         add_index: add_index,
                                         settle_index: settle_index,
                                         amt_paid_sat: amt_paid_sat,
                                         amt_paid_msat: amt_paid_msat,
                                         state: state))
end

#channel_balanceObject

ChannelBalance returns the total funds available across all open channels in satoshis.



13
14
15
# File 'lib/hodl/server/services.rb', line 13

def channel_balance
  stub.channel_balance(Lnrpc::ChannelBalanceRequest.new)
end

#close_channel(channel_point:, force: nil, target_conf: nil, sat_per_byte: nil) ⇒ Object

Parameters: channel_point ChannelPoint The outpoint (txid:index) of the funding transaction. With this value, Bob will be able to generate a signature for Alice’s version of the commitment transaction. force bool If true, then the channel will be closed forcibly. This means the current commitment transaction will be signed and broadcast. target_conf int32 The target number of blocks that the closure transaction should be confirmed by. sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the closure transaction.



187
188
189
190
191
192
# File 'lib/hodl/server/services.rb', line 187

def close_channel(channel_point:, force:nil, target_conf:nil, sat_per_byte:nil)
  stub.close_channel(Lnrpc::CloseChannelRequest.new(channel_point: channel_point,
                                                       force:         force,
                                                       target_conf:   target_conf,
                                                       sat_per_byte:  sat_per_byte))
end

#closed_channels(cooperative: nil, local_force: nil, remote_force: nil, breach: nil, funding_canceled: nil, abandoned: nil) ⇒ Object

Parameters: cooperative bool local_force bool remote_force bool breach bool funding_canceled bool abandoned bool



136
137
138
139
140
141
142
143
# File 'lib/hodl/server/services.rb', line 136

def closed_channels(cooperative:nil, local_force:nil, remote_force:nil, breach:nil, funding_canceled:nil, abandoned:nil)
  stub.closed_channels(Lnrpc::ClosedChannelsRequest.new(cooperative:      cooperative,
                                                           local_force:      local_force,
                                                           remote_force:     remote_force,
                                                           breach:           breach,
                                                           funding_canceled: funding_canceled,
                                                           abandoned:        abandoned))
end

#connect_peer(addr:, perm: nil) ⇒ Object

Parameters: addr LightningAddress Lightning address of the peer, in the format <pubkey>@host perm bool If set, the daemon will attempt to persistently connect to the target peer.

Otherwise, the call will be synchronous.


82
83
84
# File 'lib/hodl/server/services.rb', line 82

def connect_peer(addr:, perm:nil)
  stub.connect_peer(Lnrpc::ConnectPeerRequest.new(addr: addr, perm: perm))
end

#decode_pay_req(pay_req:) ⇒ Object

Parameters pay_req string The payment request string to be decoded



312
313
314
# File 'lib/hodl/server/services.rb', line 312

def decode_pay_req(pay_req:)
  stub.decode_pay_req(Lnrpc::PayReqString.new(pay_req: pay_req))
end

#delete_all_payments(confirmed: false) ⇒ Object

DeleteAllPayments deletes all outgoing payments from DB.



322
323
324
# File 'lib/hodl/server/services.rb', line 322

def delete_all_payments(confirmed:false)
  stub.delete_all_payments(Lnrpc::DeleteAllPaymentsRequest.new) if confirmed
end

#disconnect_peer(pub_key:) ⇒ Object

Parameters: pub_key string The pubkey of the node to disconnect from



91
92
93
# File 'lib/hodl/server/services.rb', line 91

def disconnect_peer(pub_key:)
  stub.disconnect_peer(Lnrpc::DisconnectPeerRequest.new(pub_key: pub_key))
end

#fee_reportObject

FeeReport allows the caller to obtain a report detailing the current fee schedule enforced by the node globally for each channel.



377
378
379
# File 'lib/hodl/server/services.rb', line 377

def fee_report
  stub.fee_report(Lnrpc::FeeReportRequest.new)
end

#get_chan_info(chan_id:) ⇒ Object

Parameters chan_id uint64 The unique channel ID for the channel. The first 3 bytes are the block height, the next 3 the index within the block, and the last 2 bytes are the output index for the channel.



332
333
334
# File 'lib/hodl/server/services.rb', line 332

def get_chan_info(chan_id:)
  stub.get_chan_info(Lnrpc::ChanInfoRequest.new(chan_id: chan_id))
end

#get_infoObject

GetInfo 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.



102
103
104
# File 'lib/hodl/server/services.rb', line 102

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

#get_network_infoObject

GetNetworkInfo returns some basic stats about the known channel graph from the point of view of the node.



367
368
369
# File 'lib/hodl/server/services.rb', line 367

def get_network_info
  stub.get_network_info(Lnrpc::NetworkInfoRequest.new)
end

#get_node_info(pub_key:) ⇒ Object

Parameters pub_key string The 33-byte hex-encoded compressed public of the target node



341
342
343
# File 'lib/hodl/server/services.rb', line 341

def get_node_info(pub_key:)
  stub.get_node_info(Lnrpc::NodeInfoRequest.new(pub_key: pub_key))
end

#get_transactionsObject

GetTransactions returns a list describing all the known transactions relevant to the wallet.



18
19
20
# File 'lib/hodl/server/services.rb', line 18

def get_transactions
  stub.get_transactions(Lnrpc::GetTransactionsRequest.new)
end

#list_channels(active_only: nil, inactive_only: nil, public_only: nil, private_only: nil) ⇒ Object

Parameters: active_only bool inactive_only bool public_only bool private_only bool



120
121
122
123
124
125
# File 'lib/hodl/server/services.rb', line 120

def list_channels(active_only:nil, inactive_only:nil, public_only:nil, private_only:nil)
  stub.list_channels(Lnrpc::ListChannelsRequest.new(active_only:   active_only,
                                                       inactive_only: inactive_only,
                                                       public_only:   public_only,
                                                       private_only:  private_only))
end

#list_invoices(pending_only: nil, index_offset: nil, um_max_invoices: nil, reversed: nil) ⇒ Object

Parameters: pending_only bool If set, only unsettled invoices will be returned in the response. index_offset uint64 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. um_max_invoices uint64 The max number of invoices to return in the response to this query. reversed bool If set, the invoices returned will result from seeking backwards from the specified index offset. This can be used to paginate backwards.



289
290
291
292
293
294
# File 'lib/hodl/server/services.rb', line 289

def list_invoices(pending_only:nil, index_offset:nil, um_max_invoices:nil, reversed: nil)
	stub.list_invoices(Lnrpc::ListInvoiceRequest.new(pending_only:    pending_only,
                                                      index_offset:    index_offset,
                                                      um_max_invoices: um_max_invoices,
                                                      reversed:        reversed))
end

#list_paymentsObject

ListPayments returns a list of all outgoing payments.



317
318
319
# File 'lib/hodl/server/services.rb', line 317

def list_payments
  stub.list_payments(Lnrpc::PayReqString.new)
end

#list_peersObject

ListPeers returns a verbose listing of all currently active peers.



96
97
98
# File 'lib/hodl/server/services.rb', line 96

def list_peers
  stub.list_peers(Lnrpc::ListPeersRequest.new)
end

#list_unspent(min_confs:, max_confs:) ⇒ Object

Parameters: min_confs int32 The minimum number of confirmations to be included. max_confs int32 The maximum number of confirmations to be included.



62
63
64
# File 'lib/hodl/server/services.rb', line 62

def list_unspent(min_confs:, max_confs:)
  stub.list_unspent(Lnrpc::ListUnspentRequest.new(min_confs: min_confs, max_confs: max_confs))
end

#lookup_invoice(r_hash_str: nil, r_hash: nil) ⇒ Object

Parameters r_hash_str string The hex-encoded payment hash of the invoice to be looked up. The passed payment hash must be exactly 32 bytes, otherwise an error is returned. r_hash bytes The payment hash of the invoice to be looked up.



302
303
304
305
# File 'lib/hodl/server/services.rb', line 302

def lookup_invoice(r_hash_str: nil, r_hash: nil)
	stub.lookup_invoice(Lnrpc::PaymentHash.new(r_hash_str: r_hash_str,
                                                r_hash: r_hash))
end

#new_address(type:) ⇒ Object

Parameters: type AddressType The address type



70
71
72
# File 'lib/hodl/server/services.rb', line 70

def new_address(type:)
  stub.new_address(Lnrpc::NewAddressRequest.new(type: type))
end

#open_channel(node_pubkey: nil, node_pubkey_string:, local_funding_amount:, push_sat: nil, target_conf: nil, sat_per_byte: nil, private_channel: nil, min_htlc_msat: nil, remote_csv_delay: nil, min_confs: nil, spend_unconfirmed: nil) ⇒ Object

Parameters: node_pubkey bytes The pubkey of the node to open a channel with node_pubkey_string string The hex encoded pubkey of the node to open a channel with local_funding_amount int64 The number of satoshis the wallet should commit to the channel push_sat int64 The number of satoshis to push to the remote side as part of the initial commitment state target_conf int32 The target number of blocks that the funding transaction should be confirmed by. sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the funding transaction. private bool Whether this channel should be private, not announced to the greater network. min_htlc_msat int64 The minimum value in millisatoshi we will require for incoming HTLCs on the channel. remote_csv_delay uint32 The delay we require on the remote’s commitment transaction. If this is not set, it will be scaled automatically with the channel size. min_confs int32 The minimum number of confirmations each one of your outputs used for the funding transaction must satisfy. spend_unconfirmed bool Whether unconfirmed outputs should be use



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/hodl/server/services.rb', line 161

def open_channel(node_pubkey:nil, node_pubkey_string:, local_funding_amount:, push_sat:nil, target_conf:nil,
                    sat_per_byte:nil, private_channel:nil, min_htlc_msat:nil, remote_csv_delay:nil, min_confs:nil, spend_unconfirmed:nil)
  stub.open_channel(Lnrpc::OpenChannelRequest.new(node_pubkey:          node_pubkey,
                                                     node_pubkey_string:   node_pubkey_string,
                                                     local_funding_amount: local_funding_amount,
                                                     push_sat:             push_sat,
                                                     target_conf:          target_conf,
                                                     sat_per_byte:         sat_per_byte,
                                                     private:              private_channel,
                                                     min_htlc_msat:        min_htlc_msat,
                                                     remote_csv_delay:     remote_csv_delay,
                                                     min_confs:            min_confs,
                                                     spend_unconfirmed:    spend_unconfirmed))
end

#pending_channelsObject

PendingChannels returns a list of all the channels that are currently considered “pending”. A channel is pending if it has finished the funding workflow and is waiting for confirmations for the funding txn, or is in the process of closure, either initiated cooperatively or non-cooperatively.



109
110
111
# File 'lib/hodl/server/services.rb', line 109

def pending_channels
  stub.pending_channels(Lnrpc::PendingChannelsRequest.new)
end

#query_routes(pub_key: nil, amt: nil, final_cltv_delta: nil, fee_limit: nil, ignored_edges: nil, source_pub_key: nil, ignored_nodes: nil) ⇒ Object

Parameters pub_key string The 33-byte hex-encoded public key for the payment destination amt int64 The amount to send expressed in satoshis final_cltv_delta int32 An optional CLTV delta from the current height that should be used for the timelock of the final hop fee_limit FeeLimit The maximum number of satoshis that will be paid as a fee of the payment. This value can be represented either as a percentage of the amount being sent, or as a fixed amount of the maximum fee the user is willing the pay to send the payment. ignored_nodes array bytes A list of nodes to ignore during path finding. ignored_edges array EdgeLocator A list of edges to ignore during path finding. source_pub_key string The source node where the request route should originated from. If empty, self is assumed.



356
357
358
359
360
361
362
363
364
# File 'lib/hodl/server/services.rb', line 356

def query_routes(pub_key:nil, amt:nil, final_cltv_delta:nil, fee_limit:nil, ignored_edges:nil, source_pub_key:nil, ignored_nodes:nil)
  stub.query_routes(Lnrpc::QueryRoutesRequest.new(pub_key:          pub_key,
                                                  amt:              amt,
                                                  final_cltv_delta: final_cltv_delta,
                                                  fee_limit:        fee_limit,
                                                  ignored_nodes:    ignored_nodes,
                                                  ignored_edges:    ignored_edges,
                                                  source_pub_key:   source_pub_key))
end

#send_coins(addr:, amount:, target_conf: nil, sat_per_byte: nil, send_all: nil) ⇒ Object

Parameters: addr string The address to send coins to amount int64 The amount in satoshis to send target_conf int32 The target number of blocks that this transaction should be confirmed by. sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the transaction. send_all bool If set, then the amount field will be ignored, and lnd will attempt to send all the coins

under control of the internal wallet to the specified address.


34
35
36
37
38
39
40
# File 'lib/hodl/server/services.rb', line 34

def send_coins(addr:, amount:, target_conf:nil, sat_per_byte:nil, send_all:nil)
  stub.send_coins(Lnrpc::SendCoinsRequest.new(addr: addr,
                                                 amount: amount,
                                                 target_conf: target_conf,
                                                 sat_per_byte:sat_per_byte,
                                                 send_all: send_all))
end

#send_many(addr_to_amount_array, target_conf: nil, sat_per_byte: nil) ⇒ Object

Parameters: AddrToAmount array AddrToAmountEntry The map from addresses to amounts target_conf int32 The target number of blocks that this transaction should be confirmed by. sat_per_byte int64 A manual fee rate set in sat/byte that should be used when crafting the transaction.



50
51
52
53
54
# File 'lib/hodl/server/services.rb', line 50

def send_many(addr_to_amount_array, target_conf:nil, sat_per_byte:nil)
  stub.send_many(Lnrpc::SendManyRequest.new(addr_to_amount: addr_to_amount_array,
                                               target_conf: target_conf,
                                               sat_per_byte: sat_per_byte))
end

#send_payment_sync(dest: nil, dest_string: nil, amt: nil, payment_hash: nil, payment_hash_string: nil, payment_request: nil, final_cltv_delta: nil, fee_limit: nil, outgoing_chan_id: nil, cltv_limit: nil) ⇒ Object

Parameters: dest bytes The identity pubkey of the payment recipient dest_string string The hex-encoded identity pubkey of the payment recipient amt int64 Number of satoshis to send. payment_hash bytes The hash to use within the payment’s HTLC payment_hash_string string The hex-encoded hash to use within the payment’s HTLC payment_request string A bare-bones invoice for a payment within the Lightning Network. With the details of the invoice, the sender has all the data necessary to send a payment to the recipient. final_cltv_delta int32 The CLTV delta from the current height that should be used to set the timelock for the final hop. fee_limit FeeLimit The maximum number of satoshis that will be paid as a fee of the payment. This value can be represented either as a percentage of the amount being sent, or as a fixed amount of the maximum fee the user is willing the pay to send the payment. outgoing_chan_id uint64 The channel id of the channel that must be taken to the first hop. If zero, any channel may be used. cltv_limit uint32 An optional maximum total time lock for the route. If zero, there is no maximum enforced.



219
220
221
222
223
224
225
226
227
228
229
# File 'lib/hodl/server/services.rb', line 219

def send_payment_sync(dest:nil, dest_string:nil, amt:nil, payment_hash:nil, payment_hash_string:nil, payment_request:nil,
                         final_cltv_delta:nil, fee_limit:nil, outgoing_chan_id:nil, cltv_limit:nil)
     stub.send_payment_sync(Lnrpc::SendRequest.new(dest:                dest,
                                                   dest_string:         dest_string,
                                                   amt:                 amt,
                                                   payment_hash:        payment_hash,
                                                   payment_hash_string: payment_hash_string,
                                                   payment_request:     payment_request,
                                                   final_cltv_delta:    final_cltv_delta,
                                                   fee_limit:           Lnrpc::FeeLimit.new(fixed: fee_limit)))
end

#stop_daemon(confirmed: false) ⇒ Object

StopDaemon will send a shutdown request to the interrupt handler, triggering a graceful shutdown of the daemon.



372
373
374
# File 'lib/hodl/server/services.rb', line 372

def stop_daemon(confirmed:false)
  stub.stop_daemon(Lnrpc::StopRequest.new) if confirmed
end

#update_channel_policy(global: nil, chan_point: nil, base_fee_msat: nil, fee_rate: nil, time_lock_delta: nil) ⇒ Object

Parameters global bool If set, then this update applies to all currently active channels. chan_point ChannelPoint If set, this update will target a specific channel. base_fee_msat int64 The base fee charged regardless of the number of milli-satoshis sent. fee_rate double The effective fee rate in milli-satoshis. The precision of this value goes up to 6 decimal places, so 1e-6. time_lock_delta uint32 The required timelock delta for HTLCs forwarded over the channel.



389
390
391
392
393
394
395
# File 'lib/hodl/server/services.rb', line 389

def update_channel_policy(global:nil, chan_point:nil, base_fee_msat:nil, fee_rate:nil, time_lock_delta:nil)
  stub.update_channel_policy(Lnrpc::PolicyUpdateRequest.new(global:          global,
                                                            chan_point:      chan_point,
                                                            base_fee_msat:   base_fee_msat,
                                                            fee_rate:        fee_rate,
                                                            time_lock_delta: time_lock_delta))
end

#wallet_balanceObject

WalletBalance returns total unspent outputs(confirmed and unconfirmed), all confirmed unspent outputs and all unconfirmed unspent outputs under control of the wallet.



8
9
10
# File 'lib/hodl/server/services.rb', line 8

def wallet_balance
  stub.wallet_balance(Lnrpc::WalletBalanceRequest.new)
end