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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -5
- data/Rakefile +1 -1
- data/components/grpc.rb +7 -5
- data/controllers/client.rb +22 -16
- data/controllers/config.rb +22 -20
- data/controllers/documentation.rb +30 -28
- data/controllers/grpc_generator.rb +56 -54
- data/controllers/service.rb +36 -34
- data/lnd-client.gemspec +8 -8
- data/logic/string.rb +9 -7
- data/ports/dsl/lnd-client.rb +2 -2
- data/static/spec.rb +12 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68daf7177bbbbbc21fe8e5c3b19230777b5d5904364ebc44211953e6fd5f36ed
|
4
|
+
data.tar.gz: e811786dd412c270cb931bd78ee30fa558bbeff87d779e53c2d4d0f6d7f8aec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3073a130f52bb94942379231f236fc79dc99f459891b696095c2928806611ef0b87e0c980fd9d39e60642ebf2a8a7847d1ee899336dd00a7d46a06ec376822a8
|
7
|
+
data.tar.gz: b63090fa41a852873e74695916614a065bb6bf824322ecd5233c93379b39b4dc2c86b3f575bb549a18869906b063569a440591070ffb128963c20f4fdc8a2fa2
|
data/Gemfile.lock
CHANGED
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.
|
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.
|
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.
|
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.
|
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.
|
151
|
+
gem push lnd-client-0.0.4.gem
|
150
152
|
```
|
data/Rakefile
CHANGED
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
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
module LNDClientInternal
|
7
|
+
module GRPC
|
8
|
+
SERVICES = {
|
9
|
+
lightning: Lnrpc::Lightning,
|
10
|
+
router: Routerrpc::Router
|
11
|
+
}.freeze
|
12
|
+
end
|
11
13
|
end
|
data/controllers/client.rb
CHANGED
@@ -4,28 +4,34 @@ require_relative '../components/grpc'
|
|
4
4
|
require_relative 'config'
|
5
5
|
require_relative 'service'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
module LNDClientInternal
|
8
|
+
class ClientController
|
9
|
+
attr_reader :config, :doc
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
def initialize(options)
|
12
|
+
@config = LNDClientInternal::ConfigController.new(self, options)
|
13
|
+
@services = {}
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
doc = Struct.new(:services)
|
16
|
+
@doc = doc.new(LNDClientInternal::GRPC::SERVICES.keys.map(&:to_s))
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def respond_to_missing?(method_name, include_private = false)
|
20
|
+
service_key = method_name.to_sym
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
LNDClientInternal::GRPC::SERVICES.include?(service_key) || super
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
def method_missing(method_name, *args)
|
26
|
+
service_key = method_name.to_sym
|
26
27
|
|
27
|
-
|
28
|
+
unless LNDClientInternal::GRPC::SERVICES.include?(service_key)
|
29
|
+
raise ArgumentError, "Method `#{method_name}` doesn't exist."
|
30
|
+
end
|
28
31
|
|
29
|
-
|
32
|
+
@services[service_key] ||= LNDClientInternal::ServiceController.new(
|
33
|
+
self, LNDClientInternal::GRPC::SERVICES[service_key], *args
|
34
|
+
)
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
data/controllers/config.rb
CHANGED
@@ -2,34 +2,36 @@
|
|
2
2
|
|
3
3
|
require 'grpc'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module LNDClientInternal
|
6
|
+
class ConfigController
|
7
|
+
attr_reader :socket_address, :credentials, :certificate, :macaroon
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
def initialize(client, options)
|
10
|
+
@client = client
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
@certificate_path = options[:certificate_path]
|
13
|
+
@certificate = options[:certificate]
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
@macaroon_path = options[:macaroon_path]
|
16
|
+
@macaroon = options[:macaroon]
|
16
17
|
|
17
|
-
|
18
|
+
@socket_address = options[:socket_address] || '127.0.0.1:10009'
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
setup_certificate!
|
21
|
+
setup_macaroon!
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
def setup_certificate!
|
25
|
+
raise 'conflicting options for certificate' if @certificate && @certificate_path
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
@certificate = File.read(@certificate_path) if @certificate_path
|
28
|
+
@credentials = ::GRPC::Core::ChannelCredentials.new(@certificate)
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
def setup_macaroon!
|
32
|
+
raise 'conflicting options for macaroon' if @macaroon && @macaroon_path
|
32
33
|
|
33
|
-
|
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
|
-
|
6
|
-
|
5
|
+
module LNDClientInternal
|
6
|
+
class DocumentationController
|
7
|
+
attr_reader :available_methods
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(service)
|
10
|
+
@service = service
|
11
|
+
@descriptions = {}
|
12
|
+
@grpc = {}
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
build!
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
21
|
+
build_description!(method_name, desc)
|
21
22
|
|
22
|
-
|
23
|
+
@grpc[method_name] = desc
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
method_name
|
26
|
+
end.sort
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
+
@descriptions[method_name] = { method: method_name }
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
@descriptions[method_name][:input] = input if input
|
36
|
+
@descriptions[method_name][:output] = output if output
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def describe(method_name)
|
40
|
+
@descriptions[method_name.to_s]
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
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
|
7
|
-
|
6
|
+
module LNDClientInternal
|
7
|
+
module GrpcGeneratorController
|
8
|
+
REQUIRE_REGEX = /^require\s+['"].*_pb['"]/
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
def self.upgrade!
|
11
|
+
cleanup!
|
11
12
|
|
12
|
-
|
13
|
+
download!
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
Dir['temp/grpc-upgrade/lnd/lnrpc/**/*.proto'].each do |proto_file|
|
16
|
+
next if proto_file =~ /googleapis/
|
16
17
|
|
17
|
-
|
18
|
-
|
18
|
+
run!(generate_command(proto_file.sub('temp/grpc-upgrade/lnd/lnrpc/', '')), print_output: true)
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
+
fix_requires!
|
21
22
|
|
22
|
-
|
23
|
+
remove_references!
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
puts "\nDone!"
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
def self.remove_references!
|
29
|
+
run!('rm -rf temp/grpc-upgrade', print_output: false)
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
36
|
+
FileUtils.mkdir_p('components/grpc')
|
37
|
+
FileUtils.mkdir_p('temp/grpc-upgrade')
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
+
apply!(file, content)
|
63
|
+
end
|
62
64
|
end
|
63
65
|
end
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
data/controllers/service.rb
CHANGED
@@ -2,39 +2,41 @@
|
|
2
2
|
|
3
3
|
require_relative './documentation'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
data/ports/dsl/lnd-client.rb
CHANGED
@@ -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
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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.
|
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-
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|