lighstorm 0.0.15 → 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.lock +1 -1
- 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/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 +74 -68
- 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
@@ -1,44 +0,0 @@
|
|
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 Decode
|
11
|
-
def self.fetch(components, code)
|
12
|
-
{
|
13
|
-
_code: code,
|
14
|
-
decode_pay_req: components[:grpc].lightning.decode_pay_req(pay_req: code).to_h
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.adapt(raw)
|
19
|
-
{
|
20
|
-
decode_pay_req: Lighstorm::Adapter::Invoice.decode_pay_req(
|
21
|
-
raw[:decode_pay_req], raw[:_code]
|
22
|
-
)
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.transform(adapted)
|
27
|
-
adapted[:decode_pay_req]
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.data(components, code, &vcr)
|
31
|
-
raw = vcr.nil? ? fetch(components, code) : vcr.call(-> { fetch(components, code) })
|
32
|
-
|
33
|
-
adapted = adapt(raw)
|
34
|
-
|
35
|
-
transform(adapted)
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.model(data, components)
|
39
|
-
Lighstorm::Models::Invoice.new(data, components)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,70 +0,0 @@
|
|
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(components, code)
|
12
|
-
at = Time.now
|
13
|
-
|
14
|
-
decoded = components[:grpc].lightning.decode_pay_req(pay_req: code).to_h
|
15
|
-
|
16
|
-
{ response: {
|
17
|
-
at: at,
|
18
|
-
decode_pay_req: decoded,
|
19
|
-
lookup_invoice: components[: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(components, code, &vcr)
|
42
|
-
raw = vcr.nil? ? fetch(components, code) : vcr.call(-> { fetch(components, 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, components)
|
52
|
-
Lighstorm::Models::Invoice.new(data, components)
|
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
|
@@ -1,54 +0,0 @@
|
|
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 FindBySecretHash
|
11
|
-
def self.fetch(components, secret_hash)
|
12
|
-
{ response: {
|
13
|
-
at: Time.now,
|
14
|
-
lookup_invoice: components[:grpc].lightning.lookup_invoice(r_hash_str: secret_hash).to_h
|
15
|
-
}, exception: nil }
|
16
|
-
rescue StandardError => e
|
17
|
-
{ exception: e }
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.adapt(raw)
|
21
|
-
raise 'missing at' if raw[:at].nil?
|
22
|
-
|
23
|
-
{
|
24
|
-
lookup_invoice: Lighstorm::Adapter::Invoice.lookup_invoice(
|
25
|
-
raw[:lookup_invoice],
|
26
|
-
raw[:at]
|
27
|
-
)
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.transform(adapted)
|
32
|
-
adapted[:lookup_invoice][:known] = true
|
33
|
-
adapted[:lookup_invoice]
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.data(components, secret_hash, &vcr)
|
37
|
-
raw = if vcr.nil?
|
38
|
-
fetch(components, secret_hash)
|
39
|
-
else
|
40
|
-
vcr.call(-> { fetch(components, secret_hash) })
|
41
|
-
end
|
42
|
-
|
43
|
-
adapted = adapt(raw[:response])
|
44
|
-
|
45
|
-
transform(adapted)
|
46
|
-
end
|
47
|
-
|
48
|
-
def self.model(data, components)
|
49
|
-
Lighstorm::Models::Invoice.new(data, components)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
data/controllers/invoice.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './concerns/impersonatable'
|
4
|
-
|
5
|
-
require_relative './invoice/all'
|
6
|
-
require_relative './invoice/decode'
|
7
|
-
require_relative './invoice/find_by_secret_hash'
|
8
|
-
require_relative './invoice/find_by_code'
|
9
|
-
require_relative './invoice/actions/create'
|
10
|
-
|
11
|
-
module Lighstorm
|
12
|
-
module Controllers
|
13
|
-
module Invoice
|
14
|
-
extend Impersonatable
|
15
|
-
|
16
|
-
class DSL < Impersonatable::DSL
|
17
|
-
def all(limit: nil, spontaneous: false)
|
18
|
-
All.model(All.data(components, limit: limit, spontaneous: spontaneous), components)
|
19
|
-
end
|
20
|
-
|
21
|
-
def first
|
22
|
-
All.model(All.data(components), components).first
|
23
|
-
end
|
24
|
-
|
25
|
-
def last
|
26
|
-
All.model(All.data(components), components).last
|
27
|
-
end
|
28
|
-
|
29
|
-
def find_by_secret_hash(secret_hash, &vcr)
|
30
|
-
FindBySecretHash.model(FindBySecretHash.data(components, secret_hash, &vcr), components)
|
31
|
-
end
|
32
|
-
|
33
|
-
def find_by_code(code, &vcr)
|
34
|
-
FindByCode.model(FindByCode.data(components, code, &vcr), components)
|
35
|
-
end
|
36
|
-
|
37
|
-
def decode(code, &vcr)
|
38
|
-
Decode.model(Decode.data(components, code, &vcr), components)
|
39
|
-
end
|
40
|
-
|
41
|
-
def create(
|
42
|
-
payable:,
|
43
|
-
description: nil, amount: nil,
|
44
|
-
# Lightning Invoice Expiration: UX Considerations
|
45
|
-
# https://d.elor.me/2022/01/lightning-invoice-expiration-ux-considerations/
|
46
|
-
expires_in: { hours: 24 },
|
47
|
-
preview: false, &vcr
|
48
|
-
)
|
49
|
-
Create.perform(
|
50
|
-
components,
|
51
|
-
payable: payable,
|
52
|
-
description: description,
|
53
|
-
amount: amount,
|
54
|
-
expires_in: expires_in,
|
55
|
-
preview: preview,
|
56
|
-
&vcr
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securerandom'
|
4
|
-
|
5
|
-
require_relative '../../../ports/grpc'
|
6
|
-
require_relative '../../../models/errors'
|
7
|
-
require_relative '../../../models/nodes/node'
|
8
|
-
require_relative '../../../adapters/nodes/node'
|
9
|
-
|
10
|
-
module Lighstorm
|
11
|
-
module Controllers
|
12
|
-
module Node
|
13
|
-
module ApplyGossip
|
14
|
-
SKIPABLE = %w[
|
15
|
-
_source
|
16
|
-
_key
|
17
|
-
].freeze
|
18
|
-
|
19
|
-
NOT_ALLOWED = [
|
20
|
-
'public_key'
|
21
|
-
].freeze
|
22
|
-
|
23
|
-
APPLICABLE = %w[
|
24
|
-
alias
|
25
|
-
color
|
26
|
-
].freeze
|
27
|
-
|
28
|
-
def self.perform(actual, gossip)
|
29
|
-
updated = Models::Node.new(Adapter::Node.subscribe_channel_graph(gossip), nil)
|
30
|
-
|
31
|
-
actual_dump = actual.dump
|
32
|
-
updated_dump = updated.dump
|
33
|
-
|
34
|
-
diff = generate_diff(actual_dump, updated_dump)
|
35
|
-
|
36
|
-
diff.each do |change|
|
37
|
-
key = change[:path].join('/')
|
38
|
-
next unless NOT_ALLOWED.include?(key)
|
39
|
-
|
40
|
-
raise IncoherentGossipError, "Gossip doesn't belong to this Node"
|
41
|
-
end
|
42
|
-
|
43
|
-
diff.filter do |change|
|
44
|
-
key = change[:path].join('/')
|
45
|
-
if SKIPABLE.include?(key)
|
46
|
-
false
|
47
|
-
elsif APPLICABLE.include?(key)
|
48
|
-
apply!(actual, key, change)
|
49
|
-
true
|
50
|
-
else
|
51
|
-
raise Lighstorm::Errors::MissingGossipHandlerError, "don't know how to apply '#{key}'"
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.apply!(actual, key, change)
|
57
|
-
case key
|
58
|
-
when 'alias'
|
59
|
-
token = SecureRandom.hex
|
60
|
-
actual.prepare_token!(token)
|
61
|
-
actual.alias = {
|
62
|
-
value: change[:to],
|
63
|
-
token: token
|
64
|
-
}
|
65
|
-
when 'color'
|
66
|
-
token = SecureRandom.hex
|
67
|
-
actual.prepare_token!(token)
|
68
|
-
actual.color = {
|
69
|
-
value: change[:to],
|
70
|
-
token: token
|
71
|
-
}
|
72
|
-
else
|
73
|
-
raise Lighstorm::Errors::MissingGossipHandlerError, "don't know how to apply '#{key}'"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.generate_diff(actual, node, path = [], diff = [])
|
78
|
-
case node
|
79
|
-
when Hash
|
80
|
-
result = {}
|
81
|
-
node.each_key do |key|
|
82
|
-
result[key] = generate_diff(actual, node[key], path.dup.push(key), diff)
|
83
|
-
end
|
84
|
-
when Array
|
85
|
-
result = []
|
86
|
-
node.each_with_index do |value, i|
|
87
|
-
result << generate_diff(actual, value, path.dup.push(i), diff)
|
88
|
-
end
|
89
|
-
else
|
90
|
-
new_value = node
|
91
|
-
|
92
|
-
unless new_value.nil?
|
93
|
-
actual_value = actual
|
94
|
-
path.each do |key|
|
95
|
-
if actual_value[key]
|
96
|
-
actual_value = actual_value[key]
|
97
|
-
else
|
98
|
-
actual_value = nil
|
99
|
-
break
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
diff << { path: path, from: actual_value, to: new_value } if actual_value != new_value
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
diff
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securerandom'
|
4
|
-
require 'digest'
|
5
|
-
|
6
|
-
require_relative '../../../ports/grpc'
|
7
|
-
require_relative '../../../models/secret'
|
8
|
-
require_relative '../../../models/errors'
|
9
|
-
require_relative '../../../models/edges/payment'
|
10
|
-
require_relative '../../../adapters/edges/payment'
|
11
|
-
require_relative '../../invoice'
|
12
|
-
require_relative '../../action'
|
13
|
-
require_relative '../../node/myself'
|
14
|
-
|
15
|
-
require_relative '../../payment/actions/pay'
|
16
|
-
|
17
|
-
module Lighstorm
|
18
|
-
module Controllers
|
19
|
-
module Node
|
20
|
-
module Pay
|
21
|
-
def self.dispatch(components, grpc_request, &vcr)
|
22
|
-
Payment::Pay.dispatch(components, grpc_request, &vcr)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.fetch(components, &vcr)
|
26
|
-
Payment::Pay.fetch(components, &vcr)
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.adapt(data, node_get_info)
|
30
|
-
Payment::Pay.adapt(data, node_get_info)
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.model(data, components)
|
34
|
-
Payment::Pay.model(data, components)
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.prepare(public_key:, amount:, times_out_in:, secret:, through:, fee: nil, message: nil)
|
38
|
-
# Appreciation note for people that suffered in the past and shared
|
39
|
-
# their knowledge, so we don't have to struggle the same:
|
40
|
-
# - https://github.com/lightningnetwork/lnd/discussions/6357
|
41
|
-
# - https://docs.lightning.engineering/lightning-network-tools/lnd/send-messages-with-keysend
|
42
|
-
# - https://peakd.com/@brianoflondon/lightning-keysend-is-strange-and-how-to-send-keysend-payment-in-lightning-with-the-lnd-rest-api-via-python
|
43
|
-
# We are standing on the shoulders of giants, thank you very much. :)
|
44
|
-
request = {
|
45
|
-
service: :router,
|
46
|
-
method: :send_payment_v2,
|
47
|
-
params: {
|
48
|
-
dest: [public_key].pack('H*'),
|
49
|
-
amt_msat: amount[:millisatoshis],
|
50
|
-
timeout_seconds: Helpers::TimeExpression.seconds(times_out_in),
|
51
|
-
allow_self_payment: true,
|
52
|
-
dest_custom_records: {}
|
53
|
-
}
|
54
|
-
}
|
55
|
-
|
56
|
-
if !message.nil? && !message.empty?
|
57
|
-
# https://github.com/satoshisstream/satoshis.stream/blob/main/TLV_registry.md
|
58
|
-
request[:params][:dest_custom_records][34_349_334] = message
|
59
|
-
end
|
60
|
-
|
61
|
-
unless fee.nil? || fee[:maximum].nil? || fee[:maximum][:millisatoshis].nil?
|
62
|
-
request[:params][:fee_limit_msat] = fee[:maximum][:millisatoshis]
|
63
|
-
end
|
64
|
-
|
65
|
-
if through.to_sym == :keysend
|
66
|
-
request[:params][:payment_hash] = [secret[:hash]].pack('H*')
|
67
|
-
request[:params][:dest_custom_records][5_482_373_484] = [secret[:preimage]].pack('H*')
|
68
|
-
elsif through.to_sym == :amp
|
69
|
-
request[:params][:amp] = true
|
70
|
-
end
|
71
|
-
|
72
|
-
request[:params].delete(:dest_custom_records) if request[:params][:dest_custom_records].empty?
|
73
|
-
|
74
|
-
request
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.perform(
|
78
|
-
components,
|
79
|
-
public_key:, amount:, through:,
|
80
|
-
times_out_in:, fee: nil,
|
81
|
-
message: nil, secret: nil,
|
82
|
-
preview: false, &vcr
|
83
|
-
)
|
84
|
-
secret = Models::Secret.create.to_h if secret.nil? && through.to_sym == :keysend
|
85
|
-
|
86
|
-
grpc_request = prepare(
|
87
|
-
public_key: public_key,
|
88
|
-
amount: amount,
|
89
|
-
fee: fee,
|
90
|
-
through: through,
|
91
|
-
times_out_in: times_out_in,
|
92
|
-
secret: secret,
|
93
|
-
message: message
|
94
|
-
)
|
95
|
-
|
96
|
-
return grpc_request if preview
|
97
|
-
|
98
|
-
response = dispatch(components, grpc_request, &vcr)
|
99
|
-
|
100
|
-
Payment::Pay.raise_error_if_exists!(grpc_request, response)
|
101
|
-
|
102
|
-
data = fetch(components, &vcr)
|
103
|
-
|
104
|
-
adapted = adapt(response, data)
|
105
|
-
|
106
|
-
model = self.model(adapted, components)
|
107
|
-
|
108
|
-
Payment::Pay.raise_failure_if_exists!(model, grpc_request, response)
|
109
|
-
|
110
|
-
Action::Output.new({ request: grpc_request, response: response[:response], result: model })
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
data/controllers/node/all.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../ports/grpc'
|
4
|
-
require_relative '../../adapters/nodes/node'
|
5
|
-
|
6
|
-
module Lighstorm
|
7
|
-
module Controllers
|
8
|
-
module Node
|
9
|
-
module All
|
10
|
-
def self.fetch(components, limit: nil)
|
11
|
-
data = {
|
12
|
-
at: Time.now,
|
13
|
-
get_info: components[:grpc].lightning.get_info.to_h,
|
14
|
-
describe_graph: components[:grpc].lightning.describe_graph.nodes
|
15
|
-
}
|
16
|
-
|
17
|
-
data[:describe_graph] = data[:describe_graph][0..limit - 1] unless limit.nil?
|
18
|
-
|
19
|
-
data
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.adapt(raw)
|
23
|
-
{
|
24
|
-
get_info: Lighstorm::Adapter::Node.get_info(raw[:get_info]),
|
25
|
-
describe_graph: raw[:describe_graph].map do |raw|
|
26
|
-
Lighstorm::Adapter::Node.describe_graph(raw.to_h)
|
27
|
-
end
|
28
|
-
}
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.transform(describe_graph, get_info)
|
32
|
-
if get_info[:public_key] == describe_graph[:public_key]
|
33
|
-
get_info.merge(myself: true)
|
34
|
-
else
|
35
|
-
describe_graph.merge(
|
36
|
-
platform: {
|
37
|
-
blockchain: get_info[:platform][:blockchain],
|
38
|
-
network: get_info[:platform][:network]
|
39
|
-
},
|
40
|
-
myself: false
|
41
|
-
)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.data(components, limit: nil, &vcr)
|
46
|
-
raw = if vcr.nil?
|
47
|
-
fetch(components, limit: limit)
|
48
|
-
else
|
49
|
-
vcr.call(-> { fetch(components, limit: limit) })
|
50
|
-
end
|
51
|
-
|
52
|
-
adapted = adapt(raw)
|
53
|
-
|
54
|
-
adapted[:describe_graph].map do |data|
|
55
|
-
transform(data, adapted[:get_info])
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.model(data, components)
|
60
|
-
data.map do |node_data|
|
61
|
-
Lighstorm::Models::Node.new(node_data, components)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../ports/grpc'
|
4
|
-
require_relative '../../adapters/nodes/node'
|
5
|
-
|
6
|
-
module Lighstorm
|
7
|
-
module Controllers
|
8
|
-
module Node
|
9
|
-
module FindByPublicKey
|
10
|
-
def self.fetch(components, public_key)
|
11
|
-
{
|
12
|
-
at: Time.now,
|
13
|
-
get_info: components[:grpc].lightning.get_info.to_h,
|
14
|
-
get_node_info: components[:grpc].lightning.get_node_info(pub_key: public_key).to_h
|
15
|
-
}
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.adapt(raw)
|
19
|
-
{
|
20
|
-
get_info: Lighstorm::Adapter::Node.get_info(raw[:get_info]),
|
21
|
-
get_node_info: Lighstorm::Adapter::Node.get_node_info(raw[:get_node_info])
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.data(components, public_key, &vcr)
|
26
|
-
raw = if vcr.nil?
|
27
|
-
fetch(components, public_key)
|
28
|
-
else
|
29
|
-
vcr.call(-> { fetch(components, public_key) })
|
30
|
-
end
|
31
|
-
|
32
|
-
adapted = adapt(raw)
|
33
|
-
|
34
|
-
if adapted[:get_info][:public_key] == adapted[:get_node_info][:public_key]
|
35
|
-
adapted[:get_info].merge(myself: true)
|
36
|
-
else
|
37
|
-
adapted[:get_node_info].merge(
|
38
|
-
platform: {
|
39
|
-
blockchain: adapted[:get_info][:platform][:blockchain],
|
40
|
-
network: adapted[:get_info][:platform][:network]
|
41
|
-
},
|
42
|
-
myself: false
|
43
|
-
)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.model(data, components)
|
48
|
-
Lighstorm::Models::Node.new(data, components)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/controllers/node/myself.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../../ports/grpc'
|
4
|
-
require_relative '../../adapters/nodes/node'
|
5
|
-
|
6
|
-
module Lighstorm
|
7
|
-
module Controllers
|
8
|
-
module Node
|
9
|
-
module Myself
|
10
|
-
def self.fetch(components)
|
11
|
-
{
|
12
|
-
at: Time.now,
|
13
|
-
get_info: components[:grpc].lightning.get_info.to_h
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.adapt(raw)
|
18
|
-
{ get_info: Lighstorm::Adapter::Node.get_info(raw[:get_info]) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.data(components, &vcr)
|
22
|
-
raw = vcr.nil? ? fetch(components) : vcr.call(-> { fetch(components) })
|
23
|
-
|
24
|
-
adapted = adapt(raw)
|
25
|
-
adapted[:get_info].merge(myself: true)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.model(data, components)
|
29
|
-
Lighstorm::Models::Node.new(data, components)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/controllers/node.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative './concerns/impersonatable'
|
4
|
-
|
5
|
-
require_relative './node/myself'
|
6
|
-
require_relative './node/all'
|
7
|
-
require_relative './node/find_by_public_key'
|
8
|
-
|
9
|
-
module Lighstorm
|
10
|
-
module Controllers
|
11
|
-
module Node
|
12
|
-
extend Impersonatable
|
13
|
-
|
14
|
-
class DSL < Impersonatable::DSL
|
15
|
-
def myself
|
16
|
-
Myself.model(Myself.data(components), components)
|
17
|
-
end
|
18
|
-
|
19
|
-
def all(limit: nil)
|
20
|
-
All.model(All.data(components, limit: limit), components)
|
21
|
-
end
|
22
|
-
|
23
|
-
def find_by_public_key(public_key)
|
24
|
-
FindByPublicKey.model(FindByPublicKey.data(components, public_key), components)
|
25
|
-
end
|
26
|
-
|
27
|
-
def adapt(dump: nil, gossip: nil)
|
28
|
-
Models::Node.adapt(dump: dump, gossip: gossip)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|