lighstorm 0.0.15 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -7
- data/adapters/bitcoin/address.rb +19 -0
- data/adapters/bitcoin/transaction.rb +34 -0
- data/adapters/lightning/connections/channel_node/fee.rb +28 -0
- data/adapters/lightning/connections/channel_node/policy.rb +63 -0
- data/adapters/lightning/connections/channel_node.rb +77 -0
- data/adapters/lightning/connections/payment_channel.rb +30 -0
- data/adapters/lightning/edges/channel.rb +98 -0
- data/adapters/lightning/edges/forward.rb +42 -0
- data/adapters/lightning/edges/payment/purpose.rb +45 -0
- data/adapters/lightning/edges/payment.rb +89 -0
- data/adapters/lightning/invoice.rb +186 -0
- data/adapters/lightning/nodes/node.rb +113 -0
- data/controllers/action.rb +1 -1
- data/controllers/bitcoin/address/actions/create.rb +91 -0
- data/controllers/bitcoin/address/actions/pay.rb +119 -0
- data/controllers/bitcoin/address.rb +24 -0
- data/controllers/bitcoin/transaction/all.rb +65 -0
- data/controllers/bitcoin/transaction.rb +25 -0
- data/controllers/concerns/impersonatable.rb +5 -3
- data/controllers/connection.rb +1 -1
- data/controllers/lightning/channel/actions/apply_gossip.rb +201 -0
- data/controllers/lightning/channel/actions/update_fee.rb +94 -0
- data/controllers/lightning/channel/all.rb +85 -0
- data/controllers/lightning/channel/find_by_id.rb +155 -0
- data/controllers/lightning/channel/mine.rb +116 -0
- data/controllers/lightning/channel.rb +43 -0
- data/controllers/lightning/forward/all.rb +250 -0
- data/controllers/lightning/forward/group_by_channel.rb +91 -0
- data/controllers/lightning/forward.rb +36 -0
- data/controllers/lightning/invoice/actions/create.rb +90 -0
- data/controllers/lightning/invoice/actions/pay.rb +97 -0
- data/controllers/lightning/invoice/actions/pay_through_route.rb +73 -0
- data/controllers/lightning/invoice/all.rb +82 -0
- data/controllers/lightning/invoice/decode.rb +50 -0
- data/controllers/lightning/invoice/find_by_code.rb +76 -0
- data/controllers/lightning/invoice/find_by_secret_hash.rb +56 -0
- data/controllers/lightning/invoice.rb +64 -0
- data/controllers/lightning/node/actions/apply_gossip.rb +114 -0
- data/controllers/lightning/node/actions/pay.rb +117 -0
- data/controllers/lightning/node/all.rb +69 -0
- data/controllers/lightning/node/find_by_public_key.rb +55 -0
- data/controllers/lightning/node/myself.rb +36 -0
- data/controllers/lightning/node.rb +35 -0
- data/controllers/lightning/payment/actions/pay.rb +110 -0
- data/controllers/lightning/payment/all.rb +439 -0
- data/controllers/lightning/payment.rb +37 -0
- data/controllers/lightning/secret/valid_proof.rb +60 -0
- data/controllers/lightning/secret.rb +16 -0
- data/controllers/wallet/activity/all.rb +196 -0
- data/controllers/wallet/activity.rb +28 -0
- data/controllers/wallet/balance.rb +3 -3
- data/controllers/wallet.rb +1 -1
- data/docs/README.md +229 -148
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/models/bitcoin/address.rb +49 -0
- data/models/bitcoin/transaction.rb +41 -0
- data/models/concerns/protectable.rb +1 -1
- data/models/errors.rb +7 -8
- data/models/lightning/connections/channel_node/accounting.rb +27 -0
- data/models/lightning/connections/channel_node/fee.rb +82 -0
- data/models/lightning/connections/channel_node/htlc/blocks/delta.rb +41 -0
- data/models/lightning/connections/channel_node/htlc.rb +88 -0
- data/models/lightning/connections/channel_node/policy.rb +41 -0
- data/models/lightning/connections/channel_node.rb +86 -0
- data/models/lightning/connections/forward_channel.rb +31 -0
- data/models/lightning/connections/payment_channel.rb +58 -0
- data/models/lightning/edges/channel/accounting.rb +87 -0
- data/models/lightning/edges/channel/hop.rb +67 -0
- data/models/lightning/edges/channel.rb +197 -0
- data/models/lightning/edges/forward.rb +51 -0
- data/models/lightning/edges/groups/channel_forwards/analysis.rb +71 -0
- data/models/lightning/edges/groups/channel_forwards.rb +39 -0
- data/models/lightning/edges/payment.rb +104 -0
- data/models/lightning/invoice.rb +115 -0
- data/models/lightning/nodes/node/lightning.rb +33 -0
- data/models/lightning/nodes/node/platform.rb +50 -0
- data/models/lightning/nodes/node.rb +145 -0
- data/models/lightning/rate.rb +37 -0
- data/models/lightning/secret.rb +57 -0
- data/models/satoshis.rb +1 -1
- data/models/wallet/activity.rb +54 -0
- data/models/wallet/balance.rb +42 -0
- data/ports/dsl/lighstorm.rb +29 -16
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +74 -68
- data/adapters/connections/channel_node/fee.rb +0 -26
- data/adapters/connections/channel_node/policy.rb +0 -61
- data/adapters/connections/channel_node.rb +0 -75
- data/adapters/connections/payment_channel.rb +0 -28
- data/adapters/edges/channel.rb +0 -96
- data/adapters/edges/forward.rb +0 -40
- data/adapters/edges/payment/purpose.rb +0 -43
- data/adapters/edges/payment.rb +0 -87
- data/adapters/invoice.rb +0 -184
- data/adapters/nodes/node.rb +0 -111
- data/adapters/transaction.rb +0 -23
- data/controllers/activity/all.rb +0 -194
- data/controllers/activity.rb +0 -26
- data/controllers/channel/actions/apply_gossip.rb +0 -193
- data/controllers/channel/actions/update_fee.rb +0 -91
- data/controllers/channel/all.rb +0 -83
- data/controllers/channel/find_by_id.rb +0 -153
- data/controllers/channel/mine.rb +0 -114
- data/controllers/channel.rb +0 -41
- data/controllers/forward/all.rb +0 -248
- data/controllers/forward/group_by_channel.rb +0 -89
- data/controllers/forward.rb +0 -34
- data/controllers/invoice/actions/create.rb +0 -88
- data/controllers/invoice/actions/pay.rb +0 -95
- data/controllers/invoice/actions/pay_through_route.rb +0 -71
- data/controllers/invoice/all.rb +0 -80
- data/controllers/invoice/decode.rb +0 -44
- data/controllers/invoice/find_by_code.rb +0 -70
- data/controllers/invoice/find_by_secret_hash.rb +0 -54
- data/controllers/invoice.rb +0 -62
- data/controllers/node/actions/apply_gossip.rb +0 -112
- data/controllers/node/actions/pay.rb +0 -115
- data/controllers/node/all.rb +0 -67
- data/controllers/node/find_by_public_key.rb +0 -53
- data/controllers/node/myself.rb +0 -34
- data/controllers/node.rb +0 -33
- data/controllers/payment/actions/pay.rb +0 -108
- data/controllers/payment/all.rb +0 -437
- data/controllers/payment.rb +0 -35
- data/controllers/secret/valid_proof.rb +0 -58
- data/controllers/transaction/all.rb +0 -61
- data/controllers/transaction.rb +0 -25
- data/models/activity.rb +0 -52
- data/models/connections/channel_node/accounting.rb +0 -25
- data/models/connections/channel_node/fee.rb +0 -80
- data/models/connections/channel_node/htlc/blocks/delta.rb +0 -39
- data/models/connections/channel_node/htlc.rb +0 -86
- data/models/connections/channel_node/policy.rb +0 -39
- data/models/connections/channel_node.rb +0 -84
- data/models/connections/forward_channel.rb +0 -29
- data/models/connections/payment_channel.rb +0 -56
- data/models/edges/channel/accounting.rb +0 -85
- data/models/edges/channel/hop.rb +0 -65
- data/models/edges/channel.rb +0 -195
- data/models/edges/forward.rb +0 -49
- data/models/edges/groups/channel_forwards/analysis.rb +0 -69
- data/models/edges/groups/channel_forwards.rb +0 -37
- data/models/edges/payment.rb +0 -102
- data/models/invoice.rb +0 -113
- data/models/nodes/node/lightning.rb +0 -31
- data/models/nodes/node/platform.rb +0 -48
- data/models/nodes/node.rb +0 -143
- data/models/rate.rb +0 -35
- data/models/secret.rb +0 -55
- data/models/transaction.rb +0 -39
- data/models/wallet.rb +0 -40
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../ports/grpc'
|
4
|
+
require_relative '../../../adapters/lightning/invoice'
|
5
|
+
require_relative '../../../models/lightning/invoice'
|
6
|
+
|
7
|
+
module Lighstorm
|
8
|
+
module Controller
|
9
|
+
module Lightning
|
10
|
+
module Secret
|
11
|
+
module ValidProof
|
12
|
+
def self.fetch(components, invoice_main_secret_hash)
|
13
|
+
{ response: {
|
14
|
+
at: Time.now,
|
15
|
+
lookup_invoice: components[:grpc].lightning.lookup_invoice(r_hash_str: invoice_main_secret_hash).to_h
|
16
|
+
}, exception: nil }
|
17
|
+
rescue StandardError => e
|
18
|
+
{ exception: e }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.adapt(raw)
|
22
|
+
{
|
23
|
+
lookup_invoice: Lighstorm::Adapter::Lightning::Invoice.lookup_invoice(
|
24
|
+
raw[:lookup_invoice],
|
25
|
+
raw[:at]
|
26
|
+
)
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.transform(adapted, candidate_proof)
|
31
|
+
return true if adapted[:lookup_invoice][:secret][:proof] == candidate_proof
|
32
|
+
|
33
|
+
return false if adapted[:lookup_invoice][:payments].nil? ||
|
34
|
+
adapted[:lookup_invoice][:payments].empty?
|
35
|
+
|
36
|
+
!adapted[:lookup_invoice][:payments].find do |payment|
|
37
|
+
next if payment[:secret].nil?
|
38
|
+
|
39
|
+
payment[:secret][:proof] == candidate_proof
|
40
|
+
end.nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.data(components, invoice_main_secret_hash, candidate_proof, &vcr)
|
44
|
+
raise 'Invalid proof' if candidate_proof.size != 64
|
45
|
+
|
46
|
+
raw = if vcr.nil?
|
47
|
+
fetch(components, invoice_main_secret_hash)
|
48
|
+
else
|
49
|
+
vcr.call(-> { fetch(components, invoice_main_secret_hash) })
|
50
|
+
end
|
51
|
+
|
52
|
+
adapted = adapt(raw[:response])
|
53
|
+
|
54
|
+
transform(adapted, candidate_proof)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../concerns/impersonatable'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Controller
|
7
|
+
module Lightning
|
8
|
+
module Secret
|
9
|
+
extend Impersonatable
|
10
|
+
|
11
|
+
class DSL < Impersonatable::DSL
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../lightning/invoice/all'
|
4
|
+
require_relative '../../lightning/payment/all'
|
5
|
+
require_relative '../../lightning/forward/all'
|
6
|
+
require_relative '../../bitcoin/transaction/all'
|
7
|
+
require_relative '../../../models/wallet/activity'
|
8
|
+
|
9
|
+
module Lighstorm
|
10
|
+
module Controller
|
11
|
+
module Wallet
|
12
|
+
module Activity
|
13
|
+
module All
|
14
|
+
def self.bitcoin_how(transaction_label)
|
15
|
+
if transaction_label =~ /:openchannel:/
|
16
|
+
'opening-channel'
|
17
|
+
elsif transaction_label =~ /:closechannel:/
|
18
|
+
'closing-channel'
|
19
|
+
else
|
20
|
+
'spontaneously'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.fetch(components, direction: nil, layer: nil, how: nil, order: nil, limit: nil)
|
25
|
+
activities = []
|
26
|
+
|
27
|
+
# components[:grpc].lightning.list_channels.channels.each do |channel|
|
28
|
+
# if (layer.nil? || layer == 'lightning')
|
29
|
+
# activities << {
|
30
|
+
# direction: 'out',
|
31
|
+
# layer: 'lightning',
|
32
|
+
# at: Time.now,
|
33
|
+
# amount: {
|
34
|
+
# millisatoshis: channel.to_h[:local_chan_reserve_sat] * 1000
|
35
|
+
# },
|
36
|
+
# how: 'reserve',
|
37
|
+
# message: nil,
|
38
|
+
# data: {}
|
39
|
+
# }
|
40
|
+
|
41
|
+
# activities << {
|
42
|
+
# direction: 'out',
|
43
|
+
# layer: 'lightning',
|
44
|
+
# at: Time.now,
|
45
|
+
# amount: {
|
46
|
+
# millisatoshis: channel.to_h[:commit_fee] * 1000
|
47
|
+
# },
|
48
|
+
# how: 'commit',
|
49
|
+
# message: nil,
|
50
|
+
# data: {}
|
51
|
+
# }
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
|
55
|
+
Bitcoin::Transaction::All.data(components).each do |transaction|
|
56
|
+
transaction_how = bitcoin_how(transaction[:label])
|
57
|
+
|
58
|
+
if (layer.nil? || layer == 'bitcoin') && (how.nil? || transaction_how =~ /#{Regexp.escape(how)}/)
|
59
|
+
activities << {
|
60
|
+
direction: (transaction[:amount][:millisatoshis]).positive? ? 'in' : 'out',
|
61
|
+
layer: 'bitcoin',
|
62
|
+
at: transaction[:at],
|
63
|
+
amount: {
|
64
|
+
millisatoshis: if (transaction[:amount][:millisatoshis]).positive?
|
65
|
+
transaction[:amount][:millisatoshis]
|
66
|
+
else
|
67
|
+
-transaction[:amount][:millisatoshis]
|
68
|
+
end
|
69
|
+
},
|
70
|
+
how: transaction_how,
|
71
|
+
message: nil,
|
72
|
+
data: { transaction: transaction }
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
next unless (layer.nil? || layer == 'lightning') && (how.nil? || transaction_how =~ /#{Regexp.escape(how)}/) && %w[
|
77
|
+
channel opening-channel closing-channel
|
78
|
+
].include?(transaction_how)
|
79
|
+
|
80
|
+
activities << {
|
81
|
+
direction: (transaction[:amount][:millisatoshis]).positive? ? 'out' : 'in',
|
82
|
+
layer: 'lightning',
|
83
|
+
at: transaction[:at] + ((transaction[:amount][:millisatoshis]).positive? ? -1 : 1),
|
84
|
+
amount: {
|
85
|
+
millisatoshis: if (transaction[:amount][:millisatoshis]).positive?
|
86
|
+
(transaction[:amount][:millisatoshis] - transaction[:fee][:millisatoshis])
|
87
|
+
else
|
88
|
+
-(transaction[:amount][:millisatoshis] + transaction[:fee][:millisatoshis])
|
89
|
+
end
|
90
|
+
},
|
91
|
+
how: transaction_how,
|
92
|
+
message: nil,
|
93
|
+
data: { transaction: transaction }
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
if (direction.nil? || direction == 'in') && (layer.nil? || layer == 'lightning')
|
98
|
+
Lightning::Invoice::All.data(components, spontaneous: true).filter do |invoice|
|
99
|
+
!invoice[:payments].nil? && invoice[:payments].size.positive?
|
100
|
+
end.each do |invoice|
|
101
|
+
activity_how = invoice[:code].nil? ? 'spontaneously' : 'with-invoice'
|
102
|
+
|
103
|
+
next if !how.nil? && how != activity_how
|
104
|
+
|
105
|
+
# TODO: Improve performance by reducing invoice fields and removing payments?
|
106
|
+
invoice[:payments].each do |payment|
|
107
|
+
activities << {
|
108
|
+
direction: 'in',
|
109
|
+
layer: 'lightning',
|
110
|
+
at: payment[:at],
|
111
|
+
amount: payment[:amount],
|
112
|
+
how: activity_how,
|
113
|
+
message: payment[:message],
|
114
|
+
data: { invoice: invoice }
|
115
|
+
}
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
Lightning::Forward::All.data(components).each do |forward|
|
120
|
+
next if !how.nil? && how != 'forwarding'
|
121
|
+
|
122
|
+
activities << {
|
123
|
+
direction: 'in',
|
124
|
+
layer: 'lightning',
|
125
|
+
at: forward[:at],
|
126
|
+
amount: forward[:fee],
|
127
|
+
how: 'forwarding',
|
128
|
+
message: nil,
|
129
|
+
data: {}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
if (direction.nil? || direction == 'out') && (layer.nil? || layer == 'lightning')
|
135
|
+
Lightning::Payment::All.data(
|
136
|
+
components,
|
137
|
+
fetch: {
|
138
|
+
get_node_info: false,
|
139
|
+
lookup_invoice: false,
|
140
|
+
decode_pay_req: true,
|
141
|
+
get_chan_info: false
|
142
|
+
}
|
143
|
+
)[:data].each do |payment|
|
144
|
+
activity_how = payment[:invoice][:code].nil? ? 'spontaneously' : 'with-invoice'
|
145
|
+
|
146
|
+
next if !how.nil? && how != activity_how
|
147
|
+
|
148
|
+
# TODO: Improve performance by reducing invoice fields?
|
149
|
+
activities << {
|
150
|
+
direction: 'out',
|
151
|
+
layer: 'lightning',
|
152
|
+
at: payment[:at],
|
153
|
+
amount: payment[:amount],
|
154
|
+
how: activity_how,
|
155
|
+
message: payment[:message],
|
156
|
+
data: { invoice: payment[:invoice] }
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
activities = if order.nil? || order == 'desc'
|
162
|
+
activities.sort_by { |activity| -activity[:at].to_i }
|
163
|
+
else
|
164
|
+
activities.sort_by { |activity| activity[:at].to_i }
|
165
|
+
end
|
166
|
+
|
167
|
+
activities = activities[0..limit - 1] unless limit.nil?
|
168
|
+
|
169
|
+
{ activities: activities }
|
170
|
+
end
|
171
|
+
|
172
|
+
def self.transform(raw)
|
173
|
+
raw[:activities].map do |activity|
|
174
|
+
activity[:_key] = SecureRandom.hex
|
175
|
+
activity
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.data(components, direction: nil, layer: nil, how: nil, order: nil, limit: nil, &vcr)
|
180
|
+
raw = if vcr.nil?
|
181
|
+
fetch(components, direction: direction, layer: layer, how: how, order: order, limit: limit)
|
182
|
+
else
|
183
|
+
vcr.call(-> { fetch(components, direction: direction, how: how, order: order, limit: limit) })
|
184
|
+
end
|
185
|
+
|
186
|
+
transform(raw)
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.model(data)
|
190
|
+
data.map { |data| Model::Wallet::Activity.new(data) }
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../concerns/impersonatable'
|
4
|
+
|
5
|
+
require_relative './activity/all'
|
6
|
+
|
7
|
+
module Lighstorm
|
8
|
+
module Controller
|
9
|
+
module Wallet
|
10
|
+
module Activity
|
11
|
+
extend Impersonatable
|
12
|
+
|
13
|
+
class DSL < Impersonatable::DSL
|
14
|
+
def all(direction: nil, layer: nil, how: nil, order: nil, limit: nil)
|
15
|
+
All.model(All.data(
|
16
|
+
components,
|
17
|
+
direction: direction,
|
18
|
+
how: how,
|
19
|
+
layer: layer,
|
20
|
+
order: order,
|
21
|
+
limit: limit
|
22
|
+
))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative '../../adapters/wallet'
|
4
|
-
require_relative '../../models/wallet'
|
4
|
+
require_relative '../../models/wallet/balance'
|
5
5
|
|
6
6
|
module Lighstorm
|
7
|
-
module
|
7
|
+
module Controller
|
8
8
|
module Wallet
|
9
9
|
module Balance
|
10
10
|
def self.fetch(components)
|
@@ -26,7 +26,7 @@ module Lighstorm
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.model(data)
|
29
|
-
|
29
|
+
Model::Wallet::Balance.new(data)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|