lighstorm 0.0.3 → 0.0.4

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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +5 -0
  3. data/.gitignore +1 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +10 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +26 -2
  8. data/README.md +29 -370
  9. data/adapters/connections/channel_node/fee.rb +26 -0
  10. data/adapters/connections/channel_node.rb +52 -0
  11. data/adapters/connections/payment_channel.rb +28 -0
  12. data/adapters/edges/channel.rb +80 -0
  13. data/adapters/edges/forward.rb +41 -0
  14. data/adapters/edges/payment/purpose.rb +34 -0
  15. data/adapters/edges/payment.rb +53 -0
  16. data/adapters/invoice.rb +50 -0
  17. data/adapters/nodes/node.rb +77 -0
  18. data/adapters/payment_request.rb +77 -0
  19. data/components/cache.rb +3 -2
  20. data/components/lnd.rb +5 -1
  21. data/controllers/channel/actions/update_fee.rb +76 -0
  22. data/controllers/channel/all.rb +79 -0
  23. data/controllers/channel/find_by_id.rb +153 -0
  24. data/controllers/channel/mine.rb +114 -0
  25. data/controllers/channel.rb +23 -0
  26. data/controllers/forward/all.rb +244 -0
  27. data/controllers/forward/group_by_channel.rb +89 -0
  28. data/controllers/forward.rb +28 -0
  29. data/controllers/invoice/actions/create.rb +36 -0
  30. data/controllers/invoice/actions/pay.rb +28 -0
  31. data/controllers/invoice/actions/pay_through_route.rb +71 -0
  32. data/controllers/invoice/all.rb +70 -0
  33. data/controllers/invoice/find_by_secret_hash.rb +42 -0
  34. data/controllers/invoice.rb +36 -0
  35. data/controllers/node/all.rb +63 -0
  36. data/controllers/node/find_by_public_key.rb +49 -0
  37. data/controllers/node/myself.rb +34 -0
  38. data/controllers/node.rb +23 -0
  39. data/controllers/payment/all.rb +352 -0
  40. data/controllers/payment.rb +21 -0
  41. data/docs/.nojekyll +0 -0
  42. data/docs/README.md +655 -0
  43. data/docs/_coverpage.md +12 -0
  44. data/docs/index.html +26 -0
  45. data/docs/vendor/docsify/docsify@4.js +1 -0
  46. data/docs/vendor/docsify-themeable/theme-simple-dark.css +3 -0
  47. data/docs/vendor/docsify-themeable/theme-simple-dark.css.map +1 -0
  48. data/docs/vendor/prismjs/prism-bash.min.js +1 -0
  49. data/docs/vendor/prismjs/prism-ruby.min.js +1 -0
  50. data/docs/vendor/prismjs/prism-tomorrow.min.css +1 -0
  51. data/lighstorm.gemspec +3 -1
  52. data/models/connections/channel_node/accounting.rb +3 -14
  53. data/models/connections/channel_node/fee.rb +39 -77
  54. data/models/connections/channel_node/htlc.rb +30 -10
  55. data/models/connections/channel_node/policy.rb +6 -18
  56. data/models/connections/channel_node.rb +20 -26
  57. data/models/connections/forward_channel.rb +8 -43
  58. data/models/connections/payment_channel.rb +18 -39
  59. data/models/edges/channel/accounting.rb +28 -20
  60. data/models/edges/channel/hop.rb +65 -0
  61. data/models/edges/channel.rb +80 -172
  62. data/models/edges/forward.rb +9 -118
  63. data/models/edges/groups/{analysis.rb → channel_forwards/analysis.rb} +9 -9
  64. data/models/edges/groups/channel_forwards.rb +10 -40
  65. data/models/edges/payment.rb +29 -214
  66. data/models/errors.rb +29 -0
  67. data/models/invoice.rb +49 -0
  68. data/models/nodes/node/lightning.rb +5 -16
  69. data/models/nodes/node/platform.rb +7 -13
  70. data/models/nodes/node.rb +20 -115
  71. data/models/payment_request.rb +69 -0
  72. data/models/rate.rb +11 -1
  73. data/models/satoshis.rb +5 -6
  74. data/ports/dsl/lighstorm/errors.rb +5 -0
  75. data/ports/dsl/lighstorm.rb +11 -9
  76. data/ports/grpc.rb +62 -0
  77. data/static/cache.rb +12 -0
  78. data/static/spec.rb +3 -1
  79. metadata +55 -6
  80. data/models/connections/channel_node/constraints.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c585645f0ccf6b55a8b0840d5351900f701002a4616f351016f1b8d9f097ed4
