lighstorm 0.0.2 → 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 +5 -1
  7. data/Gemfile.lock +32 -8
  8. data/README.md +30 -341
  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 +4 -2
  52. data/models/connections/channel_node/accounting.rb +3 -12
  53. data/models/connections/channel_node/fee.rb +44 -56
  54. data/models/connections/channel_node/htlc.rb +52 -0
  55. data/models/connections/channel_node/policy.rb +11 -12
  56. data/models/connections/channel_node.rb +20 -19
  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 +42 -18
  60. data/models/edges/channel/hop.rb +65 -0
  61. data/models/edges/channel.rb +98 -120
  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 +19 -56
  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 +12 -8
  76. data/ports/grpc.rb +62 -0
  77. data/static/cache.rb +12 -0
  78. data/static/spec.rb +3 -1
  79. metadata +58 -8
  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: 5255fb12e5463a29335c433ca7ccc20cdc6154a686f25c1272d4bf608e71764b
4
- data.tar.gz: 7865931e5f6ee408a810481f1f809edcdf3d5fabfcd31e76bf3e3cad1dfabe64
3
+ metadata.gz: 79b37e0a32c6d34ed5e4b05fc32eb894a808a08b9d2b6efea608be59644a94c9
4
+ data.tar.gz: ba7f317ff7699cdae5f9645f533e1779ca5de988aec3d8320172f2ec6807d0d1
5
5
  SHA512:
6
- metadata.gz: 7c7793a2361ffe29f9e97b1be00500274054f58acea841bb025fac94ebac969117c09f69cc644219825e06883df93a400cebce0db1f72f1b72e75ab3296e37b6
7
- data.tar.gz: 81ce8ce6fcc5d564ae5b0a51c99080d0f301ecbf9a5fb6da45bd8f633a4d35eea6adb1b77f1f0a2ecebb9bf4c8e11c0185aca35f688f21f2118ff73a0f5ac1ab
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'
9
- gem 'rubocop', '~> 1.44', '>= 1.44.1'
11
+ gem 'rspec', '~> 3.12'
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,27 +1,29 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighstorm (0.0.2)
4
+ lighstorm (0.0.4)
5
5
  dotenv (~> 2.8, >= 2.8.1)
6
- lnd-client (~> 0.0.4)
6
+ lnd-client (~> 0.0.5)
7
7
  zache (~> 0.12.0)
8
8
 
9
9
  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)
20
22
  google-protobuf (~> 3.21)
21
23
  googleapis-common-protos-types (~> 1.0)
22
24
  json (2.6.3)
23
- lnd-client (0.0.4)
24
- grpc (~> 1.51)
25
+ lnd-client (0.0.5)
26
+ grpc (~> 1.52)
25
27
  method_source (1.0.0)
26
28
  parallel (1.22.1)
27
29
  parser (3.2.1.0)
@@ -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)
@@ -45,8 +60,13 @@ GEM
45
60
  rubocop-ast (>= 1.24.1, < 2.0)
46
61
  ruby-progressbar (~> 1.7)
47
62
  unicode-display_width (>= 2.4.0, < 3.0)
