lnd-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4f21139f58c13fceea576b5df5c9d799e24591281e4bd6a9132fd7a719fc549
4
- data.tar.gz: fb569472611c466c28cf03519e1c756dee704bdf22b21381c3c355cfa983c573
3
+ metadata.gz: 68daf7177bbbbbc21fe8e5c3b19230777b5d5904364ebc44211953e6fd5f36ed
4
+ data.tar.gz: e811786dd412c270cb931bd78ee30fa558bbeff87d779e53c2d4d0f6d7f8aec5
5
5
  SHA512:
6
- metadata.gz: 83f2cce7e6334695e3118ac9dd3ed6bb4c76a1aefdbacafba6a4af785d239e0c475faadf6104392cde059928409e0603e42a84e9fa91bc180a7ccd56a55a7eaa
7
- data.tar.gz: cd147a319c1f02c50e19fb220b6dedbe7357d0680530b8a305f083d50c731c2afb8da5ac90d67b7984b1022c61e398cd2326f1fd27e050af4d471375fc3e720a
6
+ metadata.gz: 3073a130f52bb94942379231f236fc79dc99f459891b696095c2928806611ef0b87e0c980fd9d39e60642ebf2a8a7847d1ee899336dd00a7d46a06ec376822a8
7
+ data.tar.gz: b63090fa41a852873e74695916614a065bb6bf824322ecd5233c93379b39b4dc2c86b3f575bb549a18869906b063569a440591070ffb128963c20f4fdc8a2fa2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lnd-client (0.0.3)
4
+ lnd-client (0.0.4)
5
5
  grpc (~> 1.51)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  > ⚠️ Warning: Early-stage, breaking changes are expected.
4
4
 
