lighstorm 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +7 -7
  4. data/README.md +2 -2
  5. data/adapters/connections/channel_node.rb +1 -0
  6. data/adapters/edges/payment/purpose.rb +3 -3
  7. data/adapters/edges/payment.rb +1 -3
  8. data/adapters/invoice.rb +0 -2
  9. data/adapters/wallet.rb +42 -0
  10. data/components/cache.rb +1 -1
  11. data/components/lnd.rb +24 -8
  12. data/controllers/action.rb +5 -0
  13. data/controllers/activity/all.rb +85 -20
  14. data/controllers/activity.rb +15 -6
  15. data/controllers/channel/actions/apply_gossip.rb +3 -4
  16. data/controllers/channel/actions/update_fee.rb +11 -7
  17. data/controllers/channel/all.rb +11 -7
  18. data/controllers/channel/find_by_id.rb +11 -11
  19. data/controllers/channel/mine.rb +10 -10
  20. data/controllers/channel.rb +25 -11
  21. data/controllers/concerns/impersonatable.rb +33 -0
  22. data/controllers/connection.rb +33 -0
  23. data/controllers/forward/all.rb +16 -12
  24. data/controllers/forward/group_by_channel.rb +2 -2
  25. data/controllers/forward.rb +19 -13
  26. data/controllers/invoice/actions/create.rb +21 -13
  27. data/controllers/invoice/actions/pay.rb +13 -12
  28. data/controllers/invoice/actions/pay_through_route.rb +2 -2
  29. data/controllers/invoice/all.rb +7 -7
  30. data/controllers/invoice/decode.rb +6 -6
  31. data/controllers/invoice/find_by_code.rb +7 -7
  32. data/controllers/invoice/find_by_secret_hash.rb +10 -6
  33. data/controllers/invoice.rb +46 -39
  34. data/controllers/node/actions/apply_gossip.rb +1 -1
  35. data/controllers/node/actions/pay.rb +13 -12
  36. data/controllers/node/all.rb +11 -7
  37. data/controllers/node/find_by_public_key.rb +11 -7
  38. data/controllers/node/myself.rb +6 -6
  39. data/controllers/node.rb +17 -11
  40. data/controllers/payment/actions/pay.rb +23 -19
  41. data/controllers/payment/all.rb +7 -4
  42. data/controllers/payment.rb +20 -14
  43. data/controllers/secret/valid_proof.rb +5 -5
  44. data/controllers/transaction/all.rb +6 -5
  45. data/controllers/transaction.rb +14 -6
  46. data/controllers/wallet/balance.rb +34 -0
  47. data/controllers/wallet.rb +19 -0
  48. data/docs/README.md +70 -7
  49. data/docs/_coverpage.md +1 -1
  50. data/docs/index.html +1 -1
  51. data/lighstorm.gemspec +1 -1
  52. data/models/activity.rb +3 -2
  53. data/models/connections/channel_node/fee.rb +5 -2
  54. data/models/connections/channel_node/policy.rb +3 -2
  55. data/models/connections/channel_node.rb +14 -4
  56. data/models/connections/forward_channel.rb +3 -2
  57. data/models/edges/channel/hop.rb +1 -1
  58. data/models/edges/channel.rb +5 -7
  59. data/models/edges/forward.rb +4 -3
  60. data/models/edges/groups/channel_forwards.rb +3 -2
  61. data/models/edges/payment.rb +4 -3
  62. data/models/errors.rb +16 -24
  63. data/models/invoice.rb +10 -4
  64. data/models/nodes/node.rb +10 -4
  65. data/models/secret.rb +10 -4
  66. data/models/wallet.rb +40 -0
  67. data/ports/dsl/lighstorm.rb +6 -2
  68. data/ports/grpc.rb +30 -2
  69. data/static/cache.rb +2 -0
  70. data/static/spec.rb +1 -1
  71. metadata +10 -5
  72. data/deleted.sh +0 -1
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/impersonatable'
4
+
5
+ require_relative './wallet/balance'
6
+
7
+ module Lighstorm
8
+ module Controllers
9
+ module Wallet
10
+ extend Impersonatable
11
+
12
+ class DSL < Impersonatable::DSL
13
+ def balance
14
+ Balance.model(Balance.data(components))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/docs/README.md CHANGED
@@ -27,7 +27,7 @@ Lighstorm::Channel.mine.first.myself.node.alias
27
27
  Add to your `Gemfile`:
