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
@@ -1,103 +1,59 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../invoice/all'
4
- require_relative '../payment/all'
5
- require_relative '../forward/all'
3
+ require_relative '../../ports/grpc'
4
+ require_relative '../../adapters/transaction'
6
5
  require_relative '../../models/transaction'
7
6
 
8
7
  module Lighstorm
9
8
  module Controllers
10
9
  module Transaction
11
10
  module All
12
- def self.fetch(direction: nil, how: nil, limit: nil)
13
- transactions = []
14
-
15
- if direction.nil? || direction == 'in'
16
- Invoice::All.data(spontaneous: true).filter do |invoice|
17
- !invoice[:payments].nil? && invoice[:payments].size.positive?
18
- end.each do |invoice|
19
- transaction_how = invoice[:code].nil? ? 'spontaneously' : 'with-invoice'
20
-
21
- next if !how.nil? && how != transaction_how
22
-
23
- # TODO: Improve performance by reducing invoice fields and removing payments?
24
- invoice[:payments].each do |payment|
25
- transactions << {
26
- direction: 'in',
27
- at: payment[:at],
28
- amount: payment[:amount],
29
- how: transaction_how,
30
- message: payment[:message],
31
- data: { invoice: invoice }
32
- }
33
- end
34
- end
35
-
36
- Forward::All.data.each do |forward|
37
- next if !how.nil? && how != 'forwarding'
38
-
39
- transactions << {
40
- direction: 'in',
41
- at: forward[:at],
42
- amount: forward[:fee],
43
- how: 'forwarding',
44
- message: nil,
45
- data: {}
46
- }
47
- end
48
- end
11
+ def self.fetch(components, limit: nil)
12
+ at = Time.now
49
13
 
50
- if direction.nil? || direction == 'out'
51
- Payment::All.data(
52
- fetch: {
53
- get_node_info: false,
54
- lookup_invoice: false,
55
- decode_pay_req: true,
56
- get_chan_info: false
57
- }
58
- )[:data].each do |payment|
59
- transaction_how = payment[:invoice][:code].nil? ? 'spontaneously' : 'with-invoice'
14
+ transactions = []
60
15
 
61
- next if !how.nil? && how != transaction_how
16
+ response = components[:grpc].lightning.get_transactions
62
17
 
63
- # TODO: Improve performance by reducing invoice fields?
64
- transactions << {
65
- direction: 'out',
66
- at: payment[:at],
67
- amount: payment[:amount],
68
- how: transaction_how,
69
- message: payment[:message],
70
- data: { invoice: payment[:invoice] }
71
- }
72
- end
18
+ response.transactions.each do |transaction|
19
+ transactions << transaction.to_h
73
20
  end
74
21
 
75
- transactions = transactions.sort_by { |transaction| -transaction[:at].to_i }
22
+ transactions = transactions.sort_by { |raw_transaction| -raw_transaction[:time_stamp] }
76
23
 
77
24
  transactions = transactions[0..limit - 1] unless limit.nil?
78
25
 
79
- { transactions: transactions }
26
+ { at: at, get_transactions: transactions }
80
27
  end
81
28
 
82
- def self.transform(raw)
83
- raw[:transactions].map do |transaction|
84
- transaction[:_key] = SecureRandom.hex
85
- transaction
86
- end
29
+ def self.adapt(raw)
30
+ {
31
+ get_transactions: raw[:get_transactions].map do |raw_transaction|
32
+ Lighstorm::Adapter::Transaction.get_transactions(raw_transaction)
33
+ end
34
+ }
87
35
  end
88
36
 
89
- def self.data(direction: nil, how: nil, limit: nil, &vcr)
37
+ def self.transform(adapted)
38
+ adapted[:get_transactions]
39
+ end
40
+
41
+ def self.data(components, limit: nil, &vcr)
90
42
  raw = if vcr.nil?
91
- fetch(direction: direction, how: how, limit: limit)
43
+ fetch(components, limit: limit)
92
44
  else
93
- vcr.call(-> { fetch(direction: direction, how: how, limit: limit) })
45
+ vcr.call(-> { fetch(components, limit: limit) })
94
46
  end
95
47
 
96
- transform(raw)
48
+ adapted = adapt(raw)
49
+
50
+ transform(adapted)
97
51
  end
98
52
 
99
53
  def self.model(data)
100
- data.map { |data| Models::Transaction.new(data) }
54
+ data.map do |transaction_data|
55
+ Lighstorm::Models::Transaction.new(transaction_data)
56
+ end
101
57
  end
