lighstorm 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/controllers/invoice/find_by_code.rb +70 -0
- data/controllers/invoice/find_by_secret_hash.rb +5 -3
- data/controllers/invoice.rb +7 -2
- data/controllers/payment/all.rb +19 -4
- data/controllers/payment.rb +8 -0
- data/docs/README.md +46 -5
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/models/errors.rb +16 -1
- data/models/secret.rb +8 -0
- data/static/spec.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6072337300f3fd850fbca3ba5c7c804842c275d5f35fa288dfb83747fa0b1a56
|
4
|
+
data.tar.gz: 8a16d83cb96f0ed911ebd55e12707b20f0aac00a0acac8d176e544a68abad647
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ccb6cef3322fcd1c0efb1439ddaf756e631113fbc7544218d10d6f71d08ca2ad80cf08b029ae4145e6916dcefc9ee3683124567bb952b02bf70793cc794616b
|
7
|
+
data.tar.gz: 2755ec9d8c2bf041459be7292983103c880f032e5e1e315ce2da2cc97ff945bbfb9f4083259a0c88ec22df8cd0301282c8ea376d63371a438ad58677b7f3d9e6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lighstorm (0.0.
|
4
|
+
lighstorm (0.0.11)
|
5
5
|
dotenv (~> 2.8, >= 2.8.1)
|
6
6
|
lnd-client (~> 0.0.5)
|
7
7
|
zache (~> 0.12.0)
|
@@ -47,7 +47,7 @@ GEM
|
|
47
47
|
rspec-expectations (3.12.2)
|
48
48
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
49
|
rspec-support (~> 3.12.0)
|
50
|
-
rspec-mocks (3.12.
|
50
|
+
rspec-mocks (3.12.4)
|
51
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
52
|
rspec-support (~> 3.12.0)
|
53
53
|
rspec-support (3.12.0)
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ Although it tries to stay close to [Lightning's terminologies](https://docs.ligh
|
|
34
34
|
Add to your `Gemfile`:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
gem 'lighstorm', '~> 0.0.
|
37
|
+
gem 'lighstorm', '~> 0.0.11'
|
38
38
|
```
|
39
39
|
|
40
40
|
```ruby
|
@@ -46,7 +46,7 @@ Lighstorm.config!(
|
|
46
46
|
macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
|
47
47
|
)
|
48
48
|
|
49
|
-
puts Lighstorm.version # => 0.0.
|
49
|
+
puts Lighstorm.version # => 0.0.11
|
50
50
|
|
51
51
|
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
52
52
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../ports/grpc'
|
4
|
+
require_relative '../../adapters/invoice'
|
5
|
+
require_relative '../../models/invoice'
|
6
|
+
|
7
|
+
module Lighstorm
|
8
|
+
module Controllers
|
9
|
+
module Invoice
|
10
|
+
module FindByCode
|
11
|
+
def self.fetch(code)
|
12
|
+
at = Time.now
|
13
|
+
|
14
|
+
decoded = Ports::GRPC.lightning.decode_pay_req(pay_req: code).to_h
|
15
|
+
|
16
|
+
{ response: {
|
17
|
+
at: at,
|
18
|
+
decode_pay_req: decoded,
|
19
|
+
lookup_invoice: Ports::GRPC.lightning.lookup_invoice(r_hash_str: decoded[:payment_hash]).to_h
|
20
|
+
}, exception: nil }
|
21
|
+
rescue StandardError => e
|
22
|
+
{ exception: e }
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.adapt(raw)
|
26
|
+
raise 'missing at' if raw[:at].nil?
|
27
|
+
|
28
|
+
{
|
29
|
+
lookup_invoice: Lighstorm::Adapter::Invoice.lookup_invoice(
|
30
|
+
raw[:lookup_invoice],
|
31
|
+
raw[:at]
|
32
|
+
)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.transform(adapted)
|
37
|
+
adapted[:lookup_invoice][:known] = true
|
38
|
+
adapted[:lookup_invoice]
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.data(code, &vcr)
|
42
|
+
raw = vcr.nil? ? fetch(code) : vcr.call(-> { fetch(code) })
|
43
|
+
|
44
|
+
raise_error_if_exists!(raw)
|
45
|
+
|
46
|
+
adapted = adapt(raw[:response])
|
47
|
+
|
48
|
+
transform(adapted)
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.model(data)
|
52
|
+
Lighstorm::Models::Invoice.new(data)
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.raise_error_if_exists!(response)
|
56
|
+
return if response[:exception].nil?
|
57
|
+
|
58
|
+
if response[:exception].is_a?(GRPC::NotFound)
|
59
|
+
raise NoInvoiceFoundError.new(
|
60
|
+
"Invoice not found. Try using Invoice.decode if you don't own the invoice.",
|
61
|
+
grpc: response[:exception]
|
62
|
+
)
|
63
|
+
end
|
64
|
+
|
65
|
+
raise LighstormError.new(grpc: response[:exception])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -9,10 +9,12 @@ module Lighstorm
|
|
9
9
|
module Invoice
|
10
10
|
module FindBySecretHash
|
11
11
|
def self.fetch(secret_hash)
|
12
|
-
{
|
12
|
+
{ response: {
|
13
13
|
at: Time.now,
|
14
14
|
lookup_invoice: Ports::GRPC.lightning.lookup_invoice(r_hash_str: secret_hash).to_h
|
15
|
-
}
|
15
|
+
}, exception: nil }
|
16
|
+
rescue StandardError => e
|
17
|
+
{ exception: e }
|
16
18
|
end
|
17
19
|
|
18
20
|
def self.adapt(raw)
|
@@ -34,7 +36,7 @@ module Lighstorm
|
|
34
36
|
def self.data(secret_hash, &vcr)
|
35
37
|
raw = vcr.nil? ? fetch(secret_hash) : vcr.call(-> { fetch(secret_hash) })
|
36
38
|
|
37
|
-
adapted = adapt(raw)
|
39
|
+
adapted = adapt(raw[:response])
|
38
40
|
|
39
41
|
transform(adapted)
|
40
42
|
end
|
data/controllers/invoice.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative './invoice/all'
|
4
4
|
require_relative './invoice/decode'
|
5
5
|
require_relative './invoice/find_by_secret_hash'
|
6
|
+
require_relative './invoice/find_by_code'
|
6
7
|
require_relative './invoice/actions/create'
|
7
8
|
|
8
9
|
module Lighstorm
|
@@ -20,8 +21,12 @@ module Lighstorm
|
|
20
21
|
All.model(All.data).last
|
21
22
|
end
|
22
23
|
|
23
|
-
def self.find_by_secret_hash(secret_hash)
|
24
|
-
FindBySecretHash.model(FindBySecretHash.data(secret_hash))
|
24
|
+
def self.find_by_secret_hash(secret_hash, &vcr)
|
25
|
+
FindBySecretHash.model(FindBySecretHash.data(secret_hash, &vcr))
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_by_code(code, &vcr)
|
29
|
+
FindByCode.model(FindByCode.data(code, &vcr))
|
25
30
|
end
|
26
31
|
|
27
32
|
def self.decode(code, &vcr)
|
data/controllers/payment/all.rb
CHANGED
@@ -12,7 +12,7 @@ module Lighstorm
|
|
12
12
|
module Controllers
|
13
13
|
module Payment
|
14
14
|
module All
|
15
|
-
def self.fetch(purpose: nil, limit: nil, fetch: {})
|
15
|
+
def self.fetch(purpose: nil, invoice_code: nil, secret_hash: nil, limit: nil, fetch: {})
|
16
16
|
at = Time.now
|
17
17
|
|
18
18
|
grpc = Ports::GRPC.session
|
@@ -31,6 +31,10 @@ module Lighstorm
|
|
31
31
|
response.payments.each do |payment|
|
32
32
|
payment = payment.to_h
|
33
33
|
|
34
|
+
next unless invoice_code.nil? || payment[:payment_request] == invoice_code
|
35
|
+
|
36
|
+
next unless secret_hash.nil? || payment[:payment_hash] == secret_hash
|
37
|
+
|
34
38
|
payment_purpose = Adapter::Purpose.list_payments(payment, get_info)
|
35
39
|
|
36
40
|
case purpose
|
@@ -391,11 +395,22 @@ module Lighstorm
|
|
391
395
|
list_payments
|
392
396
|
end
|
393
397
|
|
394
|
-
def self.data(
|
398
|
+
def self.data(
|
399
|
+
purpose: nil, invoice_code: nil, secret_hash: nil, limit: nil,
|
400
|
+
fetch: {}, &vcr
|
401
|
+
)
|
395
402
|
raw = if vcr.nil?
|
396
|
-
self.fetch(
|
403
|
+
self.fetch(
|
404
|
+
purpose: purpose, invoice_code: invoice_code, secret_hash: secret_hash,
|
405
|
+
limit: limit, fetch: fetch
|
406
|
+
)
|
397
407
|
else
|
398
|
-
vcr.call(
|
408
|
+
vcr.call(lambda {
|
409
|
+
self.fetch(
|
410
|
+
purpose: purpose, invoice_code: invoice_code, secret_hash: secret_hash,
|
411
|
+
limit: limit, fetch: fetch
|
412
|
+
)
|
413
|
+
})
|
399
414
|
end
|
400
415
|
|
401
416
|
adapted = adapt(raw)
|
data/controllers/payment.rb
CHANGED
@@ -16,6 +16,14 @@ module Lighstorm
|
|
16
16
|
def self.last(purpose: nil, fetch: {})
|
17
17
|
All.model(All.data(purpose: purpose, fetch: fetch)).last
|
18
18
|
end
|
19
|
+
|
20
|
+
def self.find_by_secret_hash(secret_hash, &vcr)
|
21
|
+
All.model(All.data(secret_hash: secret_hash, &vcr)).first
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find_by_invoice_code(invoice_code, &vcr)
|
25
|
+
All.model(All.data(invoice_code: invoice_code, &vcr)).first
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
data/docs/README.md
CHANGED
@@ -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.11'
|
31
31
|
```
|
32
32
|
|
33
33
|
Run `bundle install`.
|
@@ -60,7 +60,7 @@ Lighstorm.config!(
|
|
60
60
|
```ruby
|
61
61
|
require 'lighstorm'
|
62
62
|
|
63
|
-
puts Lighstorm.version # => 0.0.
|
63
|
+
puts Lighstorm.version # => 0.0.11
|
64
64
|
|
65
65
|
Lighstorm::Invoice.create(
|
66
66
|
description: 'Coffee', amount: { millisatoshis: 1000 }, payable: 'once'
|
@@ -462,6 +462,12 @@ Lighstorm::Invoice.find_by_secret_hash(
|
|
462
462
|
'1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
|
463
463
|
)
|
464
464
|
|
465
|
+
invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
466
|
+
|
467
|
+
invoice.secret.valid_proof?(
|
468
|
+
'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
469
|
+
) # => true
|
470
|
+
|
465
471
|
# _key is helpful for reactive javascript frameworks.
|
466
472
|
# Please don't consider it as a unique identifier
|
467
473
|
# for the item. Instead, use it as a volatile key for
|
@@ -526,6 +532,19 @@ action.response
|
|
526
532
|
invoice = action.result
|
527
533
|
```
|
528
534
|
|
535
|
+
### Proof of Payment
|
536
|
+
|
537
|
+
[Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
|
538
|
+
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
|
542
|
+
|
543
|
+
invoice.secret.valid_proof?(
|
544
|
+
'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
545
|
+
) # => true
|
546
|
+
```
|
547
|
+
|
529
548
|
### Pay
|
530
549
|
|
531
550
|
[Understanding Lightning Invoices](https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices)
|
@@ -547,6 +566,8 @@ payment = action.result
|
|
547
566
|
payment.at
|
548
567
|
payment.state
|
549
568
|
|
569
|
+
payment.secret.proof
|
570
|
+
|
550
571
|
payment.amount.millisatoshis
|
551
572
|
payment.fee.millisatoshis
|
552
573
|
payment.fee.parts_per_million(
|
@@ -622,6 +643,7 @@ rescue PaymentError => error
|
|
622
643
|
error.result
|
623
644
|
end
|
624
645
|
```
|
646
|
+
|
625
647
|
## Payment
|
626
648
|
|
627
649
|
[![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)
|
@@ -642,6 +664,12 @@ Lighstorm::Payment.all(limit: 10, purpose: 'rebalance')
|
|
642
664
|
# 'self-payment', 'peer-to-peer',
|
643
665
|
# 'rebalance', 'payment'
|
644
666
|
|
667
|
+
Lighstorm::Payment.find_by_invoice_code('lnbc20n1pj...0eqps7h0k9')
|
668
|
+
|
669
|
+
Lighstorm::Payment.find_by_secret_hash(
|
670
|
+
'1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
|
671
|
+
)
|
672
|
+
|
645
673
|
# _key is helpful for reactive javascript frameworks.
|
646
674
|
# Please don't consider it as a unique identifier
|
647
675
|
# for the item. Instead, use it as a volatile key for
|
@@ -671,6 +699,7 @@ payment.purpose
|
|
671
699
|
# https://docs.lightning.engineering/the-lightning-network/multihop-payments
|
672
700
|
payment.secret.preimage
|
673
701
|
payment.secret.hash
|
702
|
+
payment.secret.proof
|
674
703
|
|
675
704
|
payment.invoice.created_at
|
676
705
|
payment.invoice.expires_at
|
@@ -747,6 +776,18 @@ payment.hops[0].channel.entry.public_key
|
|
747
776
|
payment.hops[0].channel.entry.alias
|
748
777
|
payment.hops[0].channel.entry.color
|
749
778
|
```
|
779
|
+
|
780
|
+
### Proof of Payment
|
781
|
+
|
782
|
+
[Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
|
783
|
+
|
784
|
+
```ruby
|
785
|
+
payment = Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay.result
|
786
|
+
|
787
|
+
payment.secret.proof
|
788
|
+
# => 'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
|
789
|
+
```
|
790
|
+
|
750
791
|
### Performance
|
751
792
|
Avoid fetching data that you don't need:
|
752
793
|
```ruby
|
@@ -1003,7 +1044,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
|
|
1003
1044
|
# demo.rb
|
1004
1045
|
require 'lighstorm'
|
1005
1046
|
|
1006
|
-
puts Lighstorm.version # => 0.0.
|
1047
|
+
puts Lighstorm.version # => 0.0.11
|
1007
1048
|
```
|
1008
1049
|
|
1009
1050
|
```sh
|
@@ -1240,13 +1281,13 @@ gem build lighstorm.gemspec
|
|
1240
1281
|
|
1241
1282
|
gem signin
|
1242
1283
|
|
1243
|
-
gem push lighstorm-0.0.
|
1284
|
+
gem push lighstorm-0.0.11.gem
|
1244
1285
|
```
|
1245
1286
|
|
1246
1287
|
_________________
|
1247
1288
|
|
1248
1289
|
<center>
|
1249
|
-
lighstorm 0.0.
|
1290
|
+
lighstorm 0.0.11
|
1250
1291
|
|
|
1251
1292
|
<a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
|
1252
1293
|
|
|
data/docs/_coverpage.md
CHANGED
data/docs/index.html
CHANGED
data/models/errors.rb
CHANGED
@@ -2,7 +2,21 @@
|
|
2
2
|
|
3
3
|
module Lighstorm
|
4
4
|
module Errors
|
5
|
-
class LighstormError < StandardError
|
5
|
+
class LighstormError < StandardError
|
6
|
+
attr_reader :grpc
|
7
|
+
|
8
|
+
def initialize(message = nil, grpc: nil)
|
9
|
+
super(message)
|
10
|
+
@grpc = grpc
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
output = { class: self.class, message: message }
|
15
|
+
output[:grpc] = grpc.message unless grpc.nil?
|
16
|
+
|
17
|
+
output
|
18
|
+
end
|
19
|
+
end
|
6
20
|
|
7
21
|
class ToDoError < LighstormError; end
|
8
22
|
|
@@ -19,6 +33,7 @@ module Lighstorm
|
|
19
33
|
class OperationNotAllowedError < LighstormError; end
|
20
34
|
class UnexpectedNumberOfHTLCsError < LighstormError; end
|
21
35
|
class UnknownChannelError < LighstormError; end
|
36
|
+
class NoInvoiceFoundError < LighstormError; end
|
22
37
|
|
23
38
|
class InvoiceMayHaveMultiplePaymentsError < LighstormError; end
|
24
39
|
|
data/models/secret.rb
CHANGED
data/static/spec.rb
CHANGED
@@ -4,7 +4,7 @@ module Lighstorm
|
|
4
4
|
module Static
|
5
5
|
SPEC = {
|
6
6
|
name: 'lighstorm',
|
7
|
-
version: '0.0.
|
7
|
+
version: '0.0.11',
|
8
8
|
author: 'icebaker',
|
9
9
|
summary: 'API for interacting with a Lightning Node.',
|
10
10
|
description: 'Lighstorm is an opinionated abstraction layer on top of the lnd-client for interacting with a Lightning Node.',
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lighstorm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- icebaker
|
@@ -103,6 +103,7 @@ files:
|
|
103
103
|
- controllers/invoice/actions/pay_through_route.rb
|
104
104
|
- controllers/invoice/all.rb
|
105
105
|
- controllers/invoice/decode.rb
|
106
|
+
- controllers/invoice/find_by_code.rb
|
106
107
|
- controllers/invoice/find_by_secret_hash.rb
|
107
108
|
- controllers/node.rb
|
108
109
|
- controllers/node/actions/apply_gossip.rb
|