lighstorm 0.0.1 → 0.0.3

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: dc2a22398ed869fa9709af719d701c1fa00f5475f8de245111b40d602211e84d
4
- data.tar.gz: c41b6c9d08350d0e4717242eb663b6e85aa9c9c714f46974e4969e340d13a033
3
+ metadata.gz: 4c585645f0ccf6b55a8b0840d5351900f701002a4616f351016f1b8d9f097ed4
4
+ data.tar.gz: fca5794bab41231c60400aab4ce82021bb649df52df63acf801ef4931bf5c53c
5
5
  SHA512:
6
- metadata.gz: f560d47006a324f3468122cc719a89595523cfb639b8ad6dc45cf4ee7bc4d3bb2befb0a5ec5b02f84d8810bd7364322ef78f224611097a407999aaab571fd8c6
7
- data.tar.gz: 1ae71460fae62e5022eeff6f3a91e15dadd23ef382162efb068b74d61cd7ae714b68182165a463b6d035eb6daa0fb5dde5ef0aa1e7c660f91e77a85f42f8f0f7
6
+ metadata.gz: 0717fc86e023d1591872b3c81c58338c713409030f3bc2351988ee62abb163b262df95e1357537c7530d3f3bd615208af99f68c92a0a53b6f6b784401d5c8e15
7
+ data.tar.gz: ff9bba186921987b3f301f95f82f1d3b7041feb4db92d8ca2a43c663915ea12e6d609615419805bc26cde7c2ba658702b713a603dd33c3f024de6b16794eca7e
data/Gemfile CHANGED
@@ -6,5 +6,5 @@ gemspec
6
6
 
7
7
  group :test, :development do
8
8
  gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
9
- gem 'rubocop', '~> 1.44', '>= 1.44.1'
9
+ gem 'rubocop', '~> 1.45', '>= 1.45.1'
10
10
  end
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighstorm (0.0.1)
4
+ lighstorm (0.0.3)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
- lnd-client (~> 0.0.4)
6
+ lnd-client (~> 0.0.5)
7
7
  zache (~> 0.12.0)
8
8
 
9
9
  GEM
@@ -16,15 +16,15 @@ GEM
16
16
  google-protobuf (3.21.12)
17
17
  googleapis-common-protos-types (1.5.0)
18
18
  google-protobuf (~> 3.14)
19
- grpc (1.51.0)
19
+ grpc (1.52.0-x86_64-linux)
20
20
  google-protobuf (~> 3.21)
21
21
  googleapis-common-protos-types (~> 1.0)
22
22
  json (2.6.3)
23
- lnd-client (0.0.4)
24
- grpc (~> 1.51)
23
+ lnd-client (0.0.5)
24
+ grpc (~> 1.52)
25
25
  method_source (1.0.0)
26
26
  parallel (1.22.1)
27
- parser (3.2.0.0)
27
+ parser (3.2.1.0)
28
28
  ast (~> 2.4.1)
29
29
  pry (0.14.2)
30
30
  coderay (~> 1.1)
@@ -33,9 +33,9 @@ GEM
33
33
  byebug (~> 11.0)
34
34
  pry (>= 0.13, < 0.15)
35
35
  rainbow (3.1.1)
36
- regexp_parser (2.6.2)
36
+ regexp_parser (2.7.0)
37
37
  rexml (3.2.5)
38
- rubocop (1.44.1)
38
+ rubocop (1.45.1)
39
39
  json (~> 2.3)
40
40
  parallel (~> 1.10)
41
41
  parser (>= 3.2.0.0)
@@ -45,8 +45,8 @@ GEM
45
45
  rubocop-ast (>= 1.24.1, < 2.0)
46
46
  ruby-progressbar (~> 1.7)
47
47
  unicode-display_width (>= 2.4.0, < 3.0)
48
- rubocop-ast (1.24.1)
49
- parser (>= 3.1.1.0)
48
+ rubocop-ast (1.26.0)
49
+ parser (>= 3.2.1.0)
50
50
  ruby-progressbar (1.11.0)
51
51
  unicode-display_width (2.4.2)
52
52
  zache (0.12.0)
@@ -57,7 +57,7 @@ PLATFORMS
57
57
  DEPENDENCIES
58
58
  lighstorm!
59
59
  pry-byebug (~> 3.10, >= 3.10.1)
60
- rubocop (~> 1.44, >= 1.44.1)
60
+ rubocop (~> 1.45, >= 1.45.1)
61
61
 
