lighstorm 0.0.11 → 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: 6072337300f3fd850fbca3ba5c7c804842c275d5f35fa288dfb83747fa0b1a56
4
- data.tar.gz: 8a16d83cb96f0ed911ebd55e12707b20f0aac00a0acac8d176e544a68abad647
3
+ metadata.gz: 026ad34b202b5f4367e287568b22126ba4850145b9d3e9398cdfd2f70d9e25d7
4
+ data.tar.gz: 63b0809d04e688ceab5c7a3ff5e9ee05588c8fece0a7b6323f96b8f0a871f9eb
5
5
  SHA512:
6
- metadata.gz: 3ccb6cef3322fcd1c0efb1439ddaf756e631113fbc7544218d10d6f71d08ca2ad80cf08b029ae4145e6916dcefc9ee3683124567bb952b02bf70793cc794616b
7
- data.tar.gz: 2755ec9d8c2bf041459be7292983103c880f032e5e1e315ce2da2cc97ff945bbfb9f4083259a0c88ec22df8cd0301282c8ea376d63371a438ad58677b7f3d9e6
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.11)
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)
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.11'
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.11
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,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.11'
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.11
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
@@ -1044,7 +1048,7 @@ gem 'lighstorm', path: '/home/user/lighstorm'
1044
1048
  # demo.rb
1045
1049
  require 'lighstorm'
1046
1050
 
1047
- puts Lighstorm.version # => 0.0.11
1051
+ puts Lighstorm.version # => 0.0.12
1048
1052
  ```
1049
1053
 
1050
1054
  ```sh
@@ -1281,13 +1285,13 @@ gem build lighstorm.gemspec
1281
1285
 
1282
1286
  gem signin
1283
1287
 
1284
- gem push lighstorm-0.0.11.gem
1288
+ gem push lighstorm-0.0.12.gem
1285
1289
  ```
1286
1290
 
1287
1291
  _________________
1288
1292
 
1289
1293
  <center>
1290
- lighstorm 0.0.11
1294
+ lighstorm 0.0.12
1291
1295
  |
1292
1296
  <a href="https://github.com/icebaker/lighstorm" rel="noopener noreferrer" target="_blank">GitHub</a>
1293
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.11
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.11',
21
+ name: 'Lighstorm 0.0.12',
22
22
  repo: 'https://github.com/icebaker/lighstorm'
23
23
  }
24
24
  </script>
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
@@ -30,8 +32,10 @@ module Lighstorm
30
32
  @preimage
31
33
  end
32
34
 
33
- def valid_proof?(candidate_preimage)
34
- candidate_preimage == preimage
35
+ def valid_proof?(candidate_preimage, &vcr)
36
+ return true if candidate_preimage == preimage
37
+
38
+ Controllers::Secret::ValidProof.data(@hash, candidate_preimage, &vcr)
35
39
  end
36
40
 
37
41
  def to_h
@@ -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.11',
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.11
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
@@ -114,6 +114,7 @@ files:
114
114
  - controllers/payment.rb
115
115
  - controllers/payment/actions/pay.rb
116
116
  - controllers/payment/all.rb
117
+ - controllers/secret/valid_proof.rb
117
118
  - controllers/transaction.rb
118
119
  - controllers/transaction/all.rb
119
120
  - deleted.sh