102
58
  end
103
59
  end
@@ -1,16 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './concerns/impersonatable'
4
+
3
5
  require_relative './transaction/all'
4
6
 
5
7
  module Lighstorm
6
8
  module Controllers
7
9
  module Transaction
8
- def self.all(direction: nil, how: nil, limit: nil)
9
- All.model(All.data(
10
- direction: direction,
11
- how: how,
12
- limit: limit
13
- ))
10
+ extend Impersonatable
11
+
12
+ class DSL < Impersonatable::DSL
13
+ def all(direction: nil, how: nil, layer: nil, limit: nil)
14
+ All.model(All.data(
15
+ components,
16
+ direction: direction,
17
+ how: how,
18
+ layer: layer,
19
+ limit: limit
20
+ ))
21
+ end
14
22
  end
15
23
  end
16
24
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../adapters/wallet'
4
+ require_relative '../../models/wallet'
5
+
6
+ module Lighstorm
7
+ module Controllers
8
+ module Wallet
9
+ module Balance
10
+ def self.fetch(components)
11
+ {
12
+ at: Time.now,
13
+ wallet_balance: components[:grpc].lightning.wallet_balance.to_h,
14
+ channel_balance: components[:grpc].lightning.channel_balance.to_h
15
+ }
16
+ end
17
+
18
+ def self.adapt(raw)
19
+ Adapter::Wallet.balance(raw)
20
+ end
21
+
22
+ def self.data(components, &vcr)
23
+ raw = vcr.nil? ? fetch(components) : vcr.call(-> { fetch(components) })
24
+
25
+ adapt(raw)
26
+ end
27
+
28
+ def self.model(data)
29
+ Models::Wallet.new(data)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './concerns/impersonatable'
4
+
5
+ require_relative './wallet/balance'
6
+
7
+ module Lighstorm
8
+ module Controllers
9
+ module Wallet
10
+ extend Impersonatable
11
+
12
+ class DSL < Impersonatable::DSL
13
+ def balance
14
+ Balance.model(Balance.data(components))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/docs/README.md CHANGED
@@ -27,40 +27,16 @@ Lighstorm::Channel.mine.first.myself.node.alias
27
27
  Add to your `Gemfile`:
28
28
 
29
29
  ```ruby
30
- gem 'lighstorm', '~> 0.0.12'
30
+ gem 'lighstorm', '~> 0.0.14'
31
31
  ```
32
32
 
33
33
  Run `bundle install`.
34
34
 
35
- ## Credentials
36
-
37
- Set the following _Environment Variables_ or create a `.env` file:
38
- ```bash
39
- LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
40
- LIGHSTORM_CERTIFICATE_PATH=/lnd/tls.cert
41
- LIGHSTORM_MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
42
- ```
43
-
44
- It will automatically load your credentials.
45
-
46
- Alternatively, you can set the credentials at runtime:
47
-
48
- ```ruby
49
- require 'lighstorm'
50
-
51
- Lighstorm.config!(
52
- lnd_address: '127.0.0.1:10009',
53
- certificate_path: '/lnd/tls.cert',
54
- macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
55
- )
56
-
57
- ```
58
-
59
35
  ## Examples