62
62
  BUNDLED WITH
63
63
  2.4.4
data/README.md CHANGED
@@ -7,7 +7,7 @@ API for interacting with a [Lightning Node](https://lightning.network).
7
7
  ![Lighstorm text written stylized with an illustration of a Graph connecting two Nodes.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/lighstorm.png)
8
8
 
9
9
  ```ruby
10
- Lighstorm::Channel.first.myself.node.alias
10
+ Lighstorm::Channel.mine.first.myself.node.alias
11
11
  ```
12
12
 
13
13
  ## Index
@@ -33,7 +33,7 @@ _Lighstorm_ is an opinionated abstraction layer on top of the [lnd-client](https
33
33
 
34
34
  It brings an [object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) approach for interacting with a [Lightning Node](https://github.com/lightningnetwork/lnd), influenced by the [Active Record Pattern](https://www.martinfowler.com/eaaCatalog/activeRecord.html) and [Active Record Models](https://guides.rubyonrails.org/active_record_basics.html) conventions.
35
35
 
36
- Although it tries to stay close to [Lightning's terminologies](https://docs.lightning.engineering/lightning-network-tools/lnd), it brings its own vocabulary and data modeling, optimizing for [programmer happiness](https://rubyonrails.org/doctrine).
36
+ Although it tries to stay close to [Lightning's terminologies](https://docs.lightning.engineering/lightning-network-tools/lnd), it brings its own vocabulary and [data modeling](#data-modeling), optimizing for [programmer happiness](https://rubyonrails.org/doctrine).
37
37
 
38
38
  ## Usage
39
39
 
@@ -42,7 +42,7 @@ Although it tries to stay close to [Lightning's terminologies](https://docs.ligh
42
42
  Add to your `Gemfile`:
43
43
 
44
44
  ```ruby
45
- gem 'lighstorm', '~> 0.0.1'
45
+ gem 'lighstorm', '~> 0.0.3'
46
46
  ```
47
47
 
48
48
  Run `bundle install`.
@@ -78,7 +78,8 @@ Lighstorm.config!(
78
78
  ```ruby
79
79
  Lighstorm::Node
80
80
 
81
- Lighstorm::Node.myself
81
+ Lighstorm::Node.myself # Your Node.
82
+ Lighstorm::Node.all # All 18k+ Nodes on the Network.
82
83
  Lighstorm::Node.find_by_public_key(
83
84
  '02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
84
85
  )
@@ -90,6 +91,7 @@ node.channels
90
91
  node.alias
91
92
  node.public_key
92
93
  node.color
94
+ node.myself?
93
95
 
94
96
  node.platform.blockchain
95
97
  node.platform.network
@@ -97,13 +99,14 @@ node.platform.lightning.implementation
97
99
  node.platform.lightning.version
98
100
 
99
101
  Lighstorm::Channel
100
- Lighstorm::Channel.all
101
- Lighstorm::Channel.first
102
- Lighstorm::Channel.last
103
- Lighstorm::Channel.find_by_id(850099509773795329)
102
+ Lighstorm::Channel.mine # Your Node's Channels.
103
+ Lighstorm::Channel.all # All 80k+ Channels on the Network.
104
+ Lighstorm::Channel.find_by_id('850099509773795329')
104
105
 
105
106
  channel.to_h
106
107
 
108
+ channel.mine?
109
+
107
110
  channel.id
108
111
  channel.opened_at
109
112
  channel.up_at
@@ -115,12 +118,30 @@ channel.accounting.sent.milisatoshis
115
118
  channel.accounting.received.milisatoshis
116
119
  channel.accounting.unsettled.milisatoshis
117
120
 
121
+ # Channels that don't belong to you:
122
+ channel.partners
123
+
124
+ channel.partners[0]
125
+ channel.partners[0].node.alias
126
+
127
+ channel.partners[1]
128
+ channel.partners[1].node.alias
129
+
130
+ # Channels that belong to you:
131
+ channel.myself
132
+ channel.myself.node.alias
133
+
134
+ channel.partner
135
+ channel.partner.node.alias
136
+
118
137
  channel.partner.accounting.balance.milisatoshis
119
138
  channel.partner.node.alias
120
139
  channel.partner.node.public_key
121
140
  channel.partner.node.color
122
141
  channel.partner.policy.fee.base.milisatoshis
123
142
  channel.partner.policy.fee.rate.parts_per_million
143
+ channel.partner.policy.htlc.minimum.milisatoshis
144
+ channel.partner.policy.htlc.maximum.milisatoshis
124
145
 
125
146
  channel.myself.accounting.balance.milisatoshis
126
147
  channel.myself.node.alias
@@ -128,6 +149,24 @@ channel.myself.node.public_key
128
149
  channel.myself.node.color
129
150
  channel.myself.policy.fee.base.milisatoshis
130
151
  channel.myself.policy.fee.rate.parts_per_million
152
+ channel.myself.policy.htlc.minimum.milisatoshis
153
+ channel.myself.policy.htlc.maximum.milisatoshis
154
+
155
+ channel.myself.policy.fee.update(
156
+ { rate: { parts_per_million: 25 } }, preview: true
157
+ )
158
+
159
+ channel.myself.policy.fee.update(
160
+ { base: { milisatoshis: 1 } }
161
+ )
162
+
163
+ channel.myself.policy.fee.update(
164
+ { rate: { parts_per_million: 25 } }
165
+ )
166
+
167
+ channel.myself.policy.fee.update(
168
+ { base: { milisatoshis: 1 }, rate: { parts_per_million: 25 } }
169
+ )
131
170
 
132
171
  Lighstorm::Forward
133
172
  Lighstorm::Forward.all
@@ -141,7 +180,9 @@ forward.id
141
180
  forward.at
142
181
 
143
182
  forward.fee.milisatoshis
144
- forward.fee.parts_per_million
183
+ forward.fee.parts_per_million(
184
+ forward.in.amount.milisatoshis
185
+ )
145
186
 
146
187
  forward.in.amount.milisatoshis
147
188
 
@@ -155,6 +196,37 @@ forward.out.channel.partner.node.alias
155
196
  forward.out.channel.partner.node.public_key
156
197
  forward.out.channel.partner.node.color
157
198
 
199
+ Lighstorm::Forward.group_by_channel(direction: :in, hours_ago: 24, limit: 5)
200
+
201
+ group.to_h
202
+
203
+ group.last_at
204
+ group.analysis.count
205
+ group.analysis.sums.amount.milisatoshis
206
+ group.analysis.sums.fee.milisatoshis
207
+ group.analysis.averages.amount.milisatoshis
208
+ group.analysis.averages.fee.milisatoshis
209
+ group.analysis.averages.fee.parts_per_million(
210
+ group.analysis.averages.amount.milisatoshis
211
+ )
212
+
213
+ group.in.id
214
+ group.in.partner.node.alias
215
+ group.in.partner.node.public_key
216
+ group.in.partner.node.color
217
+
218
+ Lighstorm::Forward.group_by_channel(direction: :out)
219
+
220
+ group.to_h
221
+
222
+ group.last_at
223
+ group.analysis.count
224
+
225
+ group.out.id
226
+ group.out.partner.node.alias
227
+ group.out.partner.node.public_key
228
+ group.out.partner.node.color
229
+
158
230
  Lighstorm::Payment
159
231
  Lighstorm::Payment.all
160
232
  Lighstorm::Payment.first
@@ -168,12 +240,17 @@ payment.purpose
168
240
  payment.status
169
241
  payment.amount.milisatoshis
170
242
  payment.fee.milisatoshis
171
- payment.fee.parts_per_million
243
+ payment.fee.parts_per_million(
244
+ payment.amount.milisatoshis
245
+ )
172
246
 
173
247
  payment.from.hop
174
248
  payment.from.amount.milisatoshis
175
249
  payment.from.fee.milisatoshis
176
- payment.from.fee.parts_per_million
250
+ payment.from.fee.parts_per_million(
251
+ payment.from.amount.milisatoshis
252
+ )
253
+
177
254
  payment.from.channel.id
178
255
  payment.from.channel.partner.node.alias
179
256
  payment.from.channel.partner.node.public_key
@@ -182,7 +259,10 @@ payment.from.channel.partner.node.color
182
259
  payment.to.hop
183
260
  payment.to.amount.milisatoshis
184
261
  payment.to.fee.milisatoshis
185
- payment.to.fee.parts_per_million
262
+ payment.to.fee.parts_per_million(
263
+ payment.to.amount.milisatoshis
264
+ )
265
+
186
266
  payment.to.channel.id
187
267
  payment.to.channel.partner.node.alias
188
268
  payment.to.channel.partner.node.public_key
@@ -193,7 +273,10 @@ payment.hops.size
193
273
  payment.hops[0].hop
194
274
  payment.hops[0].amount.milisatoshis
195
275
  payment.hops[0].fee.milisatoshis
196
- payment.hops[0].fee.parts_per_million
276
+ payment.hops[0].fee.parts_per_million(
277
+ payment.hops[0].amount.milisatoshis
278
+ )
279
+
197
280
  payment.hops[0].channel.id
198
281
  payment.hops[0].channel.partner.node.alias
199
282
  payment.hops[0].channel.partner.node.public_key
@@ -221,7 +304,7 @@ satoshis.parts_per_million(reference_in_milisatoshis)
221
304
  ```ruby
222
305
  require 'lighstorm'
223
306
 
224
- puts Lighstorm.version # => 0.0.1
307
+ puts Lighstorm.version # => 0.0.3
225
308
 
226
309
  Lighstorm::Satoshis.new(
227
310
  milisatoshis: 75621650
@@ -234,7 +317,7 @@ Lighstorm::Node.myself.to_h #> { ... }
234
317
 
235
318
  Lighstorm::Node.myself.channels.count # => 5
236
319
 
237
- Lighstorm::Channel.all.first.partner.node.alias
320
+ Lighstorm::Channel.mine.first.partner.node.alias
238
321
 
239
322
  forward = Lighstorm::Forward.all(limit: 10).first
240
323
 
@@ -268,7 +351,7 @@ So, we are going to think in terms of _Edges_, _Nodes_, and _Connections_:
268
351
  #### Channel
269
352
 
270
353
  ```ruby
271
- channel = Lighstorm::Channel.first
354
+ channel = Lighstorm::Channel.mine.first
272
355
 
273
356
  channel.id
274
357
 
@@ -343,7 +426,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
343
426
  # demo.rb
344
427
  require 'lighstorm'
345
428
 
346
- puts Lighstorm.version # => 0.0.1
429
+ puts Lighstorm.version # => 0.0.3
347
430
  ```
348
431
 
349
432
  ```sh
@@ -358,5 +441,5 @@ gem build lighstorm.gemspec
358
441
 
359
442
  gem signin
360
443
 
361
- gem push lighstorm-0.0.1.gem
444
+ gem push lighstorm-0.0.3.gem
362
445
  ```
data/components/cache.rb CHANGED
@@ -4,6 +4,8 @@ require 'singleton'
4
4
 
5
5
  require 'zache'
6
6
 
7
+ require_relative '../static/cache'
8
+
7
9
  module Lighstorm
8
10
  class Cache
9
11
  include Singleton
@@ -18,7 +20,14 @@ module Lighstorm
18
20
  @client = Zache.new
19
21
  end
20
22
 
21
- def for(key, ttl: 1, params: {}, &block)
23
+ def for(key, ttl: nil, params: {}, &block)
24
+ if ttl.nil?
25
+ ttl = Lighstorm::Static::CACHE[key.sub('lightning.', '').to_sym]
26
+ raise "missing ttl for #{key}" if ttl.nil?
27
+
28
+ ttl = ttl[:ttl]
29
+ end
30
+
22
31
  key = build_key_for(key, params)
23
32
 
24
33
  @client.get(key, lifetime: ttl) do
data/lighstorm.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ['ports/dsl']
31
31
 
32
32
  spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
33
- spec.add_dependency 'lnd-client', '~> 0.0.4'
33
+ spec.add_dependency 'lnd-client', '~> 0.0.5'
34
34
  spec.add_dependency 'zache', '~> 0.12.0'
35
35
 
36
36
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -11,6 +11,8 @@ module Lighstorm
11
11
  end
12
12
 
13
13
  def balance
14
+ return nil unless @channel.data[:list_channels]
15
+
14
16
  @balance ||= if @node.myself?
15
17
  Satoshis.new(milisatoshis: (
16
18
  @channel.data[:list_channels][:channels].first.local_balance.to_f * 1000.0
@@ -3,11 +3,17 @@
3
3
  require_relative '../../satoshis'
4
4
  require_relative '../../rate'
5
5
 
6
+ require_relative '../../../components/lnd'
7
+
6
8
  module Lighstorm
7
9
  module Models
8
10
  class Fee
11
+ attr_reader :rate, :base
12
+
9
13
  def initialize(policy, channel, node)
10
- if node.myself?
14
+ @channel = channel
15
+ @policy = policy
16
+ if channel.data[:fee_report] && node.myself?
11
17
  @base = Satoshis.new(
12
18
  milisatoshis: channel.data[:fee_report][:channel_fees].first.base_fee_msat
13
19
  )
@@ -15,11 +21,77 @@ module Lighstorm
15
21
  @rate = Rate.new(
16
22
  parts_per_million: channel.data[:fee_report][:channel_fees].first.fee_per_mil
17
23
  )
18
- else
19
- @base = Satoshis.new(milisatoshis: policy.data.fee_base_msat)
24
+ elsif policy.data
25
+ @base = policy.data.fee_base_msat ? Satoshis.new(milisatoshis: policy.data.fee_base_msat) : nil
26
+
27
+ @rate = policy.data.fee_rate_milli_msat ? Rate.new(parts_per_million: policy.data.fee_rate_milli_msat) : nil
28
+ end
29
+ end
30
+
31
+ def update(params, preview: false)
32
+ chan_point = @channel.data[:get_chan_info].chan_point.split(':')
33
+
34
+ # add_message "lnrpc.PolicyUpdateRequest" do
35
+ # optional :base_fee_msat, :int64, 3
36
+ # optional :fee_rate, :double, 4
37
+ # optional :fee_rate_ppm, :uint32, 9
38
+ # optional :time_lock_delta, :uint32, 5
39
+ # optional :max_htlc_msat, :uint64, 6
40
+ # optional :min_htlc_msat, :uint64, 7
41
+ # optional :min_htlc_msat_specified, :bool, 8
42
+ # oneof :scope do
43
+ # optional :global, :bool, 1
44
+ # optional :chan_point, :message, 2, "lnrpc.ChannelPoint"
45
+ # end
46
+ # end
47
+
48
+ grpc_request = {
49
+ method: :update_channel_policy,
50
+ params: {
51
+ chan_point: {
52
+ funding_txid_str: chan_point[0],
53
+ output_index: chan_point[1].to_i
54
+ },
55
+ fee_rate_ppm: @policy.data.fee_rate_milli_msat,
56
+ base_fee_msat: @policy.data.fee_base_msat,
57
+ time_lock_delta: @policy.data.time_lock_delta,
58
+ max_htlc_msat: @policy.data.max_htlc_msat
59
+ }
60
+ }
61
+
62
+ if params[:rate] && params[:rate][:parts_per_million]
63
+ if (params[:rate][:parts_per_million]).negative?
64
+ raise "fee rate can't be negative [#{params[:rate][:parts_per_million]}]"
65
+ end
66
+
67
+ grpc_request[:params][:fee_rate_ppm] = params[:rate][:parts_per_million]
68
+ end
69
+
70
+ if params[:base] && params[:base][:milisatoshis]
71
+ if (params[:base][:milisatoshis]).negative?
72
+ raise "fee base can't be negative [#{params[:base][:milisatoshis]}]"
73
+ end
74
+
75
+ grpc_request[:params][:base_fee_msat] = params[:base][:milisatoshis]
76
+ end
77
+
78
+ return grpc_request if preview
79
+
80
+ response = LND.instance.middleware("lightning.#{grpc_request[:method]}") do
81
+ LND.instance.client.lightning.send(grpc_request[:method], grpc_request[:params])
82
+ end
83
+
84
+ if response.failed_updates.empty?
85
+ @base = Satoshis.new(
86
+ milisatoshis: grpc_request[:params][:base_fee_msat]
87
+ )
20
88
 
21
- @rate = Rate.new(parts_per_million: policy.data.fee_rate_milli_msat)
89
+ @rate = Rate.new(
90
+ parts_per_million: grpc_request[:params][:fee_rate_ppm]
91
+ )
22
92
  end
93
+
94
+ response
23
95
  end
24
96
 
25
97
  def to_h
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../satoshis'
4
+ require_relative '../../rate'
5
+
6
+ require_relative '../../../components/lnd'
7
+
8
+ module Lighstorm
9
+ module Models
10
+ class HTLC
11
+ attr_reader :minimum, :maximum
12
+
13
+ def initialize(policy, channel, _node)
14
+ @channel = channel
15
+ @policy = policy
16
+
17
+ return unless policy.data
18
+
19
+ @minimum = Satoshis.new(milisatoshis: policy.data.min_htlc)
20
+
21
+ @maximum = Satoshis.new(milisatoshis: policy.data.max_htlc_msat)
22
+ end
23
+
24
+ def to_h
25
+ {
26
+ minimum: @minimum.to_h,
27
+ maximum: @maximum.to_h
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'fee'
4
+ require_relative 'htlc'
4
5
 
5
6
  module Lighstorm
6
7
  module Models
@@ -11,19 +12,29 @@ module Lighstorm
11
12
  end
12
13
 
13
14
  def data
14
- @data ||= if @channel.data[:get_chan_info].node1_pub == @node.public_key
15
- @channel.data[:get_chan_info].node1_policy
15
+ return @data if @data
16
+
17
+ return if !@channel.data[:get_chan_info] && !@channel.data[:describe_graph]
18
+
19
+ key = @channel.data[:get_chan_info] ? :get_chan_info : :describe_graph
20
+
21
+ @data ||= if @channel.data[key].node1_pub == @node.public_key
22
+ @channel.data[key].node1_policy
16
23
  else
17
- @channel.data[:get_chan_info].node2_policy
24
+ @channel.data[key].node2_policy
18
25
  end
19
26
  end
20
27
 
21
- def fees
22
- @fees ||= Fee.new(self, @channel, @node)
28
+ def fee
29
+ @fee ||= Fee.new(self, @channel, @node)
30
+ end
31
+
32
+ def htlc
33
+ @htlc ||= HTLC.new(self, @channel, @node)
23
34
  end
24
35
 
25
36
  def to_h
26
- { fee: fees.to_h }
37
+ { fee: fee.to_h, htlc: htlc.to_h }
27
38
  end
28
39
  end
29
40
  end
@@ -29,12 +29,19 @@ module Lighstorm
29
29
  end
30
30
 
31
31
  def to_h
32
- {
33
- accounting: accounting.to_h,
34
- node: @node.to_h,
35
- policy: policy.to_h
36
- # constraints: constraints.to_h
37
- }
32
+ if @channel.data[:get_chan_info]
33
+ {
34
+ accounting: accounting.to_h,
35
+ node: @node.to_h,
36
+ policy: policy.to_h
37
+ # constraints: constraints.to_h
38
+ }
39
+ else
40
+ {
41
+ node: @node.to_h,
42
+ policy: policy.to_h
43
+ }
44
+ end
38
45
  end
39
46
  end
40
47
  end
@@ -7,21 +7,14 @@ module Lighstorm
7
7
  class ForwardChannel
8
8
  KIND = :connection
9
9
 
10
- def initialize(direction, forward)
10
+ def initialize(direction, forward, respond_info: true)
11
+ @respond_info = respond_info
11
12
  @direction = direction
12
13
  @forward = forward
13
14
  end
14
15
 
15
16
  def channel
16
- @channel ||= if @direction == :in
17
- Channel.find_by_id(
18
- @forward.data[:forwarding_history][:forwarding_events].first.chan_id_in
19
- )
20
- else
21
- Channel.find_by_id(
22
- @forward.data[:forwarding_history][:forwarding_events].first.chan_id_out
23
- )
24
- end
17
+ @channel ||= Channel.find_by_id(channel_id)
25
18
  end
26
19
 
27
20
  def amount
@@ -35,19 +28,35 @@ module Lighstorm
35
28
  end
36
29
 
37
30
  def to_h
38
- {
31
+ response = {
39
32
  amount: amount.to_h,
40
- channel: {
41
- id: channel.id,
42
- partner: {
43
- node: {
44
- alias: channel.partner&.node&.alias,
45
- public_key: channel.partner&.node&.public_key,
46
- color: channel.partner&.node&.color
47
- }
33
+ channel: { id: channel_id }
34
+ }
35
+
36
+ return response unless @respond_info
37
+
38
+ response[:channel] = {
39
+ id: channel.id,
40
+ partner: {
41
+ node: {
42
+ alias: channel.partner&.node&.alias,
43
+ public_key: channel.partner&.node&.public_key,
44
+ color: channel.partner&.node&.color
48
45
  }
49
46
  }
50
47
  }
48
+
49
+ response
50
+ end
51
+
52
+ private
53
+
54
+ def channel_id
55
+ if @direction == :in
56
+ @forward.data[:forwarding_history][:forwarding_events].first.chan_id_in.to_s
57
+ else
58
+ @forward.data[:forwarding_history][:forwarding_events].first.chan_id_out.to_s
59
+ end
51
60
  end
52
61
  end
53
62
  end