lighstorm 0.0.12 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +18 -3
  3. data/Gemfile.lock +4 -4
  4. data/README.md +11 -5
  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/transaction.rb +23 -0
  10. data/adapters/wallet.rb +42 -0
  11. data/components/cache.rb +1 -1
  12. data/components/lnd.rb +67 -29
  13. data/controllers/action.rb +5 -0
  14. data/controllers/activity/all.rb +194 -0
  15. data/controllers/activity.rb +26 -0
  16. data/controllers/channel/actions/apply_gossip.rb +3 -4
  17. data/controllers/channel/actions/update_fee.rb +11 -7
  18. data/controllers/channel/all.rb +11 -7
  19. data/controllers/channel/find_by_id.rb +11 -11
  20. data/controllers/channel/mine.rb +10 -10
  21. data/controllers/channel.rb +25 -11
  22. data/controllers/concerns/impersonatable.rb +33 -0
  23. data/controllers/connection.rb +33 -0
  24. data/controllers/forward/all.rb +16 -12
  25. data/controllers/forward/group_by_channel.rb +2 -2
  26. data/controllers/forward.rb +19 -13
  27. data/controllers/invoice/actions/create.rb +21 -13
  28. data/controllers/invoice/actions/pay.rb +13 -12
  29. data/controllers/invoice/actions/pay_through_route.rb +2 -2
  30. data/controllers/invoice/all.rb +7 -7
  31. data/controllers/invoice/decode.rb +6 -6
  32. data/controllers/invoice/find_by_code.rb +7 -7
  33. data/controllers/invoice/find_by_secret_hash.rb +10 -6
  34. data/controllers/invoice.rb +46 -39
  35. data/controllers/node/actions/apply_gossip.rb +1 -1
  36. data/controllers/node/actions/pay.rb +13 -12
  37. data/controllers/node/all.rb +11 -7
  38. data/controllers/node/find_by_public_key.rb +11 -7
  39. data/controllers/node/myself.rb +6 -6
  40. data/controllers/node.rb +17 -11
  41. data/controllers/payment/actions/pay.rb +23 -19
  42. data/controllers/payment/all.rb +7 -4
  43. data/controllers/payment.rb +20 -14
  44. data/controllers/secret/valid_proof.rb +5 -5
  45. data/controllers/transaction/all.rb +29 -73
  46. data/controllers/transaction.rb +14 -6
  47. data/controllers/wallet/balance.rb +34 -0
  48. data/controllers/wallet.rb +19 -0
  49. data/docs/README.md +204 -31
  50. data/docs/_coverpage.md +1 -1
  51. data/docs/index.html +1 -1
  52. data/lighstorm.gemspec +1 -1
  53. data/models/activity.rb +52 -0
  54. data/models/connections/channel_node/fee.rb +5 -2
  55. data/models/connections/channel_node/policy.rb +3 -2
  56. data/models/connections/channel_node.rb +14 -4
  57. data/models/connections/forward_channel.rb +3 -2
  58. data/models/edges/channel/hop.rb +1 -1
  59. data/models/edges/channel.rb +5 -7
  60. data/models/edges/forward.rb +4 -3
  61. data/models/edges/groups/channel_forwards.rb +3 -2
  62. data/models/edges/payment.rb +4 -3
  63. data/models/errors.rb +16 -24
  64. data/models/invoice.rb +10 -4
  65. data/models/nodes/node.rb +10 -4
  66. data/models/secret.rb +10 -4
  67. data/models/transaction.rb +10 -15
  68. data/models/wallet.rb +40 -0
  69. data/ports/dsl/lighstorm.rb +8 -4
  70. data/ports/grpc.rb +30 -2
  71. data/static/cache.rb +3 -0
  72. data/static/spec.rb +1 -1
  73. metadata +14 -5
  74. data/deleted.sh +0 -1
@@ -11,11 +11,11 @@ module Lighstorm
11
11
  module Controllers
12
12
  module Channel
13
13
  module All
14
- def self.fetch(limit: nil)
14
+ def self.fetch(components, limit: nil)
15
15
  data = {
16
16
  at: Time.now,
17
- mine: Mine.fetch,
18
- describe_graph: Ports::GRPC.lightning.describe_graph.edges
17
+ mine: Mine.fetch(components),
18
+ describe_graph: components[:grpc].lightning.describe_graph.edges
19
19
  }
