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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0004783b50e9d57b22b89d956b84e88176902be82e1a6b42f4e4c4d1a385405c'
|
4
|
+
data.tar.gz: a153b71845e699695777c5b062a51e398ebf5d444c634b63fb2b6fc4b1523e8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abbeeace9a564c6cb06abc0a726dfa84e56907d4b92aaf4c6169945ff5f66fb82120046e5df233d5273034cf202e0230184554ba1f3a667522498907fae5095e
|
7
|
+
data.tar.gz: e7b887c4e3411621cdfc495f5b3026cf3b84f70b80bbca986c3b46f26f414eff0e7d02e99aab67659dd65dd5908e9ec6ca091ff7eae6c554d04e1b5eb1f04e85
|
data/Gemfile
CHANGED
@@ -10,7 +10,7 @@ group :test, :development do
|
|
10
10
|
gem 'rainbow', '~> 3.1', '>= 3.1.1'
|
11
11
|
gem 'rake', '~> 13.0', '>= 13.0.6'
|
12
12
|
gem 'rspec', '~> 3.12'
|
13
|
-
gem 'rubocop', '~> 1.48'
|
13
|
+
gem 'rubocop', '~> 1.48', '>= 1.48.1'
|
14
14
|
gem 'rubocop-rake', '~> 0.6.0'
|
15
15
|
gem 'rubocop-rspec', '~> 2.19'
|
16
16
|
end
|
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.16)
|
5
5
|
dotenv (~> 2.8, >= 2.8.1)
|
6
|
-
lnd-client (~> 0.0.
|
6
|
+
lnd-client (~> 0.0.9)
|
7
7
|
zache (~> 0.12.0)
|
8
8
|
|
9
9
|
GEM
|
@@ -18,12 +18,12 @@ GEM
|
|
18
18
|
google-protobuf (3.22.2-x86_64-linux)
|
19
19
|
googleapis-common-protos-types (1.5.0)
|
20
20
|
google-protobuf (~> 3.14)
|
21
|
-
grpc (1.
|
21
|
+
grpc (1.53.0-x86_64-linux)
|
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.
|
26
|
-
grpc (~> 1.
|
25
|
+
lnd-client (0.0.9)
|
26
|
+
grpc (~> 1.53)
|
27
27
|
method_source (1.0.0)
|
28
28
|
parallel (1.22.1)
|
29
29
|
parser (3.2.1.1)
|
@@ -61,7 +61,7 @@ GEM
|
|
61
61
|
rubocop-ast (>= 1.26.0, < 2.0)
|
62
62
|
ruby-progressbar (~> 1.7)
|
63
63
|
unicode-display_width (>= 2.4.0, < 3.0)
|
64
|
-
rubocop-ast (1.
|
64
|
+
rubocop-ast (1.28.0)
|
65
65
|
parser (>= 3.2.1.0)
|
66
66
|
rubocop-capybara (2.17.1)
|
67
67
|
rubocop (~> 1.41)
|
@@ -84,7 +84,7 @@ DEPENDENCIES
|
|
84
84
|
rainbow (~> 3.1, >= 3.1.1)
|
85
85
|
rake (~> 13.0, >= 13.0.6)
|
86
86
|
rspec (~> 3.12)
|
87
|
-
rubocop (~> 1.48)
|
87
|
+
rubocop (~> 1.48, >= 1.48.1)
|
88
88
|
rubocop-rake (~> 0.6.0)
|
89
89
|
rubocop-rspec (~> 2.19)
|
90
90
|
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ API for interacting with a [Lightning Node](https://lightning.network).
|
|
7
7
|
![Lighstorm text written stylized with an illustration of a Graph connecting two Nodes.](https://raw.githubusercontent.com/icebaker/assets/main/lighstorm/lighstorm.png)
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
Lighstorm::Channel.mine.first.myself.node.alias
|
10
|
+
Lighstorm::Lightning::Channel.mine.first.myself.node.alias
|
11
11
|
```
|
12
12
|
|
13
13
|
## Index
|
@@ -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.16'
|
39
39
|
```
|
40
40
|
|
41
41
|
```ruby
|
@@ -53,19 +53,19 @@ 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.16
|
57
57
|
|
58
|
-
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
58
|
+
Lighstorm::Lightning::Node.myself.alias # => icebaker/old-stone
|
59
59
|
|
60
|
-
Lighstorm::Invoice.create(
|
60
|
+
Lighstorm::Lightning::Invoice.create(
|
61
61
|
description: 'Coffee',
|
62
62
|
amount: { millisatoshis: 1_000 },
|
63
63
|
payable: 'once'
|
64
64
|
)
|
65
65
|
|
66
|
-
Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay
|
66
|
+
Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay
|
67
67
|
|
68
|
-
Lighstorm::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay(
|
68
|
+
Lighstorm::Lightning::Invoice.decode('lnbc20m1pv...qqdhhwkj').pay(
|
69
69
|
fee: { maximum: { millisatoshis: 1000 } }
|
70
70
|
)
|
71
71
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Adapter
|
7
|
+
module Bitcoin
|
8
|
+
class Address
|
9
|
+
def self.new_address(grpc)
|
10
|
+
{
|
11
|
+
_source: :new_address,
|
12
|
+
_key: Digest::SHA256.hexdigest([grpc[:address]].join('/')),
|
13
|
+
code: grpc[:address]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Adapter
|
7
|
+
module Bitcoin
|
8
|
+
class Transaction
|
9
|
+
def self.get_transactions(grpc)
|
10
|
+
{
|
11
|
+
_source: :get_transactions,
|
12
|
+
_key: Digest::SHA256.hexdigest(
|
13
|
+
[grpc[:time_stamp], grpc[:tx_hash], grpc[:amount], grpc[:total_fees]].join('/')
|
14
|
+
),
|
15
|
+
at: Time.at(grpc[:time_stamp]),
|
16
|
+
amount: { millisatoshis: (grpc[:amount] * 1000) + ((grpc[:amount].positive? ? -1 : 1) * (grpc[:total_fees] * 1000)) },
|
17
|
+
fee: { millisatoshis: grpc[:total_fees] * 1000 },
|
18
|
+
hash: grpc[:tx_hash],
|
19
|
+
description: grpc[:label] == '' ? nil : grpc[:label],
|
20
|
+
to: { address: { code: grpc[:dest_addresses].first } }
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.send_coins(grpc)
|
25
|
+
{
|
26
|
+
_source: :send_coins,
|
27
|
+
_key: Digest::SHA256.hexdigest([grpc[:txid]].join('/')),
|
28
|
+
hash: grpc[:txid]
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lighstorm
|
4
|
+
module Adapter
|
5
|
+
module Lightning
|
6
|
+
class Fee
|
7
|
+
def self.fee_report(grpc)
|
8
|
+
{
|
9
|
+
_source: :fee_report,
|
10
|
+
id: grpc[:chan_id].to_s,
|
11
|
+
partner: {
|
12
|
+
policy: {
|
13
|
+
fee: {
|
14
|
+
base: {
|
15
|
+
millisatoshis: grpc[:base_fee_msat]
|
16
|
+
},
|
17
|
+
rate: {
|
18
|
+
parts_per_million: grpc[:fee_per_mil]
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lighstorm
|
4
|
+
module Adapter
|
5
|
+
module Lightning
|
6
|
+
class Policy
|
7
|
+
def self.get_chan_info(grpc)
|
8
|
+
{
|
9
|
+
fee: {
|
10
|
+
base: { millisatoshis: grpc[:fee_base_msat] },
|
11
|
+
rate: { parts_per_million: grpc[:fee_rate_milli_msat] }
|
12
|
+
},
|
13
|
+
htlc: {
|
14
|
+
minimum: { millisatoshis: grpc[:min_htlc] },
|
15
|
+
maximum: { millisatoshis: grpc[:max_htlc_msat] },
|
16
|
+
# https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection
|
17
|
+
blocks: {
|
18
|
+
delta: {
|
19
|
+
minimum: grpc[:time_lock_delta] # aka cltv_expiry_delta
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.subscribe_channel_graph(json)
|
27
|
+
result = {
|
28
|
+
_source: :subscribe_channel_graph,
|
29
|
+
fee: {
|
30
|
+
base: { millisatoshis: json['routingPolicy']['feeBaseMsat'].to_i },
|
31
|
+
rate: { parts_per_million: json['routingPolicy']['feeRateMilliMsat'].to_i }
|
32
|
+
},
|
33
|
+
htlc: {
|
34
|
+
minimum: { millisatoshis: json['routingPolicy']['minHtlc'].to_i },
|
35
|
+
maximum: { millisatoshis: json['routingPolicy']['maxHtlcMsat'].to_i },
|
36
|
+
# https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection
|
37
|
+
blocks: {
|
38
|
+
delta: {
|
39
|
+
minimum: json['routingPolicy']['timeLockDelta'].to_i # aka cltv_expiry_delta
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
policy = json['routingPolicy']
|
46
|
+
|
47
|
+
result[:fee].delete(:base) unless policy.key?('feeBaseMsat') && !policy['feeBaseMsat'].nil?
|
48
|
+
result[:fee].delete(:rate) unless policy.key?('feeRateMilliMsat') && !policy['feeRateMilliMsat'].nil?
|
49
|
+
result.delete(:fee) if result[:fee].empty?
|
50
|
+
|
51
|
+
result[:htlc].delete(:minimum) unless policy.key?('minHtlc') && !policy['minHtlc'].nil?
|
52
|
+
result[:htlc].delete(:maximum) unless policy.key?('maxHtlcMsat') && !policy['maxHtlcMsat'].nil?
|
53
|
+
result[:htlc].delete(:blocks) unless policy.key?('timeLockDelta') && !policy['timeLockDelta'].nil?
|
54
|
+
result.delete(:htlc) if result[:htlc].empty?
|
55
|
+
|
56
|
+
return nil unless result.key?(:fee) || result.key?(:htlc)
|
57
|
+
|
58
|
+
result
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../nodes/node'
|
4
|
+
require_relative 'channel_node/policy'
|
5
|
+
|
6
|
+
module Lighstorm
|
7
|
+
module Adapter
|
8
|
+
module Lightning
|
9
|
+
class ChannelNode
|
10
|
+
def self.list_channels(grpc, key)
|
11
|
+
data = {
|
12
|
+
_source: :list_channels,
|
13
|
+
state: grpc[:active] ? 'active' : 'inactive',
|
14
|
+
initiator: grpc[:initiator] && key == :local,
|
15
|
+
accounting: { balance: { millisatoshis: grpc[:"#{key}_balance"] * 1000 } },
|
16
|
+
node: Node.list_channels(grpc, key)
|
17
|
+
}
|
18
|
+
|
19
|
+
data.delete(:node) if data[:node].nil?
|
20
|
+
|
21
|
+
data
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_chan_info(grpc, index)
|
25
|
+
data = {
|
26
|
+
_source: :get_chan_info,
|
27
|
+
node: Node.get_chan_info(grpc, index)
|
28
|
+
}
|
29
|
+
|
30
|
+
if grpc[:"node#{index}_policy"]
|
31
|
+
data[:state] = grpc[:"node#{index}_policy"][:disabled] ? 'inactive' : 'active'
|
32
|
+
data[:policy] = Policy.get_chan_info(grpc[:"node#{index}_policy"])
|
33
|
+
end
|
34
|
+
|
35
|
+
data.delete(:node) if data[:node].nil?
|
36
|
+
|
37
|
+
data
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.describe_graph(grpc, index)
|
41
|
+
data = {
|
42
|
+
_source: :describe_graph,
|
43
|
+
node: Node.describe_graph_from_channel(grpc, index)
|
44
|
+
}
|
45
|
+
|
46
|
+
# TODO: No examples to validate the correctness of this scenario.
|
47
|
+
if grpc[:"node#{index}_policy"]
|
48
|
+
data[:state] = grpc[:"node#{index}_policy"][:disabled] ? 'inactive' : 'active'
|
49
|
+
data[:policy] = Policy.get_chan_info(grpc[:"node#{index}_policy"])
|
50
|
+
end
|
51
|
+
|
52
|
+
data.delete(:node) if data[:node].nil?
|
53
|
+
|
54
|
+
data
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.subscribe_channel_graph(json)
|
58
|
+
data = {
|
59
|
+
_source: :subscribe_channel_graph,
|
60
|
+
node: {
|
61
|
+
public_key: json['advertisingNode']
|
62
|
+
},
|
63
|
+
policy: Policy.subscribe_channel_graph(json)
|
64
|
+
}
|
65
|
+
|
66
|
+
unless json['routingPolicy']['disabled'].nil?
|
67
|
+
data[:state] = json['routingPolicy']['disabled'] ? 'inactive' : 'active'
|
68
|
+
end
|
69
|
+
|
70
|
+
data.delete(:policy) if data[:policy].nil?
|
71
|
+
|
72
|
+
data
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Adapter
|
7
|
+
module Lightning
|
8
|
+
class PaymentChannel
|
9
|
+
def self.list_payments(grpc, index)
|
10
|
+
{
|
11
|
+
_source: :list_payments,
|
12
|
+
hop: index + 1,
|
13
|
+
amount: { millisatoshis: grpc[:amt_to_forward_msat] },
|
14
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
15
|
+
channel: {
|
16
|
+
_key: Digest::SHA256.hexdigest(grpc[:chan_id].to_s),
|
17
|
+
id: grpc[:chan_id].to_s,
|
18
|
+
partners: [
|
19
|
+
node: {
|
20
|
+
_key: Digest::SHA256.hexdigest(grpc[:pub_key].to_s),
|
21
|
+
public_key: grpc[:pub_key]
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
require_relative '../connections/channel_node'
|
6
|
+
|
7
|
+
module Lighstorm
|
8
|
+
module Adapter
|
9
|
+
module Lightning
|
10
|
+
class Channel
|
11
|
+
def self._key(id, state)
|
12
|
+
Digest::SHA256.hexdigest(
|
13
|
+
[id, state].join('/')
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.list_channels(grpc, at)
|
18
|
+
{
|
19
|
+
_source: :list_channels,
|
20
|
+
_key: _key(grpc[:chan_id], grpc[:active] ? 'active' : 'inactive'),
|
21
|
+
# Standard JSON don't support BigInt, so, a String is safer.
|
22
|
+
id: grpc[:chan_id].to_s,
|
23
|
+
transaction: {
|
24
|
+
funding: {
|
25
|
+
id: grpc[:channel_point].split(':').first,
|
26
|
+
index: grpc[:channel_point].split(':').last.to_i
|
27
|
+
}
|
28
|
+
},
|
29
|
+
opened_at: at - grpc[:lifetime],
|
30
|
+
up_at: at - grpc[:uptime],
|
31
|
+
state: grpc[:active] ? 'active' : 'inactive',
|
32
|
+
exposure: grpc[:private] ? 'private' : 'public',
|
33
|
+
accounting: {
|
34
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 },
|
35
|
+
sent: { millisatoshis: grpc[:total_satoshis_sent] * 1000 },
|
36
|
+
received: { millisatoshis: grpc[:total_satoshis_received] * 1000 },
|
37
|
+
unsettled: { millisatoshis: grpc[:unsettled_balance] * 1000 }
|
38
|
+
},
|
39
|
+
partners: [
|
40
|
+
ChannelNode.list_channels(grpc, :local),
|
41
|
+
ChannelNode.list_channels(grpc, :remote)
|
42
|
+
]
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_chan_info(grpc)
|
47
|
+
{
|
48
|
+
_source: :get_chan_info,
|
49
|
+
_key: _key(grpc[:channel_id], nil),
|
50
|
+
# Standard JSON don't support BigInt, so, a String is safer.
|
51
|
+
id: grpc[:channel_id].to_s,
|
52
|
+
accounting: {
|
53
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 }
|
54
|
+
},
|
55
|
+
partners: [
|
56
|
+
ChannelNode.get_chan_info(grpc, 1),
|
57
|
+
ChannelNode.get_chan_info(grpc, 2)
|
58
|
+
]
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.describe_graph(grpc)
|
63
|
+
{
|
64
|
+
_source: :describe_graph,
|
65
|
+
_key: _key(grpc[:channel_id], nil),
|
66
|
+
# Standard JSON don't support BigInt, so, a String is safer.
|
67
|
+
id: grpc[:channel_id].to_s,
|
68
|
+
exposure: 'public',
|
69
|
+
accounting: {
|
70
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 }
|
71
|
+
},
|
72
|
+
partners: [
|
73
|
+
ChannelNode.describe_graph(grpc, 1),
|
74
|
+
ChannelNode.describe_graph(grpc, 2)
|
75
|
+
]
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.subscribe_channel_graph(json)
|
80
|
+
{
|
81
|
+
_source: :subscribe_channel_graph,
|
82
|
+
_key: _key(json['chanId'], nil),
|
83
|
+
id: json['chanId'],
|
84
|
+
accounting: {
|
85
|
+
capacity: { millisatoshis: json['capacity'].to_i * 1000 }
|
86
|
+
},
|
87
|
+
partners: [
|
88
|
+
ChannelNode.subscribe_channel_graph(json),
|
89
|
+
{ node: {
|
90
|
+
public_key: json['connectingNode']
|
91
|
+
} }
|
92
|
+
]
|
93
|
+
}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Adapter
|
7
|
+
module Lightning
|
8
|
+
class Forward
|
9
|
+
def self.forwarding_history(grpc)
|
10
|
+
{
|
11
|
+
_source: :forwarding_history,
|
12
|
+
_key: _key(grpc),
|
13
|
+
at: Time.at(grpc[:timestamp_ns] / 1e+9),
|
14
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
15
|
+
in: {
|
16
|
+
amount: { millisatoshis: grpc[:amt_in_msat] },
|
17
|
+
channel: {
|
18
|
+
id: grpc[:chan_id_in].to_s
|
19
|
+
}
|
20
|
+
},
|
21
|
+
out: {
|
22
|
+
amount: { millisatoshis: grpc[:amt_out_msat] },
|
23
|
+
channel: {
|
24
|
+
id: grpc[:chan_id_out].to_s
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def self._key(grpc)
|
31
|
+
Digest::SHA256.hexdigest(
|
32
|
+
[
|
33
|
+
grpc[:timestamp_ns],
|
34
|
+
grpc[:chan_id_in], grpc[:chan_id_out],
|
35
|
+
grpc[:amt_in_msat], grpc[:fee_msat]
|
36
|
+
].join('/')
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lighstorm
|
4
|
+
module Adapter
|
5
|
+
module Lightning
|
6
|
+
class Purpose
|
7
|
+
def self.send_payment_v2(grpc, node_get_info)
|
8
|
+
return 'unknown' if grpc[:payment_route][:hops].empty?
|
9
|
+
|
10
|
+
return 'self-payment' if self_payment?(grpc[:payment_route][:hops])
|
11
|
+
return 'peer-to-peer' if peer_to_peer?(grpc[:payment_route][:hops])
|
12
|
+
return 'rebalance' if rebalance?(grpc[:payment_route][:hops], node_get_info)
|
13
|
+
|
14
|
+
'payment'
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.list_payments(grpc, node_get_info)
|
18
|
+
return 'unknown' if grpc[:htlcs].empty?
|
19
|
+
|
20
|
+
return 'self-payment' if self_payment?(grpc[:htlcs].last[:route][:hops])
|
21
|
+
return 'peer-to-peer' if peer_to_peer?(grpc[:htlcs].last[:route][:hops])
|
22
|
+
return 'rebalance' if rebalance?(grpc[:htlcs].last[:route][:hops], node_get_info)
|
23
|
+
|
24
|
+
'payment'
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.self_payment?(hops)
|
28
|
+
hops.size == 2 && hops[0][:chan_id] == hops[1][:chan_id]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.peer_to_peer?(hops)
|
32
|
+
hops.size == 1
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.rebalance?(hops, node_get_info)
|
36
|
+
return false if hops.size <= 2
|
37
|
+
|
38
|
+
destination_public_key = hops.last[:pub_key]
|
39
|
+
|
40
|
+
node_get_info[:identity_pubkey] == destination_public_key
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
|
5
|
+
require_relative '../connections/payment_channel'
|
6
|
+
require_relative 'payment/purpose'
|
7
|
+
|
8
|
+
require_relative '../invoice'
|
9
|
+
|
10
|
+
require_relative '../../../ports/dsl/lighstorm/errors'
|
11
|
+
|
12
|
+
module Lighstorm
|
13
|
+
module Adapter
|
14
|
+
module Lightning
|
15
|
+
class Payment
|
16
|
+
def self._key(grpc)
|
17
|
+
Digest::SHA256.hexdigest(
|
18
|
+
[
|
19
|
+
grpc[:payment_request],
|
20
|
+
grpc[:creation_time_ns],
|
21
|
+
grpc[:resolve_time_ns],
|
22
|
+
grpc[:status]
|
23
|
+
].join('/')
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.send_payment_v2(grpc, node_myself, invoice_decode)
|
28
|
+
adapted = list_payments(grpc, node_myself, invoice_decode)
|
29
|
+
adapted[:_source] = :send_payment_v2
|
30
|
+
adapted
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.list_payments(grpc, node_myself, invoice_decode = nil)
|
34
|
+
data = {
|
35
|
+
_source: :list_payments,
|
36
|
+
_key: _key(grpc),
|
37
|
+
at: Time.at(grpc[:creation_time_ns] / 1e+9),
|
38
|
+
state: grpc[:status].to_s.downcase,
|
39
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
40
|
+
amount: { millisatoshis: grpc[:value_msat] },
|
41
|
+
purpose: Purpose.list_payments(grpc, node_myself),
|
42
|
+
invoice: Invoice.list_payments(grpc, invoice_decode)
|
43
|
+
}
|
44
|
+
|
45
|
+
data[:secret] = data[:invoice][:secret]
|
46
|
+
|
47
|
+
htlc = grpc[:htlcs].last
|
48
|
+
|
49
|
+
return data if htlc.nil?
|
50
|
+
|
51
|
+
data[:hops] = htlc[:route][:hops].map.with_index do |raw_hop, i|
|
52
|
+
hop = PaymentChannel.list_payments(raw_hop, i)
|
53
|
+
hop[:channel][:target] = { public_key: raw_hop[:pub_key] }
|
54
|
+
hop
|
55
|
+
end
|
56
|
+
|
57
|
+
data[:invoice][:settled_at] = Time.at(htlc[:resolve_time_ns] / 1e+9) if htlc[:resolve_time_ns]
|
58
|
+
|
59
|
+
last_hop = htlc[:route][:hops].last
|
60
|
+
|
61
|
+
return data if last_hop.nil?
|
62
|
+
|
63
|
+
# https://github.com/satoshisstream/satoshis.stream/blob/main/TLV_registry.md
|
64
|
+
if last_hop[:custom_records][34_349_334]
|
65
|
+
data[:message] = last_hop[:custom_records][34_349_334].dup
|
66
|
+
|
67
|
+
unless data[:message].force_encoding('UTF-8').valid_encoding?
|
68
|
+
data[:message] = data[:message].unpack1('H*')
|
69
|
+
|
70
|
+
data[:message] = data[:message].scrub('?') unless data[:message].force_encoding('UTF-8').valid_encoding?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
if data[:invoice] && data[:invoice][:code] && !data[:invoice][:code].nil? && !data[:invoice][:code].empty?
|
75
|
+
data[:through] = if data[:invoice][:payable] == 'indefinitely'
|
76
|
+
'amp'
|
77
|
+
else
|
78
|
+
'non-amp'
|
79
|
+
end
|
80
|
+
else
|
81
|
+
data[:through] = last_hop[:mpp_record] ? 'amp' : 'keysend'
|
82
|
+
end
|
83
|
+
|
84
|
+
data
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|