lnd-client 0.0.1

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.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +15 -0
  4. data/Gemfile +16 -0
  5. data/Gemfile.lock +62 -0
  6. data/LICENSE +21 -0
  7. data/README.md +107 -0
  8. data/Rakefile +10 -0
  9. data/components/grpc/autopilotrpc/autopilot_pb.rb +48 -0
  10. data/components/grpc/autopilotrpc/autopilot_services_pb.rb +40 -0
  11. data/components/grpc/chainrpc/chainkit_pb.rb +36 -0
  12. data/components/grpc/chainrpc/chainkit_services_pb.rb +34 -0
  13. data/components/grpc/chainrpc/chainnotifier_pb.rb +69 -0
  14. data/components/grpc/chainrpc/chainnotifier_services_pb.rb +53 -0
  15. data/components/grpc/devrpc/dev_pb.rb +17 -0
  16. data/components/grpc/devrpc/dev_services_pb.rb +25 -0
  17. data/components/grpc/invoicesrpc/invoices_pb.rb +66 -0
  18. data/components/grpc/invoicesrpc/invoices_services_pb.rb +45 -0
  19. data/components/grpc/lightning_pb.rb +1621 -0
  20. data/components/grpc/lightning_services_pb.rb +441 -0
  21. data/components/grpc/lnclipb/lncli_pb.rb +19 -0
  22. data/components/grpc/neutrinorpc/neutrino_pb.rb +106 -0
  23. data/components/grpc/neutrinorpc/neutrino_services_pb.rb +51 -0
  24. data/components/grpc/peersrpc/peers_pb.rb +48 -0
  25. data/components/grpc/peersrpc/peers_services_pb.rb +27 -0
  26. data/components/grpc/routerrpc/router_pb.rb +299 -0
  27. data/components/grpc/routerrpc/router_services_pb.rb +115 -0
  28. data/components/grpc/signrpc/signer_pb.rb +172 -0
  29. data/components/grpc/signrpc/signer_services_pb.rb +134 -0
  30. data/components/grpc/stateservice_pb.rb +35 -0
  31. data/components/grpc/stateservice_services_pb.rb +46 -0
  32. data/components/grpc/verrpc/verrpc_pb.rb +27 -0
  33. data/components/grpc/verrpc/verrpc_services_pb.rb +27 -0
  34. data/components/grpc/walletrpc/walletkit_pb.rb +328 -0
  35. data/components/grpc/walletrpc/walletkit_services_pb.rb +230 -0
  36. data/components/grpc/walletunlocker_pb.rb +75 -0
  37. data/components/grpc/walletunlocker_services_pb.rb +72 -0
  38. data/components/grpc/watchtowerrpc/watchtower_pb.rb +21 -0
  39. data/components/grpc/watchtowerrpc/watchtower_services_pb.rb +28 -0
  40. data/components/grpc/wtclientrpc/wtclient_pb.rb +83 -0
  41. data/components/grpc/wtclientrpc/wtclient_services_pb.rb +43 -0
  42. data/components/grpc.rb +9 -0
  43. data/controllers/client.rb +31 -0
  44. data/controllers/config.rb +35 -0
  45. data/controllers/documentation.rb +45 -0
  46. data/controllers/grpc_generator.rb +80 -0
  47. data/controllers/service.rb +35 -0
  48. data/lnd-client.gemspec +35 -0
  49. data/logic/string.rb +11 -0
  50. data/ports/dsl/lnd-client.rb +14 -0
  51. data/static/spec.rb +13 -0
  52. metadata +110 -0
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../logic/string'
4
+
5
+ class DocumentationController
6
+ attr_reader :available_methods
7
+
8
+ def initialize(service)
9
+ @service = service
10
+ @descriptions = {}
11
+ @grpc = {}
12
+
13
+ build!
14
+ end
15
+
16
+ def build!
17
+ @available_methods = @service.service.rpc_descs.values.map do |desc|
18
+ method_name = StringLogic.underscore(desc.name.to_s)
19
+
20
+ build_description!(method_name, desc)
21
+
22
+ @grpc[method_name] = desc
23
+
24
+ method_name
25
+ end.sort
26
+ end
27
+
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)
31
+
32
+ @descriptions[method_name] = { method: method_name }
33
+
34
+ @descriptions[method_name][:input] = input if input
35
+ @descriptions[method_name][:output] = output if output
36
+ end
37
+
38
+ def describe(method_name)
39
+ @descriptions[method_name.to_s]
40
+ end
41
+
42
+ def grpc(method_name)
43
+ @grpc[method_name.to_s]
44
+ end
45
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'rainbow'
5
+
6
+ module GrpcGeneratorController
7
+ REQUIRE_REGEX = /^require\s+['"].*_pb['"]/
8
+
9
+ def self.upgrade!
10
+ cleanup!
11
+
12
+ download!
13
+
14
+ Dir['temp/grpc-upgrade/lnd/lnrpc/**/*.proto'].each do |proto_file|
15
+ next if proto_file =~ /googleapis/
16
+
17
+ run!(generate_command(proto_file.sub('temp/grpc-upgrade/lnd/lnrpc/', '')), print_output: true)
18
+ end
19
+
20
+ fix_requires!
21
+
22
+ remove_references!
23
+
24
+ puts "\nDone!"
25
+ end
26
+
27
+ def self.remove_references!
28
+ run!('rm -rf temp/grpc-upgrade', print_output: false)
29
+ end
30
+
31
+ def self.cleanup!
32
+ run!('rm -rf components/grpc', print_output: false)
33
+ run!('rm -rf temp/grpc-upgrade', print_output: false)
34
+
35
+ FileUtils.mkdir_p('components/grpc')
36
+ FileUtils.mkdir_p('temp/grpc-upgrade')
37
+ end
38
+
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
44
+
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
54
+
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
60
+
61
+ apply!(file, content)
62
+ end
63
+ end
64
+ end
65
+
66
+ def self.apply!(file, content)
67
+ old_code = content[REQUIRE_REGEX]
68
+ new_code = content[REQUIRE_REGEX].sub('require', 'require_relative')
69
+
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
74
+
75
+ def self.run!(command, print_output: false)
76
+ puts "\n#{Rainbow('>').yellow} #{command}"
77
+ output = `#{command}`
78
+ puts output if print_output
79
+ end
80
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './documentation'
4
+
5
+ class ServiceController
6
+ attr_reader :doc, :service
7
+
8
+ def initialize(client, rpc)
9
+ @client = client
10
+ @rpc = rpc
11
+ @service = rpc.const_get(:Service)
12
+ @stub = rpc.const_get(:Stub).new(client.config.socket_address, client.config.credentials)
13
+ @doc = DocumentationController.new(self)
14
+ end
15
+
16
+ def call!(method_key, desc, *args)
17
+ @stub.method(method_key).call(
18
+ desc.input.new(*args),
19
+ { metadata: { macaroon: @client.config.macaroon } }
20
+ )
21
+ end
22
+
23
+ def respond_to_missing?(method_name, include_private = false)
24
+ desc = @doc.grpc(method_name)
25
+ (desc && @stub.respond_to?(method_name)) || super
26
+ end
27
+
28
+ def method_missing(method_name, *args, &)
29
+ desc = @doc.grpc(method_name)
30
+
31
+ raise ArgumentError, "Method `#{method_name}` doesn't exist." unless desc && @stub.respond_to?(method_name)
32
+
33
+ call!(method_name, desc, *args, &)
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'static/spec'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = Static::SPEC[:name]
7
+ spec.version = Static::SPEC[:version]
8
+ spec.authors = [Static::SPEC[:author]]
9
+
10
+ spec.summary = Static::SPEC[:summary]
11
+ spec.description = Static::SPEC[:description]
12
+
13
+ spec.homepage = Static::SPEC[:github]
14
+
15
+ spec.license = Static::SPEC[:license]
16
+
17
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.2.0')
18
+
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = Static::SPEC[:github]
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{\A(?:test|spec|features)/})
27
+ end
28
+ end
29
+
30
+ spec.require_paths = ['ports/dsl']
31
+
32
+ spec.add_dependency 'grpc', '~> 1.50'
33
+
34
+ spec.metadata['rubygems_mfa_required'] = 'true'
35
+ end
data/logic/string.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
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
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../controllers/client'
4
+ require_relative '../../static/spec'
5
+
6
+ module LNDClient
7
+ def self.new(params)
8
+ ClientController.new(params)
9
+ end
10
+
11
+ def self.version
12
+ Static::SPEC[:version]
13
+ end
14
+ end
data/static/spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Static
4
+ SPEC = {
5
+ name: 'lnd-client',
6
+ version: '0.0.1',
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
13
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lnd-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - icebaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.50'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.50'
27
+ description: Ruby Lightning Network Daemon (lnd) Client
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rubocop.yml"
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - components/grpc.rb
41
+ - components/grpc/autopilotrpc/autopilot_pb.rb
42
+ - components/grpc/autopilotrpc/autopilot_services_pb.rb
43
+ - components/grpc/chainrpc/chainkit_pb.rb
44
+ - components/grpc/chainrpc/chainkit_services_pb.rb
45
+ - components/grpc/chainrpc/chainnotifier_pb.rb
46
+ - components/grpc/chainrpc/chainnotifier_services_pb.rb
47
+ - components/grpc/devrpc/dev_pb.rb
48
+ - components/grpc/devrpc/dev_services_pb.rb
49
+ - components/grpc/invoicesrpc/invoices_pb.rb
50
+ - components/grpc/invoicesrpc/invoices_services_pb.rb
51
+ - components/grpc/lightning_pb.rb
52
+ - components/grpc/lightning_services_pb.rb
53
+ - components/grpc/lnclipb/lncli_pb.rb
54
+ - components/grpc/neutrinorpc/neutrino_pb.rb
55
+ - components/grpc/neutrinorpc/neutrino_services_pb.rb
56
+ - components/grpc/peersrpc/peers_pb.rb
57
+ - components/grpc/peersrpc/peers_services_pb.rb
58
+ - components/grpc/routerrpc/router_pb.rb
59
+ - components/grpc/routerrpc/router_services_pb.rb
60
+ - components/grpc/signrpc/signer_pb.rb
61
+ - components/grpc/signrpc/signer_services_pb.rb
62
+ - components/grpc/stateservice_pb.rb
63
+ - components/grpc/stateservice_services_pb.rb
64
+ - components/grpc/verrpc/verrpc_pb.rb
65
+ - components/grpc/verrpc/verrpc_services_pb.rb
66
+ - components/grpc/walletrpc/walletkit_pb.rb
67
+ - components/grpc/walletrpc/walletkit_services_pb.rb
68
+ - components/grpc/walletunlocker_pb.rb
69
+ - components/grpc/walletunlocker_services_pb.rb
70
+ - components/grpc/watchtowerrpc/watchtower_pb.rb
71
+ - components/grpc/watchtowerrpc/watchtower_services_pb.rb
72
+ - components/grpc/wtclientrpc/wtclient_pb.rb
73
+ - components/grpc/wtclientrpc/wtclient_services_pb.rb
74
+ - controllers/client.rb
75
+ - controllers/config.rb
76
+ - controllers/documentation.rb
77
+ - controllers/grpc_generator.rb
78
+ - controllers/service.rb
79
+ - lnd-client.gemspec
80
+ - logic/string.rb
81
+ - ports/dsl/lnd-client.rb
82
+ - static/spec.rb
83
+ homepage: https://github.com/icebaker/lnd-client
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ allowed_push_host: https://rubygems.org
88
+ homepage_uri: https://github.com/icebaker/lnd-client
89
+ source_code_uri: https://github.com/icebaker/lnd-client
90
+ rubygems_mfa_required: 'true'
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - ports/dsl
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.2.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.4.4
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Ruby Lightning Network Daemon (lnd) Client
110
+ test_files: []