lighstorm 0.0.13 → 0.0.14
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +2 -2
- data/adapters/connections/channel_node.rb +1 -0
- data/adapters/edges/payment/purpose.rb +3 -3
- data/adapters/edges/payment.rb +1 -3
- data/adapters/invoice.rb +0 -2
- data/adapters/wallet.rb +42 -0
- data/components/cache.rb +1 -1
- data/components/lnd.rb +24 -8
- data/controllers/action.rb +5 -0
- data/controllers/activity/all.rb +85 -20
- data/controllers/activity.rb +15 -6
- data/controllers/channel/actions/apply_gossip.rb +3 -4
- data/controllers/channel/actions/update_fee.rb +11 -7
- data/controllers/channel/all.rb +11 -7
- data/controllers/channel/find_by_id.rb +11 -11
- data/controllers/channel/mine.rb +10 -10
- data/controllers/channel.rb +25 -11
- data/controllers/concerns/impersonatable.rb +33 -0
- data/controllers/connection.rb +33 -0
- data/controllers/forward/all.rb +16 -12
- data/controllers/forward/group_by_channel.rb +2 -2
- data/controllers/forward.rb +19 -13
- data/controllers/invoice/actions/create.rb +21 -13
- data/controllers/invoice/actions/pay.rb +13 -12
- data/controllers/invoice/actions/pay_through_route.rb +2 -2
- data/controllers/invoice/all.rb +7 -7
- data/controllers/invoice/decode.rb +6 -6
- data/controllers/invoice/find_by_code.rb +7 -7
- data/controllers/invoice/find_by_secret_hash.rb +10 -6
- data/controllers/invoice.rb +46 -39
- data/controllers/node/actions/apply_gossip.rb +1 -1
- data/controllers/node/actions/pay.rb +13 -12
- data/controllers/node/all.rb +11 -7
- data/controllers/node/find_by_public_key.rb +11 -7
- data/controllers/node/myself.rb +6 -6
- data/controllers/node.rb +17 -11
- data/controllers/payment/actions/pay.rb +23 -19
- data/controllers/payment/all.rb +7 -4
- data/controllers/payment.rb +20 -14
- data/controllers/secret/valid_proof.rb +5 -5
- data/controllers/transaction/all.rb +6 -5
- data/controllers/transaction.rb +14 -6
- data/controllers/wallet/balance.rb +34 -0
- data/controllers/wallet.rb +19 -0
- data/docs/README.md +70 -7
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/lighstorm.gemspec +1 -1
- data/models/activity.rb +3 -2
- data/models/connections/channel_node/fee.rb +5 -2
- data/models/connections/channel_node/policy.rb +3 -2
- data/models/connections/channel_node.rb +14 -4
- data/models/connections/forward_channel.rb +3 -2
- data/models/edges/channel/hop.rb +1 -1
- data/models/edges/channel.rb +5 -7
- data/models/edges/forward.rb +4 -3
- data/models/edges/groups/channel_forwards.rb +3 -2
- data/models/edges/payment.rb +4 -3
- data/models/errors.rb +16 -24
- data/models/invoice.rb +10 -4
- data/models/nodes/node.rb +10 -4
- data/models/secret.rb +10 -4
- data/models/wallet.rb +40 -0
- data/ports/dsl/lighstorm.rb +6 -2
- data/ports/grpc.rb +30 -2
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +10 -5
- data/deleted.sh +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b600975d39699ef54c291ec8a06aa0d3f4284df248df2093ed85c3656dea685
|
4
|
+
data.tar.gz: 6d6373c5013c5ed9ad9f8479b26072da38f5847ba1e22b845132bd01167cacf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a0b3ea07b3201a388b68cf91f38aad7d98ceecf1bd9138f699830c3539ea6522cfdb9a23479bebd3f88563a265fa04bc10e510c033eeb228dbbd039e97cc52
|
7
|
+
data.tar.gz: 32c16160feef6212038150df78f539c4b4adca382f440729217f3916871912f20fdbe2add7d4c74be22d14e0f3bb5e5369e6788124b6e6ad879368ffad60c948
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lighstorm (0.0.
|
4
|
+
lighstorm (0.0.14)
|
5
5
|
dotenv (~> 2.8, >= 2.8.1)
|
6
|
-
lnd-client (~> 0.0.
|
6
|
+
lnd-client (~> 0.0.7)
|
7
7
|
zache (~> 0.12.0)
|
8
8
|
|
9
9
|
GEM
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
google-protobuf (~> 3.21)
|
23
23
|
googleapis-common-protos-types (~> 1.0)
|
24
24
|
json (2.6.3)
|
25
|
-
lnd-client (0.0.
|
25
|
+
lnd-client (0.0.7)
|
26
26
|
grpc (~> 1.52)
|
27
27
|
method_source (1.0.0)
|
28
28
|
parallel (1.22.1)
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Although it tries to stay close to [Lightning's terminologies](https://docs.ligh
|
|
35
35
|
Add to your `Gemfile`:
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
gem 'lighstorm', '~> 0.0.
|
38
|
+
gem 'lighstorm', '~> 0.0.14'
|
39
39
|
```
|
40
40
|
|
41
41
|
```ruby
|
@@ -53,7 +53,7 @@ Lighstorm.connect!(
|
|
53
53
|
macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon'
|
54
54
|
)
|
55
55
|
|
56
|
-
puts Lighstorm.version # => 0.0.
|
56
|
+
puts Lighstorm.version # => 0.0.14
|
57
57
|
|
58
58
|
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
59
59
|
|
@@ -10,6 +10,7 @@ module Lighstorm
|
|
10
10
|
data = {
|
11
11
|
_source: :list_channels,
|
12
12
|
state: grpc[:active] ? 'active' : 'inactive',
|
13
|
+
initiator: grpc[:initiator] && key == :local,
|
13
14
|
accounting: { balance: { millisatoshis: grpc[:"#{key}_balance"] * 1000 } },
|
14
15
|
node: Node.list_channels(grpc, key)
|
15
16
|
}
|
@@ -16,9 +16,9 @@ module Lighstorm
|
|
16
16
|
def self.list_payments(grpc, node_get_info)
|
17
17
|
return 'unknown' if grpc[:htlcs].empty?
|
18
18
|
|
19
|
-
return 'self-payment' if self_payment?(grpc[:htlcs].
|
20
|
-
return 'peer-to-peer' if peer_to_peer?(grpc[:htlcs].
|
21
|
-
return 'rebalance' if rebalance?(grpc[:htlcs].
|
19
|
+
return 'self-payment' if self_payment?(grpc[:htlcs].last[:route][:hops])
|
20
|
+
return 'peer-to-peer' if peer_to_peer?(grpc[:htlcs].last[:route][:hops])
|
21
|
+
return 'rebalance' if rebalance?(grpc[:htlcs].last[:route][:hops], node_get_info)
|
22
22
|
|
23
23
|
'payment'
|
24
24
|
end
|
data/adapters/edges/payment.rb
CHANGED
@@ -30,8 +30,6 @@ module Lighstorm
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.list_payments(grpc, node_myself, invoice_decode = nil)
|
33
|
-
raise UnexpectedNumberOfHTLCsError, "htlcs: #{grpc[:htlcs].size}" if grpc[:htlcs].size > 1
|
34
|
-
|
35
33
|
data = {
|
36
34
|
_source: :list_payments,
|
37
35
|
_key: _key(grpc),
|
@@ -45,7 +43,7 @@ module Lighstorm
|
|
45
43
|
|
46
44
|
data[:secret] = data[:invoice][:secret]
|
47
45
|
|
48
|
-
htlc = grpc[:htlcs].
|
46
|
+
htlc = grpc[:htlcs].last
|
49
47
|
|
50
48
|
return data if htlc.nil?
|
51
49
|
|
data/adapters/invoice.rb
CHANGED
data/adapters/wallet.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Adapter
|
7
|
+
class Wallet
|
8
|
+
def self.balance(raw)
|
9
|
+
{
|
10
|
+
_key: Digest::SHA256.hexdigest(
|
11
|
+
[
|
12
|
+
raw[:at],
|
13
|
+
channel_balance(raw[:channel_balance])[:amount],
|
14
|
+
wallet_balance(raw[:wallet_balance])[:amount]
|
15
|
+
].join('/')
|
16
|
+
),
|
17
|
+
at: raw[:at],
|
18
|
+
bitcoin: wallet_balance(raw[:wallet_balance])[:amount],
|
19
|
+
lightning: channel_balance(raw[:channel_balance])[:amount],
|
20
|
+
total: { millisatoshis: (
|
21
|
+
wallet_balance(raw[:wallet_balance])[:amount][:millisatoshis] +
|
22
|
+
channel_balance(raw[:channel_balance])[:amount][:millisatoshis]
|
23
|
+
) }
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.wallet_balance(grpc)
|
28
|
+
{
|
29
|
+
_source: :wallet_balance,
|
30
|
+
amount: { millisatoshis: grpc[:total_balance] * 1000 }
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.channel_balance(grpc)
|
35
|
+
{
|
36
|
+
_source: :channel_balance,
|
37
|
+
amount: { millisatoshis: grpc[:local_balance][:msat] }
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/components/cache.rb
CHANGED
data/components/lnd.rb
CHANGED
@@ -33,23 +33,39 @@ module Lighstorm
|
|
33
33
|
LNDClient.add_connection!(@default_key, *params)
|
34
34
|
end
|
35
35
|
|
36
|
+
def as(id)
|
37
|
+
LNDClient.as(id)
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_connection!(...)
|
41
|
+
LNDClient.add_connection!(...)
|
42
|
+
end
|
43
|
+
|
44
|
+
def connections(...)
|
45
|
+
LNDClient.connections(...)
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_connection!(...)
|
49
|
+
LNDClient.remove_connection!(...)
|
50
|
+
end
|
51
|
+
|
36
52
|
def middleware(key, &block)
|
37
53
|
@middleware.call(key, &block)
|
38
54
|
end
|
39
55
|
|
56
|
+
def for(id)
|
57
|
+
as(id)&.connection
|
58
|
+
end
|
59
|
+
|
60
|
+
def default
|
61
|
+
client.connection.merge(id: @default_key)
|
62
|
+
end
|
63
|
+
|
40
64
|
def client
|
41
65
|
try_to_connect_from_environment_variables! unless LNDClient.connections.include?(@default_key)
|
42
66
|
LNDClient.as(@default_key)
|
43
67
|
end
|
44
68
|
|
45
|
-
def create_client_from_config
|
46
|
-
LNDClient.new(
|
47
|
-
socket_address: @config[:lnd_address],
|
48
|
-
certificate_path: @config[:certificate_path],
|
49
|
-
macaroon_path: @config[:macaroon_path]
|
50
|
-
)
|
51
|
-
end
|
52
|
-
|
53
69
|
def try_to_connect_from_environment_variables!
|
54
70
|
return connect!(ENV.fetch('LIGHSTORM_LND_CONNECT')) if ENV.fetch('LIGHSTORM_LND_CONNECT', nil)
|
55
71
|
|
data/controllers/action.rb
CHANGED
@@ -4,6 +4,10 @@ module Lighstorm
|
|
4
4
|
module Controllers
|
5
5
|
module Action
|
6
6
|
Output = Struct.new(:data) do
|
7
|
+
def request
|
8
|
+
data[:request]
|
9
|
+
end
|
10
|
+
|
7
11
|
def response
|
8
12
|
data[:response]
|
9
13
|
end
|
@@ -14,6 +18,7 @@ module Lighstorm
|
|
14
18
|
|
15
19
|
def to_h
|
16
20
|
{
|
21
|
+
request: request,
|
17
22
|
response: response,
|
18
23
|
result: result.to_h
|
19
24
|
}
|
data/controllers/activity/all.rb
CHANGED
@@ -10,31 +10,91 @@ module Lighstorm
|
|
10
10
|
module Controllers
|
11
11
|
module Activity
|
12
12
|
module All
|
13
|
-
def self.
|
13
|
+
def self.bitcoin_how(transaction_label)
|
14
|
+
if transaction_label =~ /:openchannel:/
|
15
|
+
'opening-channel'
|
16
|
+
elsif transaction_label =~ /:closechannel:/
|
17
|
+
'closing-channel'
|
18
|
+
else
|
19
|
+
'spontaneously'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.fetch(components, direction: nil, layer: nil, how: nil, order: nil, limit: nil)
|
14
24
|
activities = []
|
15
25
|
|
16
|
-
|
17
|
-
|
26
|
+
# components[:grpc].lightning.list_channels.channels.each do |channel|
|
27
|
+
# if (layer.nil? || layer == 'lightning')
|
28
|
+
# activities << {
|
29
|
+
# direction: 'out',
|
30
|
+
# layer: 'lightning',
|
31
|
+
# at: Time.now,
|
32
|
+
# amount: {
|
33
|
+
# millisatoshis: channel.to_h[:local_chan_reserve_sat] * 1000
|
34
|
+
# },
|
35
|
+
# how: 'reserve',
|
36
|
+
# message: nil,
|
37
|
+
# data: {}
|
38
|
+
# }
|
39
|
+
|
40
|
+
# activities << {
|
41
|
+
# direction: 'out',
|
42
|
+
# layer: 'lightning',
|
43
|
+
# at: Time.now,
|
44
|
+
# amount: {
|
45
|
+
# millisatoshis: channel.to_h[:commit_fee] * 1000
|
46
|
+
# },
|
47
|
+
# how: 'commit',
|
48
|
+
# message: nil,
|
49
|
+
# data: {}
|
50
|
+
# }
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
|
54
|
+
Transaction::All.data(components).each do |transaction|
|
55
|
+
transaction_how = bitcoin_how(transaction[:label])
|
56
|
+
|
57
|
+
if (layer.nil? || layer == 'bitcoin') && (how.nil? || transaction_how =~ /#{Regexp.escape(how)}/)
|
58
|
+
activities << {
|
59
|
+
direction: (transaction[:amount][:millisatoshis]).positive? ? 'in' : 'out',
|
60
|
+
layer: 'bitcoin',
|
61
|
+
at: transaction[:at],
|
62
|
+
amount: {
|
63
|
+
millisatoshis: if (transaction[:amount][:millisatoshis]).positive?
|
64
|
+
transaction[:amount][:millisatoshis]
|
65
|
+
else
|
66
|
+
-transaction[:amount][:millisatoshis]
|
67
|
+
end
|
68
|
+
},
|
69
|
+
how: transaction_how,
|
70
|
+
message: nil,
|
71
|
+
data: { transaction: transaction }
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
next unless (layer.nil? || layer == 'lightning') && (how.nil? || transaction_how =~ /#{Regexp.escape(how)}/) && %w[
|
76
|
+
channel opening-channel closing-channel
|
77
|
+
].include?(transaction_how)
|
18
78
|
|
19
79
|
activities << {
|
20
|
-
direction: (transaction[:amount][:millisatoshis]).positive? ? '
|
21
|
-
layer: '
|
22
|
-
at: transaction[:at],
|
80
|
+
direction: (transaction[:amount][:millisatoshis]).positive? ? 'out' : 'in',
|
81
|
+
layer: 'lightning',
|
82
|
+
at: transaction[:at] + ((transaction[:amount][:millisatoshis]).positive? ? -1 : 1),
|
23
83
|
amount: {
|
24
84
|
millisatoshis: if (transaction[:amount][:millisatoshis]).positive?
|
25
|
-
transaction[:amount][:millisatoshis]
|
85
|
+
(transaction[:amount][:millisatoshis] - transaction[:fee][:millisatoshis])
|
26
86
|
else
|
27
|
-
-transaction[:amount][:millisatoshis]
|
87
|
+
-(transaction[:amount][:millisatoshis] + transaction[:fee][:millisatoshis])
|
28
88
|
end
|
29
89
|
},
|
30
|
-
how:
|
90
|
+
how: transaction_how,
|
31
91
|
message: nil,
|
32
92
|
data: { transaction: transaction }
|
33
93
|
}
|
34
94
|
end
|
35
95
|
|
36
|
-
if direction.nil? || direction == 'in'
|
37
|
-
Invoice::All.data(spontaneous: true).filter do |invoice|
|
96
|
+
if (direction.nil? || direction == 'in') && (layer.nil? || layer == 'lightning')
|
97
|
+
Invoice::All.data(components, spontaneous: true).filter do |invoice|
|
38
98
|
!invoice[:payments].nil? && invoice[:payments].size.positive?
|
39
99
|
end.each do |invoice|
|
40
100
|
activity_how = invoice[:code].nil? ? 'spontaneously' : 'with-invoice'
|
@@ -45,7 +105,7 @@ module Lighstorm
|
|
45
105
|
invoice[:payments].each do |payment|
|
46
106
|
activities << {
|
47
107
|
direction: 'in',
|
48
|
-
layer: '
|
108
|
+
layer: 'lightning',
|
49
109
|
at: payment[:at],
|
50
110
|
amount: payment[:amount],
|
51
111
|
how: activity_how,
|
@@ -55,12 +115,12 @@ module Lighstorm
|
|
55
115
|
end
|
56
116
|
end
|
57
117
|
|
58
|
-
Forward::All.data.each do |forward|
|
118
|
+
Forward::All.data(components).each do |forward|
|
59
119
|
next if !how.nil? && how != 'forwarding'
|
60
120
|
|
61
121
|
activities << {
|
62
122
|
direction: 'in',
|
63
|
-
layer: '
|
123
|
+
layer: 'lightning',
|
64
124
|
at: forward[:at],
|
65
125
|
amount: forward[:fee],
|
66
126
|
how: 'forwarding',
|
@@ -70,8 +130,9 @@ module Lighstorm
|
|
70
130
|
end
|
71
131
|
end
|
72
132
|
|
73
|
-
if direction.nil? || direction == 'out'
|
133
|
+
if (direction.nil? || direction == 'out') && (layer.nil? || layer == 'lightning')
|
74
134
|
Payment::All.data(
|
135
|
+
components,
|
75
136
|
fetch: {
|
76
137
|
get_node_info: false,
|
77
138
|
lookup_invoice: false,
|
@@ -86,7 +147,7 @@ module Lighstorm
|
|
86
147
|
# TODO: Improve performance by reducing invoice fields?
|
87
148
|
activities << {
|
88
149
|
direction: 'out',
|
89
|
-
layer: '
|
150
|
+
layer: 'lightning',
|
90
151
|
at: payment[:at],
|
91
152
|
amount: payment[:amount],
|
92
153
|
how: activity_how,
|
@@ -96,7 +157,11 @@ module Lighstorm
|
|
96
157
|
end
|
97
158
|
end
|
98
159
|
|
99
|
-
activities =
|
160
|
+
activities = if order.nil? || order == 'desc'
|
161
|
+
activities.sort_by { |activity| -activity[:at].to_i }
|
162
|
+
else
|
163
|
+
activities.sort_by { |activity| activity[:at].to_i }
|
164
|
+
end
|
100
165
|
|
101
166
|
activities = activities[0..limit - 1] unless limit.nil?
|
102
167
|
|
@@ -110,11 +175,11 @@ module Lighstorm
|
|
110
175
|
end
|
111
176
|
end
|
112
177
|
|
113
|
-
def self.data(direction: nil, how: nil, limit: nil, &vcr)
|
178
|
+
def self.data(components, direction: nil, layer: nil, how: nil, order: nil, limit: nil, &vcr)
|
114
179
|
raw = if vcr.nil?
|
115
|
-
fetch(direction: direction, how: how, limit: limit)
|
180
|
+
fetch(components, direction: direction, layer: layer, how: how, order: order, limit: limit)
|
116
181
|
else
|
117
|
-
vcr.call(-> { fetch(direction: direction, how: how, limit: limit) })
|
182
|
+
vcr.call(-> { fetch(components, direction: direction, how: how, order: order, limit: limit) })
|
118
183
|
end
|
119
184
|
|
120
185
|
transform(raw)
|
data/controllers/activity.rb
CHANGED
@@ -1,16 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative './concerns/impersonatable'
|
4
|
+
|
3
5
|
require_relative './activity/all'
|
4
6
|
|
5
7
|
module Lighstorm
|
6
8
|
module Controllers
|
7
9
|
module Activity
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
extend Impersonatable
|
11
|
+
|
12
|
+
class DSL < Impersonatable::DSL
|
13
|
+
def all(direction: nil, layer: nil, how: nil, order: nil, limit: nil)
|
14
|
+
All.model(All.data(
|
15
|
+
components,
|
16
|
+
direction: direction,
|
17
|
+
how: how,
|
18
|
+
layer: layer,
|
19
|
+
order: order,
|
20
|
+
limit: limit
|
21
|
+
))
|
22
|
+
end
|
14
23
|
end
|
15
24
|
end
|
16
25
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'securerandom'
|
4
4
|
|
5
|
-
require_relative '../../../ports/grpc'
|
6
5
|
require_relative '../../../models/errors'
|
7
6
|
require_relative '../../../models/edges/channel'
|
8
7
|
require_relative '../../../adapters/edges/channel'
|
@@ -41,7 +40,7 @@ module Lighstorm
|
|
41
40
|
].freeze
|
42
41
|
|
43
42
|
def self.perform(actual, gossip)
|
44
|
-
updated = Models::Channel.new(Adapter::Channel.subscribe_channel_graph(gossip))
|
43
|
+
updated = Models::Channel.new(Adapter::Channel.subscribe_channel_graph(gossip), nil)
|
45
44
|
|
46
45
|
actual_dump = actual.dump
|
47
46
|
updated_dump = updated.dump
|
@@ -99,7 +98,7 @@ module Lighstorm
|
|
99
98
|
when 'partners/0/policy/htlc/minimum/millisatoshis',
|
100
99
|
'partners/1/policy/htlc/minimum/millisatoshis' then
|
101
100
|
if actual.partners[change[:path][1]].policy.nil?
|
102
|
-
actual.partners[change[:path][1]].policy = Lighstorm::Models::Policy.new({})
|
101
|
+
actual.partners[change[:path][1]].policy = Lighstorm::Models::Policy.new({}, nil)
|
103
102
|
end
|
104
103
|
|
105
104
|
policy = actual.partners[change[:path][1]].policy
|
@@ -113,7 +112,7 @@ module Lighstorm
|
|
113
112
|
when 'partners/0/policy/htlc/blocks/delta/minimum',
|
114
113
|
'partners/1/policy/htlc/blocks/delta/minimum' then
|
115
114
|
if actual.partners[change[:path][1]].policy.nil?
|
116
|
-
actual.partners[change[:path][1]].policy = Lighstorm::Models::Policy.new({})
|
115
|
+
actual.partners[change[:path][1]].policy = Lighstorm::Models::Policy.new({}, nil)
|
117
116
|
end
|
118
117
|
|
119
118
|
policy = actual.partners[change[:path][1]].policy
|
@@ -46,22 +46,26 @@ module Lighstorm
|
|
46
46
|
grpc_request
|
47
47
|
end
|
48
48
|
|
49
|
-
def self.call(grpc_request)
|
50
|
-
|
49
|
+
def self.call(components, grpc_request)
|
50
|
+
components[:grpc].send(grpc_request[:service]).send(
|
51
51
|
grpc_request[:method], grpc_request[:params]
|
52
52
|
).to_h
|
53
53
|
end
|
54
54
|
|
55
|
-
def self.dispatch(grpc_request, &vcr)
|
56
|
-
vcr.nil?
|
55
|
+
def self.dispatch(components, grpc_request, &vcr)
|
56
|
+
if vcr.nil?
|
57
|
+
call(components, grpc_request)
|
58
|
+
else
|
59
|
+
vcr.call(-> { call(components, grpc_request) }, :dispatch)
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
|
-
def self.perform(policy, transaction, params, preview: false, &vcr)
|
63
|
+
def self.perform(components, policy, transaction, params, preview: false, &vcr)
|
60
64
|
grpc_request = prepare(policy.to_h, transaction.to_h, params)
|
61
65
|
|
62
66
|
return grpc_request if preview
|
63
67
|
|
64
|
-
response = dispatch(grpc_request, &vcr)
|
68
|
+
response = dispatch(components, grpc_request, &vcr)
|
65
69
|
|
66
70
|
raise UpdateChannelPolicyError.new(nil, response) unless response[:failed_updates].empty?
|
67
71
|
|
@@ -79,7 +83,7 @@ module Lighstorm
|
|
79
83
|
token: token
|
80
84
|
}
|
81
85
|
|
82
|
-
Action::Output.new({ response: response, result: policy })
|
86
|
+
Action::Output.new({ request: grpc_request, response: response, result: policy })
|
83
87
|
end
|
84
88
|
end
|
85
89
|
end
|
data/controllers/channel/all.rb
CHANGED
@@ -11,11 +11,11 @@ module Lighstorm
|
|
11
11
|
module Controllers
|
12
12
|
module Channel
|
13
13
|
module All
|
14
|
-
def self.fetch(limit: nil)
|
14
|
+
def self.fetch(components, limit: nil)
|
15
15
|
data = {
|
16
16
|
at: Time.now,
|
17
|
-
mine: Mine.fetch,
|
18
|
-
describe_graph:
|
17
|
+
mine: Mine.fetch(components),
|
18
|
+
describe_graph: components[:grpc].lightning.describe_graph.edges
|
19
19
|
}
|
20
20
|
|
21
21
|
data[:describe_graph] = data[:describe_graph][0..limit - 1] unless limit.nil?
|
@@ -60,17 +60,21 @@ module Lighstorm
|
|
60
60
|
data
|
61
61
|
end
|
62
62
|
|
63
|
-
def self.data(limit: nil, &vcr)
|
64
|
-
raw = vcr.nil?
|
63
|
+
def self.data(components, limit: nil, &vcr)
|
64
|
+
raw = if vcr.nil?
|
65
|
+
fetch(components, limit: limit)
|
66
|
+
else
|
67
|
+
vcr.call(-> { fetch(components, limit: limit) })
|
68
|
+
end
|
65
69
|
|
66
70
|
adapted = adapt(raw)
|
67
71
|
|
68
72
|
adapted[:describe_graph].map { |data| transform(data, adapted) }
|
69
73
|
end
|
70
74
|
|
71
|
-
def self.model(data)
|
75
|
+
def self.model(data, components)
|
72
76
|
data.map do |node_data|
|
73
|
-
Lighstorm::Models::Channel.new(node_data)
|
77
|
+
Lighstorm::Models::Channel.new(node_data, components)
|
74
78
|
end
|
75
79
|
end
|
76
80
|
end
|
@@ -11,22 +11,22 @@ module Lighstorm
|
|
11
11
|
module Controllers
|
12
12
|
module Channel
|
13
13
|
module FindById
|
14
|
-
def self.fetch(id)
|
14
|
+
def self.fetch(components, id)
|
15
15
|
data = {
|
16
16
|
at: Time.now,
|
17
|
-
get_info:
|
17
|
+
get_info: components[:grpc].lightning.get_info.to_h,
|
18
18
|
# Ensure that we are getting fresh up-date data about our own fees.
|
19
|
-
fee_report:
|
20
|
-
get_chan_info:
|
19
|
+
fee_report: components[:grpc].lightning.fee_report.to_h,
|
20
|
+
get_chan_info: components[:grpc].lightning.get_chan_info(chan_id: id.to_i).to_h,
|
21
21
|
get_node_info: {},
|
22
22
|
list_channels: []
|
23
23
|
}
|
24
24
|
|
25
|
-
data[:get_node_info][data[:get_chan_info][:node1_pub]] =
|
25
|
+
data[:get_node_info][data[:get_chan_info][:node1_pub]] = components[:grpc].lightning.get_node_info(
|
26
26
|
pub_key: data[:get_chan_info][:node1_pub]
|
27
27
|
).to_h
|
28
28
|
|
29
|
-
data[:get_node_info][data[:get_chan_info][:node2_pub]] =
|
29
|
+
data[:get_node_info][data[:get_chan_info][:node2_pub]] = components[:grpc].lightning.get_node_info(
|
30
30
|
pub_key: data[:get_chan_info][:node2_pub]
|
31
31
|
).to_h
|
32
32
|
|
@@ -40,7 +40,7 @@ module Lighstorm
|
|
40
40
|
if is_mine
|
41
41
|
partner = partners.find { |p| p != data[:get_info][:identity_pubkey] }
|
42
42
|
|
43
|
-
data[:list_channels] =
|
43
|
+
data[:list_channels] = components[:grpc].lightning.list_channels(
|
44
44
|
peer: [partner].pack('H*')
|
45
45
|
).channels.map(&:to_h)
|
46
46
|
end
|
@@ -136,16 +136,16 @@ module Lighstorm
|
|
136
136
|
data
|
137
137
|
end
|
138
138
|
|
139
|
-
def self.data(id, &vcr)
|
140
|
-
raw = vcr.nil? ? fetch(id) : vcr.call(-> { fetch(id) })
|
139
|
+
def self.data(components, id, &vcr)
|
140
|
+
raw = vcr.nil? ? fetch(components, id) : vcr.call(-> { fetch(components, id) })
|
141
141
|
|
142
142
|
adapted = adapt(raw)
|
143
143
|
|
144
144
|
transform(adapted[:get_chan_info], adapted)
|
145
145
|
end
|
146
146
|
|
147
|
-
def self.model(data)
|
148
|
-
Lighstorm::Models::Channel.new(data)
|
147
|
+
def self.model(data, components)
|
148
|
+
Lighstorm::Models::Channel.new(data, components)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
data/controllers/channel/mine.rb
CHANGED
@@ -9,27 +9,27 @@ module Lighstorm
|
|
9
9
|
module Controllers
|
10
10
|
module Channel
|
11
11
|
module Mine
|
12
|
-
def self.fetch
|
12
|
+
def self.fetch(components)
|
13
13
|
data = {
|
14
14
|
at: Time.now,
|
15
|
-
get_info:
|
15
|
+
get_info: components[:grpc].lightning.get_info.to_h,
|
16
16
|
# Ensure that we are getting fresh up-date data about our own fees.
|
17
|
-
fee_report:
|
18
|
-
list_channels:
|
17
|
+
fee_report: components[:grpc].lightning.fee_report.to_h,
|
18
|
+
list_channels: components[:grpc].lightning.list_channels.channels.map(&:to_h),
|
19
19
|
get_chan_info: {},
|
20
20
|
get_node_info: {}
|
21
21
|
}
|
22
22
|
|
23
23
|
data[:list_channels].each do |channel|
|
24
24
|
unless data[:get_chan_info][channel[:chan_id]]
|
25
|
-
data[:get_chan_info][channel[:chan_id]] =
|
25
|
+
data[:get_chan_info][channel[:chan_id]] = components[:grpc].lightning.get_chan_info(
|
26
26
|
chan_id: channel[:chan_id]
|
27
27
|
).to_h
|
28
28
|
end
|
29
29
|
|
30
30
|
next if data[:get_node_info][channel[:remote_pubkey]]
|
31
31
|
|
32
|
-
data[:get_node_info][channel[:remote_pubkey]] =
|
32
|
+
data[:get_node_info][channel[:remote_pubkey]] = components[:grpc].lightning.get_node_info(
|
33
33
|
pub_key: channel[:remote_pubkey]
|
34
34
|
).to_h
|
35
35
|
end
|
@@ -95,17 +95,17 @@ module Lighstorm
|
|
95
95
|
data
|
96
96
|
end
|
97
97
|
|
98
|
-
def self.data(&vcr)
|
99
|
-
raw = vcr.nil? ? fetch : vcr.call(-> { fetch })
|
98
|
+
def self.data(components, &vcr)
|
99
|
+
raw = vcr.nil? ? fetch(components) : vcr.call(-> { fetch(components) })
|
100
100
|
|
101
101
|
adapted = adapt(raw)
|
102
102
|
|
103
103
|
adapted[:list_channels].map { |data| transform(data, adapted) }
|
104
104
|
end
|
105
105
|
|
106
|
-
def self.model(data)
|
106
|
+
def self.model(data, components)
|
107
107
|
data.map do |node_data|
|
108
|
-
Lighstorm::Models::Channel.new(node_data)
|
108
|
+
Lighstorm::Models::Channel.new(node_data, components)
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|