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.
- checksums.yaml +4 -4
- data/.env.example +5 -0
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +10 -0
- data/Gemfile +5 -1
- data/Gemfile.lock +32 -8
- data/README.md +30 -341
- data/adapters/connections/channel_node/fee.rb +26 -0
- data/adapters/connections/channel_node.rb +52 -0
- data/adapters/connections/payment_channel.rb +28 -0
- data/adapters/edges/channel.rb +80 -0
- data/adapters/edges/forward.rb +41 -0
- data/adapters/edges/payment/purpose.rb +34 -0
- data/adapters/edges/payment.rb +53 -0
- data/adapters/invoice.rb +50 -0
- data/adapters/nodes/node.rb +77 -0
- data/adapters/payment_request.rb +77 -0
- data/components/cache.rb +3 -2
- data/components/lnd.rb +5 -1
- data/controllers/channel/actions/update_fee.rb +76 -0
- data/controllers/channel/all.rb +79 -0
- data/controllers/channel/find_by_id.rb +153 -0
- data/controllers/channel/mine.rb +114 -0
- data/controllers/channel.rb +23 -0
- data/controllers/forward/all.rb +244 -0
- data/controllers/forward/group_by_channel.rb +89 -0
- data/controllers/forward.rb +28 -0
- data/controllers/invoice/actions/create.rb +36 -0
- data/controllers/invoice/actions/pay.rb +28 -0
- data/controllers/invoice/actions/pay_through_route.rb +71 -0
- data/controllers/invoice/all.rb +70 -0
- data/controllers/invoice/find_by_secret_hash.rb +42 -0
- data/controllers/invoice.rb +36 -0
- data/controllers/node/all.rb +63 -0
- data/controllers/node/find_by_public_key.rb +49 -0
- data/controllers/node/myself.rb +34 -0
- data/controllers/node.rb +23 -0
- data/controllers/payment/all.rb +352 -0
- data/controllers/payment.rb +21 -0
- data/docs/.nojekyll +0 -0
- data/docs/README.md +655 -0
- data/docs/_coverpage.md +12 -0
- data/docs/index.html +26 -0
- data/docs/vendor/docsify/docsify@4.js +1 -0
- data/docs/vendor/docsify-themeable/theme-simple-dark.css +3 -0
- data/docs/vendor/docsify-themeable/theme-simple-dark.css.map +1 -0
- data/docs/vendor/prismjs/prism-bash.min.js +1 -0
- data/docs/vendor/prismjs/prism-ruby.min.js +1 -0
- data/docs/vendor/prismjs/prism-tomorrow.min.css +1 -0
- data/lighstorm.gemspec +4 -2
- data/models/connections/channel_node/accounting.rb +3 -12
- data/models/connections/channel_node/fee.rb +44 -56
- data/models/connections/channel_node/htlc.rb +52 -0
- data/models/connections/channel_node/policy.rb +11 -12
- data/models/connections/channel_node.rb +20 -19
- data/models/connections/forward_channel.rb +8 -43
- data/models/connections/payment_channel.rb +18 -39
- data/models/edges/channel/accounting.rb +42 -18
- data/models/edges/channel/hop.rb +65 -0
- data/models/edges/channel.rb +98 -120
- data/models/edges/forward.rb +9 -118
- data/models/edges/groups/{analysis.rb → channel_forwards/analysis.rb} +9 -9
- data/models/edges/groups/channel_forwards.rb +10 -40
- data/models/edges/payment.rb +29 -214
- data/models/errors.rb +29 -0
- data/models/invoice.rb +49 -0
- data/models/nodes/node/lightning.rb +5 -16
- data/models/nodes/node/platform.rb +7 -13
- data/models/nodes/node.rb +19 -56
- data/models/payment_request.rb +69 -0
- data/models/rate.rb +11 -1
- data/models/satoshis.rb +5 -6
- data/ports/dsl/lighstorm/errors.rb +5 -0
- data/ports/dsl/lighstorm.rb +12 -8
- data/ports/grpc.rb +62 -0
- data/static/cache.rb +12 -0
- data/static/spec.rb +3 -1
- metadata +58 -8
- data/models/connections/channel_node/constraints.rb +0 -24
data/docs/README.md
ADDED
@@ -0,0 +1,655 @@
|
|
1
|
+
> ⚠️ Warning: Early-stage project, breaking changes are expected.
|
2
|
+
|
3
|
+
# About
|
4
|
+
|
5
|
+
> Lighstorm: API for interacting with a [Lightning Node](https://lightning.network).
|
6
|
+
|
7
|
+
_Lighstorm_ is an opinionated abstraction layer on top of the [lnd-client](https://github.com/icebaker/lnd-client).
|
8
|
+
|
9
|
+
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.
|
10
|
+
|
11
|
+
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).
|
12
|
+
|
13
|
+
# Getting Started
|
14
|
+
|
15
|
+

|
16
|
+
|
17
|
+
```ruby
|
18
|
+
Lighstorm::Channel.mine.first.myself.node.alias
|
19
|
+
```
|
20
|
+
|
21
|
+
## Installing
|
22
|
+
|
23
|
+
Add to your `Gemfile`:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'lighstorm', '~> 0.0.4'
|
27
|
+
```
|
28
|
+
|
29
|
+
Run `bundle install`.
|
30
|
+
|
31
|
+
## Credentials
|
32
|
+
|
33
|
+
Set the following _Environment Variables_ or create a `.env` file:
|
34
|
+
```bash
|
35
|
+
LIGHSTORM_LND_ADDRESS=127.0.0.1:10009
|
36
|
+
LIGHSTORM_CERTIFICATE_PATH=/lnd/tls.cert
|
37
|
+
LIGHSTORM_MACAROON_PATH=/lnd/data/chain/bitcoin/mainnet/admin.macaroon
|
38
|
+
```
|
39
|
+
|
40
|
+
It will automatically load your credentials.
|
41
|
+
|
42
|
+
Alternatively, you can set the credentials at runtime:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require 'lighstorm'
|
46
|
+
|
47
|
+
Lighstorm.config!(
|
48
|
+
lnd_address: '127.0.0.1:10009',
|
49
|
+
certificate_path: '/lnd/tls.cert',
|
50
|
+
macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
|
51
|
+
)
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
## Examples
|
56
|
+
```ruby
|
57
|
+
require 'lighstorm'
|
58
|
+
|
59
|
+
puts Lighstorm.version # => 0.0.4
|
60
|
+
|
61
|
+
Lighstorm::Satoshis.new(
|
62
|
+
milisatoshis: 75_621_650
|
63
|
+
).satoshis # => 75_621
|
64
|
+
|
65
|
+
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
66
|
+
Lighstorm::Node.myself.public_key # => 02d3...e997
|
67
|
+
|
68
|
+
Lighstorm::Node.myself.to_h #> { ... }
|
69
|
+
|
70
|
+
Lighstorm::Node.myself.channels.count # => 5
|
71
|
+
|
72
|
+
Lighstorm::Channel.mine.first.partner.node.alias
|
73
|
+
|
74
|
+
forward = Lighstorm::Forward.all(limit: 10).first
|
75
|
+
|
76
|
+
forward.in.amount.milisatoshis # => 75621650
|
77
|
+
forward.in.amount.satoshis # => 75621
|
78
|
+
forward.in.amount.bitcoins # => 0.0007562165
|
79
|
+
forward.in.channel.partner.node.alias
|
80
|
+
forward.out.channel.partner.node.alias
|
81
|
+
|
82
|
+
forward.to_h # => { ... }
|
83
|
+
|
84
|
+
payment = Lighstorm::Payment.all.first
|
85
|
+
|
86
|
+
payment.from.channel.id # => 850099509773795329
|
87
|
+
payment.to.channel.id # => 821539695188246532
|
88
|
+
payment.amount.sats # => 957262
|
89
|
+
payment.hops.size # => 4
|
90
|
+
payment.hops.first.channel.partner.node.alias
|
91
|
+
```
|
92
|
+
|
93
|
+
# Data Modeling
|
94
|
+
|
95
|
+
## Graph Theory
|
96
|
+
|
97
|
+
[Graphs](https://en.wikipedia.org/wiki/Graph_theory) provide a great representation to abstract the [Lightning Network](https://lightning.network) data.
|
98
|
+
|
99
|
+
So, we are going to think in terms of _Edges_, _Nodes_, and _Connections_:
|
100
|
+
|
101
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-theory.png)
|
102
|
+
<center style="margin-top: -1.4em;">
|
103
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-theory.png" rel="noopener noreferrer" target="_blank">
|
104
|
+
click to zoom
|
105
|
+
</a>
|
106
|
+
</center>
|
107
|
+
|
108
|
+
## Channel
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
channel = Lighstorm::Channel.mine.first
|
112
|
+
|
113
|
+
channel.id
|
114
|
+
|
115
|
+
channel.accounting.capacity.milisatoshis
|
116
|
+
|
117
|
+
channel.partner.accounting.balance.milisatoshis
|
118
|
+
channel.partner.node.alias
|
119
|
+
channel.partner.policy.fee.rate.parts_per_million
|
120
|
+
|
121
|
+
channel.myself.accounting.balance.milisatoshis
|
122
|
+
channel.myself.node.alias
|
123
|
+
channel.myself.policy.fee.rate.parts_per_million
|
124
|
+
```
|
125
|
+
|
126
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
|
127
|
+
<center style="margin-top: -1.4em;">
|
128
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png" rel="noopener noreferrer" target="_blank">
|
129
|
+
click to zoom
|
130
|
+
</a>
|
131
|
+
</center>
|
132
|
+
|
133
|
+
## Forward
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
forward = Lighstorm::Forward.last
|
137
|
+
|
138
|
+
forward.at
|
139
|
+
|
140
|
+
forward.fee.milisatoshis
|
141
|
+
forward.fee.parts_per_million
|
142
|
+
|
143
|
+
forward.in.amount.milisatoshis
|
144
|
+
forward.out.amount.milisatoshis
|
145
|
+
|
146
|
+
forward.in.channel.id
|
147
|
+
forward.in.channel.partner.node.alias
|
148
|
+
|
149
|
+
forward.out.channel.id
|
150
|
+
forward.out.channel.partner.node.alias
|
151
|
+
```
|
152
|
+
|
153
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
|
154
|
+
<center style="margin-top: -1.4em;">
|
155
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png" rel="noopener noreferrer" target="_blank">
|
156
|
+
click to zoom
|
157
|
+
</a>
|
158
|
+
</center>
|
159
|
+
|
160
|
+
## Payment
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
payment = Payment.last
|
164
|
+
|
165
|
+
payment.status
|
166
|
+
payment.created_at
|
167
|
+
|
168
|
+
# https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
|
169
|
+
payment.request.code # "lnbc20m1pv...qqdhhwkj"
|
170
|
+
|
171
|
+
payment.request.amount.milisatoshis
|
172
|
+
|
173
|
+
payment.from.hop
|
174
|
+
payment.from.amount.milisatoshis
|
175
|
+
payment.from.fee.milisatoshis
|
176
|
+
payment.from.channel.id
|
177
|
+
payment.from.channel.target.alias
|
178
|
+
payment.from.channel.exit.alias
|
179
|
+
|
180
|
+
payment.to.hop
|
181
|
+
payment.to.amount.milisatoshis
|
182
|
+
payment.to.fee.milisatoshis
|
183
|
+
payment.to.channel.id
|
184
|
+
payment.to.channel.target.alias
|
185
|
+
|
186
|
+
payment.hops[0].hop
|
187
|
+
payment.hops[0].amount.milisatoshis
|
188
|
+
payment.hops[0].fee.milisatoshis
|
189
|
+
payment.hops[0].channel.id
|
190
|
+
payment.hops[0].channel.target.alias
|
191
|
+
```
|
192
|
+
|
193
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)
|
194
|
+
<center style="margin-top: -1.4em;">
|
195
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png" rel="noopener noreferrer" target="_blank">
|
196
|
+
click to zoom
|
197
|
+
</a>
|
198
|
+
</center>
|
199
|
+
|
200
|
+
# Error Handling
|
201
|
+
|
202
|
+
## Rescuing
|
203
|
+
```ruby
|
204
|
+
require 'lighstorm'
|
205
|
+
|
206
|
+
channel = Lighstorm::Channel.mine.first
|
207
|
+
|
208
|
+
begin
|
209
|
+
channel.myself.policy.fee.update(
|
210
|
+
{ rate: { parts_per_million: -1 } }, preview: true
|
211
|
+
)
|
212
|
+
rescue Lighstorm::Errors::NegativeNotAllowedError => error
|
213
|
+
puts error.message # 'fee rate can't be negative: -1'
|
214
|
+
end
|
215
|
+
|
216
|
+
begin
|
217
|
+
channel.myself.policy.fee.update(
|
218
|
+
{ rate: { parts_per_million: -1 } }, preview: true
|
219
|
+
)
|
220
|
+
rescue Lighstorm::Errors::LighstormError => error
|
221
|
+
puts error.message # 'fee rate can't be negative: -1'
|
222
|
+
end
|
223
|
+
```
|
224
|
+
|
225
|
+
### For Short
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
require 'lighstorm'
|
229
|
+
require 'lighstorm/errors'
|
230
|
+
|
231
|
+
channel = Lighstorm::Channel.mine.first
|
232
|
+
|
233
|
+
begin
|
234
|
+
channel.myself.policy.fee.update(
|
235
|
+
{ rate: { parts_per_million: -1 } }, preview: true
|
236
|
+
)
|
237
|
+
rescue NegativeNotAllowedError => error
|
238
|
+
puts error.message # "fee rate can't be negative: -1"
|
239
|
+
end
|
240
|
+
|
241
|
+
begin
|
242
|
+
channel.myself.policy.fee.update(
|
243
|
+
{ rate: { parts_per_million: -1 } }, preview: true
|
244
|
+
)
|
245
|
+
rescue LighstormError => error
|
246
|
+
puts error.message # "fee rate can't be negative: -1"
|
247
|
+
end
|
248
|
+
```
|
249
|
+
|
250
|
+
## Errors
|
251
|
+
```ruby
|
252
|
+
LighstormError
|
253
|
+
|
254
|
+
MissingCredentialsError
|
255
|
+
MissingMilisatoshisError
|
256
|
+
MissingPartsPerMillionError
|
257
|
+
MissingTTLError
|
258
|
+
NegativeNotAllowedError
|
259
|
+
NotYourChannelError
|
260
|
+
NotYourNodeError
|
261
|
+
OperationNotAllowedError
|
262
|
+
UnexpectedNumberOfHTLCsError
|
263
|
+
UnknownChannelError
|
264
|
+
UpdateChannelPolicyError
|
265
|
+
```
|
266
|
+
|
267
|
+
# API
|
268
|
+
|
269
|
+
## Node
|
270
|
+
```ruby
|
271
|
+
Lighstorm::Node
|
272
|
+
|
273
|
+
Lighstorm::Node.myself # Your Node.
|
274
|
+
Lighstorm::Node.all # All 18k+ Nodes on the Network.
|
275
|
+
Lighstorm::Node.all(limit: 10)
|
276
|
+
Lighstorm::Node.find_by_public_key(
|
277
|
+
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
278
|
+
)
|
279
|
+
|
280
|
+
# _key is helpful for reactive javascript frameworks.
|
281
|
+
# Please don't consider it as a unique identifier
|
282
|
+
# for the item. Instead, use it as a volatile key for
|
283
|
+
# the item's current state that may change at any moment.
|
284
|
+
node._key
|
285
|
+
|
286
|
+
node.to_h
|
287
|
+
|
288
|
+
node.channels
|
289
|
+
|
290
|
+
node.alias
|
291
|
+
node.public_key
|
292
|
+
node.color
|
293
|
+
node.myself?
|
294
|
+
|
295
|
+
node.platform.blockchain
|
296
|
+
node.platform.network
|
297
|
+
node.platform.lightning.implementation
|
298
|
+
node.platform.lightning.version
|
299
|
+
```
|
300
|
+
|
301
|
+
## Channel
|
302
|
+
|
303
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png)
|
304
|
+
<center style="margin-top: -1.4em;">
|
305
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-channel.png" rel="noopener noreferrer" target="_blank">
|
306
|
+
click to zoom
|
307
|
+
</a>
|
308
|
+
</center>
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
Lighstorm::Channel
|
312
|
+
Lighstorm::Channel.mine # Your Node's Channels.
|
313
|
+
Lighstorm::Channel.all # All 80k+ Channels on the Network.
|
314
|
+
Lighstorm::Channel.all(limit: 10)
|
315
|
+
Lighstorm::Channel.find_by_id('850099509773795329')
|
316
|
+
|
317
|
+
# _key is helpful for reactive javascript frameworks.
|
318
|
+
# Please don't consider it as a unique identifier
|
319
|
+
# for the item. Instead, use it as a volatile key for
|
320
|
+
# the item's current state that may change at any moment.
|
321
|
+
channel._key
|
322
|
+
|
323
|
+
channel.to_h
|
324
|
+
|
325
|
+
channel.mine?
|
326
|
+
|
327
|
+
channel.id
|
328
|
+
channel.opened_at
|
329
|
+
channel.up_at
|
330
|
+
channel.active
|
331
|
+
channel.exposure
|
332
|
+
|
333
|
+
channel.accounting.capacity.milisatoshis
|
334
|
+
channel.accounting.sent.milisatoshis
|
335
|
+
channel.accounting.received.milisatoshis
|
336
|
+
channel.accounting.unsettled.milisatoshis
|
337
|
+
|
338
|
+
# Channels that don't belong to you:
|
339
|
+
channel.partners
|
340
|
+
|
341
|
+
channel.partners[0]
|
342
|
+
channel.partners[0].node.alias
|
343
|
+
|
344
|
+
channel.partners[1]
|
345
|
+
channel.partners[1].node.alias
|
346
|
+
|
347
|
+
# Channels that belong to you:
|
348
|
+
channel.myself
|
349
|
+
channel.myself.node.alias
|
350
|
+
|
351
|
+
channel.transaction.funding.id
|
352
|
+
channel.transaction.funding.index
|
353
|
+
|
354
|
+
channel.partner
|
355
|
+
channel.partner.node.alias
|
356
|
+
|
357
|
+
channel.partner.accounting.balance.milisatoshis
|
358
|
+
channel.partner.node.alias
|
359
|
+
channel.partner.node.public_key
|
360
|
+
channel.partner.node.color
|
361
|
+
channel.partner.policy.fee.base.milisatoshis
|
362
|
+
channel.partner.policy.fee.rate.parts_per_million
|
363
|
+
channel.partner.policy.htlc.minimum.milisatoshis
|
364
|
+
channel.partner.policy.htlc.maximum.milisatoshis
|
365
|
+
channel.partner.policy.htlc.blocks.delta.minimum
|
366
|
+
|
367
|
+
channel.myself.accounting.balance.milisatoshis
|
368
|
+
channel.myself.node.alias
|
369
|
+
channel.myself.node.public_key
|
370
|
+
channel.myself.node.color
|
371
|
+
channel.myself.policy.fee.base.milisatoshis
|
372
|
+
channel.myself.policy.fee.rate.parts_per_million
|
373
|
+
channel.myself.policy.htlc.minimum.milisatoshis
|
374
|
+
channel.myself.policy.htlc.maximum.milisatoshis
|
375
|
+
channel.myself.policy.htlc.blocks.delta.minimum
|
376
|
+
```
|
377
|
+
|
378
|
+
### Operations
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
channel = Lighstorm::Channel.mine.first
|
382
|
+
|
383
|
+
channel.myself.policy.fee.update(
|
384
|
+
{ rate: { parts_per_million: 25 } }, preview: true
|
385
|
+
)
|
386
|
+
|
387
|
+
channel.myself.policy.fee.update(
|
388
|
+
{ base: { milisatoshis: 1 } }
|
389
|
+
)
|
390
|
+
|
391
|
+
channel.myself.policy.fee.update(
|
392
|
+
{ rate: { parts_per_million: 25 } }
|
393
|
+
)
|
394
|
+
|
395
|
+
channel.myself.policy.fee.update(
|
396
|
+
{ base: { milisatoshis: 1 }, rate: { parts_per_million: 25 } }
|
397
|
+
)
|
398
|
+
```
|
399
|
+
|
400
|
+
## Invoice
|
401
|
+
|
402
|
+
```ruby
|
403
|
+
Lighstorm::Invoice
|
404
|
+
Lighstorm::Invoice.all
|
405
|
+
Lighstorm::Invoice.all(limit: 10)
|
406
|
+
Lighstorm::Invoice.first
|
407
|
+
Lighstorm::Invoice.last
|
408
|
+
|
409
|
+
Lighstorm::Invoice.find_by_secret_hash(
|
410
|
+
'1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
|
411
|
+
)
|
412
|
+
|
413
|
+
# _key is helpful for reactive javascript frameworks.
|
414
|
+
# Please don't consider it as a unique identifier
|
415
|
+
# for the item. Instead, use it as a volatile key for
|
416
|
+
# the item's current state that may change at any moment.
|
417
|
+
invoice._key
|
418
|
+
|
419
|
+
invoice.created_at
|
420
|
+
invoice.settle_at
|
421
|
+
|
422
|
+
invoice.state
|
423
|
+
|
424
|
+
# https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
|
425
|
+
invoice.request.code # "lnbc20m1pv...qqdhhwkj"
|
426
|
+
|
427
|
+
invoice.request.amount.milisatoshis
|
428
|
+
|
429
|
+
invoice.request.description.memo
|
430
|
+
invoice.request.description.hash
|
431
|
+
|
432
|
+
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
433
|
+
invoice.request.secret.preimage
|
434
|
+
invoice.request.secret.hash
|
435
|
+
|
436
|
+
invoice.request.address
|
437
|
+
```
|
438
|
+
|
439
|
+
## Payment
|
440
|
+
|
441
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)
|
442
|
+
<center style="margin-top: -1.4em;">
|
443
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png" rel="noopener noreferrer" target="_blank">
|
444
|
+
click to zoom
|
445
|
+
</a>
|
446
|
+
</center>
|
447
|
+
|
448
|
+
```ruby
|
449
|
+
Lighstorm::Payment
|
450
|
+
Lighstorm::Payment.all
|
451
|
+
Lighstorm::Payment.first
|
452
|
+
Lighstorm::Payment.last
|
453
|
+
Lighstorm::Payment.all(limit: 10, purpose: 'rebalance')
|
454
|
+
|
455
|
+
# Possible Purposes:
|
456
|
+
['self-payment', 'peer-to-peer', 'rebalance', 'payment']
|
457
|
+
|
458
|
+
# _key is helpful for reactive javascript frameworks.
|
459
|
+
# Please don't consider it as a unique identifier
|
460
|
+
# for the item. Instead, use it as a volatile key for
|
461
|
+
# the item's current state that may change at any moment.
|
462
|
+
payment._key
|
463
|
+
|
464
|
+
payment.to_h
|
465
|
+
|
466
|
+
payment.status
|
467
|
+
payment.created_at
|
468
|
+
payment.settled_at
|
469
|
+
payment.purpose
|
470
|
+
|
471
|
+
payment.fee.milisatoshis
|
472
|
+
payment.fee.parts_per_million(
|
473
|
+
payment.request.amount.milisatoshis
|
474
|
+
)
|
475
|
+
|
476
|
+
# https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
|
477
|
+
payment.request.code # "lnbc20m1pv...qqdhhwkj"
|
478
|
+
|
479
|
+
payment.request.amount.milisatoshis
|
480
|
+
|
481
|
+
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
482
|
+
payment.request.secret.preimage
|
483
|
+
payment.request.secret.hash
|
484
|
+
|
485
|
+
payment.request.address
|
486
|
+
|
487
|
+
payment.request.description.memo
|
488
|
+
payment.request.description.hash
|
489
|
+
|
490
|
+
payment.from.hop
|
491
|
+
payment.from.amount.milisatoshis
|
492
|
+
payment.from.fee.milisatoshis
|
493
|
+
payment.from.fee.parts_per_million(payment.from.amount.milisatoshis)
|
494
|
+
|
495
|
+
payment.from.channel.id
|
496
|
+
|
497
|
+
payment.from.channel.target.public_key
|
498
|
+
payment.from.channel.target.alias
|
499
|
+
payment.from.channel.target.color
|
500
|
+
|
501
|
+
payment.from.channel.exit.public_key
|
502
|
+
payment.from.channel.exit.alias
|
503
|
+
payment.from.channel.exit.color
|
504
|
+
|
505
|
+
payment.to.hop
|
506
|
+
payment.to.amount.milisatoshis
|
507
|
+
payment.to.fee.milisatoshis
|
508
|
+
payment.to.fee.parts_per_million(payment.to.amount.milisatoshis)
|
509
|
+
|
510
|
+
payment.to.channel.id
|
511
|
+
|
512
|
+
payment.to.channel.target.public_key
|
513
|
+
payment.to.channel.target.alias
|
514
|
+
payment.to.channel.target.color
|
515
|
+
|
516
|
+
payment.to.channel.entry.public_key
|
517
|
+
payment.to.channel.entry.alias
|
518
|
+
payment.to.channel.entry.color
|
519
|
+
|
520
|
+
payment.hops.size
|
521
|
+
|
522
|
+
payment.hops[0].first?
|
523
|
+
payment.hops[0].last?
|
524
|
+
|
525
|
+
payment.hops[0].hop
|
526
|
+
payment.hops[0].amount.milisatoshis
|
527
|
+
payment.hops[0].fee.milisatoshis
|
528
|
+
payment.hops[0].fee.parts_per_million(payment.hops[0].amount.milisatoshis)
|
529
|
+
|
530
|
+
payment.hops[0].channel.id
|
531
|
+
|
532
|
+
payment.hops[0].channel.target.public_key
|
533
|
+
payment.hops[0].channel.target.alias
|
534
|
+
payment.hops[0].channel.target.color
|
535
|
+
|
536
|
+
payment.hops[0].channel.entry.public_key
|
537
|
+
payment.hops[0].channel.entry.alias
|
538
|
+
payment.hops[0].channel.entry.color
|
539
|
+
```
|
540
|
+
|
541
|
+
## Forward
|
542
|
+
|
543
|
+
[](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png)
|
544
|
+
<center style="margin-top: -1.4em;">
|
545
|
+
<a href="https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-forward.png" rel="noopener noreferrer" target="_blank">
|
546
|
+
click to zoom
|
547
|
+
</a>
|
548
|
+
</center>
|
549
|
+
|
550
|
+
```ruby
|
551
|
+
Lighstorm::Forward
|
552
|
+
Lighstorm::Forward.all
|
553
|
+
Lighstorm::Forward.first
|
554
|
+
Lighstorm::Forward.last
|
555
|
+
Lighstorm::Forward.all(limit: 10)
|
556
|
+
|
557
|
+
forward.to_h
|
558
|
+
|
559
|
+
# _key is helpful for reactive javascript frameworks.
|
560
|
+
# Please don't consider it as a unique identifier
|
561
|
+
# for the item. Instead, use it as a volatile key for
|
562
|
+
# the item's current state that may change at any moment.
|
563
|
+
forward._key
|
564
|
+
|
565
|
+
forward.at
|
566
|
+
|
567
|
+
forward.fee.milisatoshis
|
568
|
+
forward.fee.parts_per_million(
|
569
|
+
forward.in.amount.milisatoshis
|
570
|
+
)
|
571
|
+
|
572
|
+
forward.in.amount.milisatoshis
|
573
|
+
|
574
|
+
forward.in.channel.id
|
575
|
+
forward.in.channel.partner.node.alias
|
576
|
+
forward.in.channel.partner.node.public_key
|
577
|
+
forward.in.channel.partner.node.color
|
578
|
+
|
579
|
+
forward.out.amount.milisatoshis
|
580
|
+
|
581
|
+
forward.out.channel.id
|
582
|
+
forward.out.channel.partner.node.alias
|
583
|
+
forward.out.channel.partner.node.public_key
|
584
|
+
forward.out.channel.partner.node.color
|
585
|
+
```
|
586
|
+
|
587
|
+
### Grouping
|
588
|
+
|
589
|
+
```ruby
|
590
|
+
Lighstorm::Forward.group_by_channel(direction: :in, hours_ago: 24, limit: 5)
|
591
|
+
|
592
|
+
group.to_h
|
593
|
+
|
594
|
+
# _key is helpful for reactive javascript frameworks.
|
595
|
+
# Please don't consider it as a unique identifier
|
596
|
+
# for the item. Instead, use it as a volatile key for
|
597
|
+
# the item's current state that may change at any moment.
|
598
|
+
group._key
|
599
|
+
|
600
|
+
group.last_at
|
601
|
+
group.analysis.count
|
602
|
+
group.analysis.sums.amount.milisatoshis
|
603
|
+
group.analysis.sums.fee.milisatoshis
|
604
|
+
group.analysis.averages.amount.milisatoshis
|
605
|
+
group.analysis.averages.fee.milisatoshis
|
606
|
+
group.analysis.averages.fee.parts_per_million(
|
607
|
+
group.analysis.averages.amount.milisatoshis
|
608
|
+
)
|
609
|
+
|
610
|
+
group.channel.id
|
611
|
+
group.channel.partner.node.alias
|
612
|
+
group.channel.partner.node.public_key
|
613
|
+
group.channel.partner.node.color
|
614
|
+
|
615
|
+
Lighstorm::Forward.group_by_channel(direction: :out)
|
616
|
+
|
617
|
+
group.to_h
|
618
|
+
|
619
|
+
group.last_at
|
620
|
+
group.analysis.count
|
621
|
+
|
622
|
+
group.channel.id
|
623
|
+
group.channel.partner.node.alias
|
624
|
+
group.channel.partner.node.public_key
|
625
|
+
group.channel.partner.node.color
|
626
|
+
```
|
627
|
+
|
628
|
+
## Satoshis
|
629
|
+
|
630
|
+
```ruby
|
631
|
+
Lighstorm::Satoshis
|
632
|
+
Lighstorm::Satoshis.new(milisatoshis: 75_621_650)
|
633
|
+
|
634
|
+
satoshis.to_h
|
635
|
+
|
636
|
+
satoshis.milisatoshis
|
637
|
+
satoshis.satoshis
|
638
|
+
satoshis.bitcoins
|
639
|
+
|
640
|
+
satoshis.msats
|
641
|
+
satoshis.sats
|
642
|
+
satoshis.btc
|
643
|
+
|
644
|
+
reference_in_milisatoshis = 75_621_650_000
|
645
|
+
satoshis.parts_per_million(reference_in_milisatoshis)
|
646
|
+
```
|
647
|
+
_________________
|
648
|
+
|
649
|
+
<center>
|
650
|
+
lighstorm 0.0.4
|
651
|
+
|
|
652
|
+
<a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
|
653
|
+
|
|
654
|
+
<a href="https://rubygems.org/gems/lighstorm" rel="noopener noreferrer" target="_blank">RubyGems</a>
|
655
|
+
</center>
|
data/docs/_coverpage.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Lighstorm
|
2
|
+
|
3
|
+
> API for interacting with a [Lightning Node](https://lightning.network).
|
4
|
+
|
5
|
+
- Make your Satoshis flow.
|
6
|
+
- Unleash the power of Graphs.
|
7
|
+
|
8
|
+
0.0.4
|
9
|
+
|
10
|
+
[Documentation](README)
|
11
|
+
[GitHub](https://github.com/icebaker/lighstorm)
|
12
|
+
[RubyGems](https://rubygems.org/gems/lighstorm)
|
data/docs/index.html
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Lighstorm: API for interacting with a Lightning Node</title>
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
7
|
+
<meta name="description" content="Description">
|
8
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="vendor/docsify-themeable/theme-simple-dark.css">
|
11
|
+
<link rel="stylesheet" href="vendor/prismjs/prism-tomorrow.min.css">
|
12
|
+
<script src="vendor/docsify/docsify@4.js" defer></script>
|
13
|
+
<script src="vendor/prismjs/prism-ruby.min.js" defer></script>
|
14
|
+
<script src="vendor/prismjs/prism-bash.min.js" defer></script>
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<div id="app"></div>
|
18
|
+
<script>
|
19
|
+
window.$docsify = {
|
20
|
+
coverpage: true,
|
21
|
+
name: 'Lighstorm 0.0.4',
|
22
|
+
repo: 'https://github.com/icebaker/lighstorm'
|
23
|
+
}
|
24
|
+
</script>
|
25
|
+
</body>
|
26
|
+
</html>
|