60
36
  ```ruby
61
37
  require 'lighstorm'
62
38
 
63
- puts Lighstorm.version # => 0.0.12
39
+ puts Lighstorm.version # => 0.0.14
64
40
 
65
41
  Lighstorm::Invoice.create(
66
42
  description: 'Coffee', amount: { millisatoshis: 1000 }, payable: 'once'
@@ -116,6 +92,180 @@ Lighstorm::Satoshis.new(
116
92
 
117
93
  - [Getting Started with Lightning Payments in Ruby](https://mirror.xyz/icebaker.eth/4RUF8umW_KRfVWHHvC2jz0c7YJqzv3RUUvLN-Mln5IU)
118
94
 
95
+ # Connecting
96
+
97
+ ## Environment Variables
98
+
99
+ Choose a method and set the following _Environment Variables_, or create a `.env` file. This will automatically load your credentials.
100
+
101
+ ### lndconnect
102
+
103
+ Read more about [lnd connect URL](https://github.com/LN-Zap/lndconnect/blob/master/lnd_connect_uri.md).
104
+
105
+ ```bash
106
+ LIGHSTORM_LND_CONNECT=lndconnect://127.0.0.1:10009?cert=MIICJz...JBEERQ&macaroon=AgEDbG...45ukJ4
107
+ ```
108
+
109
+ ### File Path
110
+
111
+ ```bash
112
+ LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
113
+ LIGHSTORM_LND_CERTIFICATE_PATH=/lnd/tls.cert
114
+ LIGHSTORM_LND_MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
115
+ ```
116
+
117
+ ### Base64
118
+
119
+ ```bash
120
+ LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
121
+ LIGHSTORM_LND_CERTIFICATE=LS0tLS1CRU...UtLS0tLQo=
122
+ LIGHSTORM_LND_MACAROON=AgEDbG5kAv...inv45ukJ4=
123
+ ```
124
+
125
+ ### Hex
126
+
127
+ ```bash
128
+ LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
129
+ LIGHSTORM_LND_CERTIFICATE=2d2d2d2d2d...2d2d2d2d0a
130
+ LIGHSTORM_LND_MACAROON=0201036c6e...bf8e6e909e
131
+ ```
132
+
133
+ ## Runtime
134
+ Alternatively, you can set the credentials at runtime:
135
+
136
+ ### lndconnect
137
+
138
+ Read more about [lnd connect URL](https://github.com/LN-Zap/lndconnect/blob/master/lnd_connect_uri.md).
139
+
140
+ ```ruby
141
+ require 'lighstorm'
142
+
143
+ Lighstorm.connect!(
144
+ 'lndconnect://127.0.0.1:10009?cert=MIICJz...JBEERQ&macaroon=AgEDbG...45ukJ4'
145
+ )
146
+ ```
147
+
148
+ ### File Path
149
+
150
+ ```ruby
151
+ require 'lighstorm'
152
+
153
+ Lighstorm.connect!(
154
+ address: '127.0.0.1:10009',
155
+ certificate_path: '/lnd/tls.cert',
156
+ macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon'
157
+ )
158
+ ```
159
+
160
+ ### Base64
161
+
162
+ ```ruby
163
+ require 'lighstorm'
164
+
165
+ Lighstorm.connect!(
166
+ address: '127.0.0.1:10009',
167
+ certificate: 'LS0tLS1CRU...UtLS0tLQo=',
168
+ macaroon: 'AgEDbG5kAv...inv45ukJ4='
169
+ )
170
+ ```
171
+
172
+ ### Hex
173
+
174
+ ```ruby
175
+ require 'lighstorm'
176
+
177
+ Lighstorm.connect!(
178
+ address: '127.0.0.1:10009',
179
+ certificate: '2d2d2d2d2d...2d2d2d2d0a',
180
+ macaroon: '0201036c6e...bf8e6e909e'
181
+ )
182
+ ```
183
+
184
+ ### Raw
185
+
186
+ ```ruby
187
+ require 'lighstorm'
188
+
189
+ Lighstorm.connect!(
190
+ address: '127.0.0.1:10009',
191
+ certificate: File.read('/lnd/tls.cert'),
192
+ macaroon: File.read('/lnd/data/chain/bitcoin/mainnet/admin.macaroon')
193
+ )
194
+ ```
195
+
196
+ ## Multiclient
197
+
198
+ Multiclient allows you to establish connections with multiple nodes and effortlessly switch between them.
199
+
200
+ ```ruby
201
+ require 'lighstorm'
202
+
203
+ Lighstorm::Connection.connect!(
204
+ address: '127.0.0.1:10009',
205
+ certificate_path: '/lnd/tls.cert',
206
+ macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon'
207
+ )
208
+
209
+ Lighstorm::Connection.add!(
210
+ 'alice',
211
+ 'lndconnect://127.0.0.2:10009?cert=MIICJz...JBEERQ&macaroon=AgEDbG...45ukJ4'
212
+ )
213
+
214
+ Lighstorm::Connection.add!(
215
+ 'bob',
216
+ address: '127.0.0.3:10009',
217
+ certificate: 'LS0tLS1CRU...UtLS0tLQo=',
218
+ macaroon: 'AgEDbG5kAv...inv45ukJ4='
219
+ )
220
+
221
+ Lighstorm::Connection.default[:address] # => '127.0.0.1:10009'
222
+ Lighstorm::Connection.for('alice')[:address] # => '127.0.0.2:10009'
223
+ Lighstorm::Connection.for('bob')[:address] # => '127.0.0.3:10009'
224
+
225
+ Lighstorm::Node.myself.alias # => 'icebaker/old-stone'
226
+ Lighstorm::Node.as('alice').myself.alias # => alice
227
+ Lighstorm::Node.as('bob').myself.alias # => bob
228
+
229
+ Lighstorm::Connection.all # => ['alice', 'bob']
230
+
231
+ Lighstorm::Connection.remove!('bob')
232
+
233
+ Lighstorm::Connection.all # => ['alice']
234
+ ```
235
+
236
+ ## Docker and Remote Access
237
+
238
+ To connect to an LND node through a Docker container or remote host, you may need to adjust your certificate settings. Follow these steps:
239
+
240
+ 1. Stop your LND node.
241
+
242
+ 2. Remove or backup existing certificate files (`tls.cert` and `tls.key`) in the LND directory.
243
+
244
+ 3. Modify `lnd.conf` to include the relevant `tlsextraip` and/or `tlsextradomain` settings:
245
+
246
+ Option A: Accept any IP or domain (Warning: high security risk):
247
+
248
+ ```conf
249
+ tlsextraip=0.0.0.0
250
+ ```
251
+
252
+ Option B: Accept only your Docker host (172.17.0.1):
253
+ ```conf
254
+ tlsextraip=172.17.0.1
255
+ ```
256
+
257
+ Option C: Accept a specific remote domain and host:
258
+ ```config
259
+ tlsextraip=<your_remote_host_ip>
260
+ tlsextradomain=<your_domain_name>
261
+ ```
262
+
263
+ 4. Save and restart your LND node. New tls.cert and tls.key files will be generated.
264
+
265
+ 5. Update your LND client configuration with the new certificate.
266
+
267
+ Choose the option that best suits your needs and environment while considering security implications.
268
+
119
269
  # Data Modeling
120
270
 
121
271
  ## Graph Theory
@@ -147,6 +297,8 @@ channel.partner.policy.fee.rate.parts_per_million
147
297
  channel.myself.accounting.balance.millisatoshis
148
298
  channel.myself.node.alias
149
299
  channel.myself.policy.fee.rate.parts_per_million
300
+
301
+ channel.myself.initiator?
150
302
  ```