28
28
 
29
29
  ```ruby
30
- gem 'lighstorm', '~> 0.0.13'
30
+ gem 'lighstorm', '~> 0.0.15'
31
31
  ```
32
32
 
33
33
  Run `bundle install`.
@@ -36,7 +36,7 @@ Run `bundle install`.
36
36
  ```ruby
37
37
  require 'lighstorm'
38
38
 
39
- puts Lighstorm.version # => 0.0.13
39
+ puts Lighstorm.version # => 0.0.15
40
40
 
41
41
  Lighstorm::Invoice.create(
42
42
  description: 'Coffee', amount: { millisatoshis: 1000 }, payable: 'once'
@@ -193,6 +193,46 @@ Lighstorm.connect!(
193
193
  )
194
194
  ```
195
195
 
196
+ ## Multiclient
197
+
198
+ Multiclient allows you to establish connections with multiple nodes and effortlessly switch between them.
199
+
200
+ ```ruby
201
+ require 'lighstorm'
202
+
203
+ Lighstorm::Connection.connect!(
204
+ address: '127.0.0.1:10009',
205
+ certificate_path: '/lnd/tls.cert',
206
+ macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon'
207
+ )
208
+
209
+ Lighstorm::Connection.add!(
210
+ 'alice',
211
+ 'lndconnect://127.0.0.2:10009?cert=MIICJz...JBEERQ&macaroon=AgEDbG...45ukJ4'
212
+ )
213
+
214
+ Lighstorm::Connection.add!(
215
+ 'bob',
216
+ address: '127.0.0.3:10009',
217
+ certificate: 'LS0tLS1CRU...UtLS0tLQo=',
218
+ macaroon: 'AgEDbG5kAv...inv45ukJ4='
219
+ )
220
+
221
+ Lighstorm::Connection.default[:address] # => '127.0.0.1:10009'
222
+ Lighstorm::Connection.for('alice')[:address] # => '127.0.0.2:10009'
223
+ Lighstorm::Connection.for('bob')[:address] # => '127.0.0.3:10009'
224
+
225
+ Lighstorm::Node.myself.alias # => 'icebaker/old-stone'
226
+ Lighstorm::Node.as('alice').myself.alias # => alice
227
+ Lighstorm::Node.as('bob').myself.alias # => bob
228
+
229
+ Lighstorm::Connection.all # => ['alice', 'bob']
230
+
231
+ Lighstorm::Connection.remove!('bob')
232
+
233
+ Lighstorm::Connection.all # => ['alice']
234
+ ```
235
+
196
236
  ## Docker and Remote Access
197
237
 
198
238
  To connect to an LND node through a Docker container or remote host, you may need to adjust your certificate settings. Follow these steps:
@@ -257,6 +297,8 @@ channel.partner.policy.fee.rate.parts_per_million
257
297
  channel.myself.accounting.balance.millisatoshis
258
298
  channel.myself.node.alias
259
299
  channel.myself.policy.fee.rate.parts_per_million
300
+
301
+ channel.myself.initiator?
260
302
  ```
261
303
 
262
304
  [![This is an image representing Channel as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
@@ -520,6 +562,7 @@ channel.partner.policy.htlc.blocks.delta.minimum
520
562
  channel.myself
521
563
  channel.myself.state
522
564
  channel.myself.active?
565
+ channel.myself.initiator?
523
566
 
524
567
  channel.myself.node.public_key
525
568
  channel.myself.node.alias
@@ -914,6 +957,21 @@ Lighstorm::Payment.all(
914
957
  )
915
958
  ```
916
959
 
