lighstorm 0.0.10 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed188ef291ac08a9cc6f91dca92931be2c88257ee184416fd0f40a3224740b20
4
- data.tar.gz: 1be060a12d9e755354764cc8151da8a26e114fcc9a0ecac470e9fe9b685a60a4
3
+ metadata.gz: 026ad34b202b5f4367e287568b22126ba4850145b9d3e9398cdfd2f70d9e25d7
4
+ data.tar.gz: 63b0809d04e688ceab5c7a3ff5e9ee05588c8fece0a7b6323f96b8f0a871f9eb
5
5
  SHA512:
6
- metadata.gz: b37802f04bae65416f4e80590506518025d62f1ca9b502b97db3cc108792b13a077f2ebb89c3e0be4cf311fb10a53f916a3c37e2f6c729b9bf01f187b0ab4892
7
- data.tar.gz: ac5f5a1f5f4ff271ab2ddef517763f380f1868b71339bcf1758975e35c7e520ddd65fddb9d210539fedde2dc3830912db8b0bbdbfed1aa454e781c8a6e43e948
6
+ metadata.gz: 00ba8bf8fa6f5930abb796bdb00434401a31d30db6d26397ea1cebeb587ce404b942777dd0df6eed38d8e24fec5f6574afaf3d343108379f1d359f7def4a80ba
7
+ data.tar.gz: 39ebcc45331f332c5aa85e824245aec7e707bed958625d123cdb655f250610a361ae56a6dc0a8657ec34dcda977bd7e0630b47e82f0edb511b5cbf3a16b584bd
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lighstorm (0.0.10)
4
+ lighstorm (0.0.12)
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.3)
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
@@ -15,6 +15,7 @@ Lighstorm::Channel.mine.first.myself.node.alias
15
15
  - [About](#about)
16
16
  - [Usage](#usage)
17
17
  - [Documentation](https://icebaker.github.io/lighstorm)
18
+ - [Tutorials and Articles](#tutorials-and-articles)
18
19
  - [Development](https://icebaker.github.io/lighstorm/#/README?id=development)
19
20
 
20
21
  ## About
@@ -34,7 +35,7 @@ Although it tries to stay close to [Lightning's terminologies](https://docs.ligh
34
35
  Add to your `Gemfile`:
35
36
 
36
37
  ```ruby
37
- gem 'lighstorm', '~> 0.0.10'
38
+ gem 'lighstorm', '~> 0.0.12'
38
39
  ```
39
40
 
40
41
  ```ruby
@@ -46,7 +47,7 @@ Lighstorm.config!(
46
47
  macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
47
48
  )
48
49
 
49
- puts Lighstorm.version # => 0.0.10
50
+ puts Lighstorm.version # => 0.0.12
50
51
 
51
52
  Lighstorm::Node.myself.alias # => icebaker/old-stone
52
53
 
@@ -69,6 +70,10 @@ Lighstorm::Satoshis.new(
69
70
 
70
71
  Check the [full documentation](https://icebaker.github.io/lighstorm).
71
72
 
73
+ ## Tutorials and Articles
74
+
75
+ - [Getting Started with Lightning Payments in Ruby](https://mirror.xyz/icebaker.eth/4RUF8umW_KRfVWHHvC2jz0c7YJqzv3RUUvLN-Mln5IU)
76
+
72
77
  ## Development
73
78
 
74
79
  Check the [development documentation](https://icebaker.github.io/lighstorm/#/README?id=development).
@@ -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
@@ -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)
@@ -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(purpose: nil, limit: nil, fetch: {}, &vcr)
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(purpose: purpose, limit: limit, fetch: 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(-> { self.fetch(purpose: purpose, limit: limit, fetch: fetch) })
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)
@@ -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
@@ -0,0 +1,58 @@
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 Secret
10
+ module ValidProof
11
+ def self.fetch(invoice_main_secret_hash)
12
+ { response: {
13
+ at: Time.now,
14
+ lookup_invoice: Ports::GRPC.lightning.lookup_invoice(r_hash_str: invoice_main_secret_hash).to_h
15
+ }, exception: nil }
16
+ rescue StandardError => e
17
+ { exception: e }
18
+ end
19
+
20
+ def self.adapt(raw)
21
+ {
22
+ lookup_invoice: Lighstorm::Adapter::Invoice.lookup_invoice(
23
+ raw[:lookup_invoice],
24
+ raw[:at]
25
+ )
26
+ }
27
+ end
28
+
29
+ def self.transform(adapted, proof)
30
+ return true if adapted[:lookup_invoice][:secret][:preimage] == proof
31
+
32
+ return false if adapted[:lookup_invoice][:payments].nil? ||
33
+ adapted[:lookup_invoice][:payments].empty?
34
+
35
+ !adapted[:lookup_invoice][:payments].find do |payment|
36
+ next if payment[:secret].nil?
37
+
38
+ payment[:secret][:preimage] == proof
39
+ end.nil?
40
+ end
41
+
42
+ def self.data(invoice_main_secret_hash, proof, &vcr)
43
+ raise 'Invalid proof' if proof.size != 64
44
+
45
+ raw = if vcr.nil?
46
+ fetch(invoice_main_secret_hash)
47
+ else
48
+ vcr.call(-> { fetch(invoice_main_secret_hash) })
49
+ end
50
+
51
+ adapted = adapt(raw[:response])
52
+
53
+ transform(adapted, proof)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,26 +1,73 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../invoice/all'
4
+ require_relative '../payment/all'
5
+ require_relative '../forward/all'
4
6
  require_relative '../../models/transaction'
5
7
 
6
8
  module Lighstorm
7
9
  module Controllers
8
10
  module Transaction
9
11
  module All
10
- def self.fetch(limit: nil)
12
+ def self.fetch(direction: nil, how: nil, limit: nil)
11
13
  transactions = []
12
14
 
13
- Invoice::All.data(spontaneous: true).filter do |invoice|
14
- !invoice[:payments].nil? && invoice[:payments].size.positive?
15
- end.each do |invoice|
16
- invoice[:payments].each do |payment|
15
+ if direction.nil? || direction == 'in'
16
+ Invoice::All.data(spontaneous: true).filter do |invoice|
17
+ !invoice[:payments].nil? && invoice[:payments].size.positive?
18
+ end.each do |invoice|
19
+ transaction_how = invoice[:code].nil? ? 'spontaneously' : 'with-invoice'
20
+
21
+ next if !how.nil? && how != transaction_how
22
+
23
+ # TODO: Improve performance by reducing invoice fields and removing payments?
24
+ invoice[:payments].each do |payment|
25
+ transactions << {
26
+ direction: 'in',
27
+ at: payment[:at],
28
+ amount: payment[:amount],
29
+ how: transaction_how,
30
+ message: payment[:message],
31
+ data: { invoice: invoice }
32
+ }
33
+ end
34
+ end
35
+
36
+ Forward::All.data.each do |forward|
37
+ next if !how.nil? && how != 'forwarding'
38
+
17
39
  transactions << {
18
40
  direction: 'in',
41
+ at: forward[:at],
42
+ amount: forward[:fee],
43
+ how: 'forwarding',
44
+ message: nil,
45
+ data: {}
46
+ }
47
+ end
48
+ end
49
+
50
+ if direction.nil? || direction == 'out'
51
+ Payment::All.data(
52
+ fetch: {
53
+ get_node_info: false,
54
+ lookup_invoice: false,
55
+ decode_pay_req: true,
56
+ get_chan_info: false
57
+ }
58
+ )[:data].each do |payment|
59
+ transaction_how = payment[:invoice][:code].nil? ? 'spontaneously' : 'with-invoice'
60
+
61
+ next if !how.nil? && how != transaction_how
62
+
63
+ # TODO: Improve performance by reducing invoice fields?
64
+ transactions << {
65
+ direction: 'out',
19
66
  at: payment[:at],
20
67
  amount: payment[:amount],
68
+ how: transaction_how,
21
69
  message: payment[:message],
22
- kind: 'invoice',
23
- data: invoice
70
+ data: { invoice: payment[:invoice] }
24
71
  }
25
72
  end
26
73
  end
@@ -39,8 +86,12 @@ module Lighstorm
39
86
  end
40
87
  end
41
88
 
42
- def self.data(limit: nil, &vcr)
43
- raw = vcr.nil? ? fetch(limit: limit) : vcr.call(-> { fetch(limit: limit) })
89
+ def self.data(direction: nil, how: nil, limit: nil, &vcr)
90
+ raw = if vcr.nil?
91
+ fetch(direction: direction, how: how, limit: limit)
92
+ else
93
+ vcr.call(-> { fetch(direction: direction, how: how, limit: limit) })
94
+ end
44
95
 
45
96
  transform(raw)
46
97
  end
@@ -5,8 +5,12 @@ require_relative './transaction/all'
5
5
  module Lighstorm
6
6
  module Controllers
7
7
  module Transaction
8
- def self.all(limit: nil)
9
- All.model(All.data(limit: limit))
8
+ def self.all(direction: nil, how: nil, limit: nil)
9
+ All.model(All.data(
10
+ direction: direction,
11
+ how: how,
12
+ limit: limit
13
+ ))
10
14
  end
11
15
  end
12
16
  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.10'
30
+ gem 'lighstorm', '~> 0.0.12'
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.10
63
+ puts Lighstorm.version # => 0.0.12
64
64
 
65
65
  Lighstorm::Invoice.create(
66
66
  description: 'Coffee', amount: { millisatoshis: 1000 }, payable: 'once'
@@ -112,6 +112,10 @@ Lighstorm::Satoshis.new(
112
112
  ).satoshis # => 75621.65
113
113
  ```
114
114
 
115
+ ## Tutorials and Articles
116
+
117
+ - [Getting Started with Lightning Payments in Ruby](https://mirror.xyz/icebaker.eth/4RUF8umW_KRfVWHHvC2jz0c7YJqzv3RUUvLN-Mln5IU)
118
+
115
119
  # Data Modeling
116
120
 
117
121
  ## Graph Theory
@@ -462,6 +466,12 @@ Lighstorm::Invoice.find_by_secret_hash(
462
466
  '1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
463
467
  )
464
468
 
469
+ invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
470
+
471
+ invoice.secret.valid_proof?(
472
+ 'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
473
+ ) # => true
474
+
465
475
  # _key is helpful for reactive javascript frameworks.
466
476
  # Please don't consider it as a unique identifier
467
477
  # for the item. Instead, use it as a volatile key for
@@ -526,6 +536,19 @@ action.response
526
536
  invoice = action.result
527
537
  ```
528
538
 
539
+ ### Proof of Payment
540
+
541
+ [Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
542
+
543
+
544
+ ```ruby
545
+ invoice = Lighstorm::Invoice.find_by_code('lnbc20n1pj...0eqps7h0k9')
546
+
547
+ invoice.secret.valid_proof?(
548
+ 'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
549
+ ) # => true
550
+ ```
551
+
529
552
  ### Pay
530
553
 
531
554
  [Understanding Lightning Invoices](https://docs.lightning.engineering/the-lightning-network/payment-lifecycle/understanding-lightning-invoices)
@@ -547,6 +570,8 @@ payment = action.result
547
570
  payment.at
548
571
  payment.state
549
572
 
573
+ payment.secret.proof
574
+
550
575
  payment.amount.millisatoshis
551
576
  payment.fee.millisatoshis
552
577
  payment.fee.parts_per_million(
@@ -622,6 +647,7 @@ rescue PaymentError => error
622
647
  error.result
623
648
  end
624
649
  ```
650
+
625
651
  ## Payment
626
652
 
627
653
  [![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 +668,12 @@ Lighstorm::Payment.all(limit: 10, purpose: 'rebalance')
642
668
  # 'self-payment', 'peer-to-peer',
643
669
  # 'rebalance', 'payment'
644
670
 
671
+ Lighstorm::Payment.find_by_invoice_code('lnbc20n1pj...0eqps7h0k9')
672
+
673
+ Lighstorm::Payment.find_by_secret_hash(
674
+ '1d438b8100518c9fba0a607e3317d6b36f74ceef3a6591836eb2f679c6853501'
675
+ )
676
+
645
677
  # _key is helpful for reactive javascript frameworks.
646
678
  # Please don't consider it as a unique identifier
647
679
  # for the item. Instead, use it as a volatile key for
@@ -671,6 +703,7 @@ payment.purpose
671
703
  # https://docs.lightning.engineering/the-lightning-network/multihop-payments
672
704
  payment.secret.preimage
673
705
  payment.secret.hash
706
+ payment.secret.proof
674
707
 
675
708
  payment.invoice.created_at
676
709
  payment.invoice.expires_at
@@ -747,6 +780,18 @@ payment.hops[0].channel.entry.public_key
747
780
  payment.hops[0].channel.entry.alias
748
781
  payment.hops[0].channel.entry.color
749
782
  ```
783
+
784
+ ### Proof of Payment
785
+
786
+ [Making Payments](https://docs.lightning.engineering/the-lightning-network/multihop-payments)
787
+
788
+ ```ruby
789
+ payment = Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay.result
790
+
791
+ payment.secret.proof
792
+ # => 'c504f73f83e3772b802844b54021e44e071c03011eeda476b198f7a093bcb09e'
793
+ ```
794
+
750
795
  ### Performance
751
796
  Avoid fetching data that you don't need:
752
797
  ```ruby
@@ -1003,7 +1048,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
1003
1048
  # demo.rb
1004
1049
  require 'lighstorm'
1005
1050
 
1006
- puts Lighstorm.version # => 0.0.10
1051
+ puts Lighstorm.version # => 0.0.12
1007
1052
  ```
1008
1053
 
1009
1054
  ```sh
@@ -1240,13 +1285,13 @@ gem build lighstorm.gemspec
1240
1285
 
1241
1286
  gem signin
1242
1287
 
1243
- gem push lighstorm-0.0.10.gem
1288
+ gem push lighstorm-0.0.12.gem
1244
1289
  ```
1245
1290
 
1246
1291
  _________________
1247
1292
 
1248
1293
  <center>
1249
- lighstorm 0.0.10
1294
+ lighstorm 0.0.12
1250
1295
  |
1251
1296
  <a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
1252
1297
  |
data/docs/_coverpage.md CHANGED
@@ -8,7 +8,7 @@
8
8
  - Built for maximum **reliability**.
9
9
  - Optimized for programmer **happiness**.
10
10
 
11
- 0.0.10
11
+ 0.0.12
12
12
 
13
13
  ⚠️ _Warning: Early-stage, breaking changes are expected._
14
14
 
data/docs/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <script>
19
19
  window.$docsify = {
20
20
  coverpage: true,
21
- name: 'Lighstorm 0.0.10',
21
+ name: 'Lighstorm 0.0.12',
22
22
  repo: 'https://github.com/icebaker/lighstorm'
23
23
  }
24
24
  </script>
data/models/errors.rb CHANGED
@@ -2,7 +2,21 @@
2
2
 
3
3
  module Lighstorm
4
4
  module Errors
5
- class LighstormError < StandardError; end
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
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative '../controllers/secret/valid_proof'
4
+
3
5
  require 'digest'
4
6
 
5
7
  module Lighstorm
@@ -26,6 +28,16 @@ module Lighstorm
26
28
  @hash = data[:hash]
27
29
  end
28
30
 
31
+ def proof
32
+ @preimage
33
+ end
34
+
35
+ def valid_proof?(candidate_preimage, &vcr)
36
+ return true if candidate_preimage == preimage
37
+
38
+ Controllers::Secret::ValidProof.data(@hash, candidate_preimage, &vcr)
39
+ end
40
+
29
41
  def to_h
30
42
  {
31
43
  preimage: preimage,
@@ -5,7 +5,7 @@ require_relative 'invoice'
5
5
  module Lighstorm
6
6
  module Models
7
7
  class Transaction
8
- attr_reader :direction, :at, :message, :_key
8
+ attr_reader :direction, :at, :message, :how, :_key
9
9
 
10
10
  def initialize(data)
11
11
  @data = data
@@ -13,6 +13,7 @@ module Lighstorm
13
13
  @_key = @data[:_key]
14
14
  @at = @data[:at]
15
15
  @direction = @data[:direction]
16
+ @how = @data[:how]
16
17
  @message = @data[:message]
17
18
  end
18
19
 
@@ -21,7 +22,7 @@ module Lighstorm
21
22
  end
22
23
 
23
24
  def invoice
24
- @invoice ||= @data[:kind] == 'invoice' ? Invoice.new(@data[:data]) : nil
25
+ @invoice ||= @data[:data][:invoice].nil? ? nil : Invoice.new(@data[:data][:invoice])
25
26
  end
26
27
 
27
28
  def to_h
@@ -30,6 +31,7 @@ module Lighstorm
30
31
  at: at,
31
32
  direction: direction,
32
33
  amount: amount.to_h,
34
+ how: how,
33
35
  message: message
34
36
  }
35
37
 
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.10',
7
+ version: '0.0.12',
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lighstorm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - icebaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-12 00:00:00.000000000 Z
11
+ date: 2023-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -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
@@ -113,6 +114,7 @@ files:
113
114
  - controllers/payment.rb
114
115
  - controllers/payment/actions/pay.rb
115
116
  - controllers/payment/all.rb
117
+ - controllers/secret/valid_proof.rb
116
118
  - controllers/transaction.rb
117
119
  - controllers/transaction/all.rb
118
120
  - deleted.sh