20
20
 
21
21
  data[:describe_graph] = data[:describe_graph][0..limit - 1] unless limit.nil?
@@ -60,17 +60,21 @@ module Lighstorm
60
60
  data
61
61
  end
62
62
 
63
- def self.data(limit: nil, &vcr)
64
- raw = vcr.nil? ? fetch(limit: limit) : vcr.call(-> { fetch(limit: limit) })
63
+ def self.data(components, limit: nil, &vcr)
64
+ raw = if vcr.nil?
65
+ fetch(components, limit: limit)
66
+ else
67
+ vcr.call(-> { fetch(components, limit: limit) })
68
+ end
65
69
 
66
70
  adapted = adapt(raw)
67
71
 
68
72
  adapted[:describe_graph].map { |data| transform(data, adapted) }
69
73
  end
70
74
 
71
- def self.model(data)
75
+ def self.model(data, components)
72
76
  data.map do |node_data|
73
- Lighstorm::Models::Channel.new(node_data)
77
+ Lighstorm::Models::Channel.new(node_data, components)
74
78
  end
75
79
  end
76
80
  end
@@ -11,22 +11,22 @@ module Lighstorm
11
11
  module Controllers
12
12
  module Channel
13
13
  module FindById
14
- def self.fetch(id)
14
+ def self.fetch(components, id)
15
15
  data = {
16
16
  at: Time.now,
17
- get_info: Ports::GRPC.lightning.get_info.to_h,
17
+ get_info: components[:grpc].lightning.get_info.to_h,
18
18
  # Ensure that we are getting fresh up-date data about our own fees.
19
- fee_report: Ports::GRPC.lightning.fee_report.to_h,
20
- get_chan_info: Ports::GRPC.lightning.get_chan_info(chan_id: id.to_i).to_h,
19
+ fee_report: components[:grpc].lightning.fee_report.to_h,
20
+ get_chan_info: components[:grpc].lightning.get_chan_info(chan_id: id.to_i).to_h,
21
21
  get_node_info: {},
22
22
  list_channels: []
23
23
  }
24
24
 
