lighstorm 0.0.12 → 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/.env.example +18 -3
- data/Gemfile.lock +4 -4
- data/README.md +11 -5
- 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/transaction.rb +23 -0
- data/adapters/wallet.rb +42 -0
- data/components/cache.rb +1 -1
- data/components/lnd.rb +67 -29
- data/controllers/action.rb +5 -0
- data/controllers/activity/all.rb +194 -0
- data/controllers/activity.rb +26 -0
- 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 +29 -73
- data/controllers/transaction.rb +14 -6
- data/controllers/wallet/balance.rb +34 -0
- data/controllers/wallet.rb +19 -0
- data/docs/README.md +204 -31
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/lighstorm.gemspec +1 -1
- data/models/activity.rb +52 -0
- 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/transaction.rb +10 -15
- data/models/wallet.rb +40 -0
- data/ports/dsl/lighstorm.rb +8 -4
- data/ports/grpc.rb +30 -2
- data/static/cache.rb +3 -0
- data/static/spec.rb +1 -1
- metadata +14 -5
- data/deleted.sh +0 -1
@@ -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
|
@@ -26,7 +26,7 @@ module Lighstorm
|
|
26
26
|
].freeze
|
27
27
|
|
28
28
|
def self.perform(actual, gossip)
|
29
|
-
updated = Models::Node.new(Adapter::Node.subscribe_channel_graph(gossip))
|
29
|
+
updated = Models::Node.new(Adapter::Node.subscribe_channel_graph(gossip), nil)
|
30
30
|
|
31
31
|
actual_dump = actual.dump
|
32
32
|
updated_dump = updated.dump
|
@@ -18,20 +18,20 @@ module Lighstorm
|
|
18
18
|
module Controllers
|
19
19
|
module Node
|
20
20
|
module Pay
|
21
|
-
def self.dispatch(grpc_request, &vcr)
|
22
|
-
Payment::Pay.dispatch(grpc_request, &vcr)
|
21
|
+
def self.dispatch(components, grpc_request, &vcr)
|
22
|
+
Payment::Pay.dispatch(components, grpc_request, &vcr)
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.fetch(&vcr)
|
26
|
-
Payment::Pay.fetch(&vcr)
|
25
|
+
def self.fetch(components, &vcr)
|
26
|
+
Payment::Pay.fetch(components, &vcr)
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.adapt(data, node_get_info)
|
30
30
|
Payment::Pay.adapt(data, node_get_info)
|
31
31
|
end
|
32
32
|
|
33
|
-
def self.model(data)
|
34
|
-
Payment::Pay.model(data)
|
33
|
+
def self.model(data, components)
|
34
|
+
Payment::Pay.model(data, components)
|
35
35
|
end
|
36
36
|
|
37
37
|
def self.prepare(public_key:, amount:, times_out_in:, secret:, through:, fee: nil, message: nil)
|
@@ -75,6 +75,7 @@ module Lighstorm
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.perform(
|
78
|
+
components,
|
78
79
|
public_key:, amount:, through:,
|
79
80
|
times_out_in:, fee: nil,
|
80
81
|
message: nil, secret: nil,
|
@@ -94,19 +95,19 @@ module Lighstorm
|
|
94
95
|
|
95
96
|
return grpc_request if preview
|
96
97
|
|
97
|
-
response = dispatch(grpc_request, &vcr)
|
98
|
+
response = dispatch(components, grpc_request, &vcr)
|
98
99
|
|
99
|
-
Payment::Pay.raise_error_if_exists!(response)
|
100
|
+
Payment::Pay.raise_error_if_exists!(grpc_request, response)
|
100
101
|
|
101
|
-
data = fetch(&vcr)
|
102
|
+
data = fetch(components, &vcr)
|
102
103
|
|
103
104
|
adapted = adapt(response, data)
|
104
105
|
|
105
|
-
model = self.model(adapted)
|
106
|
+
model = self.model(adapted, components)
|
106
107
|
|
107
|
-
Payment::Pay.raise_failure_if_exists!(model, response)
|
108
|
+
Payment::Pay.raise_failure_if_exists!(model, grpc_request, response)
|
108
109
|
|
109
|
-
Action::Output.new({ response: response[:response], result: model })
|
110
|
+
Action::Output.new({ request: grpc_request, response: response[:response], result: model })
|
110
111
|
end
|
111
112
|
end
|
112
113
|
end
|
data/controllers/node/all.rb
CHANGED
@@ -7,11 +7,11 @@ module Lighstorm
|
|
7
7
|
module Controllers
|
8
8
|
module Node
|
9
9
|
module All
|
10
|
-
def self.fetch(limit: nil)
|
10
|
+
def self.fetch(components, limit: nil)
|
11
11
|
data = {
|
12
12
|
at: Time.now,
|
13
|
-
get_info:
|
14
|
-
describe_graph:
|
13
|
+
get_info: components[:grpc].lightning.get_info.to_h,
|
14
|
+
describe_graph: components[:grpc].lightning.describe_graph.nodes
|
15
15
|
}
|
16
16
|
|
17
17
|
data[:describe_graph] = data[:describe_graph][0..limit - 1] unless limit.nil?
|
@@ -42,8 +42,12 @@ module Lighstorm
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def self.data(limit: nil, &vcr)
|
46
|
-
raw = vcr.nil?
|
45
|
+
def self.data(components, limit: nil, &vcr)
|
46
|
+
raw = if vcr.nil?
|
47
|
+
fetch(components, limit: limit)
|
48
|
+
else
|
49
|
+
vcr.call(-> { fetch(components, limit: limit) })
|
50
|
+
end
|
47
51
|
|
48
52
|
adapted = adapt(raw)
|
49
53
|
|
@@ -52,9 +56,9 @@ module Lighstorm
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
def self.model(data)
|
59
|
+
def self.model(data, components)
|
56
60
|
data.map do |node_data|
|
57
|
-
Lighstorm::Models::Node.new(node_data)
|
61
|
+
Lighstorm::Models::Node.new(node_data, components)
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -7,11 +7,11 @@ module Lighstorm
|
|
7
7
|
module Controllers
|
8
8
|
module Node
|
9
9
|
module FindByPublicKey
|
10
|
-
def self.fetch(public_key)
|
10
|
+
def self.fetch(components, public_key)
|
11
11
|
{
|
12
12
|
at: Time.now,
|
13
|
-
get_info:
|
14
|
-
get_node_info:
|
13
|
+
get_info: components[:grpc].lightning.get_info.to_h,
|
14
|
+
get_node_info: components[:grpc].lightning.get_node_info(pub_key: public_key).to_h
|
15
15
|
}
|
16
16
|
end
|
17
17
|
|
@@ -22,8 +22,12 @@ module Lighstorm
|
|
22
22
|
}
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.data(public_key, &vcr)
|
26
|
-
raw = vcr.nil?
|
25
|
+
def self.data(components, public_key, &vcr)
|
26
|
+
raw = if vcr.nil?
|
27
|
+
fetch(components, public_key)
|
28
|
+
else
|
29
|
+
vcr.call(-> { fetch(components, public_key) })
|
30
|
+
end
|
27
31
|
|
28
32
|
adapted = adapt(raw)
|
29
33
|
|
@@ -40,8 +44,8 @@ module Lighstorm
|
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
def self.model(data)
|
44
|
-
Lighstorm::Models::Node.new(data)
|
47
|
+
def self.model(data, components)
|
48
|
+
Lighstorm::Models::Node.new(data, components)
|
45
49
|
end
|
46
50
|
end
|
47
51
|
end
|
data/controllers/node/myself.rb
CHANGED
@@ -7,10 +7,10 @@ module Lighstorm
|
|
7
7
|
module Controllers
|
8
8
|
module Node
|
9
9
|
module Myself
|
10
|
-
def self.fetch
|
10
|
+
def self.fetch(components)
|
11
11
|
{
|
12
12
|
at: Time.now,
|
13
|
-
get_info:
|
13
|
+
get_info: components[:grpc].lightning.get_info.to_h
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
@@ -18,15 +18,15 @@ module Lighstorm
|
|
18
18
|
{ get_info: Lighstorm::Adapter::Node.get_info(raw[:get_info]) }
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.data(&vcr)
|
22
|
-
raw = vcr.nil? ? fetch : vcr.call(-> { fetch })
|
21
|
+
def self.data(components, &vcr)
|
22
|
+
raw = vcr.nil? ? fetch(components) : vcr.call(-> { fetch(components) })
|
23
23
|
|
24
24
|
adapted = adapt(raw)
|
25
25
|
adapted[:get_info].merge(myself: true)
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.model(data)
|
29
|
-
Lighstorm::Models::Node.new(data)
|
28
|
+
def self.model(data, components)
|
29
|
+
Lighstorm::Models::Node.new(data, components)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/controllers/node.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './concerns/impersonatable'
|
4
|
+
|
3
5
|
require_relative './node/myself'
|
4
6
|
require_relative './node/all'
|
5
7
|
require_relative './node/find_by_public_key'
|
@@ -7,20 +9,24 @@ require_relative './node/find_by_public_key'
|
|
7
9
|
module Lighstorm
|
8
10
|
module Controllers
|
9
11
|
module Node
|
10
|
-
|
11
|
-
Myself.model(Myself.data)
|
12
|
-
end
|
12
|
+
extend Impersonatable
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class DSL < Impersonatable::DSL
|
15
|
+
def myself
|
16
|
+
Myself.model(Myself.data(components), components)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def all(limit: nil)
|
20
|
+
All.model(All.data(components, limit: limit), components)
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_by_public_key(public_key)
|
24
|
+
FindByPublicKey.model(FindByPublicKey.data(components, public_key), components)
|
25
|
+
end
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
def adapt(dump: nil, gossip: nil)
|
28
|
+
Models::Node.adapt(dump: dump, gossip: gossip)
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
@@ -14,9 +14,9 @@ module Lighstorm
|
|
14
14
|
module Controllers
|
15
15
|
module Payment
|
16
16
|
module Pay
|
17
|
-
def self.call(grpc_request)
|
17
|
+
def self.call(components, grpc_request)
|
18
18
|
result = []
|
19
|
-
|
19
|
+
components[:grpc].send(grpc_request[:service]).send(
|
20
20
|
grpc_request[:method], grpc_request[:params]
|
21
21
|
) do |response|
|
22
22
|
result << response.to_h
|
@@ -26,19 +26,23 @@ module Lighstorm
|
|
26
26
|
{ exception: e }
|
27
27
|
end
|
28
28
|
|
29
|
-
def self.dispatch(grpc_request, &vcr)
|
30
|
-
vcr.nil?
|
29
|
+
def self.dispatch(components, grpc_request, &vcr)
|
30
|
+
if vcr.nil?
|
31
|
+
call(components, grpc_request)
|
32
|
+
else
|
33
|
+
vcr.call(-> { call(components, grpc_request) }, :dispatch)
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
|
-
def self.fetch_all(code)
|
37
|
+
def self.fetch_all(components, code)
|
34
38
|
{
|
35
|
-
invoice_decode: code.nil? ? nil : Invoice::Decode.data(code),
|
36
|
-
node_myself: Node::Myself.data
|
39
|
+
invoice_decode: code.nil? ? nil : Invoice::Decode.data(components, code),
|
40
|
+
node_myself: Node::Myself.data(components)
|
37
41
|
}
|
38
42
|
end
|
39
43
|
|
40
|
-
def self.fetch(code = nil, &vcr)
|
41
|
-
raw = vcr.nil? ? fetch_all(code) : vcr.call(-> { fetch_all(code) })
|
44
|
+
def self.fetch(components, code = nil, &vcr)
|
45
|
+
raw = vcr.nil? ? fetch_all(components, code) : vcr.call(-> { fetch_all(components, code) })
|
42
46
|
end
|
43
47
|
|
44
48
|
def self.adapt(grpc_data, fetch_data)
|
@@ -49,52 +53,52 @@ module Lighstorm
|
|
49
53
|
)
|
50
54
|
end
|
51
55
|
|
52
|
-
def self.model(data)
|
53
|
-
Models::Payment.new(data)
|
56
|
+
def self.model(data, components)
|
57
|
+
Models::Payment.new(data, components)
|
54
58
|
end
|
55
59
|
|
56
|
-
def self.raise_error_if_exists!(response)
|
60
|
+
def self.raise_error_if_exists!(request, response)
|
57
61
|
return if response[:exception].nil?
|
58
62
|
|
59
63
|
if response[:exception].is_a?(GRPC::AlreadyExists)
|
60
64
|
raise AlreadyPaidError.new(
|
61
65
|
'The invoice is already paid.',
|
62
|
-
grpc: response[:exception]
|
66
|
+
request: request, grpc: response[:exception]
|
63
67
|
)
|
64
68
|
end
|
65
69
|
|
66
70
|
if response[:exception].message =~ /amount must not be specified when paying a non-zero/
|
67
71
|
raise AmountForNonZeroError.new(
|
68
72
|
'Millisatoshis must not be specified when paying a non-zero amount invoice.',
|
69
|
-
grpc: response[:exception]
|
73
|
+
request: request, grpc: response[:exception]
|
70
74
|
)
|
71
75
|
end
|
72
76
|
|
73
77
|
if response[:exception].message =~ /amount must be specified when paying a zero amount/
|
74
78
|
raise MissingMillisatoshisError.new(
|
75
79
|
'Millisatoshis must be specified when paying a zero amount invoice.',
|
76
|
-
grpc: response[:exception]
|
80
|
+
request: request, grpc: response[:exception]
|
77
81
|
)
|
78
82
|
end
|
79
83
|
|
80
84
|
raise PaymentError.new(
|
81
85
|
response[:exception].message,
|
82
|
-
grpc: response[:exception]
|
86
|
+
request: request, grpc: response[:exception]
|
83
87
|
)
|
84
88
|
end
|
85
89
|
|
86
|
-
def self.raise_failure_if_exists!(model, response)
|
90
|
+
def self.raise_failure_if_exists!(model, request, response)
|
87
91
|
return unless model.state == 'failed'
|
88
92
|
|
89
93
|
if response[:response].last[:failure_reason] == :FAILURE_REASON_NO_ROUTE
|
90
94
|
raise NoRouteFoundError.new(
|
91
95
|
response[:response].last[:failure_reason],
|
92
|
-
response: response[:response], result: model
|
96
|
+
request: request, response: response[:response], result: model
|
93
97
|
)
|
94
98
|
else
|
95
99
|
raise PaymentError.new(
|
96
100
|
response[:response].last[:failure_reason],
|
97
|
-
response: response[:response], result: model
|
101
|
+
request: request, response: response[:response], result: model
|
98
102
|
)
|
99
103
|
end
|
100
104
|
end
|
data/controllers/payment/all.rb
CHANGED
@@ -12,10 +12,10 @@ module Lighstorm
|
|
12
12
|
module Controllers
|
13
13
|
module Payment
|
14
14
|
module All
|
15
|
-
def self.fetch(purpose: nil, invoice_code: nil, secret_hash: nil, limit: nil, fetch: {})
|
15
|
+
def self.fetch(components, purpose: nil, invoice_code: nil, secret_hash: nil, limit: nil, fetch: {})
|
16
16
|
at = Time.now
|
17
17
|
|
18
|
-
grpc =
|
18
|
+
grpc = components[:grpc].session
|
19
19
|
|
20
20
|
get_info = grpc.lightning.get_info.to_h
|
21
21
|
|
@@ -396,17 +396,20 @@ module Lighstorm
|
|
396
396
|
end
|
397
397
|
|
398
398
|
def self.data(
|
399
|
+
components,
|
399
400
|
purpose: nil, invoice_code: nil, secret_hash: nil, limit: nil,
|
400
401
|
fetch: {}, &vcr
|
401
402
|
)
|
402
403
|
raw = if vcr.nil?
|
403
404
|
self.fetch(
|
405
|
+
components,
|
404
406
|
purpose: purpose, invoice_code: invoice_code, secret_hash: secret_hash,
|
405
407
|
limit: limit, fetch: fetch
|
406
408
|
)
|
407
409
|
else
|
408
410
|
vcr.call(lambda {
|
409
411
|
self.fetch(
|
412
|
+
components,
|
410
413
|
purpose: purpose, invoice_code: invoice_code, secret_hash: secret_hash,
|
411
414
|
limit: limit, fetch: fetch
|
412
415
|
)
|
@@ -423,9 +426,9 @@ module Lighstorm
|
|
423
426
|
}
|
424
427
|
end
|
425
428
|
|
426
|
-
def self.model(data)
|
429
|
+
def self.model(data, components)
|
427
430
|
data[:data].map do |node_data|
|
428
|
-
Lighstorm::Models::Payment.new(node_data)
|
431
|
+
Lighstorm::Models::Payment.new(node_data, components)
|
429
432
|
end
|
430
433
|
end
|
431
434
|
end
|
data/controllers/payment.rb
CHANGED
@@ -1,28 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './concerns/impersonatable'
|
4
|
+
|
3
5
|
require_relative './payment/all'
|
4
6
|
|
5
7
|
module Lighstorm
|
6
8
|
module Controllers
|
7
9
|
module Payment
|
8
|
-
|
9
|
-
All.model(All.data(purpose: purpose, limit: limit, fetch: fetch))
|
10
|
-
end
|
10
|
+
extend Impersonatable
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class DSL < Impersonatable::DSL
|
13
|
+
def all(purpose: nil, limit: nil, fetch: {})
|
14
|
+
All.model(All.data(components, purpose: purpose, limit: limit, fetch: fetch), components)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def first(purpose: nil, fetch: {})
|
18
|
+
All.model(All.data(components, purpose: purpose, fetch: fetch), components).first
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def last(purpose: nil, fetch: {})
|
22
|
+
All.model(All.data(components, purpose: purpose, fetch: fetch), components).last
|
23
|
+
end
|
24
|
+
|
25
|
+
def find_by_secret_hash(secret_hash, &vcr)
|
26
|
+
All.model(All.data(components, secret_hash: secret_hash, &vcr), components).first
|
27
|
+
end
|
23
28
|
|
24
|
-
|
25
|
-
|
29
|
+
def find_by_invoice_code(invoice_code, &vcr)
|
30
|
+
All.model(All.data(components, invoice_code: invoice_code, &vcr), components).first
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
end
|
@@ -8,10 +8,10 @@ module Lighstorm
|
|
8
8
|
module Controllers
|
9
9
|
module Secret
|
10
10
|
module ValidProof
|
11
|
-
def self.fetch(invoice_main_secret_hash)
|
11
|
+
def self.fetch(components, invoice_main_secret_hash)
|
12
12
|
{ response: {
|
13
13
|
at: Time.now,
|
14
|
-
lookup_invoice:
|
14
|
+
lookup_invoice: components[:grpc].lightning.lookup_invoice(r_hash_str: invoice_main_secret_hash).to_h
|
15
15
|
}, exception: nil }
|
16
16
|
rescue StandardError => e
|
17
17
|
{ exception: e }
|
@@ -39,13 +39,13 @@ module Lighstorm
|
|
39
39
|
end.nil?
|
40
40
|
end
|
41
41
|
|
42
|
-
def self.data(invoice_main_secret_hash, proof, &vcr)
|
42
|
+
def self.data(components, invoice_main_secret_hash, proof, &vcr)
|
43
43
|
raise 'Invalid proof' if proof.size != 64
|
44
44
|
|
45
45
|
raw = if vcr.nil?
|
46
|
-
fetch(invoice_main_secret_hash)
|
46
|
+
fetch(components, invoice_main_secret_hash)
|
47
47
|
else
|
48
|
-
vcr.call(-> { fetch(invoice_main_secret_hash) })
|
48
|
+
vcr.call(-> { fetch(components, invoice_main_secret_hash) })
|
49
49
|
end
|
50
50
|
|
51
51
|
adapted = adapt(raw[:response])
|