4
- data.tar.gz: fca5794bab41231c60400aab4ce82021bb649df52df63acf801ef4931bf5c53c
3
+ metadata.gz: 79b37e0a32c6d34ed5e4b05fc32eb894a808a08b9d2b6efea608be59644a94c9
4
+ data.tar.gz: ba7f317ff7699cdae5f9645f533e1779ca5de988aec3d8320172f2ec6807d0d1
5
5
  SHA512:
6
- metadata.gz: 0717fc86e023d1591872b3c81c58338c713409030f3bc2351988ee62abb163b262df95e1357537c7530d3f3bd615208af99f68c92a0a53b6f6b784401d5c8e15
7
- data.tar.gz: ff9bba186921987b3f301f95f82f1d3b7041feb4db92d8ca2a43c663915ea12e6d609615419805bc26cde7c2ba658702b713a603dd33c3f024de6b16794eca7e
6
+ metadata.gz: b633147091290d526f184ca324964d9bc2fd13cb769a2009e7b732280ddd305fac82d63d2c9c735277ecc14f2fbdf4310d7b4d95611398753879746d170ed33b
7
+ data.tar.gz: e979df8953dd05ab5efceb268cde4f305190bc07d3304e304155ddef3ebf876f0444612b59420e2c7f24572d20b758e6521a7a569e3788eaf5b76037ee8ded7e
data/.env.example ADDED
@@ -0,0 +1,5 @@
1
+ LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
2
+ LIGHSTORM_CERTIFICATE_PATH=/lnd/tls.cert
3
+ LIGHSTORM_MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
4
+ LIGHSTORM_RUN_INTEGRATION_TESTS=false
5
+ LIGHSTORM_RUN_INTEGRATION_TESTS_SLOW=false
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ .env
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -9,6 +9,16 @@ Naming/FileName:
9
9
  Exclude:
10
10
  - 'ports/dsl/lighstorm.rb'
11
11
 
12
+ Metrics/MethodLength:
13
+ Enabled: false
14
+
12
15
  Layout/LineLength:
13
16
  Exclude:
14
17
  - 'static/spec.rb'
18
+
19
+ Security/MarshalLoad:
20
+ Exclude:
21
+ - 'spec/helpers/vcr.rb'
22
+
23
+ require:
24
+ - rubocop-rspec
data/Gemfile CHANGED
@@ -5,6 +5,10 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :test, :development do
8
+ gem 'babosa', '~> 2.0'
9
+ gem 'dotenv', '~> 2.8', '>= 2.8.1'
8
10
  gem 'pry-byebug', '~> 3.10', '>= 3.10.1'
11
+ gem 'rspec', '~> 3.12'
9
12
  gem 'rubocop', '~> 1.45', '>= 1.45.1'
13
+ gem 'rubocop-rspec', '~> 2.18', '>= 2.18.1'
10
14
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighstorm (0.0.3)
4
+ lighstorm (0.0.4)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
6
  lnd-client (~> 0.0.5)
7
7
  zache (~> 0.12.0)
@@ -10,10 +10,12 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  ast (2.4.2)
13
+ babosa (2.0.0)
13
14
  byebug (11.1.3)
14
15
  coderay (1.1.3)
16
+ diff-lcs (1.5.0)
15
17
  dotenv (2.8.1)
16
- google-protobuf (3.21.12)
18
+ google-protobuf (3.22.0-x86_64-linux)
17
19
  googleapis-common-protos-types (1.5.0)
18
20
  google-protobuf (~> 3.14)
19
21
  grpc (1.52.0-x86_64-linux)
@@ -35,6 +37,19 @@ GEM
35
37
  rainbow (3.1.1)
