lighstorm 0.0.1 → 0.0.3

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.
@@ -5,6 +5,8 @@ require_relative '../../../components/lnd'
5
5
  module Lighstorm
6
6
  module Models
7
7
  class Lightning
8
+ IMPLEMENTATION = 'lnd'
9
+
8
10
  def initialize(platform, node)
9
11
  raise 'cannot provide platform details for a node that is not yours' unless node.myself?
10
12
 
@@ -19,9 +21,13 @@ module Lighstorm
19
21
  { get_info: @data[:get_info].to_h }
20
22
  end
21
23
 
24
+ def implementation
25
+ @implementation ||= IMPLEMENTATION
26
+ end
27
+
22
28
  def to_h
23
29
  {
24
- implementation: 'lnd',
30
+ implementation: implementation,
25
31
  version: version
26
32
  }
27
33
  end
@@ -12,7 +12,7 @@ module Lighstorm
12
12
  def initialize(node)
13
13
  @node = node
14
14
 
15
- response = Cache.for('lightning.get_info', ttl: 1) do
15
+ response = Cache.for('lightning.get_info') do
16
16
  LND.instance.middleware('lightning.get_info') do
17
17
  LND.instance.client.lightning.get_info
18
18
  end
data/models/nodes/node.rb CHANGED
@@ -14,7 +14,7 @@ module Lighstorm
14
14
  attr_reader :alias, :public_key, :color
15
15
 
16
16
  def self.myself
17
- response = Cache.for('lightning.get_info', ttl: 1) do
17
+ response = Cache.for('lightning.get_info') do
18
18
  LND.instance.middleware('lightning.get_info') do
19
19
  LND.instance.client.lightning.get_info
20
20
  end
@@ -27,6 +27,18 @@ module Lighstorm
27
27
  Node.new({ public_key: public_key }, myself: myself)
28
28
  end
29
29
 
30
+ def self.all
31
+ response = LND.instance.middleware('lightning.describe_graph') do
32
+ LND.instance.client.lightning.describe_graph
33
+ end
34
+
35
+ myself_public_key = myself.public_key
36
+
37
+ response.nodes.map do |raw_node|
38
+ Node.new({ describe_graph: raw_node }, myself: raw_node.pub_key == myself_public_key)
39
+ end
40
+ end
41
+
30
42
  def myself?
31
43
  @myself
32
44
  end
@@ -36,45 +48,98 @@ module Lighstorm
36
48
  end
37
49
 
38
50
  def channels
39
- raise 'cannot list channels from a node that is not yours' unless myself?
40
-
41
- Channel.all
51
+ if myself?
52
+ Channel.mine
53
+ else
54
+ Channel.all
55
+ end
42
56
  end
43
57
 
44
58
  def raw
45
59
  {
46
- get_node_info: @data[:get_node_info].to_h
60
+ get_node_info: @data[:get_node_info].to_h,
61
+ describe_graph: @data[:describe_graph].to_h
47
62
  }
48
63
  end
49
64
 
50
65
  def to_h
51
- {
52
- alias: @alias,
53
- public_key: @public_key,
54
- color: @color,
55
- platform: platform.to_h
56
- }
66
+ if (@data[:get_node_info] || @data[:describe_graph]) && myself?
67
+ {
68
+ alias: @alias,
69
+ public_key: @public_key,
70
+ color: @color,
71
+ platform: platform.to_h
72
+ }
73
+ elsif @data[:get_node_info] || @data[:describe_graph]
74
+ {
75
+ alias: @alias,
76
+ public_key: @public_key,
77
+ color: @color
78
+ }
79
+ else
80
+ {
81
+ public_key: @public_key
82
+ }
83
+ end
57
84
  end
58
85
 
59
- private
86
+ def myself
87
+ return @myself unless @myself.nil?
60
88
 
61
- def initialize(params, myself: false)
62
- response = Cache.for(
63
- 'lightning.get_node_info',
64
- ttl: 5 * 60, params: { pub_key: params[:public_key] }
65
- ) do
66
- LND.instance.middleware('lightning.get_node_info') do
67
- LND.instance.client.lightning.get_node_info(pub_key: params[:public_key])
89
+ response_get_info = Cache.for('lightning.get_info') do
90
+ LND.instance.middleware('lightning.get_info') do
91
+ LND.instance.client.lightning.get_info
68
92
  end
69
93
  end
70
94
 