48
- rubocop-ast (1.24.1)
49
- parser (>= 3.1.1.0)
63
+ rubocop-ast (1.26.0)
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)
60
- rubocop (~> 1.44, >= 1.44.1)
82
+ rspec (~> 3.12)
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
@@ -7,24 +7,17 @@ API for interacting with a [Lightning Node](https://lightning.network).
7
7
  ![Lighstorm text written stylized with an illustration of a Graph connecting two Nodes.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/lighstorm.png)
8
8
 
9
9
  ```ruby
10
- Lighstorm::Channel.first.myself.node.alias
10
+ Lighstorm::Channel.mine.first.myself.node.alias
11
11
  ```
12
12
 
13
13
  ## Index
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.2'
36
+ gem 'lighstorm', '~> 0.0.4'
46
37
  ```
47
38
 
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
57
- ```
58
-
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,339 +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
82
- Lighstorm::Node.find_by_public_key(
83
- '02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
84
- )
85
-
86
- node.to_h
87
-
88
- node.channels
89
-
90
- node.alias
91
- node.public_key
92
- node.color
93
- node.myself?
94
-
95
- node.platform.blockchain
96
- node.platform.network
97
- node.platform.lightning.implementation
98
- node.platform.lightning.version
99
-
100
- Lighstorm::Channel
101
- Lighstorm::Channel.all
102
- Lighstorm::Channel.first
103
- Lighstorm::Channel.last
104
- Lighstorm::Channel.find_by_id(850099509773795329)
105
-
106
- channel.to_h
107
-
108
- channel.id
109
- channel.opened_at
110
- channel.up_at
111
- channel.active
112
- channel.exposure
113
-
114
- channel.accounting.capacity.milisatoshis
115
- channel.accounting.sent.milisatoshis
116
- channel.accounting.received.milisatoshis
117
- channel.accounting.unsettled.milisatoshis
118
-
119
- channel.partner.accounting.balance.milisatoshis
120
- channel.partner.node.alias
121
- channel.partner.node.public_key
122
- channel.partner.node.color
123
- channel.partner.policy.fee.base.milisatoshis
124
- channel.partner.policy.fee.rate.parts_per_million
125
-
126
- channel.myself.accounting.balance.milisatoshis
127
- channel.myself.node.alias
128
- channel.myself.node.public_key
129
- channel.myself.node.color
130
- channel.myself.policy.fee.base.milisatoshis
131
- channel.myself.policy.fee.rate.parts_per_million
132
-
133
- channel.myself.policy.fee.update(
134
- { rate: { parts_per_million: 25 } }, preview: true
135
- )
136
-
137
- channel.myself.policy.fee.update(
138
- { rate: { parts_per_million: 25 } }
139
- )
140
-
141
- Lighstorm::Forward
142
- Lighstorm::Forward.all
143
- Lighstorm::Forward.first
144
- Lighstorm::Forward.last
145
- Lighstorm::Forward.all(limit: 10)
146
-
147
- forward.to_h
148
-
149
- forward.id
150
- forward.at
151
-
152
- forward.fee.milisatoshis
153
- forward.fee.parts_per_million(
154
- forward.in.amount.milisatoshis
155
- )
156
-
157
- forward.in.amount.milisatoshis
158
-
159
- forward.in.channel.id
160
- forward.in.channel.partner.node.alias
161
- forward.in.channel.partner.node.public_key
162
- forward.in.channel.partner.node.color
163
-
164
- forward.out.channel.id
165
- forward.out.channel.partner.node.alias
166
- forward.out.channel.partner.node.public_key
167
- forward.out.channel.partner.node.color
168
-
169
- Lighstorm::Forward.group_by_channel(direction: :in, hours_ago: 24, limit: 5)
170
-
171
- group.to_h
172
-
173
- group.last_at
174
- group.analysis.count
175
- group.analysis.sums.amount.milisatoshis
176
- group.analysis.sums.fee.milisatoshis
177
- group.analysis.averages.amount.milisatoshis
178
- group.analysis.averages.fee.milisatoshis
179
- group.analysis.averages.fee.parts_per_million(
180
- group.analysis.averages.amount.milisatoshis
181
- )
182
-
183
- group.in.id
184
- group.in.partner.node.alias
185
- group.in.partner.node.public_key
186
- group.in.partner.node.color
187
-
188
- Lighstorm::Forward.group_by_channel(direction: :out)
189
-
190
- group.to_h
191
-
192
- group.last_at
193
- group.analysis.count
194
-
195
- group.out.id
196
- group.out.partner.node.alias
197
- group.out.partner.node.public_key
198
- group.out.partner.node.color
199
-
200
- Lighstorm::Payment
201
- Lighstorm::Payment.all
202
- Lighstorm::Payment.first
203
- Lighstorm::Payment.last
204
- Lighstorm::Payment.all(limit: 10, purpose: 'rebalance', hops: false)
205
-
206
- payment.id
207
- payment.hash
208
- payment.created_at
209
- payment.purpose
210
- payment.status
211
- payment.amount.milisatoshis
212
- payment.fee.milisatoshis
213
- payment.fee.parts_per_million(
214
- payment.amount.milisatoshis
215
- )
216
-
217
- payment.from.hop
218
- payment.from.amount.milisatoshis
219
- payment.from.fee.milisatoshis
220
- payment.from.fee.parts_per_million(
221
- payment.from.amount.milisatoshis
222
- )
223
-
224
- payment.from.channel.id
225
- payment.from.channel.partner.node.alias
226
- payment.from.channel.partner.node.public_key
227
- payment.from.channel.partner.node.color
228
-
229
- payment.to.hop
230
- payment.to.amount.milisatoshis
231
- payment.to.fee.milisatoshis
232
- payment.to.fee.parts_per_million(
233
- payment.to.amount.milisatoshis
234
- )
235
-
236
- payment.to.channel.id
237
- payment.to.channel.partner.node.alias
238
- payment.to.channel.partner.node.public_key
239
- payment.to.channel.partner.node.color
240
-
241
- payment.hops.size
242
-
243
- payment.hops[0].hop
244
- payment.hops[0].amount.milisatoshis
245
- payment.hops[0].fee.milisatoshis
246
- payment.hops[0].fee.parts_per_million(
247
- payment.hops[0].amount.milisatoshis
248
- )
249
-
250
- payment.hops[0].channel.id
251
- payment.hops[0].channel.partner.node.alias
252
- payment.hops[0].channel.partner.node.public_key
253
- payment.hops[0].channel.partner.node.color
254
-
255
- Lighstorm::Satoshis
256
- Lighstorm::Satoshis.new(milisatoshis: 75621650)
257
-
258
- satoshis.to_h
259
-
260
- satoshis.milisatoshis
261
- satoshis.satoshis
262
- satoshis.bitcoins
263
-
264
- satoshis.msats
265
- satoshis.sats
266
- satoshis.btc
267
-
268
- reference_in_milisatoshis = 75_621_650_000
269
- satoshis.parts_per_million(reference_in_milisatoshis)
270
- ```
271
-
272
- #### Examples
273
-
274
- ```ruby
275
- require 'lighstorm'
276
-
277
- puts Lighstorm.version # => 0.0.2
48
+ puts Lighstorm.version # => 0.0.4
278
49
 
279
50
  Lighstorm::Satoshis.new(
280
- milisatoshis: 75621650
281
- ).satoshis # => 75621
51
+ milisatoshis: 75_621_650
52
+ ).satoshis # => 75_621
282
53
 
