lighstorm 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +2 -2
- data/adapters/connections/channel_node.rb +1 -0
- data/adapters/edges/payment/purpose.rb +3 -3
- data/adapters/edges/payment.rb +1 -3
- data/adapters/invoice.rb +0 -2
- data/adapters/wallet.rb +42 -0
- data/components/cache.rb +1 -1
- data/components/lnd.rb +24 -8
- data/controllers/action.rb +5 -0
- data/controllers/activity/all.rb +85 -20
- data/controllers/activity.rb +15 -6
- data/controllers/channel/actions/apply_gossip.rb +3 -4
- data/controllers/channel/actions/update_fee.rb +11 -7
- data/controllers/channel/all.rb +11 -7
- data/controllers/channel/find_by_id.rb +11 -11
- data/controllers/channel/mine.rb +10 -10
- data/controllers/channel.rb +25 -11
- data/controllers/concerns/impersonatable.rb +33 -0
- data/controllers/connection.rb +33 -0
- data/controllers/forward/all.rb +16 -12
- data/controllers/forward/group_by_channel.rb +2 -2
- data/controllers/forward.rb +19 -13
- data/controllers/invoice/actions/create.rb +21 -13
- data/controllers/invoice/actions/pay.rb +13 -12
- data/controllers/invoice/actions/pay_through_route.rb +2 -2
- data/controllers/invoice/all.rb +7 -7
- data/controllers/invoice/decode.rb +6 -6
- data/controllers/invoice/find_by_code.rb +7 -7
- data/controllers/invoice/find_by_secret_hash.rb +10 -6
- data/controllers/invoice.rb +46 -39
- data/controllers/node/actions/apply_gossip.rb +1 -1
- data/controllers/node/actions/pay.rb +13 -12
- data/controllers/node/all.rb +11 -7
- data/controllers/node/find_by_public_key.rb +11 -7
- data/controllers/node/myself.rb +6 -6
- data/controllers/node.rb +17 -11
- data/controllers/payment/actions/pay.rb +23 -19
- data/controllers/payment/all.rb +7 -4
- data/controllers/payment.rb +20 -14
- data/controllers/secret/valid_proof.rb +5 -5
- data/controllers/transaction/all.rb +6 -5
- data/controllers/transaction.rb +14 -6
- data/controllers/wallet/balance.rb +34 -0
- data/controllers/wallet.rb +19 -0
- data/docs/README.md +70 -7
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/lighstorm.gemspec +1 -1
- data/models/activity.rb +3 -2
- data/models/connections/channel_node/fee.rb +5 -2
- data/models/connections/channel_node/policy.rb +3 -2
- data/models/connections/channel_node.rb +14 -4
- data/models/connections/forward_channel.rb +3 -2
- data/models/edges/channel/hop.rb +1 -1
- data/models/edges/channel.rb +5 -7
- data/models/edges/forward.rb +4 -3
- data/models/edges/groups/channel_forwards.rb +3 -2
- data/models/edges/payment.rb +4 -3
- data/models/errors.rb +16 -24
- data/models/invoice.rb +10 -4
- data/models/nodes/node.rb +10 -4
- data/models/secret.rb +10 -4
- data/models/wallet.rb +40 -0
- data/ports/dsl/lighstorm.rb +6 -2
- data/ports/grpc.rb +30 -2
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +10 -5
- data/deleted.sh +0 -1
data/controllers/channel.rb
CHANGED
@@ -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
|
-
|
11
|
-
Mine.model(Mine.data)
|
12
|
-
end
|
12
|
+
extend Impersonatable
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
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
|
data/controllers/forward/all.rb
CHANGED
@@ -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 =
|
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:
|
44
|
-
fee_report:
|
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]] =
|
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]] =
|
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
|
-
|
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]] =
|
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]] =
|
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]] =
|
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?
|
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)
|
data/controllers/forward.rb
CHANGED
@@ -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
|
-
|
10
|
-
All.model(All.data(limit: limit))
|
11
|
-
end
|
11
|
+
extend Impersonatable
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
class DSL < Impersonatable::DSL
|
14
|
+
def all(limit: nil)
|
15
|
+
All.model(All.data(components, limit: limit))
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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?
|
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(
|
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
|
data/controllers/invoice/all.rb
CHANGED
@@ -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 =
|
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:
|
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 =
|
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:
|
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:
|
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?
|
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
|
data/controllers/invoice.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './concerns/impersonatable'
|
4
|
+
|
3
5
|
require_relative './invoice/all'
|
4
6
|
require_relative './invoice/decode'
|
5
7
|
require_relative './invoice/find_by_secret_hash'
|
@@ -9,46 +11,51 @@ require_relative './invoice/actions/create'
|
|
9
11
|
module Lighstorm
|
10
12
|
module Controllers
|
11
13
|
module Invoice
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
description: description,
|
47
|
-
amount: amount,
|
48
|
-
expires_in: expires_in,
|
49
|
-
preview: preview,
|
50
|
-
&vcr
|
14
|
+
extend Impersonatable
|
15
|
+
|
16
|
+
class DSL < Impersonatable::DSL
|
17
|
+
def all(limit: nil, spontaneous: false)
|
18
|
+
All.model(All.data(components, limit: limit, spontaneous: spontaneous), components)
|
19
|
+
end
|
20
|
+
|
21
|
+
def first
|
22
|
+
All.model(All.data(components), components).first
|
23
|
+
end
|
24
|
+
|
25
|
+
def last
|
26
|
+
All.model(All.data(components), components).last
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_by_secret_hash(secret_hash, &vcr)
|
30
|
+
FindBySecretHash.model(FindBySecretHash.data(components, secret_hash, &vcr), components)
|
31
|
+
end
|
32
|
+
|
33
|
+
def find_by_code(code, &vcr)
|
34
|
+
FindByCode.model(FindByCode.data(components, code, &vcr), components)
|
35
|
+
end
|
36
|
+
|
37
|
+
def decode(code, &vcr)
|
38
|
+
Decode.model(Decode.data(components, code, &vcr), components)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create(
|
42
|
+
payable:,
|
43
|
+
description: nil, amount: nil,
|
44
|
+
# Lightning Invoice Expiration: UX Considerations
|
45
|
+
# https://d.elor.me/2022/01/lightning-invoice-expiration-ux-considerations/
|
46
|
+
expires_in: { hours: 24 },
|
47
|
+
preview: false, &vcr
|
51
48
|
)
|
49
|
+
Create.perform(
|
50
|
+
components,
|
51
|
+
payable: payable,
|
52
|
+
description: description,
|
53
|
+
amount: amount,
|
54
|
+
expires_in: expires_in,
|
55
|
+
preview: preview,
|
56
|
+
&vcr
|
57
|
+
)
|
58
|
+
end
|
52
59
|
end
|
53
60
|
end
|
54
61
|
end
|