960
+ ## Wallet
961
+
962
+ ```ruby
963
+ balance = Lighstorm::Wallet.balance
964
+
965
+ balance.at
966
+
967
+ balance.lightning.millisatoshis
968
+ balance.bitcoin.millisatoshis
969
+
970
+ balance.total.millisatoshis
971
+
972
+ balance.to_h
973
+ ```
974
+
917
975
  ## Forward
918
976
 
919
977
  [![This is an image representing Forward as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
@@ -1127,19 +1185,24 @@ LighstormError
1127
1185
 
1128
1186
  ArgumentError
1129
1187
  IncoherentGossipError
1188
+ InvoiceMayHaveMultiplePaymentsError
1189
+ MissingComponentsError
1130
1190
  MissingCredentialsError
1131
1191
  MissingGossipHandlerError
1132
1192
  MissingPartsPerMillionError
1193
+ MissingTTLError
1133
1194
  NegativeNotAllowedError
1134
1195
  NotYourChannelError
1135
1196
  NotYourNodeError
1136
1197
  OperationNotAllowedError
1137
1198
  TooManyArgumentsError
1138
- UnexpectedNumberOfHTLCsError
1139
1199
  UnknownChannelError
1140
- UpdateChannelPolicyError
1141
1200
 
1201
+ RequestError
1202
+
1203
+ NoInvoiceFoundError
1142
1204
  PaymentError
1205
+ UpdateChannelPolicyError
1143
1206
 
1144
1207
  AlreadyPaidError
1145
1208
  AmountForNonZeroError
@@ -1158,7 +1221,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
1158
1221
  # demo.rb
1159
1222
  require 'lighstorm'
1160
1223
 
1161
- puts Lighstorm.version # => 0.0.13
1224
+ puts Lighstorm.version # => 0.0.15
1162
1225
  ```
1163
1226
 
1164
1227
  ```sh
@@ -1395,13 +1458,13 @@ gem build lighstorm.gemspec
1395
1458
 
1396
1459
  gem signin
1397
1460
 
1398
- gem push lighstorm-0.0.13.gem
1461
+ gem push lighstorm-0.0.15.gem
1399
1462
  ```
1400
1463
 
1401
1464
  _________________
1402
1465
 
1403
1466
  <center>
1404
- lighstorm 0.0.13
1467
+ lighstorm 0.0.15
1405
1468
  |
1406
1469
  <a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
1407
1470
  |
data/docs/_coverpage.md CHANGED
@@ -8,7 +8,7 @@
8
8
  - Built for maximum **reliability**.
9
9
  - Optimized for programmer **happiness**.
10
10
 
11
- 0.0.13
11
+ 0.0.15
12
12
 
13
13
  ⚠️ _Warning: Early-stage, breaking changes are expected._
14
14
 
data/docs/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <script>
19
19
  window.$docsify = {
20
20
  coverpage: true,
21
- name: 'Lighstorm 0.0.13',
21
+ name: 'Lighstorm 0.0.15',
22
22
  repo: 'https://github.com/icebaker/lighstorm'
23
23
  }
24
24
  </script>
data/lighstorm.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['ports/dsl']
33
33
 
34
34
  spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
35
- spec.add_dependency 'lnd-client', '~> 0.0.6'
35
+ spec.add_dependency 'lnd-client', '~> 0.0.9'
36
36
  spec.add_dependency 'zache', '~> 0.12.0'
37
37
 
38
38
  spec.metadata['rubygems_mfa_required'] = 'true'
data/models/activity.rb CHANGED
@@ -24,7 +24,7 @@ module Lighstorm
24
24
  end
25
25
 
26
26
  def invoice
27
- @invoice ||= @data[:data][:invoice].nil? ? nil : Invoice.new(@data[:data][:invoice])
27
+ @invoice ||= @data[:data][:invoice].nil? ? nil : Invoice.new(@data[:data][:invoice], nil)
28
28
  end
29
29
 
30
30
  def transaction
@@ -36,8 +36,9 @@ module Lighstorm
36
36
  _key: _key,
37
37
  at: at,
38
38
  direction: direction,
39
- amount: amount.to_h,
39
+ layer: layer,
40
40
  how: how,
41
+ amount: amount.to_h,
41
42
  message: message
42
43
  }
43
44
 
@@ -6,7 +6,6 @@ require_relative '../../satoshis'
6
6
  require_relative '../../rate'
7
7
  require_relative '../../concerns/protectable'
8
8
 
9
- require_relative '../../../components/lnd'
10
9
  require_relative '../../../controllers/channel/actions/update_fee'
11
10
 
12
11
  module Lighstorm
@@ -14,8 +13,9 @@ module Lighstorm
14
13
  class Fee
15
14
  include Protectable
16
15
 
17
- def initialize(policy, data)
16
+ def initialize(policy, components, data)
18
17
  @policy = policy
18
+ @components = components
19
19
  @data = data
20
20
  end
21
21
 
@@ -47,7 +47,10 @@ module Lighstorm
47
47
  end
48
48
 
49
49
  def update(params, preview: false, &vcr)
50
+ raise MissingComponentsError if @components.nil?
51
+
50
52
  Controllers::Channel::UpdateFee.perform(
53
+ @components,
51
54
  @policy, @policy.transaction, params,
52
55
  preview: preview, &vcr
53
56
  )
@@ -8,13 +8,14 @@ module Lighstorm
8
8
  class Policy
9
9
  attr_reader :transaction
10
10
 
11
- def initialize(data, transaction)
11
+ def initialize(data, components, transaction)
12
12
  @data = data
13
+ @components = components
13
14
  @transaction = transaction
14
15
  end
15
16
 
16
17
  def fee
17
- @fee ||= Fee.new(self, @data ? @data[:fee] : {})
18
+ @fee ||= Fee.new(self, @components, @data ? @data[:fee] : {})
18
19
  end
19
20
 
20
21
  def htlc
@@ -13,9 +13,11 @@ module Lighstorm
13
13
 
14
14
  attr_reader :state
15
15
 
16
- def initialize(data, is_mine, transaction)
16
+ def initialize(data, components, is_mine, transaction)
17
17
  @data = data
18
+ @components = components
18
19
  @state = data[:state]
20
+ @initiator = data[:initiator]
19
21
  @is_mine = is_mine
20
22
  @transaction = transaction
21
23
  end
@@ -24,12 +26,16 @@ module Lighstorm
24
26
  state == 'active'
25
27
  end
26
28
 
29
+ def initiator?
30
+ @initiator
31
+ end
32
+
27
33
  def node
28
- @node ||= Node.new(@data[:node])
34
+ @node ||= Node.new(@data[:node], @components)
29
35
  end
30
36
 
31
37
  def policy
32
- @policy ||= Policy.new(@data[:policy], @transaction)
38
+ @policy ||= Policy.new(@data[:policy], @components, @transaction)
33
39
  end
34
40
 
35
41
  def accounting
@@ -39,7 +45,11 @@ module Lighstorm
39
45
  end
40
46
 
41
47
  def to_h
42
- restult = { state: state, node: node.to_h }
48
+ restult = {
49
+ state: state,
50
+ initiator: @initiator,
51
+ node: node.to_h
52
+ }
43
53
 
44
54
  restult[:accounting] = accounting.to_h if @is_mine
45
55
  restult[:policy] = policy.to_h if @data[:policy]
@@ -5,8 +5,9 @@ require_relative '../edges/channel'
5
5
  module Lighstorm
6
6
  module Models
7
7
  class ForwardChannel
8
- def initialize(data)
8
+ def initialize(data, components)
9
9
  @data = data
10
+ @components = components
10
11
  end
11
12
 
12
13
  def amount
@@ -14,7 +15,7 @@ module Lighstorm
14
15
  end
15
16
 
16
17
  def channel
17
- @channel ||= Channel.new(@data[:channel])
18
+ @channel ||= Channel.new(@data[:channel], @components)
18
19
  end
19
20
 
20
21
  def to_h
@@ -8,7 +8,7 @@ module Lighstorm
8
8
  def initialize(data, payment)
9
9
  @hop_data = data
10
10
  @payment = payment
11
- super(data[:channel])
11
+ super(data[:channel], nil)
12
12
  end
13
13
 
14
14
  def target
@@ -5,9 +5,6 @@ require 'time'
5
5
  require_relative '../../ports/grpc'
6
6
  require_relative '../../adapters/edges/channel'
7
7
 
8
- require_relative '../../components/lnd'
9
- require_relative '../../components/cache'
10
-
11
8
  require_relative '../nodes/node'
12
9
  require_relative './channel/accounting'
13
10
 
@@ -22,8 +19,9 @@ module Lighstorm
22
19
  class Channel
23
20
  attr_reader :data, :_key, :id
24
21
 
25
- def initialize(data)
22
+ def initialize(data, components)
26
23
  @data = data
24
+ @components = components
27
25
 
28
26
  @_key = data[:_key]
29
27
  @id = data[:id]
@@ -78,7 +76,7 @@ module Lighstorm
78
76
  def partners
79
77
  @partners ||= if @data[:partners]
80
78
  @data[:partners].map do |data|
81
- ChannelNode.new(data, known? ? mine? : nil, transaction)
79
+ ChannelNode.new(data, @components, known? ? mine? : nil, transaction)
82
80
  end
83
81
  else
84
82
  []
@@ -170,9 +168,9 @@ module Lighstorm
170
168
  raise ArgumentError, 'missing gossip: or dump:' if gossip.nil? && dump.nil?
171
169
 
172
170
  if !gossip.nil?
173
- new(Adapter::Channel.subscribe_channel_graph(gossip))
171
+ new(Adapter::Channel.subscribe_channel_graph(gossip), nil)
174
172
  elsif !dump.nil?
175
- new(dump)
173
+ new(dump, nil)
176
174
  end
177
175
  end
178
176
 
@@ -12,8 +12,9 @@ module Lighstorm
12
12
  class Forward
13
13
  attr_reader :_key, :at
14
14
 
15
- def initialize(data)
15
+ def initialize(data, components)
16
16
  @data = data
17
+ @components = components
17
18
 
18
19
  @_key = data[:_key]
19
20
  @at = data[:at]
@@ -24,11 +25,11 @@ module Lighstorm
24
25
  end
25
26
 
26
27
  def in
27
- @in ||= ForwardChannel.new(@data[:in])
28
+ @in ||= ForwardChannel.new(@data[:in], @components)
28
29
  end
29
30
 
30
31
  def out
31
- @out ||= ForwardChannel.new(@data[:out])
32
+ @out ||= ForwardChannel.new(@data[:out], @components)
32
33
  end
33
34
 
34
35
  def to_h
@@ -8,8 +8,9 @@ module Lighstorm
8
8
  class ChannelForwardsGroup
9
9
  attr_reader :_key, :last_at
10
10
 
11
- def initialize(data)
11
+ def initialize(data, components)
12
12
  @data = data
13
+ @components = components
13
14
 
14
15
  @_key = data[:_key]
15
16
  @last_at = data[:last_at]
@@ -20,7 +21,7 @@ module Lighstorm
20
21
  end
21
22
 
22
23
  def channel
23
- @channel ||= Channel.new(@data[:channel])
24
+ @channel ||= Channel.new(@data[:channel], @components)
24
25
  end
25
26
 
26
27
  def to_h
@@ -14,8 +14,9 @@ module Lighstorm
14
14
  class Payment
15
15
  attr_reader :_key, :at, :state, :secret, :purpose, :through, :message
16
16
 
17
- def initialize(data)
17
+ def initialize(data, components)
18
18
  @data = data
19
+ @components = components
19
20
 
20
21
  @_key = data[:_key]
21
22
  @at = data[:at]
@@ -30,7 +31,7 @@ module Lighstorm
30
31
  end
31
32
 
32
33
  def invoice
33
- @invoice ||= !spontaneous? && @data[:invoice] ? Invoice.new(@data[:invoice]) : nil
34
+ @invoice ||= !spontaneous? && @data[:invoice] ? Invoice.new(@data[:invoice], @components) : nil
34
35
  end
35
36
 
36
37
  def amount
@@ -42,7 +43,7 @@ module Lighstorm
42
43
  end
43
44
 
44
45
  def secret
45
- @secret ||= @data[:secret] ? Secret.new(@data[:secret]) : nil
46
+ @secret ||= @data[:secret] ? Secret.new(@data[:secret], @components) : nil
46
47
  end
47
48
 
48
49
  def hops
data/models/errors.rb CHANGED
@@ -3,23 +3,18 @@
3
3
  module Lighstorm
4
4
  module Errors
5
5
  class LighstormError < StandardError
6
- attr_reader :grpc
7
-
8
- def initialize(message = nil, grpc: nil)
6
+ def initialize(message = nil)
9
7
  super(message)
10
- @grpc = grpc
11
8
  end
12
9
 
13
10
  def to_h
14
- output = { class: self.class, message: message }
15
- output[:grpc] = grpc.message unless grpc.nil?
16
-
17
- output
11
+ { class: self.class, message: message }
18
12
  end
19
13
  end
20
14
 
21
15
  class ToDoError < LighstormError; end
22
16
 
17
+ class MissingComponentsError < LighstormError; end
23
18
  class ArgumentError < LighstormError; end
24
19
  class TooManyArgumentsError < LighstormError; end
25
20
  class IncoherentGossipError < LighstormError; end
@@ -31,45 +26,42 @@ module Lighstorm
31
26
  class NotYourChannelError < LighstormError; end
32
27
  class NotYourNodeError < LighstormError; end
33
28
  class OperationNotAllowedError < LighstormError; end
34
- class UnexpectedNumberOfHTLCsError < LighstormError; end
35
29
  class UnknownChannelError < LighstormError; end
36
- class NoInvoiceFoundError < LighstormError; end
37
30
 
38
31
  class InvoiceMayHaveMultiplePaymentsError < LighstormError; end
39
32
 
40
- class PaymentError < LighstormError
41
- attr_reader :response, :result, :grpc
33
+ class RequestError < LighstormError
34
+ attr_reader :request, :response, :result, :grpc
42
35
 
43
- def initialize(message, response: nil, result: nil, grpc: nil)
36
+ def initialize(message, request: nil, response: nil, result: nil, grpc: nil)
44
37
  super(message)
38
+ @request = request
45
39
  @response = response
46
40
  @result = result
47
41
  @grpc = grpc
48
42
  end
49
43
 
50
44
  def to_h
51
- output = { message: message }
45
+ output = { class: self.class, message: message }
52
46
 
47
+ output[:request] = request unless request.nil?
53
48
  output[:response] = response unless response.nil?
54
49
  output[:result] = result.to_h unless result.nil?
55
- output[:grpc] = grpc.message unless grpc.nil?
50
+ output[:grpc] = { class: grpc.class, message: grpc.message } unless grpc.nil?
56
51
 
57
52
  output
58
53
  end
59
54
  end
60
55
 
56
+ class UpdateChannelPolicyError < RequestError; end
57
+
58
+ class NoInvoiceFoundError < RequestError; end
59
+
60
+ class PaymentError < RequestError; end
61
+
61
62
  class NoRouteFoundError < PaymentError; end
62
63
  class AlreadyPaidError < PaymentError; end
63
64
  class AmountForNonZeroError < PaymentError; end
64
65
  class MissingMillisatoshisError < PaymentError; end
65
-
66
- class UpdateChannelPolicyError < LighstormError
67
- attr_reader :response
68
-
69
- def initialize(message, response)
70
- super(message)
71
- @response = response
72
- end
73
- end
74
66
  end
75
67
  end
data/models/invoice.rb CHANGED
@@ -12,8 +12,9 @@ module Lighstorm
12
12
  class Invoice
13
13
  attr_reader :_key, :created_at, :expires_at, :settled_at, :state, :payable, :code
14
14
 
15
- def initialize(data)
15
+ def initialize(data, components)
16
16
  @data = data
17
+ @components = components
17
18
 
18
19
  @_key = data[:_key]
19
20
  @created_at = data[:created_at]
@@ -35,7 +36,7 @@ module Lighstorm
35
36
  end
36
37
 
37
38
  def payments
38
- @payments ||= @data[:payments]&.map { |data| Payment.new(data) }
39
+ @payments ||= @data[:payments]&.map { |data| Payment.new(data, @components) }
39
40
  end
40
41
 
41
42
  def amount
@@ -47,7 +48,7 @@ module Lighstorm
47
48
  end
48
49
 
49
50
  def secret
50
- @secret ||= Secret.new(@data[:secret])
51
+ @secret ||= Secret.new(@data[:secret], @components)
51
52
  end
52
53
 
53
54
  def description
@@ -89,10 +90,15 @@ module Lighstorm
89
90
  times_out_in: { seconds: 5 },
90
91
  preview: false
91
92
  )
93
+ raise MissingComponentsError if @components.nil?
94
+
92
95
  if route
93
- Controllers::Invoice::PayThroughRoute.perform(self, route: route, preview: preview)
96
+ Controllers::Invoice::PayThroughRoute.perform(
97
+ @components, self, route: route, preview: preview
98
+ )
94
99
  else
95
100
  Controllers::Invoice::Pay.perform(
101
+ @components,
96
102
  code: code,
97
103
  amount: amount,
98
104
  fee: fee,
data/models/nodes/node.rb CHANGED
@@ -16,8 +16,9 @@ module Lighstorm
16
16
 
17
17
  attr_reader :data, :_key, :alias, :public_key, :color
18
18
 
19
- def initialize(data)
19
+ def initialize(data, components)
20
20
  @data = data
21
+ @components = components
21
22
 
22
23
  @_key = @data[:_key]
23
24
  @alias = @data[:alias]
@@ -36,7 +37,9 @@ module Lighstorm
36
37
  def channels
37
38
  raise Errors::NotYourNodeError unless myself?
38
39
 
39
- Controllers::Channel.mine
40
+ raise MissingComponentsError if @components.nil?
41
+
42
+ Controllers::Channel.mine(@components)
40
43
  end
41
44
 
42
45
  def to_h
@@ -87,9 +90,9 @@ module Lighstorm
87
90
  raise ArgumentError, 'missing gossip: or dump:' if gossip.nil? && dump.nil?
88
91
 
89
92
  if !gossip.nil?
90
- new(Adapter::Node.subscribe_channel_graph(gossip))
93
+ new(Adapter::Node.subscribe_channel_graph(gossip), nil)
91
94
  elsif !dump.nil?
92
- new(dump)
95
+ new(dump, nil)
93
96
  end
94
97
  end
95
98
 
@@ -121,7 +124,10 @@ module Lighstorm
121
124
  times_out_in: { seconds: 5 }, through: 'amp',
122
125
  preview: false
123
126
  )
127
+ raise MissingComponentsError if @components.nil?
128
+
124
129
  Controllers::Node::Pay.perform(
130
+ @components,
125
131
  public_key: public_key,
126
132
  amount: amount,
127
133
  fee: fee,
data/models/secret.rb CHANGED
@@ -15,14 +15,15 @@ module Lighstorm
15
15
  data
16
16
  end
17
17
 
18
- def self.create(&vcr)
18
+ def self.create(components = nil, &vcr)
19
19
  data = vcr.nil? ? generate : vcr.call(-> { generate })
20
20
 
21
- Secret.new(data)
21
+ Secret.new(data, components)
22
22
  end
23
23
 
24
- def initialize(data)
24
+ def initialize(data, components)
25
25
  @data = data
26
+ @components = components
26
27
 
27
28
  @preimage = data[:preimage]
28
29
  @hash = data[:hash]
@@ -33,9 +34,14 @@ module Lighstorm
33
34
  end
34
35
 
35
36
  def valid_proof?(candidate_preimage, &vcr)
37
+ raise MissingComponentsError if @components.nil?
38
+
36
39
  return true if candidate_preimage == preimage
37
40
 
38
- Controllers::Secret::ValidProof.data(@hash, candidate_preimage, &vcr)
41
+ Controllers::Secret::ValidProof.data(
42
+ @components,
43
+ @hash, candidate_preimage, &vcr
44
+ )
39
45
  end
40
46
 
41
47
  def to_h