25
- data[:get_node_info][data[:get_chan_info][:node1_pub]] = Ports::GRPC.lightning.get_node_info(
25
+ data[:get_node_info][data[:get_chan_info][:node1_pub]] = components[:grpc].lightning.get_node_info(
26
26
  pub_key: data[:get_chan_info][:node1_pub]
27
27
  ).to_h
28
28
 
29
- data[:get_node_info][data[:get_chan_info][:node2_pub]] = Ports::GRPC.lightning.get_node_info(
29
+ data[:get_node_info][data[:get_chan_info][:node2_pub]] = components[:grpc].lightning.get_node_info(
30
30
  pub_key: data[:get_chan_info][:node2_pub]
31
31
  ).to_h
32
32
 
@@ -40,7 +40,7 @@ module Lighstorm
40
40
  if is_mine
41
41
  partner = partners.find { |p| p != data[:get_info][:identity_pubkey] }
42
42
 
43
- data[:list_channels] = Ports::GRPC.lightning.list_channels(
43
+ data[:list_channels] = components[:grpc].lightning.list_channels(
44
44
  peer: [partner].pack('H*')
45
45
  ).channels.map(&:to_h)
46
46
  end
@@ -136,16 +136,16 @@ module Lighstorm
136
136
  data
137
137
  end
138
138
 
139
- def self.data(id, &vcr)
140
- raw = vcr.nil? ? fetch(id) : vcr.call(-> { fetch(id) })
139
+ def self.data(components, id, &vcr)
140
+ raw = vcr.nil? ? fetch(components, id) : vcr.call(-> { fetch(components, id) })
141
141
 
142
142
  adapted = adapt(raw)
143
143
 
144
144
  transform(adapted[:get_chan_info], adapted)
145
145
  end
146
146
 
147
- def self.model(data)
148
- Lighstorm::Models::Channel.new(data)
147
+ def self.model(data, components)
148
+ Lighstorm::Models::Channel.new(data, components)
149
149
  end
150
150
  end
151
151
  end
@@ -9,27 +9,27 @@ module Lighstorm
9
9
  module Controllers
10
10
  module Channel
11
11
  module Mine
12
- def self.fetch
12
+ def self.fetch(components)
13
13
  data = {
14
14
  at: Time.now,
15
- get_info: Ports::GRPC.lightning.get_info.to_h,
15
+ get_info: components[:grpc].lightning.get_info.to_h,
16
16
  # Ensure that we are getting fresh up-date data about our own fees.
17
- fee_report: Ports::GRPC.lightning.fee_report.to_h,
18
- list_channels: Ports::GRPC.lightning.list_channels.channels.map(&:to_h),
17
+ fee_report: components[:grpc].lightning.fee_report.to_h,
18
+ list_channels: components[:grpc].lightning.list_channels.channels.map(&:to_h),
19
19
  get_chan_info: {},
20
20
  get_node_info: {}
21
21
  }
22
22
 
23
23
  data[:list_channels].each do |channel|
24
24
  unless data[:get_chan_info][channel[:chan_id]]
25
- data[:get_chan_info][channel[:chan_id]] = Ports::GRPC.lightning.get_chan_info(
25
+ data[:get_chan_info][channel[:chan_id]] = components[:grpc].lightning.get_chan_info(
26
26
  chan_id: channel[:chan_id]
27
27
  ).to_h
28
28
  end
29
29
 
30
30
  next if data[:get_node_info][channel[:remote_pubkey]]
31
31
 
32
- data[:get_node_info][channel[:remote_pubkey]] = Ports::GRPC.lightning.get_node_info(
32
+ data[:get_node_info][channel[:remote_pubkey]] = components[:grpc].lightning.get_node_info(
33
33
  pub_key: channel[:remote_pubkey]
34
34
  ).to_h
35
35
  end
@@ -95,17 +95,17 @@ module Lighstorm
95
95
  data
96
96
  end
97
97
 
98
- def self.data(&vcr)
99
- raw = vcr.nil? ? fetch : vcr.call(-> { fetch })
98
+ def self.data(components, &vcr)
99
+ raw = vcr.nil? ? fetch(components) : vcr.call(-> { fetch(components) })
100
100
 
101
101
  adapted = adapt(raw)
102
102
 
103
103
  adapted[:list_channels].map { |data| transform(data, adapted) }
104
104
  end
105
105
 
106
- def self.model(data)
106
+ def self.model(data, components)
107
107
  data.map do |node_data|
108
- Lighstorm::Models::Channel.new(node_data)
108
+ Lighstorm::Models::Channel.new(node_data, components)
109
109
  end
110
110
  end
111
111
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/impersonatable'
4
+
3
5
  require_relative './channel/mine'
4
6
  require_relative './channel/all'
5
7
  require_relative './channel/find_by_id'
@@ -7,20 +9,32 @@ require_relative './channel/find_by_id'
7
9
  module Lighstorm
8
10
  module Controllers
9
11
  module Channel
10
- def self.mine
11
- Mine.model(Mine.data)
12
- end
12
+ extend Impersonatable
13
13
 
14
- def self.all(limit: nil)
15
- All.model(All.data(limit: limit))
16
- end
14
+ class DSL < Impersonatable::DSL
15
+ def mine(injected_components = nil)
16
+ if injected_components.nil?
17
+ Mine.model(Mine.data(components), components)
18
+ else
19
+ Mine.model(Mine.data(injected_components), injected_components)
20
+ end
21
+ end
17
22
 
18
- def self.find_by_id(id)
19
- FindById.model(FindById.data(id))
20
- end
23
+ def all(limit: nil)
24
+ All.model(All.data(components, limit: limit), components)
25
+ end
26
+
27
+ def find_by_id(id, injected_components = nil)
28
+ if injected_components.nil?
29
+ FindById.model(FindById.data(components, id), components)
30
+ else
31
+ FindById.model(FindById.data(injected_components, id), injected_components)
32
+ end
33
+ end
21
34
 
22
- def self.adapt(dump: nil, gossip: nil)
23
- Models::Channel.adapt(dump: dump, gossip: gossip)
35
+ def adapt(dump: nil, gossip: nil)
36
+ Models::Channel.adapt(dump: dump, gossip: gossip)
37
+ end
24
38
  end
25
39
  end
26
40
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../ports/grpc'
4
+
5
+ module Lighstorm
6
+ module Controllers
7
+ module Impersonatable
8
+ class DSL
9
+ attr_reader :components
10
+
11
+ def initialize(components = nil)
12
+ @components = components.nil? ? { grpc: Ports::GRPC } : components
13
+ end
14
+ end
15
+
16
+ def as(id)
17
+ self::DSL.new({ grpc: Ports::GRPC::Impersonatable.new(id) })
18
+ end
19
+
20
+ def method_missing(method_name, *args, &block)
21
+ if args.size == 1 && args.first.is_a?(Hash)
22
+ self::DSL.new.send(method_name, **args.first, &block)
23
+ else
24
+ self::DSL.new.send(method_name, *args, &block)
25
+ end
26
+ end
27
+
28
+ def respond_to_missing?(method_name, include_private = false)
29
+ self::DSL.method_defined?(method_name) || super
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/impersonatable'
4
+
5
+ module Lighstorm
6
+ module Controllers
7
+ module Connection
8
+ def self.connect!(...)
9
+ LND.instance.connect!(...)
10
+ end
11
+
12
+ def self.add!(...)
13
+ LND.instance.add_connection!(...)
14
+ end
15
+
16
+ def self.all(...)
17
+ LND.instance.connections(...)
18
+ end
19
+
20
+ def self.default(...)
21
+ LND.instance.default(...)
22
+ end
23
+
24
+ def self.for(...)
25
+ LND.instance.for(...)
26
+ end
27
+
28
+ def self.remove!(...)
29
+ LND.instance.remove_connection!(...)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -14,7 +14,7 @@ module Lighstorm
14
14
  module Controllers
15
15
  module Forward
16
16
  module All
17
- def self.fetch(limit: nil)
17
+ def self.fetch(components, limit: nil)
18
18
  at = Time.now
19
19
 
20
20
  last_offset = 0
@@ -22,7 +22,7 @@ module Lighstorm
22
22
  forwards = []
23
23
 
24
24
  loop do
25
- response = Ports::GRPC.lightning.forwarding_history(index_offset: last_offset)
25
+ response = components[:grpc].lightning.forwarding_history(index_offset: last_offset)
26
26
 
27
27
  response.forwarding_events.each { |forward| forwards << forward.to_h }
28
28
 
@@ -40,8 +40,8 @@ module Lighstorm
40
40
 
41
41
  data = {
42
42
  at: at,
43
- get_info: Ports::GRPC.lightning.get_info.to_h,
44
- fee_report: Ports::GRPC.lightning.fee_report.to_h,
43
+ get_info: components[:grpc].lightning.get_info.to_h,
44
+ fee_report: components[:grpc].lightning.fee_report.to_h,
45
45
  forwarding_history: forwards,
46
46
  list_channels: {},
47
47
  get_chan_info: {},
@@ -51,7 +51,7 @@ module Lighstorm
51
51
  forwards.each do |forward|
52
52
  unless data[:get_chan_info][forward[:chan_id_in]]
53
53
  begin
54
- data[:get_chan_info][forward[:chan_id_in]] = Ports::GRPC.lightning.get_chan_info(
54
+ data[:get_chan_info][forward[:chan_id_in]] = components[:grpc].lightning.get_chan_info(
55
55
  chan_id: forward[:chan_id_in]
56
56
  ).to_h
57
57
  rescue GRPC::Unknown => e
@@ -62,7 +62,7 @@ module Lighstorm
62
62
  next if data[:get_chan_info][forward[:chan_id_out]]
63
63
 
64
64
  begin
65
- data[:get_chan_info][forward[:chan_id_out]] = Ports::GRPC.lightning.get_chan_info(
65
+ data[:get_chan_info][forward[:chan_id_out]] = components[:grpc].lightning.get_chan_info(
66
66
  chan_id: forward[:chan_id_out]
67
67
  ).to_h
68
68
  rescue GRPC::Unknown => e
@@ -83,7 +83,7 @@ module Lighstorm
83
83
  partner = partners.find { |p| p != data[:get_info][:identity_pubkey] }
84
84
 
85
85
  unless list_channels_done[partner]
86
- Ports::GRPC.lightning.list_channels(
86
+ components[:grpc].lightning.list_channels(
87
87
  peer: [partner].pack('H*')
88
88
  ).channels.map(&:to_h).each do |list_channels|
89
89
  data[:list_channels][list_channels[:chan_id]] = list_channels
@@ -94,14 +94,14 @@ module Lighstorm
94
94
  end
95
95
 
96
96
  unless data[:get_node_info][channel[:node1_pub]]
97
- data[:get_node_info][channel[:node1_pub]] = Ports::GRPC.lightning.get_node_info(
97
+ data[:get_node_info][channel[:node1_pub]] = components[:grpc].lightning.get_node_info(
98
98
  pub_key: channel[:node1_pub]
99
99
  ).to_h
100
100
  end
101
101
 
102
102
  next if data[:get_node_info][channel[:node2_pub]]
103
103
 
104
- data[:get_node_info][channel[:node2_pub]] = Ports::GRPC.lightning.get_node_info(
104
+ data[:get_node_info][channel[:node2_pub]] = components[:grpc].lightning.get_node_info(
105
105
  pub_key: channel[:node2_pub]
106
106
  ).to_h
107
107
  end
@@ -109,7 +109,7 @@ module Lighstorm
109
109
  data[:list_channels].each_value do |channel|
110
110
  next if data[:get_node_info][channel[:remote_pubkey]]
111
111
 
112
- data[:get_node_info][channel[:remote_pubkey]] = Ports::GRPC.lightning.get_node_info(
112
+ data[:get_node_info][channel[:remote_pubkey]] = components[:grpc].lightning.get_node_info(
113
113
  pub_key: channel[:remote_pubkey]
114
114
  ).to_h
115
115
  end
@@ -221,8 +221,12 @@ module Lighstorm
221
221
  data
222
222
  end
223
223
 
224
- def self.data(limit: nil, &vcr)
225
- raw = vcr.nil? ? fetch(limit: limit) : vcr.call(-> { fetch(limit: limit) })
224
+ def self.data(components, limit: nil, &vcr)
225
+ raw = if vcr.nil?
226
+ fetch(components, limit: limit)
227
+ else
228
+ vcr.call(-> { fetch(components, limit: limit) })
229
+ end
226
230
 
227
231
  adapted = adapt(raw)
228
232
 
@@ -67,8 +67,8 @@ module Lighstorm
67
67
  .sort_by { |group| - group[:analysis][:count] }
68
68
  end
69
69
 
70
- def self.data(direction: :out, hours_ago: nil, limit: nil, &vcr)
71
- data = All.data(&vcr)
70
+ def self.data(components, direction: :out, hours_ago: nil, limit: nil, &vcr)
71
+ data = All.data(components, &vcr)
72
72
 
73
73
  filtered = filter(data, hours_ago)
74
74
  groups = group(filtered, direction)
@@ -1,27 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/impersonatable'
4
+
3
5
  require_relative './forward/all'
4
6
  require_relative './forward/group_by_channel'
5
7
 
6
8
  module Lighstorm
7
9
  module Controllers
8
10
  module Forward
9
- def self.all(limit: nil)
10
- All.model(All.data(limit: limit))
11
- end
11
+ extend Impersonatable
12
12
 
13
- def self.first
14
- All.model(All.data).first
15
- end
13
+ class DSL < Impersonatable::DSL
14
+ def all(limit: nil)
15
+ All.model(All.data(components, limit: limit))
16
+ end
16
17
 
17
- def self.last
18
- All.model(All.data).last
19
- end
18
+ def first
19
+ All.model(All.data(components)).first
20
+ end
21
+
22
+ def last
23
+ All.model(All.data(components)).last
24
+ end
20
25
 
21
- def self.group_by_channel(direction: :out, hours_ago: nil, limit: nil)
22
- GroupByChannel.model(
23
- GroupByChannel.data(direction: direction, hours_ago: hours_ago, limit: limit)
24
- )
26
+ def group_by_channel(direction: :out, hours_ago: nil, limit: nil)
27
+ GroupByChannel.model(
28
+ GroupByChannel.data(components, direction: direction, hours_ago: hours_ago, limit: limit)
29
+ )
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -10,8 +10,8 @@ module Lighstorm
10
10
  module Controllers
11
11
  module Invoice
12
12
  module Create
13
- def self.call(grpc_request)
14
- Lighstorm::Ports::GRPC.send(grpc_request[:service]).send(
13
+ def self.call(components, grpc_request)
14
+ components[:grpc].send(grpc_request[:service]).send(
15
15
  grpc_request[:method], grpc_request[:params]
16
16
  ).to_h
17
17
  end
@@ -39,23 +39,31 @@ module Lighstorm
39
39
  request
40
40
  end
41
41
 
42
- def self.dispatch(grpc_request, &vcr)
43
- vcr.nil? ? call(grpc_request) : vcr.call(-> { call(grpc_request) }, :dispatch)
42
+ def self.dispatch(components, grpc_request, &vcr)
43
+ if vcr.nil?
44
+ call(components, grpc_request)
45
+ else
46
+ vcr.call(-> { call(components, grpc_request) }, :dispatch)
47
+ end
44
48
  end
45
49
 
46
50
  def self.adapt(response)
47
51
  Lighstorm::Adapter::Invoice.add_invoice(response)
48
52
  end
49
53
 
50
- def self.fetch(adapted, &vcr)
51
- FindBySecretHash.data(adapted[:secret][:hash], &vcr)
54
+ def self.fetch(components, adapted, &vcr)
55
+ FindBySecretHash.data(components, adapted[:secret][:hash], &vcr)
52
56
  end
53
57
 
54
- def self.model(data)
55
- FindBySecretHash.model(data)
58
+ def self.model(data, components)
59
+ FindBySecretHash.model(data, components)
56
60
  end
57
61
 
58
- def self.perform(payable:, expires_in:, description: nil, amount: nil, preview: false, &vcr)
62
+ def self.perform(
63
+ components,
64
+ payable:, expires_in:, description: nil, amount: nil,
65
+ preview: false, &vcr
66
+ )
59
67
  grpc_request = prepare(
60
68
  description: description,
61
69
  amount: amount,
@@ -65,14 +73,14 @@ module Lighstorm
65
73
 
66
74
  return grpc_request if preview
67
75
 
68
- response = dispatch(grpc_request, &vcr)
76
+ response = dispatch(components, grpc_request, &vcr)
69
77
 
70
78
  adapted = adapt(response)
71
79
 
72
- data = fetch(adapted, &vcr)
73
- model = self.model(data)
80
+ data = fetch(components, adapted, &vcr)
81
+ model = self.model(data, components)
74
82
 
75
- Action::Output.new({ response: response, result: model })
83
+ Action::Output.new({ request: grpc_request, response: response, result: model })
76
84
  end
77
85
  end
78
86
  end
@@ -14,20 +14,20 @@ module Lighstorm
14
14
  module Controllers
15
15
  module Invoice
16
16
  module Pay
17
- def self.dispatch(grpc_request, &vcr)
18
- Payment::Pay.dispatch(grpc_request, &vcr)
17
+ def self.dispatch(components, grpc_request, &vcr)
18
+ Payment::Pay.dispatch(components, grpc_request, &vcr)
19
19
  end
20
20
 
21
- def self.fetch(code, &vcr)
22
- Payment::Pay.fetch(code, &vcr)
21
+ def self.fetch(components, code, &vcr)
22
+ Payment::Pay.fetch(components, code, &vcr)
23
23
  end
24
24
 
25
25
  def self.adapt(data, node_get_info)
26
26
  Payment::Pay.adapt(data, node_get_info)
27
27
  end
28
28
 
29
- def self.model(data)
30
- Payment::Pay.model(data)
29
+ def self.model(data, components)
30
+ Payment::Pay.model(data, components)
31
31
  end
32
32
 
33
33
  def self.prepare(code:, times_out_in:, amount: nil, fee: nil, message: nil)
@@ -59,6 +59,7 @@ module Lighstorm
59
59
  end
60
60
 
61
61
  def self.perform(
62
+ components,
62
63
  times_out_in:, code:,
63
64
  amount: nil, fee: nil,
64
65
  message: nil,
@@ -74,19 +75,19 @@ module Lighstorm
74
75
 
75
76
  return grpc_request if preview
76
77
 
77
- response = dispatch(grpc_request, &vcr)
78
+ response = dispatch(components, grpc_request, &vcr)
78
79
 
79
- Payment::Pay.raise_error_if_exists!(response)
80
+ Payment::Pay.raise_error_if_exists!(grpc_request, response)
80
81
 
81
- data = fetch(code, &vcr)
82
+ data = fetch(components, code, &vcr)
82
83
 
83
84
  adapted = adapt(response, data)
84
85
 
85
- model = self.model(adapted)
86
+ model = self.model(adapted, components)
86
87
 
87
- Payment::Pay.raise_failure_if_exists!(model, response)
88
+ Payment::Pay.raise_failure_if_exists!(model, grpc_request, response)
88
89
 
89
- Action::Output.new({ response: response[:response], result: model })
90
+ Action::Output.new({ request: grpc_request, response: response[:response], result: model })
90
91
  end
91
92
  end
92
93
  end
@@ -7,11 +7,11 @@ module Lighstorm
7
7
  module Controllers
8
8
  module Invoice
9
9
  module PayThroughRoute
10
- def self.perform(_invoice, route:, preview: false, fake: false)
10
+ def self.perform(components, _invoice, route:, preview: false, fake: false)
11
11
  raise Errors::ToDoError, self
12
12
 
13
13
  channels = route.map do |channel_id|
14
- Channel.find_by_id(channel_id)
14
+ Channel.find_by_id(channel_id, components)
15
15
  end
16
16
 
17
17
  outgoing_channel_id = channels.first.id
@@ -8,7 +8,7 @@ module Lighstorm
8
8
  module Controllers
9
9
  module Invoice
10
10
  module All
11
- def self.fetch(limit: nil, spontaneous: false)
11
+ def self.fetch(components, limit: nil, spontaneous: false)
12
12
  at = Time.now
13
13
 
14
14
  last_offset = 0
@@ -16,7 +16,7 @@ module Lighstorm
16
16
  invoices = []
17
17
 
18
18
  loop do
19
- response = Ports::GRPC.lightning.list_invoices(
19
+ response = components[:grpc].lightning.list_invoices(
20
20
  index_offset: last_offset,
21
21
  num_max_invoices: 10
22
22
  )
@@ -57,11 +57,11 @@ module Lighstorm
57
57
  end
58
58
  end
59
59
 
60
- def self.data(limit: nil, spontaneous: false, &vcr)
60
+ def self.data(components, limit: nil, spontaneous: false, &vcr)
61
61
  raw = if vcr.nil?
62
- fetch(limit: limit, spontaneous: spontaneous)
62
+ fetch(components, limit: limit, spontaneous: spontaneous)
63
63
  else
64
- vcr.call(-> { fetch(limit: limit, spontaneous: spontaneous) })
64
+ vcr.call(-> { fetch(components, limit: limit, spontaneous: spontaneous) })
65
65
  end
66
66
 
67
67
  adapted = adapt(raw)
@@ -69,9 +69,9 @@ module Lighstorm
69
69
  transform(adapted)
70
70
  end
71
71
 
72
- def self.model(data)
72
+ def self.model(data, components)
73
73
  data.map do |node_data|
74
- Lighstorm::Models::Invoice.new(node_data)
74
+ Lighstorm::Models::Invoice.new(node_data, components)
75
75
  end
76
76
  end
77
77
  end
@@ -8,10 +8,10 @@ module Lighstorm
8
8
  module Controllers
9
9
  module Invoice
10
10
  module Decode
11
- def self.fetch(code)
11
+ def self.fetch(components, code)
12
12
  {
13
13
  _code: code,
14
- decode_pay_req: Ports::GRPC.lightning.decode_pay_req(pay_req: code).to_h
14
+ decode_pay_req: components[:grpc].lightning.decode_pay_req(pay_req: code).to_h
15
15
  }
16
16
  end
17
17
 
@@ -27,16 +27,16 @@ module Lighstorm
27
27
  adapted[:decode_pay_req]
28
28
  end
29
29
 
30
- def self.data(code, &vcr)
31
- raw = vcr.nil? ? fetch(code) : vcr.call(-> { fetch(code) })
30
+ def self.data(components, code, &vcr)
31
+ raw = vcr.nil? ? fetch(components, code) : vcr.call(-> { fetch(components, code) })
32
32
 
33
33
  adapted = adapt(raw)
34
34
 
35
35
  transform(adapted)
36
36
  end
37
37
 
38
- def self.model(data)
39
- Lighstorm::Models::Invoice.new(data)
38
+ def self.model(data, components)
39
+ Lighstorm::Models::Invoice.new(data, components)
40
40
  end
41
41
  end
42
42
  end