36
38
  regexp_parser (2.7.0)
37
39
  rexml (3.2.5)
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.1)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.3)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.0)
38
53
  rubocop (1.45.1)
39
54
  json (~> 2.3)
40
55
  parallel (~> 1.10)
@@ -47,6 +62,11 @@ GEM
47
62
  unicode-display_width (>= 2.4.0, < 3.0)
48
63
  rubocop-ast (1.26.0)
49
64
  parser (>= 3.2.1.0)
65
+ rubocop-capybara (2.17.1)
66
+ rubocop (~> 1.41)
67
+ rubocop-rspec (2.18.1)
68
+ rubocop (~> 1.33)
69
+ rubocop-capybara (~> 2.17)
50
70
  ruby-progressbar (1.11.0)
51
71
  unicode-display_width (2.4.2)
52
72
  zache (0.12.0)
@@ -55,9 +75,13 @@ PLATFORMS
55
75
  x86_64-linux
56
76
 
57
77
  DEPENDENCIES
78
+ babosa (~> 2.0)
79
+ dotenv (~> 2.8, >= 2.8.1)
58
80
  lighstorm!
59
81
  pry-byebug (~> 3.10, >= 3.10.1)
82
+ rspec (~> 3.12)
60
83
  rubocop (~> 1.45, >= 1.45.1)
84
+ rubocop-rspec (~> 2.18, >= 2.18.1)
61
85
 
62
86
  BUNDLED WITH
63
87
  2.4.4
data/README.md CHANGED
@@ -14,17 +14,10 @@ Lighstorm::Channel.mine.first.myself.node.alias
14
14
 
