lnrpc 0.5.2.beta → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9f1749c1fa4257d3624d77aa15e4b8d47f1c6ef2bc19c33965a9bbc8c544b39
4
- data.tar.gz: b7792de3c448b8a2d53376befe522bdfa819e15cecd0387934742233152a5912
3
+ metadata.gz: 4079c08041cc28f7f4f489ac59fb3223aab2621845c994b7bcad33fc36bef99b
4
+ data.tar.gz: d01a5e679555dab57793833fe1614fafd9cc7fe9c25961eee2ea72795e16b169
5
5
  SHA512:
6
- metadata.gz: 27ebcf6544a548ab97d5bdeeb2452ebdaa5f5ea1a1870339e8c54e38e23b576c15dfb1ea6b0a5421e854beed8ccc645f8dbd5cc6c030e61f19d9a834b28e1f31
7
- data.tar.gz: f3fa6207e3c74da86a8d4054163eb028be1b07ef146b4be10370da210c11684f46503c18d9d67ddfae332c67e1e61b34c8a3a9615a4161ced4a266e394751d64
6
+ metadata.gz: 3488c416c8ff54a371e81256dfe9cc7a9f2144a8d7a53f7f73f8c48b7410899f1c4a26be01ce51a840d2de1aacdc0030e3668d183a2930213c79ef051ed4cf93
7
+ data.tar.gz: 270b6e3681a5e59ca790b94f2ed35381e936b39b20b50524ffe9c8b44965fcfc4d1095d3957df4360a4315fcfce21ef165322ca12e825a6463396c867e84180d
data/Gemfile.lock CHANGED
@@ -1,17 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lnrpc (0.1.0)
5
- grpc (>= 1.16.0)
4
+ lnrpc (0.5.2.beta)
5
+ google-protobuf (>= 3.7)
6
+ grpc (>= 1.19.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  diff-lcs (1.3)
11
- google-protobuf (3.6.1)
12
+ google-protobuf (3.7.0)
12
13
  googleapis-common-protos-types (1.0.3)
13
14
  google-protobuf (~> 3.0)
14
- grpc (1.18.0)
15
+ grpc (1.19.0)
15
16
  google-protobuf (~> 3.1)
16
17
  googleapis-common-protos-types (~> 1.0.0)
17
18
  rake (10.5.0)
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- # Lnrpc
1
+ # Lnrpc - ruby gRPC client for LND
2
2
 
3
- gRPC service definitions for lnd packed as ruby gem.
3
+ a [gRPC](https://grpc.io/) client for [LND, the Lightning Network Daemon](https://github.com/lightningnetwork/lnd/) packed as ruby gem.
4
+
5
+ Currently published as [beta release](https://rubygems.org/gems/lnrpc) to rubygems for LND v0.5.2.beta. (see [#Versioning](#Versioning))
4
6
 
5
- currently highly experimental and subject to change.
6
7
 
7
8
  ## Installation
8
9
 
@@ -19,10 +20,119 @@ And then execute:
19
20
  Or install it yourself as:
20
21
 
21
22
  $ gem install lnrpc
23
+ # or for pre releases:
24
+ $ gem install lnrcp --pre
22
25
 
23
26
  ## Usage
24
27
 
25
- TODO: Write usage instructions here
28
+ This gem makes the gRPC client classes created from the [LND service defintions](https://github.com/lightningnetwork/lnd/tree/master/lnrpc) available.
29
+
30
+ ```ruby
31
+ require "lnrpc"
32
+
33
+ # the gRPC client is available under the Lnrpc namespace, e.g.
34
+
35
+ Lnrpc::Lightning::Stub
36
+ Lnrpc::GetInfoRequest
37
+ ```
38
+
39
+ Learn more about [gRPC](https://grpc.io/) on [gRPC.io](https://grpc.io/).
40
+
41
+ The LND API reference can be found here: [https://api.lightning.community/](https://api.lightning.community/)
42
+
43
+ ### Example
44
+
45
+ ```ruby
46
+ require "lnrpc"
47
+
48
+ credentials = File.read("/path/to/tls.cert")
49
+ macaroon = File.read("/path/to/readonly.macaroon").unpack("H*")
50
+
51
+ # initialize a new client
52
+ client = Lnrpc::Lightning::Stub.new("localhost:10009", GRPC::Core::ChannelCredentials.new(self.credentials))
53
+
54
+ # perform a request
55
+ request = Lnrpc::GetInfoRequest.new
56
+ response = client.get_info(request, { metadata: { macaroon: macaroon } }) #=> Lnrpc::GetInfoResponse
57
+ puts response.alias
58
+ ```
59
+
60
+ ### Client wrapper
61
+
62
+ An optional client wrapper ([Lnrpc::Client](https://github.com/bumi/lnrpc/blob/master/lib/lnrpc/client.rb")) makes
63
+ initializing the gRPC client easier and removes the need for some boilerplate code for calling RPC methods.
64
+
65
+ #### Example
66
+ ```ruby
67
+ lnd = Lnrpc::Client.new({credentials_path: '/path/to.cert.cls', macaroon_path: '/path/to/admin.macaroon'})
68
+ lnd.get_info
69
+ ```
70
+
71
+ Also have a look at [examples.rb](https://github.com/bumi/lnrpc/blob/master/examples.rb)
72
+
73
+ #### Initializing a new client
74
+
75
+ The Lnrpc::Client constructor allows the following options:
76
+
77
+ * credentials:
78
+ - `credentials` : the credentials data as string
79
+ - `credentials_path` : the path to a credentials file (tls.cert) as string
80
+ * macaroon:
81
+ - `macaroon` : the macaroon as hex string
82
+ - `macaroon_path` : the path to the macaroon file created by lnd as string
83
+ * address:
84
+ - `address` : lnd address as string. format: address:port, e.g. default: localhost:10009
85
+
86
+
87
+ ```ruby
88
+ require 'lnrpc'
89
+
90
+ lnd = Lnrpc::Client.new({
91
+ credentials_path: '/path/to.cert.cls',
92
+ macaroon_path: '/path/to/admin.macaroon',
93
+ address: 'host:port'
94
+ })
95
+
96
+ # the actual gRPC client is available through:
97
+ lnd.grpc_client
98
+ ```
99
+
100
+ #### Calling RPC methods
101
+
102
+ The client wrapper passes any supported RPC method call to the gRPC client applying the following conventions:
103
+
104
+ If the first parameter is a hash or blank the corresponding gRPC request object will be instantiated.
105
+
106
+ Example:
107
+
108
+ ```ruby
109
+ client.get_info
110
+ # is the same as:
111
+ client.grpc_client.get_info(Lnrpc::GetInfoRequest.new)
112
+
113
+ client.list_channels(inactive_only: true)
114
+ # is the same as:
115
+ request = Lnrpc::ListChannelsRequest.new(inactive_only: true)
116
+ client.grpc_client.list_channels(request)
117
+
118
+ client.wallet_balance.total_balance
119
+ # is the same as:
120
+ request = Lnrpc::WalletBalanceRequest.new()
121
+ client.grpc_client.wallet_balance(request).total_balance
122
+ ```
123
+
124
+
125
+ ## Versioning
126
+
127
+ This gem follows the LND versions and will update the gRPC service definitions accordingly.
128
+ e.g. gem version 0.5.2 includes the gRPC service definitions from LND v0.5.2
129
+
130
+
131
+ ## Other resources
132
+
133
+ * [LND gRPC API Reference](https://api.lightning.community)
134
+ * [LND Developer Site](https://dev.lightning.community/)
135
+ * [gRPC Ruby quick start](https://grpc.io/docs/quickstart/ruby.html)
26
136
 
27
137
  ## Contributing
28
138
 
data/examples.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "lnrpc"
2
+
3
+ lnd = Lnrpc::Client.new() # use defaults for credentials, macaraoon and address
4
+
5
+ get_info_res = lnd.get_info
6
+ puts get_info_res.alias
7
+
8
+ puts lnd.wallet_balance.total_balance
9
+
10
+ pay_request = "lntb50u1pw9mmndpp5nvnff958pxc9eqknwntyxapjw7l5grt5e2y70cmmnu0lljfa0sdqdpsgfkx7cmtwd68yetpd5s9xct5v4kxc6t5v5s8yatz0ysxwetdcqzysxqyz5vqjkhlyn40z76gyn7dx32p9j58dftve9xrlvnqqazht7w2fdauukhyhr9y4k3ngjn8s6srglj8swk7tm70ng54wdkq47ahytpwffvaeusp500csz"
11
+ lnd.pay(pay_request) # or:
12
+ lnd.send_payment_sync(payment_request: pay_request)
13
+
14
+ invoice_res = lnd.add_invoice(value: 1000, memo: 'I :heart: ruby')
15
+ puts invoice_res.payment_request
data/lib/lnrpc/client.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require "grpc"
2
+ require "lnrpc/macaroon_interceptor"
1
3
  module Lnrpc
2
4
  class Client
3
5
  attr_accessor :address, :credentials, :macaroon, :grpc_client
@@ -7,6 +9,25 @@ module Lnrpc
7
9
  DEFAULT_CREDENTIALS_PATH = "#{LND_HOME_DIR}/tls.cert"
8
10
  DEFAULT_MACAROON_PATH = "#{LND_HOME_DIR}/data/chain/bitcoin/mainnet/admin.macaroon"
9
11
 
12
+ NON_CONVENTION_REQUEST_CLASSES = {
13
+ add_invoice: Lnrpc::Invoice,
14
+ send_payment: Lnrpc::SendRequest,
15
+ send_payment_sync: Lnrpc::SendRequest,
16
+ open_channel_sync: Lnrpc::OpenChannelRequest,
17
+ send_to_route_sync: Lnrpc::SendToRouteRequest,
18
+ lookup_invoice: Lnrpc::PaymentHash,
19
+ decode_pay_req: Lnrpc::PayReqString,
20
+ describe_graph: Lnrpc::ChannelGraphRequest,
21
+ get_chan_info: Lnrpc::ChanInfoRequest,
22
+ get_node_info: Lnrpc::NodeInfoRequest,
23
+ get_network_info: Lnrpc::NetworkInfoRequest,
24
+ stop_daemon: Lnrpc::StopRequest,
25
+ update_channel_policy: Lnrpc::PolicyUpdateResponse,
26
+ subscribe_channel_graph: Lnrpc::GraphTopologySubscription,
27
+ subscribe_invoices: Lnrpc::InvoiceSubscription,
28
+ subscribe_transactions: Lnrpc::GetTransactionsRequest
29
+ }
30
+
10
31
  def initialize(options={})
11
32
  self.address = options[:address] || DEFAULT_ADDRESS
12
33
 
@@ -19,7 +40,10 @@ module Lnrpc
19
40
  end
20
41
  self.macaroon = options[:macaroon]
21
42
 
22
- self.grpc_client = Lnrpc::Lightning::Stub.new(self.address, GRPC::Core::ChannelCredentials.new(self.credentials))
43
+ self.grpc_client = Lnrpc::Lightning::Stub.new(self.address,
44
+ GRPC::Core::ChannelCredentials.new(self.credentials),
45
+ interceptors: [Lnrpc::MacaroonInterceptor.new(self.macaroon)]
46
+ )
23
47
  end
24
48
 
25
49
  def pay(payreq)
@@ -29,20 +53,27 @@ module Lnrpc
29
53
  def method_missing(m, *args, &block)
30
54
  if self.grpc_client.respond_to?(m)
31
55
  params = args[0]
32
- options = args[1] || { metadata: { macaroon: self.macaroon } }
33
56
 
34
- request = params.nil? ? request_class_for(m).new : request_class_for(m).new(params)
35
- self.grpc_client.send(m, request, options)
57
+ args[0] = params.nil? ? request_class_for(m).new : request_class_for(m).new(params)
58
+ self.grpc_client.send(m, *args)
36
59
  else
37
60
  super
38
61
  end
39
62
  end
40
63
 
64
+ def inspect
65
+ "#{self.to_s} @address=\"#{self.address}\""
66
+ end
67
+
41
68
  private
42
69
  def request_class_for(method_name)
43
- string = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
44
- string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
45
- Lnrpc.const_get("#{string}Request")
70
+ if NON_CONVENTION_REQUEST_CLASSES.key?(method_name.to_sym)
71
+ NON_CONVENTION_REQUEST_CLASSES[method_name.to_sym]
72
+ else
73
+ klass = method_name.to_s.sub(/^[a-z\d]*/) { |match| match.capitalize }
74
+ klass.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
75
+ Lnrpc.const_get("#{klass}Request")
76
+ end
46
77
  end
47
78
  end
48
79
  end
@@ -0,0 +1,22 @@
1
+ require "grpc"
2
+
3
+ module Lnrpc
4
+ class MacaroonInterceptor < GRPC::ClientInterceptor
5
+ def initialize(macaroon_hex)
6
+ @macaroon = macaroon_hex
7
+ end
8
+
9
+ def inject_macaroon_metadata(request:, call:, method:, metadata:)
10
+ if !metadata.has_key?('macaroon') && !metadata.has_key?(:macaroon)
11
+ metadata[:macaroon] = @macaroon
12
+ end
13
+ yield
14
+ end
15
+
16
+ alias :request_response :inject_macaroon_metadata
17
+ alias :client_streamer :inject_macaroon_metadata
18
+ alias :server_streamer :inject_macaroon_metadata
19
+ alias :bidi_streamer :inject_macaroon_metadata
20
+
21
+ end
22
+ end
data/lib/lnrpc/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lnrpc
2
- VERSION = "0.5.2.beta"
2
+ VERSION = "0.5.2"
3
3
  end
data/lib/lnrpc.rb CHANGED
@@ -4,6 +4,7 @@ require "lnrpc/rpc_services_pb"
4
4
  module Lnrpc
5
5
  class Error < StandardError; end
6
6
  autoload :Client, 'lnrpc/client'
7
+ autoload :MacaroonInterceptor, 'lnrpc/macaroon_interceptor'
7
8
  end
8
9
 
9
10
 
data/lnrpc.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["hello@michaelbumann.com"]
11
11
 
12
12
  spec.summary = %q{gRPC interface for lnd packed as ruby gem}
13
- spec.description = %q{gRPC service definitions for the Lightning Network Daemon (lnd) gRPC interace packed as ruby gem}
13
+ spec.description = %q{gRPC service definitions for the Lightning Network Daemon (lnd) gRPC interface packed as ruby gem}
14
14
  spec.homepage = "https://github.com/bumi/lnrpc"
15
15
  spec.license = "MIT"
16
16
 
@@ -27,5 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
 
30
- spec.add_dependency "grpc", ">= 1.16.0"
30
+ spec.add_dependency "grpc", ">= 1.19.0"
31
+ spec.add_dependency "google-protobuf", ">=3.7"
31
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lnrpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2.beta
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bumann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,16 +58,30 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.16.0
61
+ version: 1.19.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.16.0
68
+ version: 1.19.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: google-protobuf
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
69
83
  description: gRPC service definitions for the Lightning Network Daemon (lnd) gRPC
70
- interace packed as ruby gem
84
+ interface packed as ruby gem
71
85
  email:
72
86
  - hello@michaelbumann.com
73
87
  executables: []
@@ -83,8 +97,10 @@ files:
83
97
  - Rakefile
84
98
  - bin/console
85
99
  - bin/setup
100
+ - examples.rb
86
101
  - lib/lnrpc.rb
87
102
  - lib/lnrpc/client.rb
103
+ - lib/lnrpc/macaroon_interceptor.rb
88
104
  - lib/lnrpc/rpc.proto
89
105
  - lib/lnrpc/rpc_pb.rb
90
106
  - lib/lnrpc/rpc_services_pb.rb
@@ -105,9 +121,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
121
  version: '0'
106
122
  required_rubygems_version: !ruby/object:Gem::Requirement
107
123
  requirements:
108
- - - ">"
124
+ - - ">="
109
125
  - !ruby/object:Gem::Version
110
- version: 1.3.1
126
+ version: '0'
111
127
  requirements: []
112
128
  rubyforge_project:
113
129
  rubygems_version: 2.7.6