lighstorm 0.0.14 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +7 -7
- data/adapters/bitcoin/address.rb +19 -0
- data/adapters/bitcoin/transaction.rb +34 -0
- data/adapters/lightning/connections/channel_node/fee.rb +28 -0
- data/adapters/lightning/connections/channel_node/policy.rb +63 -0
- data/adapters/lightning/connections/channel_node.rb +77 -0
- data/adapters/lightning/connections/payment_channel.rb +30 -0
- data/adapters/lightning/edges/channel.rb +98 -0
- data/adapters/lightning/edges/forward.rb +42 -0
- data/adapters/lightning/edges/payment/purpose.rb +45 -0
- data/adapters/lightning/edges/payment.rb +89 -0
- data/adapters/lightning/invoice.rb +186 -0
- data/adapters/lightning/nodes/node.rb +113 -0
- data/controllers/action.rb +1 -1
- data/controllers/bitcoin/address/actions/create.rb +91 -0
- data/controllers/bitcoin/address/actions/pay.rb +119 -0
- data/controllers/bitcoin/address.rb +24 -0
- data/controllers/bitcoin/transaction/all.rb +65 -0
- data/controllers/bitcoin/transaction.rb +25 -0
- data/controllers/concerns/impersonatable.rb +5 -3
- data/controllers/connection.rb +1 -1
- data/controllers/lightning/channel/actions/apply_gossip.rb +201 -0
- data/controllers/lightning/channel/actions/update_fee.rb +94 -0
- data/controllers/lightning/channel/all.rb +85 -0
- data/controllers/lightning/channel/find_by_id.rb +155 -0
- data/controllers/lightning/channel/mine.rb +116 -0
- data/controllers/lightning/channel.rb +43 -0
- data/controllers/lightning/forward/all.rb +250 -0
- data/controllers/lightning/forward/group_by_channel.rb +91 -0
- data/controllers/lightning/forward.rb +36 -0
- data/controllers/lightning/invoice/actions/create.rb +90 -0
- data/controllers/lightning/invoice/actions/pay.rb +97 -0
- data/controllers/lightning/invoice/actions/pay_through_route.rb +73 -0
- data/controllers/lightning/invoice/all.rb +82 -0
- data/controllers/lightning/invoice/decode.rb +50 -0
- data/controllers/lightning/invoice/find_by_code.rb +76 -0
- data/controllers/lightning/invoice/find_by_secret_hash.rb +56 -0
- data/controllers/lightning/invoice.rb +64 -0
- data/controllers/lightning/node/actions/apply_gossip.rb +114 -0
- data/controllers/lightning/node/actions/pay.rb +117 -0
- data/controllers/lightning/node/all.rb +69 -0
- data/controllers/lightning/node/find_by_public_key.rb +55 -0
- data/controllers/lightning/node/myself.rb +36 -0
- data/controllers/lightning/node.rb +35 -0
- data/controllers/lightning/payment/actions/pay.rb +110 -0
- data/controllers/lightning/payment/all.rb +439 -0
- data/controllers/lightning/payment.rb +37 -0
- data/controllers/lightning/secret/valid_proof.rb +60 -0
- data/controllers/lightning/secret.rb +16 -0
- data/controllers/wallet/activity/all.rb +196 -0
- data/controllers/wallet/activity.rb +28 -0
- data/controllers/wallet/balance.rb +3 -3
- data/controllers/wallet.rb +1 -1
- data/docs/README.md +229 -148
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/lighstorm.gemspec +1 -1
- data/models/bitcoin/address.rb +49 -0
- data/models/bitcoin/transaction.rb +41 -0
- data/models/concerns/protectable.rb +1 -1
- data/models/errors.rb +7 -8
- data/models/lightning/connections/channel_node/accounting.rb +27 -0
- data/models/lightning/connections/channel_node/fee.rb +82 -0
- data/models/lightning/connections/channel_node/htlc/blocks/delta.rb +41 -0
- data/models/lightning/connections/channel_node/htlc.rb +88 -0
- data/models/lightning/connections/channel_node/policy.rb +41 -0
- data/models/lightning/connections/channel_node.rb +86 -0
- data/models/lightning/connections/forward_channel.rb +31 -0
- data/models/lightning/connections/payment_channel.rb +58 -0
- data/models/lightning/edges/channel/accounting.rb +87 -0
- data/models/lightning/edges/channel/hop.rb +67 -0
- data/models/lightning/edges/channel.rb +197 -0
- data/models/lightning/edges/forward.rb +51 -0
- data/models/lightning/edges/groups/channel_forwards/analysis.rb +71 -0
- data/models/lightning/edges/groups/channel_forwards.rb +39 -0
- data/models/lightning/edges/payment.rb +104 -0
- data/models/lightning/invoice.rb +115 -0
- data/models/lightning/nodes/node/lightning.rb +33 -0
- data/models/lightning/nodes/node/platform.rb +50 -0
- data/models/lightning/nodes/node.rb +145 -0
- data/models/lightning/rate.rb +37 -0
- data/models/lightning/secret.rb +57 -0
- data/models/satoshis.rb +1 -1
- data/models/wallet/activity.rb +54 -0
- data/models/wallet/balance.rb +42 -0
- data/ports/dsl/lighstorm.rb +29 -16
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +76 -70
- data/adapters/connections/channel_node/fee.rb +0 -26
- data/adapters/connections/channel_node/policy.rb +0 -61
- data/adapters/connections/channel_node.rb +0 -75
- data/adapters/connections/payment_channel.rb +0 -28
- data/adapters/edges/channel.rb +0 -96
- data/adapters/edges/forward.rb +0 -40
- data/adapters/edges/payment/purpose.rb +0 -43
- data/adapters/edges/payment.rb +0 -87
- data/adapters/invoice.rb +0 -184
- data/adapters/nodes/node.rb +0 -111
- data/adapters/transaction.rb +0 -23
- data/controllers/activity/all.rb +0 -194
- data/controllers/activity.rb +0 -26
- data/controllers/channel/actions/apply_gossip.rb +0 -193
- data/controllers/channel/actions/update_fee.rb +0 -91
- data/controllers/channel/all.rb +0 -83
- data/controllers/channel/find_by_id.rb +0 -153
- data/controllers/channel/mine.rb +0 -114
- data/controllers/channel.rb +0 -41
- data/controllers/forward/all.rb +0 -248
- data/controllers/forward/group_by_channel.rb +0 -89
- data/controllers/forward.rb +0 -34
- data/controllers/invoice/actions/create.rb +0 -88
- data/controllers/invoice/actions/pay.rb +0 -95
- data/controllers/invoice/actions/pay_through_route.rb +0 -71
- data/controllers/invoice/all.rb +0 -80
- data/controllers/invoice/decode.rb +0 -44
- data/controllers/invoice/find_by_code.rb +0 -70
- data/controllers/invoice/find_by_secret_hash.rb +0 -54
- data/controllers/invoice.rb +0 -62
- data/controllers/node/actions/apply_gossip.rb +0 -112
- data/controllers/node/actions/pay.rb +0 -115
- data/controllers/node/all.rb +0 -67
- data/controllers/node/find_by_public_key.rb +0 -53
- data/controllers/node/myself.rb +0 -34
- data/controllers/node.rb +0 -33
- data/controllers/payment/actions/pay.rb +0 -108
- data/controllers/payment/all.rb +0 -437
- data/controllers/payment.rb +0 -35
- data/controllers/secret/valid_proof.rb +0 -58
- data/controllers/transaction/all.rb +0 -61
- data/controllers/transaction.rb +0 -25
- data/models/activity.rb +0 -52
- data/models/connections/channel_node/accounting.rb +0 -25
- data/models/connections/channel_node/fee.rb +0 -80
- data/models/connections/channel_node/htlc/blocks/delta.rb +0 -39
- data/models/connections/channel_node/htlc.rb +0 -86
- data/models/connections/channel_node/policy.rb +0 -39
- data/models/connections/channel_node.rb +0 -84
- data/models/connections/forward_channel.rb +0 -29
- data/models/connections/payment_channel.rb +0 -56
- data/models/edges/channel/accounting.rb +0 -85
- data/models/edges/channel/hop.rb +0 -65
- data/models/edges/channel.rb +0 -195
- data/models/edges/forward.rb +0 -49
- data/models/edges/groups/channel_forwards/analysis.rb +0 -69
- data/models/edges/groups/channel_forwards.rb +0 -37
- data/models/edges/payment.rb +0 -102
- data/models/invoice.rb +0 -113
- data/models/nodes/node/lightning.rb +0 -31
- data/models/nodes/node/platform.rb +0 -48
- data/models/nodes/node.rb +0 -143
- data/models/rate.rb +0 -35
- data/models/secret.rb +0 -55
- data/models/transaction.rb +0 -39
- data/models/wallet.rb +0 -40
data/docs/README.md
CHANGED
@@ -19,7 +19,7 @@ Although it tries to stay close to [Lightning's terminologies](https://docs.ligh
|
|
19
19
|
![Lighstorm text written stylized with an illustration of a Graph connecting two Nodes.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/lighstorm.png)
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
Lighstorm::Channel.mine.first.myself.node.alias
|
22
|
+
Lighstorm::Lightning::Channel.mine.first.myself.node.alias
|
23
23
|
```
|
24
24
|
|
25
25
|
## Installing
|
@@ -27,7 +27,7 @@ Lighstorm::Channel.mine.first.myself.node.alias
|
|
27
27
|
Add to your `Gemfile`:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
gem 'lighstorm', '~> 0.0.
|
30
|
+
gem 'lighstorm', '~> 0.0.16'
|
31
31
|
```
|
32
32
|
|
33
33
|
Run `bundle install`.
|
@@ -36,36 +36,36 @@ Run `bundle install`.
|
|
36
36
|
```ruby
|
37
37
|
require 'lighstorm'
|
38
38
|
|
39
|
-
puts Lighstorm.version # => 0.0.
|
39
|
+
puts Lighstorm.version # => 0.0.16
|
40
40
|
|
41
|
-
Lighstorm::Invoice.create(
|
41
|
+
Lighstorm::Lightning::Invoice.create(
|
42
42
|
description: 'Coffee', amount: { millisatoshis: 1000 }, payable: 'once'
|
43
43
|
)
|
44
44
|
|
45
|
-
Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay
|
45
|
+
Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay
|
46
46
|
|
47
|
-
Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay(
|
47
|
+
Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay(
|
48
48
|
fee: { maximum: { millisatoshis: 1000 } }
|
49
49
|
)
|
50
50
|
|
51
|
-
Lighstorm::Node.find_by_public_key(
|
51
|
+
Lighstorm::Lightning::Node.find_by_public_key(
|
52
52
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
53
53
|
).pay(amount: { millisatoshis: 1000 })
|
54
54
|
|
55
|
-
Lighstorm::Node.find_by_public_key(
|
55
|
+
Lighstorm::Lightning::Node.find_by_public_key(
|
56
56
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
57
57
|
).send_message('Hello from Lighstorm!', amount: { millisatoshis: 1000 })
|
58
58
|
|
59
|
-
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
60
|
-
Lighstorm::Node.myself.public_key # => 02d3...e997
|
59
|
+
Lighstorm::Lightning::Node.myself.alias # => icebaker/old-stone
|
60
|
+
Lighstorm::Lightning::Node.myself.public_key # => 02d3...e997
|
61
61
|
|
62
|
-
Lighstorm::Node.myself.to_h #> { ... }
|
62
|
+
Lighstorm::Lightning::Node.myself.to_h #> { ... }
|
63
63
|
|
64
|
-
Lighstorm::Node.myself.channels.count # => 5
|
64
|
+
Lighstorm::Lightning::Node.myself.channels.count # => 5
|
65
65
|
|
66
|
-
Lighstorm::Channel.mine.first.partner.node.alias
|
66
|
+
Lighstorm::Lightning::Channel.mine.first.partner.node.alias
|
67
67
|
|
68
|
-
forward = Lighstorm::Forward.all(limit: 10).first
|
68
|
+
forward = Lighstorm::Lightning::Forward.all(limit: 10).first
|
69
69
|
|
70
70
|
forward.in.amount.millisatoshis # => 75621650
|
71
71
|
forward.in.amount.satoshis # => 75621
|
@@ -75,7 +75,7 @@ forward.out.channel.partner.node.alias
|
|
75
75
|
|
76
76
|
forward.to_h # => { ... }
|
77
77
|
|
78
|
-
payment = Lighstorm::Payment.all.first
|
78
|
+
payment = Lighstorm::Lightning::Payment.all.first
|
79
79
|
|
80
80
|
payment.from.channel.id # => 850099509773795329
|
81
81
|
payment.to.channel.id # => 821539695188246532
|
@@ -222,9 +222,9 @@ Lighstorm::Connection.default[:address] # => '127.0.0.1:10009'
|
|
222
222
|
Lighstorm::Connection.for('alice')[:address] # => '127.0.0.2:10009'
|
223
223
|
Lighstorm::Connection.for('bob')[:address] # => '127.0.0.3:10009'
|
224
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
|
225
|
+
Lighstorm::Lightning::Node.myself.alias # => 'icebaker/old-stone'
|
226
|
+
Lighstorm::Lightning::Node.as('alice').myself.alias # => alice
|
227
|
+
Lighstorm::Lightning::Node.as('bob').myself.alias # => bob
|
228
228
|
|
229
229
|
Lighstorm::Connection.all # => ['alice', 'bob']
|
230
230
|
|
@@ -284,7 +284,7 @@ So, we are going to think in terms of _Edges_, _Nodes_, and _Connections_:
|
|
284
284
|
### Channel
|
285
285
|
|
286
286
|
```ruby
|
287
|
-
channel = Lighstorm::Channel.mine.first
|
287
|
+
channel = Lighstorm::Lightning::Channel.mine.first
|
288
288
|
|
289
289
|
channel.id
|
290
290
|
|
@@ -311,7 +311,7 @@ channel.myself.initiator?
|
|
311
311
|
### Forward
|
312
312
|
|
313
313
|
```ruby
|
314
|
-
forward = Lighstorm::Forward.last
|
314
|
+
forward = Lighstorm::Lightning::Forward.last
|
315
315
|
|
316
316
|
forward.at
|
317
317
|
|
@@ -340,7 +340,7 @@ forward.out.channel.partner.node.alias
|
|
340
340
|
### Payment
|
341
341
|
|
342
342
|
```ruby
|
343
|
-
payment = Lighstorm::Payment.last
|
343
|
+
payment = Lighstorm::Lightning::Payment.last
|
344
344
|
|
345
345
|
payment.at
|
346
346
|
payment.state
|
@@ -379,14 +379,116 @@ payment.hops[0].channel.target.alias
|
|
379
379
|
|
380
380
|
# API
|
381
381
|
|
382
|
-
##
|
382
|
+
## Satoshis
|
383
|
+
|
383
384
|
```ruby
|
384
|
-
Lighstorm::
|
385
|
+
Lighstorm::Satoshis
|
386
|
+
Lighstorm::Satoshis.new(bitcoins: 0.005)
|
387
|
+
Lighstorm::Satoshis.new(millisatoshis: 75621650)
|
388
|
+
|
389
|
+
satoshis.to_h
|
390
|
+
|
391
|
+
satoshis.millisatoshis
|
392
|
+
satoshis.satoshis
|
393
|
+
satoshis.bitcoins
|
394
|
+
|
395
|
+
satoshis.msats
|
396
|
+
satoshis.sats
|
397
|
+
satoshis.btc
|
385
398
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
399
|
+
reference_in_millisatoshis = 75621650000
|
400
|
+
satoshis.parts_per_million(reference_in_millisatoshis)
|
401
|
+
```
|
402
|
+
|
403
|
+
## Wallet
|
404
|
+
|
405
|
+
### Balance
|
406
|
+
|
407
|
+
```ruby
|
408
|
+
balance = Lighstorm::Wallet.balance
|
409
|
+
|
410
|
+
balance.at
|
411
|
+
|
412
|
+
balance.lightning.millisatoshis
|
413
|
+
balance.bitcoin.millisatoshis
|
414
|
+
|
415
|
+
balance.total.millisatoshis
|
416
|
+
|
417
|
+
balance.to_h
|
418
|
+
```
|
419
|
+
|
420
|
+
## Bitcoin
|
421
|
+
|
422
|
+
### Address
|
423
|
+
|
424
|
+
#### Create
|
425
|
+
|
426
|
+
The Lightning Network promotes the idea of creating a new Bitcoin address every time you need one, which helps maintain transaction privacy and fund security. This makes it harder for others to trace your activity, providing a more secure and private experience.
|
427
|
+
|
428
|
+
```ruby
|
429
|
+
Lighstorm::Bitcoin::Address.create(preview: true)
|
430
|
+
|
431
|
+
action = Lighstorm::Bitcoin::Address.create
|
432
|
+
|
433
|
+
action.request
|
434
|
+
action.response
|
435
|
+
|
436
|
+
address = action.result
|
437
|
+
|
438
|
+
address._key
|
439
|
+
address.created_at
|
440
|
+
address.code # 'bcrt1qpma0wpaf2wzlflvamgz2zvw3x0k4vfzwq45x9s'
|
441
|
+
```
|
442
|
+
|
443
|
+
```ruby
|
444
|
+
address = Lighstorm::Bitcoin::Address.create.result.code
|
445
|
+
```
|
446
|
+
|
447
|
+
#### Pay
|
448
|
+
|
449
|
+
```ruby
|
450
|
+
Lighstorm::Bitcoin::Address.new(
|
451
|
+
code: 'bcrt1qq5gl3thf4ka93eluz0guweek9vmeyqyrck3py2'
|
452
|
+
).pay(
|
453
|
+
amount: { millisatoshis: 250_000_000 },
|
454
|
+
fee: { satoshis_per_vitual_byte: 4 },
|
455
|
+
preview: true
|
456
|
+
)
|
457
|
+
|
458
|
+
action = Lighstorm::Bitcoin::Address.new(
|
459
|
+
code: 'bcrt1qq5gl3thf4ka93eluz0guweek9vmeyqyrck3py2'
|
460
|
+
).pay(
|
461
|
+
amount: { millisatoshis: 500_000_000 },
|
462
|
+
fee: { satoshis_per_vitual_byte: 1 },
|
463
|
+
description: 'Wallet Withdrawal',
|
464
|
+
required_confirmations: 6
|
465
|
+
)
|
466
|
+
|
467
|
+
action.request
|
468
|
+
action.response
|
469
|
+
|
470
|
+
transaction = action.result
|
471
|
+
|
472
|
+
transaction._key
|
473
|
+
transaction.at
|
474
|
+
transaction.amount.millisatoshis
|
475
|
+
transaction.fee.millisatoshis
|
476
|
+
transaction.description
|
477
|
+
|
478
|
+
transaction.hash
|
479
|
+
transaction.to.address.code
|
480
|
+
```
|
481
|
+
|
482
|
+
## Lightning
|
483
|
+
|
484
|
+
### Node
|
485
|
+
```ruby
|
486
|
+
Lighstorm::Lightning::Node
|
487
|
+
|
488
|
+
Lighstorm::Lightning::Node.myself # Your Node.
|
489
|
+
Lighstorm::Lightning::Node.all # All 18k+ Nodes on the Network.
|
490
|
+
Lighstorm::Lightning::Node.all(limit: 10)
|
491
|
+
Lighstorm::Lightning::Node.find_by_public_key(
|
390
492
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
391
493
|
)
|
392
494
|
|
@@ -411,12 +513,12 @@ node.platform.lightning.implementation
|
|
411
513
|
node.platform.lightning.version
|
412
514
|
```
|
413
515
|
|
414
|
-
|
516
|
+
#### Pay
|
415
517
|
|
416
518
|
Read more about [_Spontaneous Payments_](https://docs.lightning.engineering/lightning-network-tools/lnd/send-messages-with-keysend#send-a-spontaneous-payment).
|
417
519
|
|
418
520
|
```ruby
|
419
|
-
destination = Lighstorm::Node.find_by_public_key(
|
521
|
+
destination = Lighstorm::Lightning::Node.find_by_public_key(
|
420
522
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
421
523
|
)
|
422
524
|
|
@@ -441,15 +543,19 @@ destination.pay(
|
|
441
543
|
)
|
442
544
|
|
443
545
|
action = destination.pay(amount: { millisatoshis: 1000 })
|
546
|
+
|
547
|
+
action.request
|
548
|
+
action.response
|
549
|
+
|
444
550
|
action.result.fee.millisatoshis
|
445
551
|
```
|
446
552
|
|
447
|
-
|
553
|
+
#### Send Messages
|
448
554
|
|
449
555
|
**Warning:** Sending messages through Lightning Network requires you to spend satoshis and potentially pay fees.
|
450
556
|
|
451
557
|
```ruby
|
452
|
-
destination = Lighstorm::Node.find_by_public_key(
|
558
|
+
destination = Lighstorm::Lightning::Node.find_by_public_key(
|
453
559
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
454
560
|
)
|
455
561
|
|
@@ -480,6 +586,10 @@ action = destination.send_message(
|
|
480
586
|
'Hello from Lighstorm!',
|
481
587
|
amount: { millisatoshis: 1000 }
|
482
588
|
)
|
589
|
+
|
590
|
+
action.request
|
591
|
+
action.response
|
592
|
+
|
483
593
|
action.result.fee.millisatoshis
|
484
594
|
```
|
485
595
|
|
@@ -488,10 +598,10 @@ Read more about sending messages:
|
|
488
598
|
- [_Does Private messaging over Bitcoin’s Lightning Network have potential?_](https://cryptopurview.com/private-messaging-over-bitcoins-lightning-network/)
|
489
599
|
- [_How Bitcoin's Lightning Can Be Used for Private Messaging_](https://www.coindesk.com/markets/2019/11/09/how-bitcoins-lightning-can-be-used-for-private-messaging/)
|
490
600
|
|
491
|
-
|
601
|
+
#### Error Handling
|
492
602
|
Same error handling used for [Invoices Payment Errors](?id=error-handling-1)
|
493
603
|
|
494
|
-
|
604
|
+
### Channel
|
495
605
|
|
496
606
|
[![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)
|
497
607
|
<center style="margin-top: -1.4em;">
|
@@ -501,11 +611,11 @@ Same error handling used for [Invoices Payment Errors](?id=error-handling-1)
|
|
501
611
|
</center>
|
502
612
|
|
503
613
|
```ruby
|
504
|
-
Lighstorm::Channel
|
505
|
-
Lighstorm::Channel.mine # Your Node's Channels.
|
506
|
-
Lighstorm::Channel.all # All 80k+ Channels on the Network.
|
507
|
-
Lighstorm::Channel.all(limit: 10)
|
508
|
-
Lighstorm::Channel.find_by_id('850099509773795329')
|
614
|
+
Lighstorm::Lightning::Channel
|
615
|
+
Lighstorm::Lightning::Channel.mine # Your Node's Channels.
|
616
|
+
Lighstorm::Lightning::Channel.all # All 80k+ Channels on the Network.
|
617
|
+
Lighstorm::Lightning::Channel.all(limit: 10)
|
618
|
+
Lighstorm::Lightning::Channel.find_by_id('850099509773795329')
|
509
619
|
|
510
620
|
# _key is helpful for reactive javascript frameworks.
|
511
621
|
# Please don't consider it as a unique identifier
|
@@ -578,10 +688,10 @@ channel.myself.policy.htlc.maximum.millisatoshis
|
|
578
688
|
channel.myself.policy.htlc.blocks.delta.minimum
|
579
689
|
```
|
580
690
|
|
581
|
-
|
691
|
+
#### Fee Update
|
582
692
|
|
583
693
|
```ruby
|
584
|
-
channel = Lighstorm::Channel.mine.first
|
694
|
+
channel = Lighstorm::Lightning::Channel.mine.first
|
585
695
|
|
586
696
|
# 'preview' let you check the expected operation
|
587
697
|
# before actually performing it for debug purposes
|
@@ -602,24 +712,24 @@ channel.myself.policy.fee.update(
|
|
602
712
|
)
|
603
713
|
```
|
604
714
|
|
605
|
-
|
715
|
+
### Invoice
|
606
716
|
|
607
717
|
[Understanding Lightning Invoices](https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices)
|
608
718
|
|
609
719
|
```ruby
|
610
|
-
Lighstorm::Invoice
|
611
|
-
Lighstorm::Invoice.all
|
612
|
-
Lighstorm::Invoice.all(limit: 10)
|
613
|
-
Lighstorm::Invoice.first
|
614
|
-
Lighstorm::Invoice.last
|
720
|
+
Lighstorm::Lightning::Invoice
|
721
|
+
Lighstorm::Lightning::Invoice.all
|
722
|
+
Lighstorm::Lightning::Invoice.all(limit: 10)
|
723
|
+
Lighstorm::Lightning::Invoice.first
|
724
|
+
Lighstorm::Lightning::Invoice.last
|
615
725
|
|
616
|
-
Lighstorm::Invoice.decode('lnbc20n1pj...0eqps7h0k9')
|
726
|
+
Lighstorm::Lightning::Invoice.decode('lnbc20n1pj...0eqps7h0k9')
|
617
727
|
|
618
|
-
Lighstorm::Invoice.find_by_secret_hash(
|
728
|
+
Lighstorm::Lightning::Invoice.find_by_secret_hash(
|
619
729
|
'1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
|
620
730
|
)
|
621
731
|
|
622
|
-
invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
732
|
+
invoice = Lighstorm::Lightning::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
623
733
|
|
624
734
|
invoice.secret.valid_proof?(
|
625
735
|
'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
@@ -648,66 +758,68 @@ invoice.description.memo
|
|
648
758
|
invoice.description.hash
|
649
759
|
|
650
760
|
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
651
|
-
invoice.secret.
|
761
|
+
invoice.secret.proof
|
652
762
|
invoice.secret.hash
|
653
763
|
```
|
654
764
|
|
655
|
-
|
765
|
+
#### Create
|
656
766
|
|
657
767
|
[Understanding Lightning Invoices](https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices)
|
658
768
|
|
659
769
|
```ruby
|
660
770
|
# 'preview' let you check the expected operation
|
661
771
|
# before actually performing it for debug purposes
|
662
|
-
preview = Lighstorm::Invoice.create(
|
772
|
+
preview = Lighstorm::Lightning::Invoice.create(
|
663
773
|
description: 'Coffee', amount: { millisatoshis: 1000 },
|
664
774
|
payable: 'once', preview: true
|
665
775
|
)
|
666
776
|
|
667
|
-
action = Lighstorm::Invoice.create(
|
777
|
+
action = Lighstorm::Lightning::Invoice.create(
|
668
778
|
description: 'Coffee', amount: { millisatoshis: 1000 },
|
669
779
|
payable: 'once', expires_in: { minutes: 5 }
|
670
780
|
)
|
671
781
|
|
672
|
-
action = Lighstorm::Invoice.create(
|
782
|
+
action = Lighstorm::Lightning::Invoice.create(
|
673
783
|
description: 'Beer', payable: 'once'
|
674
784
|
)
|
675
785
|
|
676
|
-
action = Lighstorm::Invoice.create(
|
786
|
+
action = Lighstorm::Lightning::Invoice.create(
|
677
787
|
description: 'Donations', payable: 'indefinitely',
|
678
788
|
expires_in: { hours: 24 }
|
679
789
|
)
|
680
790
|
|
681
|
-
action = Lighstorm::Invoice.create(
|
791
|
+
action = Lighstorm::Lightning::Invoice.create(
|
682
792
|
description: 'Concert Ticket', amount: { millisatoshis: 500000000 },
|
683
793
|
payable: 'indefinitely', expires_in: { days: 5 }
|
684
794
|
)
|
685
795
|
|
686
796
|
action.to_h
|
687
797
|
|
798
|
+
action.request
|
688
799
|
action.response
|
800
|
+
|
689
801
|
invoice = action.result
|
690
802
|
```
|
691
803
|
|
692
|
-
|
804
|
+
#### Proof of Payment
|
693
805
|
|
694
806
|
[Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
|
695
807
|
|
696
808
|
|
697
809
|
```ruby
|
698
|
-
invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
810
|
+
invoice = Lighstorm::Lightning::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
699
811
|
|
700
812
|
invoice.secret.valid_proof?(
|
701
813
|
'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
702
814
|
) # => true
|
703
815
|
```
|
704
816
|
|
705
|
-
|
817
|
+
#### Pay
|
706
818
|
|
707
819
|
[Understanding Lightning Invoices](https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices)
|
708
820
|
|
709
821
|
```ruby
|
710
|
-
invoice = Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj')
|
822
|
+
invoice = Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj')
|
711
823
|
|
712
824
|
# 'preview' let you check the expected operation
|
713
825
|
# before actually performing it for debug purposes
|
@@ -717,7 +829,9 @@ action = invoice.pay
|
|
717
829
|
|
718
830
|
action.to_h
|
719
831
|
|
832
|
+
action.request
|
720
833
|
action.response
|
834
|
+
|
721
835
|
payment = action.result
|
722
836
|
|
723
837
|
payment.at
|
@@ -744,7 +858,7 @@ invoice.pay(
|
|
744
858
|
)
|
745
859
|
```
|
746
860
|
|
747
|
-
|
861
|
+
##### Error Handling
|
748
862
|
Check [Error Handling](?id=error-handling-2)
|
749
863
|
|
750
864
|
```ruby
|
@@ -801,7 +915,7 @@ rescue PaymentError => error
|
|
801
915
|
end
|
802
916
|
```
|
803
917
|
|
804
|
-
|
918
|
+
### Payment
|
805
919
|
|
806
920
|
[![This is an image representing Payment as a graph.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/graph-payment.png)
|
807
921
|
<center style="margin-top: -1.4em;">
|
@@ -811,19 +925,19 @@ end
|
|
811
925
|
</center>
|
812
926
|
|
813
927
|
```ruby
|
814
|
-
Lighstorm::Payment
|
815
|
-
Lighstorm::Payment.all
|
816
|
-
Lighstorm::Payment.first
|
817
|
-
Lighstorm::Payment.last
|
818
|
-
Lighstorm::Payment.all(limit: 10, purpose: 'rebalance')
|
928
|
+
Lighstorm::Lightning::Payment
|
929
|
+
Lighstorm::Lightning::Payment.all
|
930
|
+
Lighstorm::Lightning::Payment.first
|
931
|
+
Lighstorm::Lightning::Payment.last
|
932
|
+
Lighstorm::Lightning::Payment.all(limit: 10, purpose: 'rebalance')
|
819
933
|
|
820
934
|
# Possible Purposes:
|
821
935
|
# 'self-payment', 'peer-to-peer',
|
822
936
|
# 'rebalance', 'payment'
|
823
937
|
|
824
|
-
Lighstorm::Payment.find_by_invoice_code('lnbc20n1pj...0eqps7h0k9')
|
938
|
+
Lighstorm::Lightning::Payment.find_by_invoice_code('lnbc20n1pj...0eqps7h0k9')
|
825
939
|
|
826
|
-
Lighstorm::Payment.find_by_secret_hash(
|
940
|
+
Lighstorm::Lightning::Payment.find_by_secret_hash(
|
827
941
|
'1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
|
828
942
|
)
|
829
943
|
|
@@ -854,7 +968,6 @@ payment.purpose
|
|
854
968
|
# 'rebalance', 'payment'
|
855
969
|
|
856
970
|
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
857
|
-
payment.secret.preimage
|
858
971
|
payment.secret.hash
|
859
972
|
payment.secret.proof
|
860
973
|
|
@@ -874,8 +987,8 @@ payment.invoice.description.memo
|
|
874
987
|
payment.invoice.description.hash
|
875
988
|
|
876
989
|
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
877
|
-
payment.invoice.secret.preimage
|
878
990
|
payment.invoice.secret.hash
|
991
|
+
payment.invoice.secret.proof
|
879
992
|
|
880
993
|
payment.from.hop
|
881
994
|
payment.from.amount.millisatoshis
|
@@ -934,21 +1047,21 @@ payment.hops[0].channel.entry.alias
|
|
934
1047
|
payment.hops[0].channel.entry.color
|
935
1048
|
```
|
936
1049
|
|
937
|
-
|
1050
|
+
#### Proof of Payment
|
938
1051
|
|
939
1052
|
[Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
|
940
1053
|
|
941
1054
|
```ruby
|
942
|
-
payment = Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay.result
|
1055
|
+
payment = Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay.result
|
943
1056
|
|
944
1057
|
payment.secret.proof
|
945
1058
|
# => 'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
946
1059
|
```
|
947
1060
|
|
948
|
-
|
1061
|
+
#### Performance
|
949
1062
|
Avoid fetching data that you don't need:
|
950
1063
|
```ruby
|
951
|
-
Lighstorm::Payment.all(
|
1064
|
+
Lighstorm::Lightning::Payment.all(
|
952
1065
|
fetch: {
|
953
1066
|
get_node_info: false,
|
954
1067
|
lookup_invoice: false,
|
@@ -957,22 +1070,7 @@ Lighstorm::Payment.all(
|
|
957
1070
|
)
|
958
1071
|
```
|
959
1072
|
|
960
|
-
|
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
|
-
|
975
|
-
## Forward
|
1073
|
+
### Forward
|
976
1074
|
|
977
1075
|
[![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)
|
978
1076
|
<center style="margin-top: -1.4em;">
|
@@ -982,11 +1080,11 @@ balance.to_h
|
|
982
1080
|
</center>
|
983
1081
|
|
984
1082
|
```ruby
|
985
|
-
Lighstorm::Forward
|
986
|
-
Lighstorm::Forward.all
|
987
|
-
Lighstorm::Forward.first
|
988
|
-
Lighstorm::Forward.last
|
989
|
-
Lighstorm::Forward.all(limit: 10)
|
1083
|
+
Lighstorm::Lightning::Forward
|
1084
|
+
Lighstorm::Lightning::Forward.all
|
1085
|
+
Lighstorm::Lightning::Forward.first
|
1086
|
+
Lighstorm::Lightning::Forward.last
|
1087
|
+
Lighstorm::Lightning::Forward.all(limit: 10)
|
990
1088
|
|
991
1089
|
forward.to_h
|
992
1090
|
|
@@ -1018,10 +1116,12 @@ forward.out.channel.partner.node.public_key
|
|
1018
1116
|
forward.out.channel.partner.node.color
|
1019
1117
|
```
|
1020
1118
|
|
1021
|
-
|
1119
|
+
#### Grouping
|
1022
1120
|
|
1023
1121
|
```ruby
|
1024
|
-
Lighstorm::Forward.group_by_channel(
|
1122
|
+
Lighstorm::Lightning::Forward.group_by_channel(
|
1123
|
+
direction: :in, hours_ago: 24, limit: 5
|
1124
|
+
)
|
1025
1125
|
|
1026
1126
|
group.to_h
|
1027
1127
|
|
@@ -1046,7 +1146,7 @@ group.channel.partner.node.alias
|
|
1046
1146
|
group.channel.partner.node.public_key
|
1047
1147
|
group.channel.partner.node.color
|
1048
1148
|
|
1049
|
-
Lighstorm::Forward.group_by_channel(direction: :out)
|
1149
|
+
Lighstorm::Lightning::Forward.group_by_channel(direction: :out)
|
1050
1150
|
|
1051
1151
|
group.to_h
|
1052
1152
|
|
@@ -1059,11 +1159,11 @@ group.channel.partner.node.public_key
|
|
1059
1159
|
group.channel.partner.node.color
|
1060
1160
|
```
|
1061
1161
|
|
1062
|
-
|
1162
|
+
### Gossip
|
1063
1163
|
|
1064
1164
|
[The Gossip Network](https://docs.lightning.engineering/the-lightning-network/the-gossip-network)
|
1065
1165
|
|
1066
|
-
|
1166
|
+
#### Node
|
1067
1167
|
|
1068
1168
|
```ruby
|
1069
1169
|
gossip = {
|
@@ -1072,18 +1172,18 @@ gossip = {
|
|
1072
1172
|
'color' => '#eb34a4'
|
1073
1173
|
}
|
1074
1174
|
|
1075
|
-
Lighstorm::Node.adapt(gossip: gossip)
|
1175
|
+
Lighstorm::Lightning::Node.adapt(gossip: gossip)
|
1076
1176
|
|
1077
|
-
node = Lighstorm::Node.find_by_public_key(
|
1177
|
+
node = Lighstorm::Lightning::Node.find_by_public_key(
|
1078
1178
|
'02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
1079
1179
|
)
|
1080
1180
|
|
1081
1181
|
diff = node.apply!(gossip: gossip)
|
1082
1182
|
|
1083
|
-
Lighstorm::Node.adapt(dump: node.dump)
|
1183
|
+
Lighstorm::Lightning::Node.adapt(dump: node.dump)
|
1084
1184
|
```
|
1085
1185
|
|
1086
|
-
|
1186
|
+
#### Channel
|
1087
1187
|
|
1088
1188
|
```ruby
|
1089
1189
|
gossip = {
|
@@ -1099,34 +1199,13 @@ gossip = {
|
|
1099
1199
|
'advertisingNode' => '02d3c80335a8ccb2ed364c06875f32240f36f7edb37d80f8dbe321b4c364b6e997'
|
1100
1200
|
}
|
1101
1201
|
|
1102
|
-
Lighstorm::Channel.adapt(gossip: gossip)
|
1202
|
+
Lighstorm::Lightning::Channel.adapt(gossip: gossip)
|
1103
1203
|
|
1104
|
-
channel = Lighstorm::Channel.find_by_id('850099509773795329')
|
1204
|
+
channel = Lighstorm::Lightning::Channel.find_by_id('850099509773795329')
|
1105
1205
|
|
1106
1206
|
diff = channel.apply!(gossip: gossip)
|
1107
1207
|
|
1108
|
-
Lighstorm::Channel.adapt(dump: channel.dump)
|
1109
|
-
```
|
1110
|
-
|
1111
|
-
## Satoshis
|
1112
|
-
|
1113
|
-
```ruby
|
1114
|
-
Lighstorm::Satoshis
|
1115
|
-
Lighstorm::Satoshis.new(bitcoins: 0.005)
|
1116
|
-
Lighstorm::Satoshis.new(millisatoshis: 75621650)
|
1117
|
-
|
1118
|
-
satoshis.to_h
|
1119
|
-
|
1120
|
-
satoshis.millisatoshis
|
1121
|
-
satoshis.satoshis
|
1122
|
-
satoshis.bitcoins
|
1123
|
-
|
1124
|
-
satoshis.msats
|
1125
|
-
satoshis.sats
|
1126
|
-
satoshis.btc
|
1127
|
-
|
1128
|
-
reference_in_millisatoshis = 75621650000
|
1129
|
-
satoshis.parts_per_million(reference_in_millisatoshis)
|
1208
|
+
Lighstorm::Lightning::Channel.adapt(dump: channel.dump)
|
1130
1209
|
```
|
1131
1210
|
|
1132
1211
|
# Error Handling
|
@@ -1135,7 +1214,7 @@ satoshis.parts_per_million(reference_in_millisatoshis)
|
|
1135
1214
|
```ruby
|
1136
1215
|
require 'lighstorm'
|
1137
1216
|
|
1138
|
-
channel = Lighstorm::Channel.mine.first
|
1217
|
+
channel = Lighstorm::Lightning::Channel.mine.first
|
1139
1218
|
|
1140
1219
|
begin
|
1141
1220
|
channel.myself.policy.fee.update(
|
@@ -1160,7 +1239,7 @@ end
|
|
1160
1239
|
require 'lighstorm'
|
1161
1240
|
require 'lighstorm/errors'
|
1162
1241
|
|
1163
|
-
channel = Lighstorm::Channel.mine.first
|
1242
|
+
channel = Lighstorm::Lightning::Channel.mine.first
|
1164
1243
|
|
1165
1244
|
begin
|
1166
1245
|
channel.myself.policy.fee.update(
|
@@ -1200,10 +1279,12 @@ UnknownChannelError
|
|
1200
1279
|
|
1201
1280
|
RequestError
|
1202
1281
|
|
1282
|
+
AmountBelowDustLimitError
|
1203
1283
|
NoInvoiceFoundError
|
1204
|
-
PaymentError
|
1205
1284
|
UpdateChannelPolicyError
|
1206
1285
|
|
1286
|
+
PaymentError
|
1287
|
+
|
1207
1288
|
AlreadyPaidError
|
1208
1289
|
AmountForNonZeroError
|
1209
1290
|
MissingMillisatoshisError
|
@@ -1221,7 +1302,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
|
|
1221
1302
|
# demo.rb
|
1222
1303
|
require 'lighstorm'
|
1223
1304
|
|
1224
|
-
puts Lighstorm.version # => 0.0.
|
1305
|
+
puts Lighstorm.version # => 0.0.16
|
1225
1306
|
```
|
1226
1307
|
|
1227
1308
|
```sh
|
@@ -1252,17 +1333,17 @@ Let's get practical.
|
|
1252
1333
|
|
1253
1334
|
To _request_ all Nodes you:
|
1254
1335
|
```ruby
|
1255
|
-
Lighstorm::Node.all
|
1336
|
+
Lighstorm::Lightning::Node.all
|
1256
1337
|
```
|
1257
1338
|
|
1258
1339
|
Internally, what's happening:
|
1259
1340
|
```ruby
|
1260
|
-
nodes = Lighstorm::Node.all
|
1341
|
+
nodes = Lighstorm::Lightning::Node.all
|
1261
1342
|
|
1262
|
-
data =
|
1263
|
-
adapted =
|
1264
|
-
transformed =
|
1265
|
-
models =
|
1343
|
+
data = Controller::Lightning::Node::All.fetch # side effect
|
1344
|
+
adapted = Controller::Lightning::Node::All.adapt(data) # pure
|
1345
|
+
transformed = Controller::Lightning::Node::All.transform(adapted) # pure
|
1346
|
+
models = Controller::Lightning::Node::All.model(transformed) # pure
|
1266
1347
|
nodes = models # pure
|
1267
1348
|
|
1268
1349
|
nodes.first.public_key
|
@@ -1280,22 +1361,22 @@ The downside is that we can't [lazy-load](https://en.wikipedia.org/wiki/Lazy_loa
|
|
1280
1361
|
|
1281
1362
|
To perform an _action_, like creating an Invoice, you:
|
1282
1363
|
```ruby
|
1283
|
-
Lighstorm::Invoice.create(
|
1364
|
+
Lighstorm::Lightning::Invoice.create(
|
1284
1365
|
description: 'Coffee', amount: { millisatoshis: 1000 }
|
1285
1366
|
)
|
1286
1367
|
```
|
1287
1368
|
|
1288
1369
|
Internally, what's happening:
|
1289
1370
|
```ruby
|
1290
|
-
action = Lighstorm::Invoice.create(
|
1371
|
+
action = Lighstorm::Lightning::Invoice.create(
|
1291
1372
|
description: 'Coffee', amount: { millisatoshis: 1000 }
|
1292
1373
|
)
|
1293
1374
|
|
1294
|
-
request =
|
1295
|
-
response =
|
1296
|
-
adapted =
|
1297
|
-
data =
|
1298
|
-
model =
|
1375
|
+
request = Controller::Lightning::Invoice::Create.prepare(params) # pure
|
1376
|
+
response = Controller::Lightning::Invoice::Create.dispatch(request) # side effect
|
1377
|
+
adapted = Controller::Lightning::Invoice::Create.adapt(response) # pure
|
1378
|
+
data = Controller::Lightning::Invoice::Create.fetch(adapted) # side effect
|
1379
|
+
model = Controller::Lightning::Invoice::Create.model(data) # pure
|
1299
1380
|
action = { response: response, result: model } # pure
|
1300
1381
|
|
1301
1382
|
invoice = action.result
|
@@ -1458,13 +1539,13 @@ gem build lighstorm.gemspec
|
|
1458
1539
|
|
1459
1540
|
gem signin
|
1460
1541
|
|
1461
|
-
gem push lighstorm-0.0.
|
1542
|
+
gem push lighstorm-0.0.16.gem
|
1462
1543
|
```
|
1463
1544
|
|
1464
1545
|
_________________
|
1465
1546
|
|
1466
1547
|
<center>
|
1467
|
-
lighstorm 0.0.
|
1548
|
+
lighstorm 0.0.16
|
1468
1549
|
|
|
1469
1550
|
<a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
|
1470
1551
|
|
|