5
+ This is a low-level client library. For a better experience, you may want to check out the [Lighstorm](https://github.com/icebaker/lighstorm) abstraction.
6
+
5
7
  - [Usage](#usage)
6
8
  - [Channel Arguments](#channel-arguments)
7
9
  - [Documentation](#documentation)
@@ -14,13 +16,13 @@
14
16
  Add to your `Gemfile`:
15
17
 
16
18
  ```ruby
17
- gem 'lnd-client', '~> 0.0.3'
19
+ gem 'lnd-client', '~> 0.0.4'
18
20
  ```
19
21
 
20
22
  ```ruby
21
23
  require 'lnd-client'
22
24
 
23
- puts LNDClient.version # => 0.0.3
25
+ puts LNDClient.version # => 0.0.4
24
26
 
25
27
  client = LNDClient.new(
26
28
  certificate_path: '/lnd/tls.cert',
@@ -56,7 +58,7 @@ end
56
58
  ```ruby
57
59
  require 'lnd-client'
58
60
 
59
- puts LNDClient.version # => 0.0.3
61
+ puts LNDClient.version # => 0.0.4
60
62
 
61
63
  client = LNDClient.new(
62
64
  certificate_path: '/lnd/tls.cert',
@@ -79,7 +81,7 @@ graph.edges # => [...]
79
81
  ```ruby
80
82
  require 'lnd-client'
81
83
 
82
- puts LNDClient.version # => 0.0.3
84
+ puts LNDClient.version # => 0.0.4
83
85
 
84
86
  client = LNDClient.new(
85
87
  certificate_path: '/lnd/tls.cert',
@@ -146,5 +148,5 @@ gem build lnd-client.gemspec
146
148
 
147
149
  gem signin
148
150
 
149
- gem push lnd-client-0.0.3.gem
151
+ gem push lnd-client-0.0.4.gem
150
152
  ```
data/Rakefile CHANGED
@@ -5,6 +5,6 @@ require_relative './controllers/grpc_generator'
5
5
  namespace :grpc do
6
6
  desc 'Upgrade lnd Protocol Buffers for gGRPC'
7
7
  task :upgrade do
8
- GrpcGeneratorController.upgrade!
8
+ LNDClientInternal::GrpcGeneratorController.upgrade!
9
9
  end
10
10
  end
data/components/grpc.rb CHANGED
@@ -3,9 +3,11 @@
3
3
  require_relative './grpc/lightning_services_pb'
4
4
  require_relative './grpc/routerrpc/router_services_pb'
5
5
 
6
- module GRPC
7
- SERVICES = {
8
- lightning: Lnrpc::Lightning,
9
- router: Routerrpc::Router
10
- }.freeze
6
+ module LNDClientInternal
7
+ module GRPC
8
+ SERVICES = {
9
+ lightning: Lnrpc::Lightning,
10
+ router: Routerrpc::Router
11
+ }.freeze
12
+ end
11
13
  end
@@ -4,28 +4,34 @@ require_relative '../components/grpc'
4
4
  require_relative 'config'
5
5
  require_relative 'service'
6
6
 
7
- class ClientController
8
- attr_reader :config, :doc
7
+ module LNDClientInternal
8
+ class ClientController
9
+ attr_reader :config, :doc
9
10
 
10
- def initialize(options)
11
- @config = ConfigController.new(self, options)
12
- @services = {}
11
+ def initialize(options)
12
+ @config = LNDClientInternal::ConfigController.new(self, options)
13
+ @services = {}
13
14
 
14
- doc = Struct.new(:services)
15
- @doc = doc.new(GRPC::SERVICES.keys.map(&:to_s))
16
- end
15
+ doc = Struct.new(:services)
16
+ @doc = doc.new(LNDClientInternal::GRPC::SERVICES.keys.map(&:to_s))
17
+ end
17
18
 
18
- def respond_to_missing?(method_name, include_private = false)
19
- service_key = method_name.to_sym
19
+ def respond_to_missing?(method_name, include_private = false)
20
+ service_key = method_name.to_sym
20
21
 
21
- GRPC::SERVICES.include?(service_key) || super
22
- end
22
+ LNDClientInternal::GRPC::SERVICES.include?(service_key) || super
23
+ end
23
24
 
24
- def method_missing(method_name, *args)
25
- service_key = method_name.to_sym
25
+ def method_missing(method_name, *args)
26
+ service_key = method_name.to_sym
26
27
 
27
- raise ArgumentError, "Method `#{method_name}` doesn't exist." unless GRPC::SERVICES.include?(service_key)
28
+ unless LNDClientInternal::GRPC::SERVICES.include?(service_key)
29
+ raise ArgumentError, "Method `#{method_name}` doesn't exist."
30
+ end
28
31
 
29
- @services[service_key] ||= ServiceController.new(self, GRPC::SERVICES[service_key], *args)
32
+ @services[service_key] ||= LNDClientInternal::ServiceController.new(
33
+ self, LNDClientInternal::GRPC::SERVICES[service_key], *args
34
+ )
35
+ end
30
36
  end
31
37
  end
@@ -2,34 +2,36 @@
2
2
 
3
3
  require 'grpc'
4
4
 
5
- class ConfigController
6
- attr_reader :socket_address, :credentials, :certificate, :macaroon
5
+ module LNDClientInternal
6
+ class ConfigController
7
+ attr_reader :socket_address, :credentials, :certificate, :macaroon
7
8
 
8
- def initialize(client, options)
9
- @client = client
9
+ def initialize(client, options)
10
+ @client = client
10
11
 
11
- @certificate_path = options[:certificate_path]
12
- @certificate = options[:certificate]
12
+ @certificate_path = options[:certificate_path]
13
+ @certificate = options[:certificate]
13
14
 
14
- @macaroon_path = options[:macaroon_path]
15
- @macaroon = options[:macaroon]
15
+ @macaroon_path = options[:macaroon_path]
16
+ @macaroon = options[:macaroon]
16
17
 
17
- @socket_address = options[:socket_address] || '127.0.0.1:10009'
18
+ @socket_address = options[:socket_address] || '127.0.0.1:10009'
18
19
 
19
- setup_certificate!
20
- setup_macaroon!
21
- end
20
+ setup_certificate!
21
+ setup_macaroon!
22
+ end
22
23
 
23
- def setup_certificate!
24
- raise 'conflicting options for certificate' if @certificate && @certificate_path
24
+ def setup_certificate!
25
+ raise 'conflicting options for certificate' if @certificate && @certificate_path
25
26
 
26
- @certificate = File.read(@certificate_path) if @certificate_path
27
- @credentials = GRPC::Core::ChannelCredentials.new(@certificate)
28
- end
27
+ @certificate = File.read(@certificate_path) if @certificate_path
28
+ @credentials = ::GRPC::Core::ChannelCredentials.new(@certificate)
29
+ end
29
30
 
30
- def setup_macaroon!
31
- raise 'conflicting options for macaroon' if @macaroon && @macaroon_path
31
+ def setup_macaroon!
32
+ raise 'conflicting options for macaroon' if @macaroon && @macaroon_path
32
33
 
33
- @macaroon = File.read(@macaroon_path).unpack('H*') if @macaroon_path
34
+ @macaroon = File.read(@macaroon_path).unpack('H*') if @macaroon_path
35
+ end
34
36
  end
35
37
  end
@@ -2,44 +2,46 @@
2
2
 
3
3
  require_relative '../logic/string'
4
4
 
5
- class DocumentationController
6
- attr_reader :available_methods
5
+ module LNDClientInternal
6
+ class DocumentationController
7
+ attr_reader :available_methods
7
8
 
8
- def initialize(service)
9
- @service = service
10
- @descriptions = {}
11
- @grpc = {}
9
+ def initialize(service)
10
+ @service = service
11
+ @descriptions = {}
12
+ @grpc = {}
12
13
 
13
- build!
14
- end
14
+ build!
15
+ end
15
16
 
16
- def build!
17
- @available_methods = @service.service.rpc_descs.values.map do |desc|
18
- method_name = StringLogic.underscore(desc.name.to_s)
17
+ def build!
18
+ @available_methods = @service.service.rpc_descs.values.map do |desc|
19
+ method_name = LNDClientInternal::StringLogic.underscore(desc.name.to_s)
19
20
 
20
- build_description!(method_name, desc)
21
+ build_description!(method_name, desc)
21
22
 
22
- @grpc[method_name] = desc
23
+ @grpc[method_name] = desc
23
24
 
24
- method_name
25
- end.sort
26
- end
25
+ method_name
26
+ end.sort
27
+ end
27
28
 
28
- def build_description!(method_name, desc)
29
- input = desc.input.new.to_h if desc.input.respond_to?(:new)
30
- output = desc.output.new.to_h if desc.output.respond_to?(:new)
29
+ def build_description!(method_name, desc)
30
+ input = desc.input.new.to_h if desc.input.respond_to?(:new)
31
+ output = desc.output.new.to_h if desc.output.respond_to?(:new)
31
32
 
32
- @descriptions[method_name] = { method: method_name }
33
+ @descriptions[method_name] = { method: method_name }
33
34
 
34
- @descriptions[method_name][:input] = input if input
35
- @descriptions[method_name][:output] = output if output
36
- end
35
+ @descriptions[method_name][:input] = input if input
36
+ @descriptions[method_name][:output] = output if output
37
+ end
37
38
 
38
- def describe(method_name)
39
- @descriptions[method_name.to_s]
40
- end
39
+ def describe(method_name)
40
+ @descriptions[method_name.to_s]
41
+ end
41
42
 
42
- def grpc(method_name)
43
- @grpc[method_name.to_s]
43
+ def grpc(method_name)
44
+ @grpc[method_name.to_s]
45
+ end
44
46
  end
45
47
  end
@@ -3,78 +3,80 @@
3
3
  require 'fileutils'
4
4
  require 'rainbow'
5
5
 
6
- module GrpcGeneratorController
7
- REQUIRE_REGEX = /^require\s+['"].*_pb['"]/
6
+ module LNDClientInternal
7
+ module GrpcGeneratorController
8
+ REQUIRE_REGEX = /^require\s+['"].*_pb['"]/
8
9
 
9
- def self.upgrade!
10
- cleanup!
10
+ def self.upgrade!
11
+ cleanup!
11
12
 
12
- download!
13
+ download!
13
14
 
14
- Dir['temp/grpc-upgrade/lnd/lnrpc/**/*.proto'].each do |proto_file|
15
- next if proto_file =~ /googleapis/
15
+ Dir['temp/grpc-upgrade/lnd/lnrpc/**/*.proto'].each do |proto_file|
16
+ next if proto_file =~ /googleapis/
16
17
 
17
- run!(generate_command(proto_file.sub('temp/grpc-upgrade/lnd/lnrpc/', '')), print_output: true)
18
- end
18
+ run!(generate_command(proto_file.sub('temp/grpc-upgrade/lnd/lnrpc/', '')), print_output: true)
19
+ end
19
20
 
20
- fix_requires!
21
+ fix_requires!
21
22
 
22
- remove_references!
23
+ remove_references!
23
24
 
24
- puts "\nDone!"
25
- end
25
+ puts "\nDone!"
26
+ end
26
27
 
27
- def self.remove_references!
28
- run!('rm -rf temp/grpc-upgrade', print_output: false)
29
- end
28
+ def self.remove_references!
29
+ run!('rm -rf temp/grpc-upgrade', print_output: false)
30
+ end
30
31
 
31
- def self.cleanup!
32
- run!('rm -rf components/grpc', print_output: false)
33
- run!('rm -rf temp/grpc-upgrade', print_output: false)
32
+ def self.cleanup!
33
+ run!('rm -rf components/grpc', print_output: false)
34
+ run!('rm -rf temp/grpc-upgrade', print_output: false)
34
35
 
35
- FileUtils.mkdir_p('components/grpc')
36
- FileUtils.mkdir_p('temp/grpc-upgrade')
37
- end
36
+ FileUtils.mkdir_p('components/grpc')
37
+ FileUtils.mkdir_p('temp/grpc-upgrade')
38
+ end
38
39
 
39
- def self.download!
40
- run!('git clone https://github.com/lightningnetwork/lnd.git temp/grpc-upgrade/lnd', print_output: false)
41
- run!('git clone https://github.com/googleapis/googleapis.git temp/grpc-upgrade/lnd/lnrpc/googleapis',
42
- print_output: false)
43
- end
40
+ def self.download!
41
+ run!('git clone https://github.com/lightningnetwork/lnd.git temp/grpc-upgrade/lnd', print_output: false)
42
+ run!('git clone https://github.com/googleapis/googleapis.git temp/grpc-upgrade/lnd/lnrpc/googleapis',
43
+ print_output: false)
44
+ end
44
45
 
45
- def self.generate_command(proto_file)
46
- [
47
- 'cd temp/grpc-upgrade/lnd/lnrpc/; grpc_tools_ruby_protoc',
48
- '--proto_path googleapis:.',
49
- '--ruby_out=../../../../components/grpc/',
50
- '--grpc_out=../../../../components/grpc/',
51
- proto_file
52
- ].join(' ')
53
- end
46
+ def self.generate_command(proto_file)
47
+ [
48
+ 'cd temp/grpc-upgrade/lnd/lnrpc/; grpc_tools_ruby_protoc',
49
+ '--proto_path googleapis:.',
50
+ '--ruby_out=../../../../components/grpc/',
51
+ '--grpc_out=../../../../components/grpc/',
52
+ proto_file
53
+ ].join(' ')
54
+ end
54
55
 
55
- def self.fix_requires!
56
- 5.times do
57
- Dir['components/grpc/**/*.rb'].each do |file|
58
- content = File.read(file)
59
- next unless content =~ REQUIRE_REGEX
56
+ def self.fix_requires!
57
+ 5.times do
58
+ Dir['components/grpc/**/*.rb'].each do |file|
59
+ content = File.read(file)
60
+ next unless content =~ REQUIRE_REGEX
60
61
 
61
- apply!(file, content)
62
+ apply!(file, content)
63
+ end
62
64
  end
63
65
  end
64
- end
65
66
 
66
- def self.apply!(file, content)
67
- old_code = content[REQUIRE_REGEX]
68
- new_code = content[REQUIRE_REGEX].sub('require', 'require_relative')
67
+ def self.apply!(file, content)
68
+ old_code = content[REQUIRE_REGEX]
69
+ new_code = content[REQUIRE_REGEX].sub('require', 'require_relative')
69
70
 
70
- puts "\n#{Rainbow('>').yellow} #{file}"
71
- puts " #{Rainbow(old_code).red} -> #{Rainbow(new_code).green}"
72
- File.write(file, content.gsub(old_code, new_code))
73
- end
71
+ puts "\n#{Rainbow('>').yellow} #{file}"
72
+ puts " #{Rainbow(old_code).red} -> #{Rainbow(new_code).green}"
73
+ File.write(file, content.gsub(old_code, new_code))
74
+ end
74
75
 
75
- def self.run!(command, print_output: false)
76
- puts "\n#{Rainbow('>').yellow} #{command}"
77
- output = `#{command}`
78
- puts output if print_output
76
+ def self.run!(command, print_output: false)
77
+ puts "\n#{Rainbow('>').yellow} #{command}"
78
+ output = `#{command}`
79
+ puts output if print_output
80
+ end
79
81
  end
80
82
  end
@@ -2,39 +2,41 @@
2
2
 
3
3
  require_relative './documentation'
4
4
 
5
- class ServiceController
6
- attr_reader :doc, :service
7
-
8
- def initialize(client, rpc, params = {})
9
- @client = client
10
- @rpc = rpc
11
- @service = rpc.const_get(:Service)
12
- @stub = rpc.const_get(:Stub).new(
13
- client.config.socket_address,
14
- client.config.credentials,
15
- **params
16
- )
17
- @doc = DocumentationController.new(self)
18
- end
19
-
20
- def call!(method_key, desc, *args, &block)
21
- @stub.method(method_key).call(
22
- desc.input.new(*args),
23
- { metadata: { macaroon: @client.config.macaroon } },
24
- &block
25
- )
26
- end
27
-
28
- def respond_to_missing?(method_name, include_private = false)
29
- desc = @doc.grpc(method_name)
30
- (desc && @stub.respond_to?(method_name)) || super
31
- end
32
-
33
- def method_missing(method_name, *args, &block)
34
- desc = @doc.grpc(method_name)
35
-
36
- raise ArgumentError, "Method `#{method_name}` doesn't exist." unless desc && @stub.respond_to?(method_name)
37
-
38
- call!(method_name, desc, *args, &block)
5
+ module LNDClientInternal
6
+ class ServiceController
7
+ attr_reader :doc, :service
8
+
9
+ def initialize(client, rpc, params = {})
10
+ @client = client
11
+ @rpc = rpc
12
+ @service = rpc.const_get(:Service)
13
+ @stub = rpc.const_get(:Stub).new(
14
+ client.config.socket_address,
15
+ client.config.credentials,
16
+ **params
17
+ )
18
+ @doc = LNDClientInternal::DocumentationController.new(self)
19
+ end
20
+
21
+ def call!(method_key, desc, *args, &block)
22
+ @stub.method(method_key).call(
23
+ desc.input.new(*args),
24
+ { metadata: { macaroon: @client.config.macaroon } },
25
+ &block
26
+ )
27
+ end
28
+
29
+ def respond_to_missing?(method_name, include_private = false)
30
+ desc = @doc.grpc(method_name)
31
+ (desc && @stub.respond_to?(method_name)) || super
32
+ end
33
+
34
+ def method_missing(method_name, *args, &block)
35
+ desc = @doc.grpc(method_name)
36
+
37
+ raise ArgumentError, "Method `#{method_name}` doesn't exist." unless desc && @stub.respond_to?(method_name)
38
+
39
+ call!(method_name, desc, *args, &block)
40
+ end
39
41
  end
40
42
  end
data/lnd-client.gemspec CHANGED
@@ -3,23 +3,23 @@
3
3
  require_relative 'static/spec'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = Static::SPEC[:name]
7
- spec.version = Static::SPEC[:version]
8
- spec.authors = [Static::SPEC[:author]]
6
+ spec.name = LNDClientInternal::Static::SPEC[:name]
7
+ spec.version = LNDClientInternal::Static::SPEC[:version]
8
+ spec.authors = [LNDClientInternal::Static::SPEC[:author]]
9
9
 
10
- spec.summary = Static::SPEC[:summary]
11
- spec.description = Static::SPEC[:description]
10
+ spec.summary = LNDClientInternal::Static::SPEC[:summary]
11
+ spec.description = LNDClientInternal::Static::SPEC[:description]
12
12
 
13
- spec.homepage = Static::SPEC[:github]
13
+ spec.homepage = LNDClientInternal::Static::SPEC[:github]
14
14
 
15
- spec.license = Static::SPEC[:license]
15
+ spec.license = LNDClientInternal::Static::SPEC[:license]
16
16
 
17
17
  spec.required_ruby_version = Gem::Requirement.new('>= 3.0.0')
18
18
 
19
19
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
20
 
21
21
  spec.metadata['homepage_uri'] = spec.homepage
22
- spec.metadata['source_code_uri'] = Static::SPEC[:github]
22
+ spec.metadata['source_code_uri'] = LNDClientInternal::Static::SPEC[:github]
23
23
 
24
24
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
25
  `git ls-files -z`.split("\x0").reject do |f|
data/logic/string.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module StringLogic
4
- def self.underscore(string)
5
- string.gsub(/::/, '/')
6
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
7
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
8
- .tr('-', '_')
9
- .downcase
3
+ module LNDClientInternal
4
+ module StringLogic
5
+ def self.underscore(string)
6
+ string.gsub(/::/, '/')
7
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
8
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
9
+ .tr('-', '_')
10
+ .downcase
11
+ end
10
12
  end
11
13
  end
@@ -5,10 +5,10 @@ require_relative '../../static/spec'
5
5
 
6
6
  module LNDClient
7
7
  def self.new(params)
8
- ClientController.new(params)
8
+ LNDClientInternal::ClientController.new(params)
9
9
  end
10
10
 
11
11
  def self.version
12
- Static::SPEC[:version]
12
+ LNDClientInternal::Static::SPEC[:version]
13
13
  end
14
14
  end
data/static/spec.rb CHANGED
@@ -1,13 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Static
4
- SPEC = {
5
- name: 'lnd-client',
6
- version: '0.0.3',
7
- author: 'icebaker',
8
- summary: 'Ruby Lightning Network Daemon (lnd) Client',
9
- description: 'Ruby Lightning Network Daemon (lnd) Client',
10
- github: 'https://github.com/icebaker/lnd-client',
11
- license: 'MIT'
12
- }.freeze
3
+ module LNDClientInternal
4
+ module Static
5
+ SPEC = {
6
+ name: 'lnd-client',
7
+ version: '0.0.4',
8
+ author: 'icebaker',
9
+ summary: 'Ruby Lightning Network Daemon (lnd) Client',
10
+ description: 'Ruby Lightning Network Daemon (lnd) Client',
11
+ github: 'https://github.com/icebaker/lnd-client',
12
+ license: 'MIT'
13
+ }.freeze
14
+ end
13
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lnd-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - icebaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-02 00:00:00.000000000 Z
11
+ date: 2023-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc