Merge pull request #22 from iraszl/master

Minor updates to examples
This commit is contained in:
bumi 2022-09-12 11:56:30 +02:00 committed by GitHub
commit a1bf3a8516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 1 deletions

View File

@ -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,12 @@ lnd.lightning.update_channel_policy({
base_fee_msat: 1100,
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")
response = lnd.lightning.open_channel({node_pubkey: pubkey, local_funding_amount: 21000})