lighstorm 0.0.14 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -7
- data/README.md +7 -7
- data/adapters/bitcoin/address.rb +19 -0
- data/adapters/bitcoin/transaction.rb +34 -0
- data/adapters/lightning/connections/channel_node/fee.rb +28 -0
- data/adapters/lightning/connections/channel_node/policy.rb +63 -0
- data/adapters/lightning/connections/channel_node.rb +77 -0
- data/adapters/lightning/connections/payment_channel.rb +30 -0
- data/adapters/lightning/edges/channel.rb +98 -0
- data/adapters/lightning/edges/forward.rb +42 -0
- data/adapters/lightning/edges/payment/purpose.rb +45 -0
- data/adapters/lightning/edges/payment.rb +89 -0
- data/adapters/lightning/invoice.rb +186 -0
- data/adapters/lightning/nodes/node.rb +113 -0
- data/controllers/action.rb +1 -1
- data/controllers/bitcoin/address/actions/create.rb +91 -0
- data/controllers/bitcoin/address/actions/pay.rb +119 -0
- data/controllers/bitcoin/address.rb +24 -0
- data/controllers/bitcoin/transaction/all.rb +65 -0
- data/controllers/bitcoin/transaction.rb +25 -0
- data/controllers/concerns/impersonatable.rb +5 -3
- data/controllers/connection.rb +1 -1
- data/controllers/lightning/channel/actions/apply_gossip.rb +201 -0
- data/controllers/lightning/channel/actions/update_fee.rb +94 -0
- data/controllers/lightning/channel/all.rb +85 -0
- data/controllers/lightning/channel/find_by_id.rb +155 -0
- data/controllers/lightning/channel/mine.rb +116 -0
- data/controllers/lightning/channel.rb +43 -0
- data/controllers/lightning/forward/all.rb +250 -0
- data/controllers/lightning/forward/group_by_channel.rb +91 -0
- data/controllers/lightning/forward.rb +36 -0
- data/controllers/lightning/invoice/actions/create.rb +90 -0
- data/controllers/lightning/invoice/actions/pay.rb +97 -0
- data/controllers/lightning/invoice/actions/pay_through_route.rb +73 -0
- data/controllers/lightning/invoice/all.rb +82 -0
- data/controllers/lightning/invoice/decode.rb +50 -0
- data/controllers/lightning/invoice/find_by_code.rb +76 -0
- data/controllers/lightning/invoice/find_by_secret_hash.rb +56 -0
- data/controllers/lightning/invoice.rb +64 -0
- data/controllers/lightning/node/actions/apply_gossip.rb +114 -0
- data/controllers/lightning/node/actions/pay.rb +117 -0
- data/controllers/lightning/node/all.rb +69 -0
- data/controllers/lightning/node/find_by_public_key.rb +55 -0
- data/controllers/lightning/node/myself.rb +36 -0
- data/controllers/lightning/node.rb +35 -0
- data/controllers/lightning/payment/actions/pay.rb +110 -0
- data/controllers/lightning/payment/all.rb +439 -0
- data/controllers/lightning/payment.rb +37 -0
- data/controllers/lightning/secret/valid_proof.rb +60 -0
- data/controllers/lightning/secret.rb +16 -0
- data/controllers/wallet/activity/all.rb +196 -0
- data/controllers/wallet/activity.rb +28 -0
- data/controllers/wallet/balance.rb +3 -3
- data/controllers/wallet.rb +1 -1
- data/docs/README.md +229 -148
- data/docs/_coverpage.md +1 -1
- data/docs/index.html +1 -1
- data/lighstorm.gemspec +1 -1
- data/models/bitcoin/address.rb +49 -0
- data/models/bitcoin/transaction.rb +41 -0
- data/models/concerns/protectable.rb +1 -1
- data/models/errors.rb +7 -8
- data/models/lightning/connections/channel_node/accounting.rb +27 -0
- data/models/lightning/connections/channel_node/fee.rb +82 -0
- data/models/lightning/connections/channel_node/htlc/blocks/delta.rb +41 -0
- data/models/lightning/connections/channel_node/htlc.rb +88 -0
- data/models/lightning/connections/channel_node/policy.rb +41 -0
- data/models/lightning/connections/channel_node.rb +86 -0
- data/models/lightning/connections/forward_channel.rb +31 -0
- data/models/lightning/connections/payment_channel.rb +58 -0
- data/models/lightning/edges/channel/accounting.rb +87 -0
- data/models/lightning/edges/channel/hop.rb +67 -0
- data/models/lightning/edges/channel.rb +197 -0
- data/models/lightning/edges/forward.rb +51 -0
- data/models/lightning/edges/groups/channel_forwards/analysis.rb +71 -0
- data/models/lightning/edges/groups/channel_forwards.rb +39 -0
- data/models/lightning/edges/payment.rb +104 -0
- data/models/lightning/invoice.rb +115 -0
- data/models/lightning/nodes/node/lightning.rb +33 -0
- data/models/lightning/nodes/node/platform.rb +50 -0
- data/models/lightning/nodes/node.rb +145 -0
- data/models/lightning/rate.rb +37 -0
- data/models/lightning/secret.rb +57 -0
- data/models/satoshis.rb +1 -1
- data/models/wallet/activity.rb +54 -0
- data/models/wallet/balance.rb +42 -0
- data/ports/dsl/lighstorm.rb +29 -16
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +76 -70
- data/adapters/connections/channel_node/fee.rb +0 -26
- data/adapters/connections/channel_node/policy.rb +0 -61
- data/adapters/connections/channel_node.rb +0 -75
- data/adapters/connections/payment_channel.rb +0 -28
- data/adapters/edges/channel.rb +0 -96
- data/adapters/edges/forward.rb +0 -40
- data/adapters/edges/payment/purpose.rb +0 -43
- data/adapters/edges/payment.rb +0 -87
- data/adapters/invoice.rb +0 -184
- data/adapters/nodes/node.rb +0 -111
- data/adapters/transaction.rb +0 -23
- data/controllers/activity/all.rb +0 -194
- data/controllers/activity.rb +0 -26
- data/controllers/channel/actions/apply_gossip.rb +0 -193
- data/controllers/channel/actions/update_fee.rb +0 -91
- data/controllers/channel/all.rb +0 -83
- data/controllers/channel/find_by_id.rb +0 -153
- data/controllers/channel/mine.rb +0 -114
- data/controllers/channel.rb +0 -41
- data/controllers/forward/all.rb +0 -248
- data/controllers/forward/group_by_channel.rb +0 -89
- data/controllers/forward.rb +0 -34
- data/controllers/invoice/actions/create.rb +0 -88
- data/controllers/invoice/actions/pay.rb +0 -95
- data/controllers/invoice/actions/pay_through_route.rb +0 -71
- data/controllers/invoice/all.rb +0 -80
- data/controllers/invoice/decode.rb +0 -44
- data/controllers/invoice/find_by_code.rb +0 -70
- data/controllers/invoice/find_by_secret_hash.rb +0 -54
- data/controllers/invoice.rb +0 -62
- data/controllers/node/actions/apply_gossip.rb +0 -112
- data/controllers/node/actions/pay.rb +0 -115
- data/controllers/node/all.rb +0 -67
- data/controllers/node/find_by_public_key.rb +0 -53
- data/controllers/node/myself.rb +0 -34
- data/controllers/node.rb +0 -33
- data/controllers/payment/actions/pay.rb +0 -108
- data/controllers/payment/all.rb +0 -437
- data/controllers/payment.rb +0 -35
- data/controllers/secret/valid_proof.rb +0 -58
- data/controllers/transaction/all.rb +0 -61
- data/controllers/transaction.rb +0 -25
- data/models/activity.rb +0 -52
- data/models/connections/channel_node/accounting.rb +0 -25
- data/models/connections/channel_node/fee.rb +0 -80
- data/models/connections/channel_node/htlc/blocks/delta.rb +0 -39
- data/models/connections/channel_node/htlc.rb +0 -86
- data/models/connections/channel_node/policy.rb +0 -39
- data/models/connections/channel_node.rb +0 -84
- data/models/connections/forward_channel.rb +0 -29
- data/models/connections/payment_channel.rb +0 -56
- data/models/edges/channel/accounting.rb +0 -85
- data/models/edges/channel/hop.rb +0 -65
- data/models/edges/channel.rb +0 -195
- data/models/edges/forward.rb +0 -49
- data/models/edges/groups/channel_forwards/analysis.rb +0 -69
- data/models/edges/groups/channel_forwards.rb +0 -37
- data/models/edges/payment.rb +0 -102
- data/models/invoice.rb +0 -113
- data/models/nodes/node/lightning.rb +0 -31
- data/models/nodes/node/platform.rb +0 -48
- data/models/nodes/node.rb +0 -143
- data/models/rate.rb +0 -35
- data/models/secret.rb +0 -55
- data/models/transaction.rb +0 -39
- data/models/wallet.rb +0 -40
data/adapters/invoice.rb
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'digest'
|
4
|
-
|
5
|
-
require_relative '../ports/dsl/lighstorm/errors'
|
6
|
-
|
7
|
-
module Lighstorm
|
8
|
-
module Adapter
|
9
|
-
class Invoice
|
10
|
-
def self.add_invoice(grpc)
|
11
|
-
{
|
12
|
-
_source: :add_invoice,
|
13
|
-
code: grpc[:payment_request],
|
14
|
-
address: grpc[:payment_addr].unpack1('H*'),
|
15
|
-
secret: {
|
16
|
-
hash: grpc[:r_hash].unpack1('H*')
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.decode_pay_req(grpc, code = nil)
|
22
|
-
adapted = {
|
23
|
-
_source: :decode_pay_req,
|
24
|
-
_key: Digest::SHA256.hexdigest(
|
25
|
-
[
|
26
|
-
grpc[:payment_hash],
|
27
|
-
grpc[:num_satoshis],
|
28
|
-
grpc[:timestamp],
|
29
|
-
grpc[:payment_addr]
|
30
|
-
].join('/')
|
31
|
-
),
|
32
|
-
payable: 'once',
|
33
|
-
created_at: Time.at(grpc[:timestamp]),
|
34
|
-
expires_at: Time.at(grpc[:timestamp] + grpc[:expiry]),
|
35
|
-
amount: (grpc[:num_msat]).zero? ? nil : { millisatoshis: grpc[:num_msat] },
|
36
|
-
description: {
|
37
|
-
memo: grpc[:description].empty? ? nil : grpc[:description],
|
38
|
-
hash: grpc[:description_hash] == '' ? nil : grpc[:description_hash]
|
39
|
-
},
|
40
|
-
address: grpc[:payment_addr].unpack1('H*'),
|
41
|
-
secret: {
|
42
|
-
hash: grpc[:payment_hash]
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
adapted[:code] = code unless code.nil?
|
47
|
-
|
48
|
-
if grpc[:features].key?(30) && grpc[:features][30][:is_required]
|
49
|
-
raise "unexpected feature[30] name #{grpc[:features][30][:name]}" if grpc[:features][30][:name] != 'amp'
|
50
|
-
|
51
|
-
adapted[:payable] = 'indefinitely'
|
52
|
-
end
|
53
|
-
|
54
|
-
adapted
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.lookup_invoice(grpc, at)
|
58
|
-
adapted = list_or_lookup_invoice(grpc, at)
|
59
|
-
adapted[:_source] = :lookup_invoice
|
60
|
-
adapted
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.list_invoices(grpc, at)
|
64
|
-
adapted = list_or_lookup_invoice(grpc, at)
|
65
|
-
adapted[:_source] = :list_invoices
|
66
|
-
adapted
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.list_or_lookup_invoice(grpc, at)
|
70
|
-
raise 'missing at' if at.nil?
|
71
|
-
|
72
|
-
adapted = {
|
73
|
-
_key: _key(grpc),
|
74
|
-
created_at: Time.at(grpc[:creation_date]),
|
75
|
-
expires_at: Time.at(grpc[:creation_date] + grpc[:expiry]),
|
76
|
-
settled_at: grpc[:settle_date].nil? || !grpc[:settle_date].positive? ? nil : Time.at(grpc[:settle_date]),
|
77
|
-
state: grpc[:state].to_s.downcase,
|
78
|
-
code: grpc[:payment_request].empty? ? nil : grpc[:payment_request],
|
79
|
-
payable: grpc[:is_amp] == true ? 'indefinitely' : 'once',
|
80
|
-
description: {
|
81
|
-
memo: grpc[:memo].empty? ? nil : grpc[:memo],
|
82
|
-
hash: grpc[:description_hash].empty? ? nil : grpc[:description_hash]
|
83
|
-
},
|
84
|
-
address: grpc[:payment_addr].unpack1('H*'),
|
85
|
-
secret: {
|
86
|
-
preimage: grpc[:r_preimage].empty? ? nil : grpc[:r_preimage].unpack1('H*'),
|
87
|
-
hash: grpc[:r_hash].empty? ? nil : grpc[:r_hash].unpack1('H*')
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
adapted[:amount] = { millisatoshis: grpc[:value_msat] } if grpc[:value_msat] != 0
|
92
|
-
|
93
|
-
adapted[:received] = { millisatoshis: grpc[:amt_paid_msat] } if grpc[:amt_paid_msat] != 0
|
94
|
-
|
95
|
-
if adapted[:state] == 'settled' &&
|
96
|
-
adapted[:payable] == 'indefinitely' &&
|
97
|
-
adapted[:expires_at] > at
|
98
|
-
adapted[:state] = 'open'
|
99
|
-
end
|
100
|
-
|
101
|
-
raise 'todo: received with canceled' if !adapted[:received].nil? && adapted[:state] == 'canceled'
|
102
|
-
|
103
|
-
adapted[:payments] = []
|
104
|
-
|
105
|
-
grpc[:htlcs].each do |htlc|
|
106
|
-
next unless htlc[:state] == :SETTLED
|
107
|
-
|
108
|
-
payment = {
|
109
|
-
amount: { millisatoshis: htlc[:amt_msat] },
|
110
|
-
hops: [{ channel: { id: htlc[:chan_id] } }],
|
111
|
-
at: Time.at(htlc[:resolve_time])
|
112
|
-
}
|
113
|
-
|
114
|
-
if grpc[:is_amp]
|
115
|
-
payment[:secret] = {
|
116
|
-
preimage: htlc[:amp][:preimage].unpack1('H*'),
|
117
|
-
hash: htlc[:amp][:hash].unpack1('H*')
|
118
|
-
}
|
119
|
-
end
|
120
|
-
|
121
|
-
# https://github.com/satoshisstream/satoshis.stream/blob/main/TLV_registry.md
|
122
|
-
if htlc[:custom_records][34_349_334]
|
123
|
-
payment[:message] = htlc[:custom_records][34_349_334].dup
|
124
|
-
|
125
|
-
unless payment[:message].force_encoding('UTF-8').valid_encoding?
|
126
|
-
payment[:message] = payment[:message].unpack1('H*')
|
127
|
-
|
128
|
-
unless payment[:message].force_encoding('UTF-8').valid_encoding?
|
129
|
-
payment[:message] = payment[:message].scrub('?')
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
adapted[:payments] << payment
|
135
|
-
end
|
136
|
-
|
137
|
-
adapted[:payments] = adapted[:payments].sort_by { |payment| -payment[:at].to_i }
|
138
|
-
|
139
|
-
adapted.delete(:payments) if adapted[:payments].empty?
|
140
|
-
|
141
|
-
adapted
|
142
|
-
end
|
143
|
-
|
144
|
-
def self.list_payments(grpc, invoice_decode = nil)
|
145
|
-
data = {
|
146
|
-
_key: _key(grpc),
|
147
|
-
_source: :list_payments,
|
148
|
-
created_at: Time.at(grpc[:creation_date]),
|
149
|
-
settled_at: grpc[:settle_date].nil? || !grpc[:settle_date].positive? ? nil : Time.at(grpc[:settle_date]),
|
150
|
-
state: nil,
|
151
|
-
payable: grpc[:is_amp] == true ? 'indefinitely' : 'once',
|
152
|
-
code: grpc[:payment_request].empty? ? nil : grpc[:payment_request],
|
153
|
-
amount: { millisatoshis: grpc[:value_msat] },
|
154
|
-
description: {
|
155
|
-
memo: grpc[:memo],
|
156
|
-
hash: grpc[:description_hash] == '' ? nil : grpc[:description_hash]
|
157
|
-
},
|
158
|
-
secret: {
|
159
|
-
preimage: grpc[:payment_preimage],
|
160
|
-
hash: grpc[:payment_hash]
|
161
|
-
}
|
162
|
-
}
|
163
|
-
|
164
|
-
unless invoice_decode.nil?
|
165
|
-
data[:payable] = invoice_decode[:payable]
|
166
|
-
data[:expires_at] = invoice_decode[:expires_at]
|
167
|
-
end
|
168
|
-
|
169
|
-
data
|
170
|
-
end
|
171
|
-
|
172
|
-
def self._key(grpc)
|
173
|
-
Digest::SHA256.hexdigest(
|
174
|
-
[
|
175
|
-
grpc[:creation_date],
|
176
|
-
grpc[:settle_date],
|
177
|
-
grpc[:payment_request],
|
178
|
-
grpc[:state]
|
179
|
-
].join('/')
|
180
|
-
)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
data/adapters/nodes/node.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'digest'
|
4
|
-
|
5
|
-
module Lighstorm
|
6
|
-
module Adapter
|
7
|
-
class Node
|
8
|
-
def self._key(public_key)
|
9
|
-
Digest::SHA256.hexdigest(
|
10
|
-
[public_key].join('/')
|
11
|
-
)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.get_chan_info(grpc, index)
|
15
|
-
{
|
16
|
-
_source: :get_chan_info,
|
17
|
-
_key: _key(grpc[:"node#{index}_pub"]),
|
18
|
-
public_key: grpc[:"node#{index}_pub"]
|
19
|
-
}
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.list_channels(grpc, key)
|
23
|
-
data = {
|
24
|
-
_source: :list_channels,
|
25
|
-
_key: _key(key == :remote ? grpc[:remote_pubkey] : nil),
|
26
|
-
public_key: key == :remote ? grpc[:remote_pubkey] : nil
|
27
|
-
}
|
28
|
-
|
29
|
-
return nil if data[:public_key].nil?
|
30
|
-
|
31
|
-
data
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.get_info(grpc)
|
35
|
-
data = {
|
36
|
-
_source: :get_info,
|
37
|
-
_key: _key(grpc[:identity_pubkey]),
|
38
|
-
public_key: grpc[:identity_pubkey],
|
39
|
-
alias: grpc[:alias],
|
40
|
-
color: grpc[:color],
|
41
|
-
platform: {
|
42
|
-
blockchain: grpc[:chains][0][:chain],
|
43
|
-
network: grpc[:chains][0][:network],
|
44
|
-
lightning: {
|
45
|
-
implementation: 'lnd',
|
46
|
-
version: grpc[:version]
|
47
|
-
}
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
return nil if data[:public_key].nil? && data[:alias].nil? && data[:color].nil?
|
52
|
-
|
53
|
-
data
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.get_node_info(grpc)
|
57
|
-
data = {
|
58
|
-
_source: :get_node_info,
|
59
|
-
_key: _key(grpc[:node][:pub_key]),
|
60
|
-
public_key: grpc[:node][:pub_key],
|
61
|
-
alias: grpc[:node][:alias],
|
62
|
-
color: grpc[:node][:color]
|
63
|
-
}
|
64
|
-
|
65
|
-
return nil if data[:public_key].nil? && data[:alias].nil? && data[:color].nil?
|
66
|
-
|
67
|
-
data
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.describe_graph(grpc)
|
71
|
-
data = {
|
72
|
-
_source: :describe_graph,
|
73
|
-
_key: _key(grpc[:pub_key]),
|
74
|
-
public_key: grpc[:pub_key],
|
75
|
-
alias: grpc[:alias],
|
76
|
-
color: grpc[:color]
|
77
|
-
}
|
78
|
-
|
79
|
-
return nil if data[:public_key].nil? && data[:alias].nil? && data[:color].nil?
|
80
|
-
|
81
|
-
data
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.describe_graph_from_channel(grpc, index)
|
85
|
-
data = {
|
86
|
-
_source: :describe_graph,
|
87
|
-
_key: _key(grpc[:"node#{index}_pub"]),
|
88
|
-
public_key: grpc[:"node#{index}_pub"]
|
89
|
-
}
|
90
|
-
|
91
|
-
return nil if data[:public_key].nil?
|
92
|
-
|
93
|
-
data
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.subscribe_channel_graph(json)
|
97
|
-
data = {
|
98
|
-
_source: :subscribe_channel_graph,
|
99
|
-
_key: _key(json['identityKey']),
|
100
|
-
public_key: json['identityKey'],
|
101
|
-
alias: json['alias'],
|
102
|
-
color: json['color']
|
103
|
-
}
|
104
|
-
|
105
|
-
return nil if data[:public_key].nil? && data[:alias].nil? && data[:color].nil?
|
106
|
-
|
107
|
-
data
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
data/adapters/transaction.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'digest'
|
4
|
-
|
5
|
-
module Lighstorm
|
6
|
-
module Adapter
|
7
|
-
class Transaction
|
8
|
-
def self.get_transactions(grpc)
|
9
|
-
{
|
10
|
-
_source: :get_transactions,
|
11
|
-
_key: Digest::SHA256.hexdigest(
|
12
|
-
[grpc[:time_stamp], grpc[:tx_hash], grpc[:amount], grpc[:total_fees]].join('/')
|
13
|
-
),
|
14
|
-
at: Time.at(grpc[:time_stamp]),
|
15
|
-
amount: { millisatoshis: grpc[:amount] * 1000 },
|
16
|
-
fee: { millisatoshis: grpc[:total_fees] * 1000 },
|
17
|
-
hash: grpc[:tx_hash],
|
18
|
-
label: grpc[:label]
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/controllers/activity/all.rb
DELETED
@@ -1,194 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../invoice/all'
|
4
|
-
require_relative '../payment/all'
|
5
|
-
require_relative '../forward/all'
|
6
|
-
require_relative '../transaction/all'
|
7
|
-
require_relative '../../models/activity'
|
8
|
-
|
9
|
-
module Lighstorm
|
10
|
-
module Controllers
|
11
|
-
module Activity
|
12
|
-
module All
|
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)
|
24
|
-
activities = []
|
25
|
-
|
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)
|
78
|
-
|
79
|
-
activities << {
|
80
|
-
direction: (transaction[:amount][:millisatoshis]).positive? ? 'out' : 'in',
|
81
|
-
layer: 'lightning',
|
82
|
-
at: transaction[:at] + ((transaction[:amount][:millisatoshis]).positive? ? -1 : 1),
|
83
|
-
amount: {
|
84
|
-
millisatoshis: if (transaction[:amount][:millisatoshis]).positive?
|
85
|
-
(transaction[:amount][:millisatoshis] - transaction[:fee][:millisatoshis])
|
86
|
-
else
|
87
|
-
-(transaction[:amount][:millisatoshis] + transaction[:fee][:millisatoshis])
|
88
|
-
end
|
89
|
-
},
|
90
|
-
how: transaction_how,
|
91
|
-
message: nil,
|
92
|
-
data: { transaction: transaction }
|
93
|
-
}
|
94
|
-
end
|
95
|
-
|
96
|
-
if (direction.nil? || direction == 'in') && (layer.nil? || layer == 'lightning')
|
97
|
-
Invoice::All.data(components, spontaneous: true).filter do |invoice|
|
98
|
-
!invoice[:payments].nil? && invoice[:payments].size.positive?
|
99
|
-
end.each do |invoice|
|
100
|
-
activity_how = invoice[:code].nil? ? 'spontaneously' : 'with-invoice'
|
101
|
-
|
102
|
-
next if !how.nil? && how != activity_how
|
103
|
-
|
104
|
-
# TODO: Improve performance by reducing invoice fields and removing payments?
|
105
|
-
invoice[:payments].each do |payment|
|
106
|
-
activities << {
|
107
|
-
direction: 'in',
|
108
|
-
layer: 'lightning',
|
109
|
-
at: payment[:at],
|
110
|
-
amount: payment[:amount],
|
111
|
-
how: activity_how,
|
112
|
-
message: payment[:message],
|
113
|
-
data: { invoice: invoice }
|
114
|
-
}
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
Forward::All.data(components).each do |forward|
|
119
|
-
next if !how.nil? && how != 'forwarding'
|
120
|
-
|
121
|
-
activities << {
|
122
|
-
direction: 'in',
|
123
|
-
layer: 'lightning',
|
124
|
-
at: forward[:at],
|
125
|
-
amount: forward[:fee],
|
126
|
-
how: 'forwarding',
|
127
|
-
message: nil,
|
128
|
-
data: {}
|
129
|
-
}
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
if (direction.nil? || direction == 'out') && (layer.nil? || layer == 'lightning')
|
134
|
-
Payment::All.data(
|
135
|
-
components,
|
136
|
-
fetch: {
|
137
|
-
get_node_info: false,
|
138
|
-
lookup_invoice: false,
|
139
|
-
decode_pay_req: true,
|
140
|
-
get_chan_info: false
|
141
|
-
}
|
142
|
-
)[:data].each do |payment|
|
143
|
-
activity_how = payment[:invoice][:code].nil? ? 'spontaneously' : 'with-invoice'
|
144
|
-
|
145
|
-
next if !how.nil? && how != activity_how
|
146
|
-
|
147
|
-
# TODO: Improve performance by reducing invoice fields?
|
148
|
-
activities << {
|
149
|
-
direction: 'out',
|
150
|
-
layer: 'lightning',
|
151
|
-
at: payment[:at],
|
152
|
-
amount: payment[:amount],
|
153
|
-
how: activity_how,
|
154
|
-
message: payment[:message],
|
155
|
-
data: { invoice: payment[:invoice] }
|
156
|
-
}
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
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
|
165
|
-
|
166
|
-
activities = activities[0..limit - 1] unless limit.nil?
|
167
|
-
|
168
|
-
{ activities: activities }
|
169
|
-
end
|
170
|
-
|
171
|
-
def self.transform(raw)
|
172
|
-
raw[:activities].map do |activity|
|
173
|
-
activity[:_key] = SecureRandom.hex
|
174
|
-
activity
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
def self.data(components, direction: nil, layer: nil, how: nil, order: nil, limit: nil, &vcr)
|
179
|
-
raw = if vcr.nil?
|
180
|
-
fetch(components, direction: direction, layer: layer, how: how, order: order, limit: limit)
|
181
|
-
else
|
182
|
-
vcr.call(-> { fetch(components, direction: direction, how: how, order: order, limit: limit) })
|
183
|
-
end
|
184
|
-
|
185
|
-
transform(raw)
|
186
|
-
end
|
187
|
-
|
188
|
-
def self.model(data)
|
189
|
-
data.map { |data| Models::Activity.new(data) }
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
data/controllers/activity.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './concerns/impersonatable'
|
4
|
-
|
5
|
-
require_relative './activity/all'
|
6
|
-
|
7
|
-
module Lighstorm
|
8
|
-
module Controllers
|
9
|
-
module Activity
|
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
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|