lighstorm 0.0.13 → 0.0.15

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 (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
@@ -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
@@ -8,15 +8,15 @@ module Lighstorm
8
8
  module Controllers
9
9
  module Invoice
10
10
  module FindByCode
11
- def self.fetch(code)
11
+ def self.fetch(components, code)
12
12
  at = Time.now
13
13
 
14
- decoded = Ports::GRPC.lightning.decode_pay_req(pay_req: code).to_h
14
+ decoded = components[:grpc].lightning.decode_pay_req(pay_req: code).to_h
15
15
 
16
16
  { response: {
17
17
  at: at,
18
18
  decode_pay_req: decoded,
19
- lookup_invoice: Ports::GRPC.lightning.lookup_invoice(r_hash_str: decoded[:payment_hash]).to_h
19
+ lookup_invoice: components[:grpc].lightning.lookup_invoice(r_hash_str: decoded[:payment_hash]).to_h
20
20
  }, exception: nil }
21
21
  rescue StandardError => e
22
22
  { exception: e }
@@ -38,8 +38,8 @@ module Lighstorm
38
38
  adapted[:lookup_invoice]
39
39
  end
40
40
 
41
- def self.data(code, &vcr)
42
- raw = vcr.nil? ? fetch(code) : vcr.call(-> { fetch(code) })
41
+ def self.data(components, code, &vcr)
42
+ raw = vcr.nil? ? fetch(components, code) : vcr.call(-> { fetch(components, code) })
43
43
 
44
44
  raise_error_if_exists!(raw)
45
45
 
@@ -48,8 +48,8 @@ module Lighstorm
48
48
  transform(adapted)
49
49
  end
50
50
 
51
- def self.model(data)
52
- Lighstorm::Models::Invoice.new(data)
51
+ def self.model(data, components)
52
+ Lighstorm::Models::Invoice.new(data, components)
53
53
  end
54
54
 
55
55
  def self.raise_error_if_exists!(response)
@@ -8,10 +8,10 @@ module Lighstorm
8
8
  module Controllers
9
9
  module Invoice
10
10
  module FindBySecretHash
11
- def self.fetch(secret_hash)
11
+ def self.fetch(components, secret_hash)
12
12
  { response: {
13
13
  at: Time.now,
14
- lookup_invoice: Ports::GRPC.lightning.lookup_invoice(r_hash_str: secret_hash).to_h
14
+ lookup_invoice: components[:grpc].lightning.lookup_invoice(r_hash_str: secret_hash).to_h
15
15
  }, exception: nil }
16
16
  rescue StandardError => e
17
17
  { exception: e }
@@ -33,16 +33,20 @@ module Lighstorm
33
33
  adapted[:lookup_invoice]
34
34
  end
35
35
 
36
- def self.data(secret_hash, &vcr)
37
- raw = vcr.nil? ? fetch(secret_hash) : vcr.call(-> { fetch(secret_hash) })
36
+ def self.data(components, secret_hash, &vcr)
37
+ raw = if vcr.nil?
38
+ fetch(components, secret_hash)
39
+ else
40
+ vcr.call(-> { fetch(components, secret_hash) })
41
+ end
38
42
 
39
43
  adapted = adapt(raw[:response])
40
44
 
41
45
  transform(adapted)
42
46
  end
43
47
 
44
- def self.model(data)
45
- Lighstorm::Models::Invoice.new(data)
48
+ def self.model(data, components)
49
+ Lighstorm::Models::Invoice.new(data, components)
46
50
  end
47
51
  end
48
52
  end