71
- @data = { get_node_info: response }
95
+ @myself = public_key == response_get_info.identity_pubkey
96
+ end
97
+
98
+ def error?
99
+ !@data[:error].nil?
100
+ end
101
+
102
+ def error
103
+ @data[:error]
104
+ end
105
+
106
+ def initialize(params, myself: false, fetch: true)
107
+ if params[:public_key] && fetch
108
+ begin
109
+ response = Cache.for('lightning.get_node_info', params: { pub_key: params[:public_key] }) do
110
+ LND.instance.middleware('lightning.get_node_info') do
111
+ LND.instance.client.lightning.get_node_info(pub_key: params[:public_key])
112
+ end
113
+ end
114
+
115
+ @data = { get_node_info: response }
116
+ @raw_node = response.node
117
+ rescue StandardError => e
118
+ @data = { get_node_info: nil, error: e }
119
+ @public_key = params[:public_key]
120
+ end
121
+ elsif params[:describe_graph]
122
+ @data = { describe_graph: params[:describe_graph] }
123
+
124
+ @raw_node = params[:describe_graph]
125
+ else
126
+ @data = {}
127
+ end
128
+
129
+ @myself = myself
130
+
131
+ if params[:public_key] && !fetch
132
+ @public_key = params[:public_key]
133
+ return
134
+ end
72
135
 
73
136
  @myself = myself
74
137
 
75
- @alias = @data[:get_node_info].node.alias
76
- @public_key = @data[:get_node_info].node.pub_key
77
- @color = @data[:get_node_info].node.color
138
+ return unless @raw_node
139
+
140
+ @alias = @raw_node.alias
141
+ @public_key = @raw_node.pub_key
142
+ @color = @raw_node.color
78
143
  end
79
144
  end
80
145
  end
data/models/rate.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  module Lighstorm
4
4
  module Models
5
5
  class Rate
6
+ attr_reader :parts_per_million
7
+
6
8
  # https://en.wikipedia.org/wiki/Parts-per_notation
7
9
  def initialize(parts_per_million: nil)
8
10
  raise 'missing parts_per_million' if parts_per_million.nil?
@@ -4,6 +4,8 @@ require 'dotenv/load'
4
4
 
5
5
  require_relative '../../static/spec'
6
6
 
7
+ require_relative '../../models/satoshis'
8
+
7
9
  require_relative '../../models/nodes/node'
8
10
 
9
11
  require_relative '../../models/edges/channel'
data/static/cache.rb ADDED
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lighstorm
4
+ module Static
5
+ CACHE = {
6
+ fee_report: {
7
+ ttl: 0.01,
8
+ properties: %i[
9
+ base_fee_msat fee_per_mil
10
+ ]
11
+ },
12
+ forwarding_history: {
13
+ ttl: 1,
14
+ properties: %i[
15
+ amt_in_msat
16
+ amt_out_msat
17
+ chan_id_in
18
+ chan_id_out
19
+ fee_msat
20
+ timestamp_ns
21
+ ]
22
+ },
23
+ get_chan_info: {
24
+ ttl: 5 * 60,
25
+ properties: %i[
26
+ channel_id
27
+ chan_point
28
+ node1_pub
29
+ node1_policy
30
+ node2_pub
31
+ node2_policy
32
+ capacity
33
+ ]
34
+ },
35
+ get_info: {
36
+ ttl: 5 * 60,
37
+ properties: %i[identity_pubkey version chains chain network]
38
+ },
39
+ get_node_info: {
40
+ ttl: 5 * 60,
41
+ properties: %i[alias pub_key color]
42
+ },
43
+ list_channels: {
44
+ ttl: 1,
45
+ properties: %i[
46
+ local_balance remote_balance unsettled_balance
47
+ local_constraints remote_constraints
48
+ active private
49
+ lifetime uptime
50
+ total_satoshis_sent total_satoshis_received
51
+ ]
52
+ },
53
+ list_payments: {
54
+ ttl: 1,
55
+ properties: %i[
56
+ creation_date payment_hash status
57
+ value_msat fee_msat
58
+ htlcs route hops
59
+ chan_id pub_key
60
+ amt_to_forward_msat fee_msat
61
+ ]
62
+ }
63
+ }.freeze
64
+ end
65
+ end
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.1',
7
+ version: '0.0.3',
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.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - icebaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-05 00:00:00.000000000 Z
11
+ date: 2023-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.0.4
39
+ version: 0.0.5
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.0.4
46
+ version: 0.0.5
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: zache
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -78,12 +78,15 @@ files:
78
78
  - models/connections/channel_node/accounting.rb
79
79
  - models/connections/channel_node/constraints.rb
80
80
  - models/connections/channel_node/fee.rb
81
+ - models/connections/channel_node/htlc.rb
81
82
  - models/connections/channel_node/policy.rb
82
83
  - models/connections/forward_channel.rb
83
84
  - models/connections/payment_channel.rb
84
85
  - models/edges/channel.rb
85
86
  - models/edges/channel/accounting.rb
86
87
  - models/edges/forward.rb
88
+ - models/edges/groups/analysis.rb
89
+ - models/edges/groups/channel_forwards.rb
87
90
  - models/edges/payment.rb
88
91
  - models/nodes/node.rb
89
92
  - models/nodes/node/lightning.rb
@@ -91,6 +94,7 @@ files:
91
94
  - models/rate.rb
92
95
  - models/satoshis.rb
93
96
  - ports/dsl/lighstorm.rb
97
+ - static/cache.rb
94
98
  - static/spec.rb
95
99
  homepage: https://github.com/icebaker/lighstorm
96
100
  licenses: