From bce4cf0b77ba660a22691b88c8af0d452e48923f Mon Sep 17 00:00:00 2001 From: Ivan Raszl Date: Mon, 12 Sep 2022 16:55:15 +0800 Subject: [PATCH 1/2] Add open channel command and section titles Minor improvements --- examples.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples.rb b/examples.rb index 89054a1..a9a60e8 100644 --- a/examples.rb +++ b/examples.rb @@ -1,26 +1,34 @@ require "lnrpc" -lnd = Lnrpc::Client.new() # use defaults for credentials, macaraoon and address +# establish a connection +lnd = Lnrpc::Client.new() # use defaults for credentials, macaroon and address +# get basic info get_info_res = lnd.lightning.get_info puts get_info_res.alias +# get wallet balance puts lnd.lightning.wallet_balance.total_balance +# pay an invoice pay_request = "lntb50u1pw9mmndpp5nvnff958pxc9eqknwntyxapjw7l5grt5e2y70cmmnu0lljfa0sdqdpsgfkx7cmtwd68yetpd5s9xct5v4kxc6t5v5s8yatz0ysxwetdcqzysxqyz5vqjkhlyn40z76gyn7dx32p9j58dftve9xrlvnqqazht7w2fdauukhyhr9y4k3ngjn8s6srglj8swk7tm70ng54wdkq47ahytpwffvaeusp500csz" lnd.pay(payment_request: pay_request) # or: lnd.router.send_payment_v2(payment_request: pay_request) +# keysend payment dest = Lnrpc.to_byte_array('038474ec195f497cf4036e5994bd820dd365bb0aaa7fb42bd9b536913a1a2dcc9e') lnd.keysend(dest: dest, amt: 1000) +# create invoice invoice_res = lnd.lightning.add_invoice(value: 1000, memo: 'I :heart: ruby') puts invoice_res.payment_request +# get fee estimates puts lnd.versioner.get_version puts lnd.wallet_kit.estimate_fee(conf_target: 10) puts lnd.wallet_kit.next_addr +# print incoming invoices lnd.lightning.subscribe_invoices(settle_index: 1).each do |invoice| puts invoice.payment_request end @@ -67,3 +75,8 @@ lnd.lightning.update_channel_policy({ base_fee_msat: 1100, chan_point: channel_point }) + +# open channel +# note: Lnrpc needs to connect with an admin macaroon, and the node needs to be an existing peer. +pubkey = Lnrpc.to_byte_array("031f2669adab71548fad4432277a0d90233e3bc07ac29cfb0b3e01bd3fb26cb9fa") +response = lnd.lightning.open_channel({node_pubkey: pubkey, local_funding_amount: 21000}) From 67bd66fd7cdd6cb8d43c37968a289474a00e261e Mon Sep 17 00:00:00 2001 From: Ivan Raszl Date: Mon, 12 Sep 2022 17:04:46 +0800 Subject: [PATCH 2/2] Add peering to examples --- examples.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples.rb b/examples.rb index a9a60e8..daa0e6b 100644 --- a/examples.rb +++ b/examples.rb @@ -76,6 +76,10 @@ lnd.lightning.update_channel_policy({ chan_point: channel_point }) +# peer node +address = {pubkey: "03423790614f023e3c0cdaa654a3578e919947e4c3a14bf5044e7c787ebd11af1a", host: "98.142.251.170:9735"} +response = lnd.lightning.connect_peer(addr: address) + # open channel # note: Lnrpc needs to connect with an admin macaroon, and the node needs to be an existing peer. pubkey = Lnrpc.to_byte_array("031f2669adab71548fad4432277a0d90233e3bc07ac29cfb0b3e01bd3fb26cb9fa")