283
54
  Lighstorm::Node.myself.alias # => icebaker/old-stone
284
- Lighstorm::Node.myself.public_key # => 02d3...e997
285
-
286
- Lighstorm::Node.myself.to_h #> { ... }
287
-
288
- Lighstorm::Node.myself.channels.count # => 5
289
-
290
- Lighstorm::Channel.all.first.partner.node.alias
291
-
292
- forward = Lighstorm::Forward.all(limit: 10).first
293
-
294
- forward.in.amount.milisatoshis # => 75621650
295
- forward.in.amount.satoshis # => 75621
296
- forward.in.amount.bitcoins # => 0.0007562165
297
- forward.in.channel.partner.node.alias
298
- forward.out.channel.partner.node.alias
299
-
300
- forward.to_h # => { ... }
301
-
302
- payment = Lighstorm::Payment.all.first
303
-
304
- payment.from.channel.id # => 850099509773795329
305
- payment.to.channel.id # => 821539695188246532
306
- payment.amount.sats # => 957262
307
- payment.hops.size # => 4
308
- payment.hops.first.channel.partner.node.alias
309
55
  ```
310
56
 
311
- ### Data Modeling
312
-
313
- #### Graph Theory
57
+ Check the [full documentation](https://icebaker.github.io/lighstorm).
314
58
 
315
- [Graphs](https://en.wikipedia.org/wiki/Graph_theory) provide a great representation to abstract the [Lightning Network](https://lightning.network) data.
316
-
317
- So, we are going to think in terms of _Edges_, _Nodes_, and _Connections_:
318
-
319
- ![This is an image describing Graphs and their terminologies.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-theory.png)
59
+ ## Development
320
60
 
321
- #### Channel
61
+ Copy the `.env.example` file to `.env` and provide the required data.
322
62
 
323
63
  ```ruby
