mirror of
https://github.com/bumi/lnrpc
synced 2026-02-22 02:07:49 +00:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 449696fbb6 | |||
| 5194b2b413 | |||
| dbba4fd09a | |||
| 135bc614aa | |||
| 1fd764f55a | |||
| a839d09e6e | |||
| 050f0d0802 | |||
| 30b1f2bddc | |||
| df9165414f | |||
| 57f36b69ff | |||
| 26e15192eb | |||
| ddeea4da42 | |||
| 780a638c0e | |||
|
|
cb549f4fe6 | ||
| 80bf0bb600 | |||
|
|
fcf2486af3 | ||
| 6ab8336244 | |||
|
|
ccda3a0aa0 | ||
|
|
957515b0fe | ||
| 21f6466529 |
38
Gemfile.lock
38
Gemfile.lock
@@ -1,34 +1,34 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
lnrpc (0.11.1)
|
||||
google-protobuf (>= 3.12)
|
||||
lnrpc (0.14.1)
|
||||
google-protobuf (>= 3.15.7)
|
||||
grpc (>= 1.28.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
diff-lcs (1.4.4)
|
||||
google-protobuf (3.17.3)
|
||||
googleapis-common-protos-types (1.1.0)
|
||||
diff-lcs (1.5.0)
|
||||
google-protobuf (3.21.1)
|
||||
googleapis-common-protos-types (1.3.1)
|
||||
google-protobuf (~> 3.14)
|
||||
grpc (1.38.0)
|
||||
google-protobuf (~> 3.15)
|
||||
grpc (1.46.3)
|
||||
google-protobuf (~> 3.19)
|
||||
googleapis-common-protos-types (~> 1.0)
|
||||
rake (13.0.6)
|
||||
rspec (3.10.0)
|
||||
rspec-core (~> 3.10.0)
|
||||
rspec-expectations (~> 3.10.0)
|
||||
rspec-mocks (~> 3.10.0)
|
||||
rspec-core (3.10.1)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-expectations (3.10.1)
|
||||
rspec (3.11.0)
|
||||
rspec-core (~> 3.11.0)
|
||||
rspec-expectations (~> 3.11.0)
|
||||
rspec-mocks (~> 3.11.0)
|
||||
rspec-core (3.11.0)
|
||||
rspec-support (~> 3.11.0)
|
||||
rspec-expectations (3.11.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-mocks (3.10.2)
|
||||
rspec-support (~> 3.11.0)
|
||||
rspec-mocks (3.11.1)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.10.0)
|
||||
rspec-support (3.10.2)
|
||||
rspec-support (~> 3.11.0)
|
||||
rspec-support (3.11.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
@@ -40,4 +40,4 @@ DEPENDENCIES
|
||||
rspec (~> 3.0)
|
||||
|
||||
BUNDLED WITH
|
||||
2.1.4
|
||||
2.2.33
|
||||
|
||||
15
README.md
15
README.md
@@ -5,13 +5,10 @@ a [gRPC](https://grpc.io/) client for [LND, the Lightning Network Daemon](https:
|
||||
|
||||
## Installation
|
||||
|
||||
Note: there is still an GRPC/protobuf [issue with Ruby 2.7](https://github.com/protocolbuffers/protobuf/issues/7070).
|
||||
So lnrpc requires Ruby < 2.7.
|
||||
|
||||
Add this line to your application's Gemfile:
|
||||
|
||||
```ruby
|
||||
gem 'lnrpc', '~> 0.11.0'
|
||||
gem 'lnrpc', '~> 0.13.0'
|
||||
```
|
||||
lnrpc follows the lnd versioning, thus it is recommended to specify the exact version you need for your lnd node as dependency (see [#Versioning](#Versioning)).
|
||||
|
||||
@@ -27,7 +24,7 @@ Or install it yourself as:
|
||||
|
||||
## Usage
|
||||
|
||||
This gem makes the gRPC client classes created from the [LND service defintions](https://github.com/lightningnetwork/lnd/tree/master/lnrpc) available.
|
||||
This gem makes the gRPC client classes created from the [LND service definitions](https://github.com/lightningnetwork/lnd/tree/master/lnrpc) available.
|
||||
|
||||
```ruby
|
||||
require "lnrpc"
|
||||
@@ -35,7 +32,7 @@ require "lnrpc"
|
||||
# With the changes in LND v.10.0 this load the `Lnrpc` and `Routerrpc` namespace
|
||||
|
||||
Lnrpc::Lightning::Stub
|
||||
Routerrpc:::Routerrpc::Stub
|
||||
Routerrpc::Routerrpc::Stub
|
||||
Lnrpc::GetInfoRequest
|
||||
...
|
||||
```
|
||||
@@ -78,7 +75,7 @@ lnd = Lnrpc::Client.new({credentials_path: '/path/to.cert.cls', macaroon_path: '
|
||||
lnd.lightning # => Lnrpc::Lightning::Stub
|
||||
lnd.router # => Lnrpc::Router::Stub
|
||||
|
||||
lnd.ligthning.get_info
|
||||
lnd.lightning.get_info
|
||||
```
|
||||
|
||||
Also have a look at [examples.rb](https://github.com/bumi/lnrpc/blob/master/examples.rb)
|
||||
@@ -133,7 +130,7 @@ client.lightning.grpc.list_channels(request)
|
||||
|
||||
client.lightning.wallet_balance.total_balance
|
||||
# is the same as:
|
||||
request = Lnrpc::WalletBalanceRequest.new()
|
||||
request = Lnrpc::WalletBalanceRequest.new
|
||||
client.lightning.grpc.wallet_balance(request).total_balance
|
||||
```
|
||||
|
||||
@@ -144,7 +141,7 @@ If you have a running BTC Pay Server with LND support, integrating with lnrpc is
|
||||
- Navigate to Services on the Server Settings page
|
||||
- Click "see information" for your gRPC Server
|
||||
- The link by "More details..." will expose the address and various macaroon hex strings
|
||||
- Initialize your client with the options detailed above. BTC Pay Server utilizes LetsEncrypt for trusted TLC Certificates so set that option to nil.
|
||||
- Initialize your client with the options detailed above. BTC Pay Server utilizes LetsEncrypt for trusted TLC Certificates so set that option to nil.
|
||||
|
||||
Don't have a BTC Pay Server? [Setting one up is easy.](https://medium.com/@BtcpayServer/launch-btcpay-server-via-web-interface-and-deploy-full-bitcoin-node-lnd-in-less-than-a-minute-dc8bc6f06a3)
|
||||
|
||||
|
||||
43
examples.rb
43
examples.rb
@@ -24,3 +24,46 @@ puts lnd.wallet_kit.next_addr
|
||||
lnd.lightning.subscribe_invoices(settle_index: 1).each do |invoice|
|
||||
puts invoice.payment_request
|
||||
end
|
||||
|
||||
# sign a message with your node
|
||||
signed_message = lnd.lightning.sign_message({ msg: "Money printer goes brrr" })
|
||||
puts "Signature: " + signed_message.signature
|
||||
|
||||
# verify a signed message by another node
|
||||
verification_response = lnd.lightning.verify_message({
|
||||
msg: "Money printer goes brrr",
|
||||
signature: signed_message.signature
|
||||
})
|
||||
puts "Pubkey: " + verification_response.pubkey # pubkey of the node that signed
|
||||
puts "Valid: " + verification_response.valid.to_s
|
||||
|
||||
# get information on a node
|
||||
node_info_response = lnd.lightning.get_node_info(pub_key: verification_response.pubkey, include_channels: true)
|
||||
puts "Updated: " + Time.at(node_info_response.node.last_update).to_s
|
||||
puts "Pubkey: " + node_info_response.node.pub_key.to_s
|
||||
puts "Alias: " + node_info_response.node.alias.to_s
|
||||
puts "Color: " + node_info_response.node.color.to_s
|
||||
puts "Channels: " + node_info_response.num_channels.to_s
|
||||
puts "Capacity SAT: " + node_info_response.total_capacity.to_s
|
||||
puts "Address: " + node_info_response.node.addresses.first["addr"].to_s
|
||||
|
||||
# extract channel information
|
||||
node_info_response.channels.each do |channel|
|
||||
puts "Channel ID: " + channel["channel_id"].to_s
|
||||
puts "Channel 1:" + channel["node1_pub"].to_s # pubkey of the first node
|
||||
puts "Channel 2:" + channel["node2_pub"].to_s # pubkey of the second node
|
||||
puts "Channel Capacity:" + channel["capacity"].to_s
|
||||
end
|
||||
|
||||
# update channel policy
|
||||
channel = lnd.lightning.list_channels.channels[0]
|
||||
puts lnd.lightning.get_chan_info(chan_id: channel.chan_id)
|
||||
channel_point = {
|
||||
funding_txid_str: channel.channel_point.split(":")[0],
|
||||
output_index: channel.channel_point.split(":")[1].to_i
|
||||
}
|
||||
lnd.lightning.update_channel_policy({
|
||||
time_lock_delta: 40,
|
||||
base_fee_msat: 1100,
|
||||
chan_point: channel_point
|
||||
})
|
||||
|
||||
@@ -18,9 +18,8 @@ for file in $PROTOS; do
|
||||
echo "Generating protos from ${file}, into ${LNRPC_TARGET_DIR}/${DIRECTORY}"
|
||||
|
||||
# writes all ruby files in the ruby directory
|
||||
grpc_tools_ruby_protoc -I/usr/local/include \
|
||||
-I. \
|
||||
-I$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
|
||||
grpc_tools_ruby_protoc -I. \
|
||||
-I$GOPATH/src/github.com/googleapis/googleapis \
|
||||
-I$GOPATH/src/github.com/lightningnetwork/lnd/lnrpc \
|
||||
--ruby_out=plugins=grpc,paths=source_relative:${LNRPC_TARGET_DIR} \
|
||||
--grpc_out=${LNRPC_TARGET_DIR} "${file}"
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
require 'google/protobuf'
|
||||
|
||||
require 'rpc_pb'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_file("invoicesrpc/invoices.proto", :syntax => :proto3) do
|
||||
add_message "invoicesrpc.CancelInvoiceMsg" do
|
||||
@@ -25,6 +26,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
end
|
||||
add_message "invoicesrpc.AddHoldInvoiceResp" do
|
||||
optional :payment_request, :string, 1
|
||||
optional :add_index, :uint64, 2
|
||||
optional :payment_addr, :bytes, 3
|
||||
end
|
||||
add_message "invoicesrpc.SettleInvoiceMsg" do
|
||||
optional :preimage, :bytes, 1
|
||||
@@ -34,6 +37,19 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_message "invoicesrpc.SubscribeSingleInvoiceRequest" do
|
||||
optional :r_hash, :bytes, 2
|
||||
end
|
||||
add_message "invoicesrpc.LookupInvoiceMsg" do
|
||||
optional :lookup_modifier, :enum, 4, "invoicesrpc.LookupModifier"
|
||||
oneof :invoice_ref do
|
||||
optional :payment_hash, :bytes, 1
|
||||
optional :payment_addr, :bytes, 2
|
||||
optional :set_id, :bytes, 3
|
||||
end
|
||||
end
|
||||
add_enum "invoicesrpc.LookupModifier" do
|
||||
value :DEFAULT, 0
|
||||
value :HTLC_SET_ONLY, 1
|
||||
value :HTLC_SET_BLANK, 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,4 +61,6 @@ module Invoicesrpc
|
||||
SettleInvoiceMsg = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("invoicesrpc.SettleInvoiceMsg").msgclass
|
||||
SettleInvoiceResp = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("invoicesrpc.SettleInvoiceResp").msgclass
|
||||
SubscribeSingleInvoiceRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("invoicesrpc.SubscribeSingleInvoiceRequest").msgclass
|
||||
LookupInvoiceMsg = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("invoicesrpc.LookupInvoiceMsg").msgclass
|
||||
LookupModifier = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("invoicesrpc.LookupModifier").enummodule
|
||||
end
|
||||
|
||||
@@ -34,6 +34,10 @@ module Invoicesrpc
|
||||
# SettleInvoice settles an accepted invoice. If the invoice is already
|
||||
# settled, this call will succeed.
|
||||
rpc :SettleInvoice, ::Invoicesrpc::SettleInvoiceMsg, ::Invoicesrpc::SettleInvoiceResp
|
||||
#
|
||||
# LookupInvoiceV2 attempts to look up at invoice. An invoice can be refrenced
|
||||
# using either its payment hash, payment address, or set ID.
|
||||
rpc :LookupInvoiceV2, ::Invoicesrpc::LookupInvoiceMsg, ::Lnrpc::Invoice
|
||||
end
|
||||
|
||||
Stub = Service.rpc_stub_class
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
require 'google/protobuf'
|
||||
|
||||
require 'verrpc/verrpc_pb'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_file("lnclipb/lncli.proto", :syntax => :proto3) do
|
||||
add_message "lnclipb.VersionResponse" do
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
require 'google/protobuf'
|
||||
|
||||
require 'rpc_pb'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_file("routerrpc/router.proto", :syntax => :proto3) do
|
||||
add_message "routerrpc.SendPaymentRequest" do
|
||||
@@ -61,6 +62,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
end
|
||||
add_message "routerrpc.XImportMissionControlRequest" do
|
||||
repeated :pairs, :message, 1, "routerrpc.PairHistory"
|
||||
optional :force, :bool, 2
|
||||
end
|
||||
add_message "routerrpc.XImportMissionControlResponse" do
|
||||
end
|
||||
@@ -147,6 +149,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_message "routerrpc.ForwardFailEvent" do
|
||||
end
|
||||
add_message "routerrpc.SettleEvent" do
|
||||
optional :preimage, :bytes, 1
|
||||
end
|
||||
add_message "routerrpc.LinkFailEvent" do
|
||||
optional :info, :message, 1, "routerrpc.HtlcInfo"
|
||||
|
||||
@@ -43,6 +43,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_message "signrpc.SignMessageReq" do
|
||||
optional :msg, :bytes, 1
|
||||
optional :key_loc, :message, 2, "signrpc.KeyLocator"
|
||||
optional :double_hash, :bool, 3
|
||||
optional :compact_sig, :bool, 4
|
||||
end
|
||||
add_message "signrpc.SignMessageResp" do
|
||||
optional :signature, :bytes, 1
|
||||
|
||||
@@ -5,6 +5,7 @@ require 'google/protobuf'
|
||||
|
||||
require 'rpc_pb'
|
||||
require 'signrpc/signer_pb'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_file("walletrpc/walletkit.proto", :syntax => :proto3) do
|
||||
add_message "walletrpc.ListUnspentRequest" do
|
||||
@@ -35,6 +36,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
end
|
||||
add_message "walletrpc.AddrRequest" do
|
||||
optional :account, :string, 1
|
||||
optional :type, :enum, 2, "walletrpc.AddressType"
|
||||
optional :change, :bool, 3
|
||||
end
|
||||
add_message "walletrpc.AddrResponse" do
|
||||
optional :addr, :string, 1
|
||||
@@ -170,6 +173,12 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
optional :outpoint, :message, 2, "lnrpc.OutPoint"
|
||||
optional :expiration, :uint64, 3
|
||||
end
|
||||
add_message "walletrpc.SignPsbtRequest" do
|
||||
optional :funded_psbt, :bytes, 1
|
||||
end
|
||||
add_message "walletrpc.SignPsbtResponse" do
|
||||
optional :signed_psbt, :bytes, 1
|
||||
end
|
||||
add_message "walletrpc.FinalizePsbtRequest" do
|
||||
optional :funded_psbt, :bytes, 1
|
||||
optional :account, :string, 5
|
||||
@@ -245,6 +254,8 @@ module Walletrpc
|
||||
FundPsbtResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.FundPsbtResponse").msgclass
|
||||
TxTemplate = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.TxTemplate").msgclass
|
||||
UtxoLease = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.UtxoLease").msgclass
|
||||
SignPsbtRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.SignPsbtRequest").msgclass
|
||||
SignPsbtResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.SignPsbtResponse").msgclass
|
||||
FinalizePsbtRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.FinalizePsbtRequest").msgclass
|
||||
FinalizePsbtResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.FinalizePsbtResponse").msgclass
|
||||
ListLeasesRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("walletrpc.ListLeasesRequest").msgclass
|
||||
|
||||
@@ -169,6 +169,19 @@ module Walletrpc
|
||||
# an error on the caller's side.
|
||||
rpc :FundPsbt, ::Walletrpc::FundPsbtRequest, ::Walletrpc::FundPsbtResponse
|
||||
#
|
||||
# SignPsbt expects a partial transaction with all inputs and outputs fully
|
||||
# declared and tries to sign all unsigned inputs that have all required fields
|
||||
# (UTXO information, BIP32 derivation information, witness or sig scripts)
|
||||
# set.
|
||||
# If no error is returned, the PSBT is ready to be given to the next signer or
|
||||
# to be finalized if lnd was the last signer.
|
||||
#
|
||||
# NOTE: This RPC only signs inputs (and only those it can sign), it does not
|
||||
# perform any other tasks (such as coin selection, UTXO locking or
|
||||
# input/output/fee value validation, PSBT finalization). Any input that is
|
||||
# incomplete will be skipped.
|
||||
rpc :SignPsbt, ::Walletrpc::SignPsbtRequest, ::Walletrpc::SignPsbtResponse
|
||||
#
|
||||
# FinalizePsbt expects a partial transaction with all inputs and outputs fully
|
||||
# declared and tries to sign all inputs that belong to the wallet. Lnd must be
|
||||
# the last signer of the transaction. That means, if there are any unsigned
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
require 'google/protobuf'
|
||||
|
||||
require 'rpc_pb'
|
||||
|
||||
Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
add_file("walletunlocker.proto", :syntax => :proto3) do
|
||||
add_message "lnrpc.GenSeedRequest" do
|
||||
@@ -21,10 +22,24 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
||||
optional :recovery_window, :int32, 4
|
||||
optional :channel_backups, :message, 5, "lnrpc.ChanBackupSnapshot"
|
||||
optional :stateless_init, :bool, 6
|
||||
optional :extended_master_key, :string, 7
|
||||
optional :extended_master_key_birthday_timestamp, :uint64, 8
|
||||
optional :watch_only, :message, 9, "lnrpc.WatchOnly"
|
||||
end
|
||||
add_message "lnrpc.InitWalletResponse" do
|
||||
optional :admin_macaroon, :bytes, 1
|
||||
end
|
||||
add_message "lnrpc.WatchOnly" do
|
||||
optional :master_key_birthday_timestamp, :uint64, 1
|
||||
optional :master_key_fingerprint, :bytes, 2
|
||||
repeated :accounts, :message, 3, "lnrpc.WatchOnlyAccount"
|
||||
end
|
||||
add_message "lnrpc.WatchOnlyAccount" do
|
||||
optional :purpose, :uint32, 1
|
||||
optional :coin_type, :uint32, 2
|
||||
optional :account, :uint32, 3
|
||||
optional :xpub, :string, 4
|
||||
end
|
||||
add_message "lnrpc.UnlockWalletRequest" do
|
||||
optional :wallet_password, :bytes, 1
|
||||
optional :recovery_window, :int32, 2
|
||||
@@ -50,6 +65,8 @@ module Lnrpc
|
||||
GenSeedResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.GenSeedResponse").msgclass
|
||||
InitWalletRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.InitWalletRequest").msgclass
|
||||
InitWalletResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.InitWalletResponse").msgclass
|
||||
WatchOnly = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.WatchOnly").msgclass
|
||||
WatchOnlyAccount = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.WatchOnlyAccount").msgclass
|
||||
UnlockWalletRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.UnlockWalletRequest").msgclass
|
||||
UnlockWalletResponse = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.UnlockWalletResponse").msgclass
|
||||
ChangePasswordRequest = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("lnrpc.ChangePasswordRequest").msgclass
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require "grpc"
|
||||
require "digest"
|
||||
require "lnrpc/macaroon_interceptor"
|
||||
module Lnrpc
|
||||
class Client
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
module Lnrpc
|
||||
VERSION = "0.13.0"
|
||||
VERSION = "0.14.3.1"
|
||||
end
|
||||
|
||||
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
|
||||
spec.add_development_dependency "rspec", "~> 3.0"
|
||||
|
||||
spec.add_dependency "grpc", ">= 1.28.0"
|
||||
spec.add_dependency "google-protobuf", ">=3.12"
|
||||
spec.add_dependency "google-protobuf", ">=3.15.7"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user