151
303
 
152
304
  [![This is an image representing Channel as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
@@ -410,6 +562,7 @@ channel.partner.policy.htlc.blocks.delta.minimum
410
562
  channel.myself
411
563
  channel.myself.state
412
564
  channel.myself.active?
565
+ channel.myself.initiator?
413
566
 
414
567
  channel.myself.node.public_key
415
568
  channel.myself.node.alias
@@ -804,6 +957,21 @@ Lighstorm::Payment.all(
804
957
  )
805
958
  ```
806
959
 
960
+ ## Wallet
961
+
962
+ ```ruby
963
+ balance = Lighstorm::Wallet.balance
964
+
965
+ balance.at
966
+
967
+ balance.lightning.millisatoshis
968
+ balance.bitcoin.millisatoshis
969
+
970
+ balance.total.millisatoshis
971
+
972
+ balance.to_h
973
+ ```
974
+
807
975
  ## Forward
808
976
 
809
977
  [![This is an image representing Forward as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
@@ -1017,19 +1185,24 @@ LighstormError
1017
1185
 
1018
1186
  ArgumentError
1019
1187
  IncoherentGossipError
1188
+ InvoiceMayHaveMultiplePaymentsError
1189
+ MissingComponentsError
1020
1190
  MissingCredentialsError
1021
1191
  MissingGossipHandlerError
1022
1192
  MissingPartsPerMillionError
1193
+ MissingTTLError
1023
1194
  NegativeNotAllowedError
1024
1195
  NotYourChannelError
1025
1196
  NotYourNodeError
1026
1197
  OperationNotAllowedError
1027
1198
  TooManyArgumentsError
1028
- UnexpectedNumberOfHTLCsError
1029
1199
  UnknownChannelError
1030
- UpdateChannelPolicyError
1031
1200
 
1201
+ RequestError
1202
+
1203
+ NoInvoiceFoundError
1032
1204
  PaymentError
1205
+ UpdateChannelPolicyError
1033
1206
 
1034
1207
  AlreadyPaidError
1035
1208
  AmountForNonZeroError
@@ -1048,7 +1221,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
1048
1221
  # demo.rb
1049
1222
  require 'lighstorm'
1050
1223
 
1051
- puts Lighstorm.version # => 0.0.12
1224
+ puts Lighstorm.version # => 0.0.14
1052
1225
  ```
1053
1226
 
1054
1227
  ```sh
@@ -1285,13 +1458,13 @@ gem build lighstorm.gemspec
1285
1458
 
1286
1459
  gem signin
1287
1460
 
1288
- gem push lighstorm-0.0.12.gem
1461
+ gem push lighstorm-0.0.14.gem
1289
1462
  ```
1290
1463
 
1291
1464
  _________________
1292
1465
 
1293
1466
  <center>
1294
- lighstorm 0.0.12
1467
+ lighstorm 0.0.14
1295
1468
  |
1296
1469
  <a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
1297
1470
  |
data/docs/_coverpage.md CHANGED
@@ -8,7 +8,7 @@
8
8
  - Built for maximum **reliability**.
9
9
  - Optimized for programmer **happiness**.
10
10
 
11
- 0.0.12
11
+ 0.0.14
12
12
 
13
13
  ⚠️ _Warning: Early-stage, breaking changes are expected._
14
14
 
data/docs/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <script>
19
19
  window.$docsify = {
20
20
  coverpage: true,
21
- name: 'Lighstorm 0.0.12',
21
+ name: 'Lighstorm 0.0.14',
22
22
  repo: 'https://github.com/icebaker/lighstorm'
23
23
  }
24
24
  </script>
data/lighstorm.gemspec CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['ports/dsl']
33
33
 
34
34
  spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
35
- spec.add_dependency 'lnd-client', '~> 0.0.5'
35
+ spec.add_dependency 'lnd-client', '~> 0.0.7'
36
36
  spec.add_dependency 'zache', '~> 0.12.0'
37
37
 
38
38
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'invoice'
4
+ require_relative 'transaction'
5
+
6
+ module Lighstorm
7
+ module Models
8
+ class Activity
9
+ attr_reader :direction, :at, :message, :layer, :how, :_key
10
+
11
+ def initialize(data)
12
+ @data = data
13
+
14
+ @_key = @data[:_key]
15
+ @at = @data[:at]
16
+ @direction = @data[:direction]
17
+ @layer = @data[:layer]
18
+ @how = @data[:how]
19
+ @message = @data[:message]
20
+ end
21
+
22
+ def amount
23
+ @amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
24
+ end
25
+
26
+ def invoice
27
+ @invoice ||= @data[:data][:invoice].nil? ? nil : Invoice.new(@data[:data][:invoice], nil)
28
+ end
29
+
30
+ def transaction
31
+ @transaction ||= @data[:data][:transaction].nil? ? nil : Transaction.new(@data[:data][:transaction])
32
+ end
33
+
34
+ def to_h
35
+ output = {
36
+ _key: _key,
37
+ at: at,
38
+ direction: direction,
39
+ layer: layer,
40
+ how: how,
41
+ amount: amount.to_h,
42
+ message: message
43
+ }
44
+
45
+ output[:invoice] = invoice.to_h unless invoice.nil?
46
+ output[:transaction] = transaction.to_h unless transaction.nil?
47
+
48
+ output
49
+ end
50
+ end
51
+ end
52
+ end
@@ -6,7 +6,6 @@ require_relative '../../satoshis'
6
6
  require_relative '../../rate'
7
7
  require_relative '../../concerns/protectable'
8
8
 
9
- require_relative '../../../components/lnd'
10
9
  require_relative '../../../controllers/channel/actions/update_fee'
11
10
 
12
11
  module Lighstorm
@@ -14,8 +13,9 @@ module Lighstorm
14
13
  class Fee
15
14
  include Protectable
16
15
 
17
- def initialize(policy, data)
16
+ def initialize(policy, components, data)
18
17
  @policy = policy
18
+ @components = components
19
19
  @data = data
20
20
  end
21
21
 
@@ -47,7 +47,10 @@ module Lighstorm
47
47
  end
48
48
 
49
49
  def update(params, preview: false, &vcr)
50
+ raise MissingComponentsError if @components.nil?
51
+
50
52
  Controllers::Channel::UpdateFee.perform(
53
+ @components,
51
54
  @policy, @policy.transaction, params,
52
55
  preview: preview, &vcr
53
56
  )
@@ -8,13 +8,14 @@ module Lighstorm
8
8
  class Policy
9
9
  attr_reader :transaction
10
10
 
11
- def initialize(data, transaction)
11
+ def initialize(data, components, transaction)
12
12
  @data = data
13
+ @components = components
13
14
  @transaction = transaction
14
15
  end
15
16
 
16
17
  def fee
17
- @fee ||= Fee.new(self, @data ? @data[:fee] : {})
18
+ @fee ||= Fee.new(self, @components, @data ? @data[:fee] : {})
18
19
  end
19
20
 
20
21
  def htlc