324
- channel = Lighstorm::Channel.first
325
-
326
- channel.id
327
-
328
- channel.accounting.capacity.milisatoshis
64
+ # Gemfile
65
+ gem 'lighstorm', path: '/home/user/lighstorm'
329
66
 
330
- channel.partner.accounting.balance.milisatoshis
331
- channel.partner.node.alias
332
- channel.partner.policy.fee.rate.parts_per_million
67
+ # demo.rb
68
+ require 'lighstorm'
333
69
 
334
- channel.myself.accounting.balance.milisatoshis
335
- channel.myself.node.alias
336
- channel.myself.policy.fee.rate.parts_per_million
70
+ puts Lighstorm.version # => 0.0.4
337
71
  ```
338
72
 
339
- ![This is an image representing Channel as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
340
-
341
- #### Forward
342
-
343
- ```ruby
344
- forward = Lighstorm::Forward.last
345
-
346
- forward.at
347
-
348
- forward.fee.parts_per_million
349
-
350
- forward.in.amount.milisatoshis
351
-
352
- forward.in.channel.id
353
- forward.in.channel.partner.node.alias
354
-
355
- forward.out.channel.id
356
- forward.out.channel.partner.node.alias
73
+ ```sh
74
+ bundle
75
+ rubocop -A
357
76
  ```
358
77
 
359
- ![This is an image representing Forward as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
78
+ ### Testing
360
79
 
361
- #### Payment
80
+ Copy the `.env.example` file to `.env` and provide the required data.
362
81
 
363
- ```ruby
364
- payment = Payment.last
365
-
366
- payment.hash
367
- payment.amount.milisatoshis
368
-
369
- payment.from.hop
370
- payment.from.amount.milisatoshis
371
- payment.from.fee.milisatoshis
372
- payment.from.channel.id
373
- payment.from.channel.partner.node.alias
374
-
375
- payment.to.hop
376
- payment.to.amount.milisatoshis
377
- payment.to.fee.milisatoshis
378
- payment.to.channel.id
379
- payment.to.channel.partner.node.alias
380
-
381
- payment.hops[0].hop
382
- payment.hops[0].amount.milisatoshis
383
- payment.hops[0].fee.milisatoshis
384
- payment.hops[0].channel.id
385
- payment.hops[0].channel.partner.node.alias
386
82
  ```
83
+ bundle
387
84
 
388
- ![This is an image representing Payment as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)
389
-
390
- ## Development
391
-
392
- ```ruby
393
- # Gemfile
394
- gem 'lighstorm', path: '/home/user/lighstorm'
395
-
396
- # demo.rb
397
- require 'lighstorm'
398
-
399
- puts Lighstorm.version # => 0.0.2
85
+ bundle exec rspec
400
86
  ```
401
87
 
88
+ ### Generating Documentation
89
+
402
90
  ```sh
403
- bundle
404
- rubocop -A
91
+ npm i docsify-cli -g
92
+
93
+ docsify serve ./docs
405
94
  ```
406
95
 
407
96
  ### Publish to RubyGems
@@ -411,5 +100,5 @@ gem build lighstorm.gemspec
411
100
 
412
101
  gem signin
413
102
 
414
- gem push lighstorm-0.0.2.gem
103
+ gem push lighstorm-0.0.4.gem
415
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