15
15
  - [About](#about)
16
16
  - [Usage](#usage)
17
- - [Installing](#installing)
18
- - [Credentials](#credentials)
19
- - [Documentation](#documentation)
20
- - [API](#api)
21
- - [Examples](#examples)
22
- - [Data Modeling](#data-modeling)
23
- - [Graph Theory](#graph-theory)
24
- - [Channel](#channel)
25
- - [Forward](#forward)
26
- - [Payment](#payment)
17
+ - [Documentation](https://icebaker.github.io/lighstorm)
27
18
  - [Development](#development)
19
+ - [Testing](#testing)
20
+ - [Generating Documentation](#generating-documentation)
28
21
  - [Publish to RubyGems](#publish-to-rubygems)
29
22
 
30
23
  ## About
@@ -33,33 +26,16 @@ _Lighstorm_ is an opinionated abstraction layer on top of the [lnd-client](https
33
26
 
34
27
  It brings an [object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) approach for interacting with a [Lightning Node](https://github.com/lightningnetwork/lnd), influenced by the [Active Record Pattern](https://www.martinfowler.com/eaaCatalog/activeRecord.html) and [Active Record Models](https://guides.rubyonrails.org/active_record_basics.html) conventions.
35
28
 
36
- Although it tries to stay close to [Lightning's terminologies](https://docs.lightning.engineering/lightning-network-tools/lnd), it brings its own vocabulary and [data modeling](#data-modeling), optimizing for [programmer happiness](https://rubyonrails.org/doctrine).
29
+ Although it tries to stay close to [Lightning's terminologies](https://docs.lightning.engineering/lightning-network-tools/lnd), it brings its own vocabulary and [data modeling](https://icebaker.github.io/lighstorm/#/README?id=data-modeling), optimizing for [programmer happiness](https://rubyonrails.org/doctrine).
37
30
 
38
31
  ## Usage
39
32
 
40
- ### Installing
41
-
42
33
  Add to your `Gemfile`:
43
34
 
44
35
  ```ruby
45
- gem 'lighstorm', '~> 0.0.3'
46
- ```
47
-
48
- Run `bundle install`.
49
-
50
- ### Credentials
51
-
52
- Set the following _Environment Variables_ or create a `.env` file:
53
- ```bash
54
- LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
55
- LIGHSTORM_CERTIFICATE_PATH=/lnd/tls.cert
56
- LIGHSTORM_MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
36
+ gem 'lighstorm', '~> 0.0.4'
57
37
  ```
58
38
 
59
- It will automatically load your credentials.
60
-
61
- Alternatively, you can set the credentials at runtime:
62
-
63
39
  ```ruby
64
40
  require 'lighstorm'
65
41
 
@@ -69,369 +45,52 @@ Lighstorm.config!(
69
45
  macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
70
46
  )
71
47
 
72
- ```
73
-
74
- ### Documentation
75
-
76
- #### API
77
-
78
- ```ruby
79
- Lighstorm::Node
80
-
81
- Lighstorm::Node.myself # Your Node.
82
- Lighstorm::Node.all # All 18k+ Nodes on the Network.
83
- Lighstorm::Node.find_by_public_key(
84
- '02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
85
- )
86
-
87
- node.to_h
88
-
89
- node.channels
90
-
91
- node.alias
92
- node.public_key
93
- node.color
94
- node.myself?
95
-
96
- node.platform.blockchain
97
- node.platform.network
98
- node.platform.lightning.implementation
99
- node.platform.lightning.version
100
-
101
- Lighstorm::Channel
102
- Lighstorm::Channel.mine # Your Node's Channels.
103
- Lighstorm::Channel.all # All 80k+ Channels on the Network.
104
- Lighstorm::Channel.find_by_id('850099509773795329')
105
-
106
- channel.to_h
107
-
108
- channel.mine?
109
-
110
- channel.id
111
- channel.opened_at
112
- channel.up_at
113
- channel.active
114
- channel.exposure
115
-
116
- channel.accounting.capacity.milisatoshis
117
- channel.accounting.sent.milisatoshis
118
- channel.accounting.received.milisatoshis
119
- channel.accounting.unsettled.milisatoshis
120
-
121
- # Channels that don't belong to you:
122
- channel.partners
123
-
124
- channel.partners[0]
125
- channel.partners[0].node.alias
126
-
127
- channel.partners[1]
128
- channel.partners[1].node.alias
129
-
130
- # Channels that belong to you:
131
- channel.myself
132
- channel.myself.node.alias
133
-
134
- channel.partner
135
- channel.partner.node.alias
136
-
137
- channel.partner.accounting.balance.milisatoshis
138
- channel.partner.node.alias
139
- channel.partner.node.public_key
140
- channel.partner.node.color
141
- channel.partner.policy.fee.base.milisatoshis
142
- channel.partner.policy.fee.rate.parts_per_million
143
- channel.partner.policy.htlc.minimum.milisatoshis
144
- channel.partner.policy.htlc.maximum.milisatoshis
145
-
146
- channel.myself.accounting.balance.milisatoshis
147
- channel.myself.node.alias
148
- channel.myself.node.public_key
149
- channel.myself.node.color
150
- channel.myself.policy.fee.base.milisatoshis
151
- channel.myself.policy.fee.rate.parts_per_million
152
- channel.myself.policy.htlc.minimum.milisatoshis
153
- channel.myself.policy.htlc.maximum.milisatoshis
154
-
155
- channel.myself.policy.fee.update(
156
- { rate: { parts_per_million: 25 } }, preview: true
157
- )
158
-
159
- channel.myself.policy.fee.update(
160
- { base: { milisatoshis: 1 } }
161
- )
162
-
163
- channel.myself.policy.fee.update(
164
- { rate: { parts_per_million: 25 } }
165
- )
166
-
167
- channel.myself.policy.fee.update(
168
- { base: { milisatoshis: 1 }, rate: { parts_per_million: 25 } }
169
- )
170
-
171
- Lighstorm::Forward
172
- Lighstorm::Forward.all
173
- Lighstorm::Forward.first
174
- Lighstorm::Forward.last
175
- Lighstorm::Forward.all(limit: 10)
176
-
177
- forward.to_h
178
-
179
- forward.id
180
- forward.at
181
-
182
- forward.fee.milisatoshis
183
- forward.fee.parts_per_million(
184
- forward.in.amount.milisatoshis
185
- )
186
-
187
- forward.in.amount.milisatoshis
188
-
189
- forward.in.channel.id
190
- forward.in.channel.partner.node.alias
191
- forward.in.channel.partner.node.public_key
192
- forward.in.channel.partner.node.color
193
-
194
- forward.out.channel.id
195
- forward.out.channel.partner.node.alias
196
- forward.out.channel.partner.node.public_key
197
- forward.out.channel.partner.node.color
198
-
199
- Lighstorm::Forward.group_by_channel(direction: :in, hours_ago: 24, limit: 5)
200
-
201
- group.to_h
202
-
203
- group.last_at
204
- group.analysis.count
205
- group.analysis.sums.amount.milisatoshis
206
- group.analysis.sums.fee.milisatoshis
207
- group.analysis.averages.amount.milisatoshis
208
- group.analysis.averages.fee.milisatoshis
209
- group.analysis.averages.fee.parts_per_million(
210
- group.analysis.averages.amount.milisatoshis
211
- )
212
-
213
- group.in.id
214
- group.in.partner.node.alias
215
- group.in.partner.node.public_key
216
- group.in.partner.node.color
217
-
218
- Lighstorm::Forward.group_by_channel(direction: :out)
219
-
220
- group.to_h
221
-
222
- group.last_at
223
- group.analysis.count
224
-
225
- group.out.id
226
- group.out.partner.node.alias
227
- group.out.partner.node.public_key
228
- group.out.partner.node.color
229
-
230
- Lighstorm::Payment
231
- Lighstorm::Payment.all
232
- Lighstorm::Payment.first
233
- Lighstorm::Payment.last
234
- Lighstorm::Payment.all(limit: 10, purpose: 'rebalance', hops: false)
235
-
236
- payment.id
237
- payment.hash
238
- payment.created_at
239
- payment.purpose
240
- payment.status
241
- payment.amount.milisatoshis
242
- payment.fee.milisatoshis
243
- payment.fee.parts_per_million(
244
- payment.amount.milisatoshis
245
- )
246
-
247
- payment.from.hop
248
- payment.from.amount.milisatoshis
249
- payment.from.fee.milisatoshis
250
- payment.from.fee.parts_per_million(
251
- payment.from.amount.milisatoshis
252
- )
253
-
254
- payment.from.channel.id
255
- payment.from.channel.partner.node.alias
256
- payment.from.channel.partner.node.public_key
257
- payment.from.channel.partner.node.color
258
-
259
- payment.to.hop
260
- payment.to.amount.milisatoshis
261
- payment.to.fee.milisatoshis
262
- payment.to.fee.parts_per_million(
263
- payment.to.amount.milisatoshis
264
- )
265
-
266
- payment.to.channel.id
267
- payment.to.channel.partner.node.alias
268
- payment.to.channel.partner.node.public_key
269
- payment.to.channel.partner.node.color
270
-
271
- payment.hops.size
272
-
273
- payment.hops[0].hop
274
- payment.hops[0].amount.milisatoshis
275
- payment.hops[0].fee.milisatoshis
276
- payment.hops[0].fee.parts_per_million(
277
- payment.hops[0].amount.milisatoshis
278
- )
279
-
280
- payment.hops[0].channel.id
281
- payment.hops[0].channel.partner.node.alias
282
- payment.hops[0].channel.partner.node.public_key
283
- payment.hops[0].channel.partner.node.color
284
-
285
- Lighstorm::Satoshis
286
- Lighstorm::Satoshis.new(milisatoshis: 75621650)
287
-
288
- satoshis.to_h
289
-
290
- satoshis.milisatoshis
291
- satoshis.satoshis
292
- satoshis.bitcoins
293
-
294
- satoshis.msats
295
- satoshis.sats
296
- satoshis.btc
297
-
298
- reference_in_milisatoshis = 75_621_650_000
299
- satoshis.parts_per_million(reference_in_milisatoshis)
300
- ```
301
-
302
- #### Examples
303
-
304
- ```ruby
305
- require 'lighstorm'
306
-
307
- puts Lighstorm.version # => 0.0.3
48
+ puts Lighstorm.version # => 0.0.4
308
49
 
309
50
  Lighstorm::Satoshis.new(
310
- milisatoshis: 75621650
311
- ).satoshis # => 75621
51
+ milisatoshis: 75_621_650
52
+ ).satoshis # => 75_621
312
53
 
313
54
  Lighstorm::Node.myself.alias # => icebaker/old-stone
314
- Lighstorm::Node.myself.public_key # => 02d3...e997
315
-
316
- Lighstorm::Node.myself.to_h #> { ... }
317
-
318
- Lighstorm::Node.myself.channels.count # => 5
319
-
320
- Lighstorm::Channel.mine.first.partner.node.alias
321
-
322
- forward = Lighstorm::Forward.all(limit: 10).first
323
-
324
- forward.in.amount.milisatoshis # => 75621650
325
- forward.in.amount.satoshis # => 75621
326
- forward.in.amount.bitcoins # => 0.0007562165
327
- forward.in.channel.partner.node.alias
328
- forward.out.channel.partner.node.alias
329
-
330
- forward.to_h # => { ... }
331
-
332
- payment = Lighstorm::Payment.all.first
333
-
334
- payment.from.channel.id # => 850099509773795329
335
- payment.to.channel.id # => 821539695188246532
336
- payment.amount.sats # => 957262
337
- payment.hops.size # => 4
338
- payment.hops.first.channel.partner.node.alias
339
55
  ```
340
56
 
341
- ### Data Modeling
342
-
343
- #### Graph Theory
57
+ Check the [full documentation](https://icebaker.github.io/lighstorm).
344
58
 
345
- [Graphs](https://en.wikipedia.org/wiki/Graph_theory) provide a great representation to abstract the [Lightning Network](https://lightning.network) data.
346
-
347
- So, we are going to think in terms of _Edges_, _Nodes_, and _Connections_:
348
-
349
- ![This is an image describing Graphs and their terminologies.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-theory.png)
59
+ ## Development
350
60
 
351
- #### Channel
61
+ Copy the `.env.example` file to `.env` and provide the required data.
352
62
 
353
63
  ```ruby
354
- channel = Lighstorm::Channel.mine.first
355
-
356
- channel.id
357
-
358
- channel.accounting.capacity.milisatoshis
64
+ # Gemfile
65
+ gem 'lighstorm', path: '/home/user/lighstorm'
359
66
 
360
- channel.partner.accounting.balance.milisatoshis
361
- channel.partner.node.alias
362
- channel.partner.policy.fee.rate.parts_per_million
67
+ # demo.rb
68
+ require 'lighstorm'
363
69
 
364
- channel.myself.accounting.balance.milisatoshis
365
- channel.myself.node.alias
366
- channel.myself.policy.fee.rate.parts_per_million
70
+ puts Lighstorm.version # => 0.0.4
367
71
  ```
368
72
 
369
- ![This is an image representing Channel as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
370
-
371
- #### Forward
372
-
373
- ```ruby
374
- forward = Lighstorm::Forward.last
375
-
376
- forward.at
377
-
378
- forward.fee.parts_per_million
379
-
380
- forward.in.amount.milisatoshis
381
-
382
- forward.in.channel.id
383
- forward.in.channel.partner.node.alias
384
-
385
- forward.out.channel.id
386
- forward.out.channel.partner.node.alias
73
+ ```sh
74
+ bundle
75
+ rubocop -A
387
76
  ```
388
77
 
389
- ![This is an image representing Forward as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
78
+ ### Testing
390
79
 
391
- #### Payment
80
+ Copy the `.env.example` file to `.env` and provide the required data.
392
81
 
393
- ```ruby
394
- payment = Payment.last
395
-
396
- payment.hash
397
- payment.amount.milisatoshis
398
-
399
- payment.from.hop
400
- payment.from.amount.milisatoshis
401
- payment.from.fee.milisatoshis
402
- payment.from.channel.id
403
- payment.from.channel.partner.node.alias
404
-
405
- payment.to.hop
406
- payment.to.amount.milisatoshis
407
- payment.to.fee.milisatoshis
408
- payment.to.channel.id
409
- payment.to.channel.partner.node.alias
410
-
411
- payment.hops[0].hop
412
- payment.hops[0].amount.milisatoshis
413
- payment.hops[0].fee.milisatoshis
414
- payment.hops[0].channel.id
415
- payment.hops[0].channel.partner.node.alias
416
82
  ```
83
+ bundle
417
84
 
418
- ![This is an image representing Payment as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)
419
-
420
- ## Development
421
-
422
- ```ruby
423
- # Gemfile
424
- gem 'lighstorm', path: '/home/user/lighstorm'
425
-
426
- # demo.rb
427
- require 'lighstorm'
428
-
429
- puts Lighstorm.version # => 0.0.3
85
+ bundle exec rspec
430
86
  ```
431
87
 
88
+ ### Generating Documentation
89
+
432
90
  ```sh
433
- bundle
434
- rubocop -A
91
+ npm i docsify-cli -g
92
+
93
+ docsify serve ./docs
435
94
  ```
436
95
 
437
96
  ### Publish to RubyGems
@@ -441,5 +100,5 @@ gem build lighstorm.gemspec
441
100
 
442
101
  gem signin
443
102
 
444
- gem push lighstorm-0.0.3.gem
103
+ gem push lighstorm-0.0.4.gem
445
104
  ```
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lighstorm
4
+ module Adapter
5
+ class Fee
6
+ def self.fee_report(grpc)
7
+ {
8
+ _source: :fee_report,
9
+ id: grpc[:chan_id].to_s,
10
+ partner: {
11
+ policy: {
12
+ fee: {
13
+ base: {
14
+ milisatoshis: grpc[:base_fee_msat]
15
+ },
16
+ rate: {
17
+ parts_per_million: grpc[:fee_per_mil]
18
+ }
19
+ }
20
+ }
21
+ }
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../nodes/node'
4
+
5
+ module Lighstorm
6
+ module Adapter
7
+ class ChannelNode
8
+ def self.list_channels(grpc, key)
9
+ {
10
+ _source: :list_channels,
11
+ accounting: { balance: { milisatoshis: grpc[:"#{key}_balance"] * 1000 } },
12
+ node: Node.list_channels(grpc, key)
13
+ }
14
+ end
15
+
16
+ def self.get_chan_info(grpc, index)
17
+ data = {
18
+ _source: :get_chan_info,
19
+ node: Node.get_chan_info(grpc, index)
20
+ }
21
+
22
+ if grpc[:"node#{index}_policy"]
23
+ data[:policy] = {
24
+ fee: {
25
+ base: { milisatoshis: grpc[:"node#{index}_policy"][:fee_base_msat] },
26
+ rate: { parts_per_million: grpc[:"node#{index}_policy"][:fee_rate_milli_msat] }
27
+ },
28
+ htlc: {
29
+ minimum: { milisatoshis: grpc[:"node#{index}_policy"][:min_htlc] },
30
+ maximum: { milisatoshis: grpc[:"node#{index}_policy"][:max_htlc_msat] },
31
+ # https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection
32
+ blocks: {
33
+ delta: {
34
+ minimum: grpc[:"node#{index}_policy"][:time_lock_delta] # aka cltv_expiry_delta
35
+ }
36
+ }
37
+ }
38
+ }
39
+ end
40
+
41
+ data
42
+ end
43
+
44
+ def self.describe_graph(grpc, index)
45
+ {
46
+ _source: :describe_graph,
47
+ node: Node.describe_graph_from_channel(grpc, index)
48
+ }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module Lighstorm
6
+ module Adapter
7
+ class PaymentChannel
8
+ def self.list_payments(grpc, index)
9
+ {
10
+ _source: :list_payments,
11
+ hop: index + 1,
12
+ amount: { milisatoshis: grpc[:amt_to_forward_msat] },
13
+ fee: { milisatoshis: grpc[:fee_msat] },
14
+ channel: {
15
+ _key: Digest::SHA256.hexdigest(grpc[:chan_id].to_s),
16
+ id: grpc[:chan_id].to_s,
17
+ partners: [
18
+ node: {
19
+ _key: Digest::SHA256.hexdigest(grpc[:pub_key].to_s),
20
+ public_key: grpc[:pub_key]
21
+ }
22
+ ]
23
+ }
24
+ }
25
+ end
26
+ end
27
+ end
28
+ end