lighstorm 0.0.5 → 0.0.7
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 +17 -55
- data/adapters/connections/channel_node/fee.rb +1 -1
- data/adapters/connections/channel_node/policy.rb +6 -6
- data/adapters/connections/channel_node.rb +1 -1
- data/adapters/connections/payment_channel.rb +2 -2
- data/adapters/edges/channel.rb +7 -7
- data/adapters/edges/forward.rb +3 -3
- data/adapters/edges/payment.rb +1 -1
- data/adapters/invoice.rb +16 -1
- data/adapters/payment_request.rb +14 -3
- data/components/cache.rb +8 -5
- data/controllers/action.rb +24 -0
- data/controllers/channel/actions/apply_gossip.rb +18 -18
- data/controllers/channel/actions/update_fee.rb +33 -22
- data/controllers/forward/group_by_channel.rb +3 -3
- data/controllers/invoice/actions/create.rb +39 -11
- data/controllers/invoice/actions/pay_through_route.rb +1 -1
- data/controllers/invoice.rb +3 -3
- data/docs/README.md +405 -140
- data/docs/_coverpage.md +6 -1
- data/docs/index.html +1 -1
- data/models/connections/channel_node/accounting.rb +1 -1
- data/models/connections/channel_node/fee.rb +5 -4
- data/models/connections/channel_node/htlc.rb +4 -4
- data/models/connections/forward_channel.rb +1 -1
- data/models/connections/payment_channel.rb +4 -4
- data/models/edges/channel/accounting.rb +5 -5
- data/models/edges/forward.rb +3 -3
- data/models/edges/groups/channel_forwards/analysis.rb +8 -8
- data/models/edges/payment.rb +3 -3
- data/models/errors.rb +1 -1
- data/models/payment_request.rb +2 -2
- data/models/satoshis.rb +12 -12
- data/static/cache.rb +2 -0
- data/static/spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3a0597ad2e13c24bcf64efd0e12e2b6c8ae0c7b6b012b6fab89caffd2ac06a9
|
4
|
+
data.tar.gz: 01fa72d76dcdb97c62a1edd5f8829d8038baba9639de245e75059bbf6309d199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7e7d996345446669475259095ad4843783ec21083094e3acbb883fbde421b57efec0d1ca5a495526ee6e1c536920003a3472db21eb6ee2394218bcf07fc235e
|
7
|
+
data.tar.gz: 8e4b80f814feff68293a6db0ecdc9346640d19e3f761d16fafa5c0f1dcfbea978208dca9c6e186834ef9b28bac0b296f37d5b3aeba5a0b05f4cac06e38bcbc4f
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lighstorm (0.0.
|
4
|
+
lighstorm (0.0.7)
|
5
5
|
dotenv (~> 2.8, >= 2.8.1)
|
6
6
|
lnd-client (~> 0.0.5)
|
7
7
|
zache (~> 0.12.0)
|
@@ -50,14 +50,14 @@ GEM
|
|
50
50
|
diff-lcs (>= 1.2.0, < 2.0)
|
51
51
|
rspec-support (~> 3.12.0)
|
52
52
|
rspec-support (3.12.0)
|
53
|
-
rubocop (1.
|
53
|
+
rubocop (1.46.0)
|
54
54
|
json (~> 2.3)
|
55
55
|
parallel (~> 1.10)
|
56
56
|
parser (>= 3.2.0.0)
|
57
57
|
rainbow (>= 2.2.2, < 4.0)
|
58
58
|
regexp_parser (>= 1.8, < 3.0)
|
59
59
|
rexml (>= 3.2.5, < 4.0)
|
60
|
-
rubocop-ast (>= 1.
|
60
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
61
61
|
ruby-progressbar (~> 1.7)
|
62
62
|
unicode-display_width (>= 2.4.0, < 3.0)
|
63
63
|
rubocop-ast (1.26.0)
|
data/README.md
CHANGED
@@ -15,25 +15,26 @@ Lighstorm::Channel.mine.first.myself.node.alias
|
|
15
15
|
- [About](#about)
|
16
16
|
- [Usage](#usage)
|
17
17
|
- [Documentation](https://icebaker.github.io/lighstorm)
|
18
|
-
- [Development](
|
19
|
-
- [Testing](#testing)
|
20
|
-
- [Generating Documentation](#generating-documentation)
|
21
|
-
- [Publish to RubyGems](#publish-to-rubygems)
|
18
|
+
- [Development](https://icebaker.github.io/lighstorm/#/README?id=development)
|
22
19
|
|
23
20
|
## About
|
24
21
|
|
25
22
|
_Lighstorm_ is an opinionated abstraction layer on top of the [lnd-client](https://github.com/icebaker/lnd-client).
|
26
23
|
|
27
|
-
It brings an [
|
24
|
+
It brings an [_object-oriented_](https://en.wikipedia.org/wiki/Object-oriented_programming) approach for interacting with a [Lightning Node](https://github.com/lightningnetwork/lnd), influenced by the [Active Record Pattern](https://www.martinfowler.com/eaaCatalog/activeRecord.html) and [Active Record Models](https://guides.rubyonrails.org/active_record_basics.html) conventions.
|
28
25
|
|
29
|
-
|
26
|
+
However, despite the fluidity of _Object Orientation_ being desired in its public interface, internally, most of its code is structured following the [_Hexagonal Architecture_](https://en.wikipedia.org/wiki/Hexagonal_architecture_(software)) and [_Functional Programming_](https://en.wikipedia.org/wiki/Functional_programming) principles.
|
27
|
+
|
28
|
+
It aims to be intuitive to use while being highly **reliable**, as it deals with people's money, and easily testable since its [tests](https://icebaker.github.io/lighstorm/#/README?id=testing) are the foundation for its reliability.
|
29
|
+
|
30
|
+
Although it tries to stay close to [Lightning's terminologies](https://docs.lightning.engineering/the-lightning-network/overview), it brings its own vocabulary and [data modeling](https://icebaker.github.io/lighstorm/#/README?id=data-modeling), optimizing for [programmer happiness](https://rubyonrails.org/doctrine#optimize-for-programmer-happiness).
|
30
31
|
|
31
32
|
## Usage
|
32
33
|
|
33
34
|
Add to your `Gemfile`:
|
34
35
|
|
35
36
|
```ruby
|
36
|
-
gem 'lighstorm', '~> 0.0.
|
37
|
+
gem 'lighstorm', '~> 0.0.7'
|
37
38
|
```
|
38
39
|
|
39
40
|
```ruby
|
@@ -45,60 +46,21 @@ Lighstorm.config!(
|
|
45
46
|
macaroon_path: '/lnd/data/chain/bitcoin/mainnet/admin.macaroon',
|
46
47
|
)
|
47
48
|
|
48
|
-
puts Lighstorm.version # => 0.0.
|
49
|
+
puts Lighstorm.version # => 0.0.7
|
50
|
+
|
51
|
+
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
52
|
+
|
53
|
+
Lighstorm::Invoice.create(
|
54
|
+
description: 'Coffee', millisatoshis: 1_000
|
55
|
+
)
|
49
56
|
|
50
57
|
Lighstorm::Satoshis.new(
|
51
|
-
|
58
|
+
millisatoshis: 75_621_650
|
52
59
|
).satoshis # => 75_621
|
53
|
-
|
54
|
-
Lighstorm::Node.myself.alias # => icebaker/old-stone
|
55
60
|
```
|
56
61
|
|
57
62
|
Check the [full documentation](https://icebaker.github.io/lighstorm).
|
58
63
|
|
59
64
|
## Development
|
60
65
|
|
61
|
-
|
62
|
-
|
63
|
-
```ruby
|
64
|
-
# Gemfile
|
65
|
-
gem 'lighstorm', path: '/home/user/lighstorm'
|
66
|
-
|
67
|
-
# demo.rb
|
68
|
-
require 'lighstorm'
|
69
|
-
|
70
|
-
puts Lighstorm.version # => 0.0.5
|
71
|
-
```
|
72
|
-
|
73
|
-
```sh
|
74
|
-
bundle
|
75
|
-
rubocop -A
|
76
|
-
```
|
77
|
-
|
78
|
-
### Testing
|
79
|
-
|
80
|
-
Copy the `.env.example` file to `.env` and provide the required data.
|
81
|
-
|
82
|
-
```
|
83
|
-
bundle
|
84
|
-
|
85
|
-
bundle exec rspec
|
86
|
-
```
|
87
|
-
|
88
|
-
### Generating Documentation
|
89
|
-
|
90
|
-
```sh
|
91
|
-
npm i docsify-cli -g
|
92
|
-
|
93
|
-
docsify serve ./docs
|
94
|
-
```
|
95
|
-
|
96
|
-
### Publish to RubyGems
|
97
|
-
|
98
|
-
```sh
|
99
|
-
gem build lighstorm.gemspec
|
100
|
-
|
101
|
-
gem signin
|
102
|
-
|
103
|
-
gem push lighstorm-0.0.5.gem
|
104
|
-
```
|
66
|
+
Check the [development documentation](https://icebaker.github.io/lighstorm/#/README?id=development).
|
@@ -6,12 +6,12 @@ module Lighstorm
|
|
6
6
|
def self.get_chan_info(grpc)
|
7
7
|
{
|
8
8
|
fee: {
|
9
|
-
base: {
|
9
|
+
base: { millisatoshis: grpc[:fee_base_msat] },
|
10
10
|
rate: { parts_per_million: grpc[:fee_rate_milli_msat] }
|
11
11
|
},
|
12
12
|
htlc: {
|
13
|
-
minimum: {
|
14
|
-
maximum: {
|
13
|
+
minimum: { millisatoshis: grpc[:min_htlc] },
|
14
|
+
maximum: { millisatoshis: grpc[:max_htlc_msat] },
|
15
15
|
# https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection
|
16
16
|
blocks: {
|
17
17
|
delta: {
|
@@ -26,12 +26,12 @@ module Lighstorm
|
|
26
26
|
result = {
|
27
27
|
_source: :subscribe_channel_graph,
|
28
28
|
fee: {
|
29
|
-
base: {
|
29
|
+
base: { millisatoshis: json['routingPolicy']['feeBaseMsat'].to_i },
|
30
30
|
rate: { parts_per_million: json['routingPolicy']['feeRateMilliMsat'].to_i }
|
31
31
|
},
|
32
32
|
htlc: {
|
33
|
-
minimum: {
|
34
|
-
maximum: {
|
33
|
+
minimum: { millisatoshis: json['routingPolicy']['minHtlc'].to_i },
|
34
|
+
maximum: { millisatoshis: json['routingPolicy']['maxHtlcMsat'].to_i },
|
35
35
|
# https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#cltv_expiry_delta-selection
|
36
36
|
blocks: {
|
37
37
|
delta: {
|
@@ -10,7 +10,7 @@ module Lighstorm
|
|
10
10
|
data = {
|
11
11
|
_source: :list_channels,
|
12
12
|
state: grpc[:active] ? 'active' : 'inactive',
|
13
|
-
accounting: { balance: {
|
13
|
+
accounting: { balance: { millisatoshis: grpc[:"#{key}_balance"] * 1000 } },
|
14
14
|
node: Node.list_channels(grpc, key)
|
15
15
|
}
|
16
16
|
|
@@ -9,8 +9,8 @@ module Lighstorm
|
|
9
9
|
{
|
10
10
|
_source: :list_payments,
|
11
11
|
hop: index + 1,
|
12
|
-
amount: {
|
13
|
-
fee: {
|
12
|
+
amount: { millisatoshis: grpc[:amt_to_forward_msat] },
|
13
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
14
14
|
channel: {
|
15
15
|
_key: Digest::SHA256.hexdigest(grpc[:chan_id].to_s),
|
16
16
|
id: grpc[:chan_id].to_s,
|
data/adapters/edges/channel.rb
CHANGED
@@ -30,10 +30,10 @@ module Lighstorm
|
|
30
30
|
state: grpc[:active] ? 'active' : 'inactive',
|
31
31
|
exposure: grpc[:private] ? 'private' : 'public',
|
32
32
|
accounting: {
|
33
|
-
capacity: {
|
34
|
-
sent: {
|
35
|
-
received: {
|
36
|
-
unsettled: {
|
33
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 },
|
34
|
+
sent: { millisatoshis: grpc[:total_satoshis_sent] * 1000 },
|
35
|
+
received: { millisatoshis: grpc[:total_satoshis_received] * 1000 },
|
36
|
+
unsettled: { millisatoshis: grpc[:unsettled_balance] * 1000 }
|
37
37
|
},
|
38
38
|
partners: [
|
39
39
|
ChannelNode.list_channels(grpc, :local),
|
@@ -49,7 +49,7 @@ module Lighstorm
|
|
49
49
|
# Standard JSON don't support BigInt, so, a String is safer.
|
50
50
|
id: grpc[:channel_id].to_s,
|
51
51
|
accounting: {
|
52
|
-
capacity: {
|
52
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 }
|
53
53
|
},
|
54
54
|
partners: [
|
55
55
|
ChannelNode.get_chan_info(grpc, 1),
|
@@ -66,7 +66,7 @@ module Lighstorm
|
|
66
66
|
id: grpc[:channel_id].to_s,
|
67
67
|
exposure: 'public',
|
68
68
|
accounting: {
|
69
|
-
capacity: {
|
69
|
+
capacity: { millisatoshis: grpc[:capacity] * 1000 }
|
70
70
|
},
|
71
71
|
partners: [
|
72
72
|
ChannelNode.describe_graph(grpc, 1),
|
@@ -81,7 +81,7 @@ module Lighstorm
|
|
81
81
|
_key: _key(json['chanId'], nil),
|
82
82
|
id: json['chanId'],
|
83
83
|
accounting: {
|
84
|
-
capacity: {
|
84
|
+
capacity: { millisatoshis: json['capacity'].to_i * 1000 }
|
85
85
|
},
|
86
86
|
partners: [
|
87
87
|
ChannelNode.subscribe_channel_graph(json),
|
data/adapters/edges/forward.rb
CHANGED
@@ -10,15 +10,15 @@ module Lighstorm
|
|
10
10
|
_source: :forwarding_history,
|
11
11
|
_key: _key(grpc),
|
12
12
|
at: Time.at(grpc[:timestamp_ns] / 1e+9),
|
13
|
-
fee: {
|
13
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
14
14
|
in: {
|
15
|
-
amount: {
|
15
|
+
amount: { millisatoshis: grpc[:amt_in_msat] },
|
16
16
|
channel: {
|
17
17
|
id: grpc[:chan_id_in].to_s
|
18
18
|
}
|
19
19
|
},
|
20
20
|
out: {
|
21
|
-
amount: {
|
21
|
+
amount: { millisatoshis: grpc[:amt_out_msat] },
|
22
22
|
channel: {
|
23
23
|
id: grpc[:chan_id_out].to_s
|
24
24
|
}
|
data/adapters/edges/payment.rb
CHANGED
@@ -31,7 +31,7 @@ module Lighstorm
|
|
31
31
|
_key: _key(grpc),
|
32
32
|
created_at: Time.at(grpc[:creation_time_ns] / 1e+9),
|
33
33
|
status: grpc[:status].to_s.downcase,
|
34
|
-
fee: {
|
34
|
+
fee: { millisatoshis: grpc[:fee_msat] },
|
35
35
|
purpose: Purpose.list_payments(grpc, node_get_info),
|
36
36
|
request: PaymentRequest.list_payments(grpc),
|
37
37
|
hops: grpc[:htlcs].first[:route][:hops].map.with_index do |raw_hop, i|
|
data/adapters/invoice.rb
CHANGED
@@ -7,6 +7,21 @@ require_relative 'payment_request'
|
|
7
7
|
module Lighstorm
|
8
8
|
module Adapter
|
9
9
|
class Invoice
|
10
|
+
def self.add_invoice(grpc)
|
11
|
+
{
|
12
|
+
_source: :add_invoice,
|
13
|
+
_key: Digest::SHA256.hexdigest(
|
14
|
+
[
|
15
|
+
grpc[:r_hash],
|
16
|
+
grpc[:add_index],
|
17
|
+
grpc[:payment_request],
|
18
|
+
grpc[:payment_addr]
|
19
|
+
].join('/')
|
20
|
+
),
|
21
|
+
request: PaymentRequest.add_invoice(grpc)
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
10
25
|
def self.lookup_invoice(grpc)
|
11
26
|
adapted = list_or_lookup(grpc)
|
12
27
|
|
@@ -29,7 +44,7 @@ module Lighstorm
|
|
29
44
|
{
|
30
45
|
_key: _key(grpc),
|
31
46
|
created_at: Time.at(grpc[:creation_date]),
|
32
|
-
settle_at: Time.at(grpc[:settle_date]),
|
47
|
+
settle_at: grpc[:settle_date].nil? || !grpc[:settle_date].positive? ? nil : Time.at(grpc[:settle_date]),
|
33
48
|
state: grpc[:state].to_s.downcase
|
34
49
|
}
|
35
50
|
end
|
data/adapters/payment_request.rb
CHANGED
@@ -7,10 +7,21 @@ require_relative '../ports/dsl/lighstorm/errors'
|
|
7
7
|
module Lighstorm
|
8
8
|
module Adapter
|
9
9
|
class PaymentRequest
|
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
|
+
|
10
21
|
def self.decode_pay_req(grpc)
|
11
22
|
{
|
12
23
|
_source: :decode_pay_req,
|
13
|
-
amount: {
|
24
|
+
amount: { millisatoshis: grpc[:num_msat] },
|
14
25
|
description: {
|
15
26
|
memo: grpc[:description],
|
16
27
|
hash: grpc[:description_hash] == '' ? nil : grpc[:description_hash]
|
@@ -37,7 +48,7 @@ module Lighstorm
|
|
37
48
|
def self.list_or_lookup_invoice(grpc)
|
38
49
|
{
|
39
50
|
code: grpc[:payment_request],
|
40
|
-
amount: {
|
51
|
+
amount: { millisatoshis: grpc[:value_msat] },
|
41
52
|
description: {
|
42
53
|
memo: grpc[:memo],
|
43
54
|
hash: grpc[:description_hash] == '' ? nil : grpc[:description_hash]
|
@@ -56,7 +67,7 @@ module Lighstorm
|
|
56
67
|
data = {
|
57
68
|
_source: :list_payments,
|
58
69
|
code: grpc[:payment_request],
|
59
|
-
amount: {
|
70
|
+
amount: { millisatoshis: grpc[:value_msat] },
|
60
71
|
secret: {
|
61
72
|
preimage: grpc[:payment_preimage],
|
62
73
|
hash: grpc[:payment_hash]
|
data/components/cache.rb
CHANGED
@@ -24,15 +24,18 @@ module Lighstorm
|
|
24
24
|
def for(key, ttl: nil, params: {}, &block)
|
25
25
|
if ttl.nil?
|
26
26
|
ttl = Lighstorm::Static::CACHE[key.sub('lightning.', '').to_sym]
|
27
|
-
raise MissingTTLError, "missing ttl for #{key} static/cache.rb" if ttl.nil?
|
27
|
+
raise MissingTTLError, "missing ttl for #{key.sub('lightning.', '')} static/cache.rb" if ttl.nil?
|
28
28
|
|
29
|
-
ttl = ttl[:ttl]
|
29
|
+
ttl = ttl == false ? false : ttl[:ttl]
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
@client.get(key, lifetime: ttl) do
|
32
|
+
if ttl == false
|
35
33
|
block.call
|
34
|
+
else
|
35
|
+
key = build_key_for(key, params)
|
36
|
+
@client.get(key, lifetime: ttl) do
|
37
|
+
block.call
|
38
|
+
end
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lighstorm
|
4
|
+
module Controllers
|
5
|
+
module Action
|
6
|
+
Output = Struct.new(:data) do
|
7
|
+
def response
|
8
|
+
data[:response]
|
9
|
+
end
|
10
|
+
|
11
|
+
def result
|
12
|
+
data[:result]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_h
|
16
|
+
{
|
17
|
+
response: response,
|
18
|
+
result: result.to_h
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -25,17 +25,17 @@ module Lighstorm
|
|
25
25
|
].freeze
|
26
26
|
|
27
27
|
APPLICABLE = [
|
28
|
-
'accounting/capacity/
|
29
|
-
'partners/0/policy/fee/base/
|
28
|
+
'accounting/capacity/millisatoshis',
|
29
|
+
'partners/0/policy/fee/base/millisatoshis',
|
30
30
|
'partners/0/state',
|
31
|
-
'partners/1/policy/fee/base/
|
31
|
+
'partners/1/policy/fee/base/millisatoshis',
|
32
32
|
'partners/1/state',
|
33
33
|
'partners/1/policy/fee/rate/parts_per_million',
|
34
34
|
'partners/0/policy/fee/rate/parts_per_million',
|
35
|
-
'partners/0/policy/htlc/minimum/
|
36
|
-
'partners/1/policy/htlc/minimum/
|
37
|
-
'partners/0/policy/htlc/maximum/
|
38
|
-
'partners/1/policy/htlc/maximum/
|
35
|
+
'partners/0/policy/htlc/minimum/millisatoshis',
|
36
|
+
'partners/1/policy/htlc/minimum/millisatoshis',
|
37
|
+
'partners/0/policy/htlc/maximum/millisatoshis',
|
38
|
+
'partners/1/policy/htlc/maximum/millisatoshis',
|
39
39
|
'partners/0/policy/htlc/blocks/delta/minimum',
|
40
40
|
'partners/1/policy/htlc/blocks/delta/minimum'
|
41
41
|
].freeze
|
@@ -79,25 +79,25 @@ module Lighstorm
|
|
79
79
|
|
80
80
|
def self.apply!(actual, key, change)
|
81
81
|
case key
|
82
|
-
when 'accounting/capacity/
|
82
|
+
when 'accounting/capacity/millisatoshis'
|
83
83
|
token = SecureRandom.hex
|
84
84
|
actual.accounting.prepare_token!(token)
|
85
85
|
actual.accounting.capacity = {
|
86
|
-
value: Models::Satoshis.new(
|
86
|
+
value: Models::Satoshis.new(millisatoshis: change[:to]),
|
87
87
|
token: token
|
88
88
|
}
|
89
|
-
when 'partners/0/policy/htlc/maximum/
|
90
|
-
'partners/1/policy/htlc/maximum/
|
89
|
+
when 'partners/0/policy/htlc/maximum/millisatoshis',
|
90
|
+
'partners/1/policy/htlc/maximum/millisatoshis' then
|
91
91
|
policy = actual.partners[change[:path][1]].policy
|
92
92
|
|
93
93
|
token = SecureRandom.hex
|
94
94
|
policy.htlc.prepare_token!(token)
|
95
95
|
policy.htlc.maximum = {
|
96
|
-
value: Models::Satoshis.new(
|
96
|
+
value: Models::Satoshis.new(millisatoshis: change[:to]),
|
97
97
|
token: token
|
98
98
|
}
|
99
|
-
when 'partners/0/policy/htlc/minimum/
|
100
|
-
'partners/1/policy/htlc/minimum/
|
99
|
+
when 'partners/0/policy/htlc/minimum/millisatoshis',
|
100
|
+
'partners/1/policy/htlc/minimum/millisatoshis' then
|
101
101
|
if actual.partners[change[:path][1]].policy.nil?
|
102
102
|
actual.partners[change[:path][1]].policy = Lighstorm::Models::Policy.new({})
|
103
103
|
end
|
@@ -107,7 +107,7 @@ module Lighstorm
|
|
107
107
|
token = SecureRandom.hex
|
108
108
|
policy.htlc.prepare_token!(token)
|
109
109
|
policy.htlc.minimum = {
|
110
|
-
value: Models::Satoshis.new(
|
110
|
+
value: Models::Satoshis.new(millisatoshis: change[:to]),
|
111
111
|
token: token
|
112
112
|
}
|
113
113
|
when 'partners/0/policy/htlc/blocks/delta/minimum',
|
@@ -134,14 +134,14 @@ module Lighstorm
|
|
134
134
|
value: Models::Rate.new(parts_per_million: change[:to]),
|
135
135
|
token: token
|
136
136
|
}
|
137
|
-
when 'partners/0/policy/fee/base/
|
138
|
-
'partners/1/policy/fee/base/
|
137
|
+
when 'partners/0/policy/fee/base/millisatoshis',
|
138
|
+
'partners/1/policy/fee/base/millisatoshis' then
|
139
139
|
policy = actual.partners[change[:path][1]].policy
|
140
140
|
|
141
141
|
token = SecureRandom.hex
|
142
142
|
policy.fee.prepare_token!(token)
|
143
143
|
policy.fee.base = {
|
144
|
-
value: Models::Satoshis.new(
|
144
|
+
value: Models::Satoshis.new(millisatoshis: change[:to]),
|
145
145
|
token: token
|
146
146
|
}
|
147
147
|
when 'partners/0/state',
|
@@ -4,25 +4,26 @@ require_relative '../../../ports/grpc'
|
|
4
4
|
require_relative '../../../models/errors'
|
5
5
|
require_relative '../../../models/satoshis'
|
6
6
|
require_relative '../../../models/rate'
|
7
|
+
require_relative '../../action'
|
7
8
|
|
8
9
|
module Lighstorm
|
9
10
|
module Controllers
|
10
11
|
module Channel
|
11
12
|
module UpdateFee
|
12
|
-
def self.
|
13
|
+
def self.prepare(policy, transaction, params)
|
13
14
|
grpc_request = {
|
14
15
|
service: :lightning,
|
15
16
|
method: :update_channel_policy,
|
16
17
|
params: {
|
17
18
|
chan_point: {
|
18
|
-
funding_txid_str:
|
19
|
-
output_index:
|
19
|
+
funding_txid_str: transaction[:funding][:id],
|
20
|
+
output_index: transaction[:funding][:index]
|
20
21
|
},
|
21
|
-
base_fee_msat: policy
|
22
|
-
fee_rate_ppm: policy
|
23
|
-
time_lock_delta: policy
|
24
|
-
max_htlc_msat: policy
|
25
|
-
min_htlc_msat: policy
|
22
|
+
base_fee_msat: policy[:fee][:base][:millisatoshis],
|
23
|
+
fee_rate_ppm: policy[:fee][:rate][:parts_per_million],
|
24
|
+
time_lock_delta: policy[:htlc][:blocks][:delta][:minimum],
|
25
|
+
max_htlc_msat: policy[:htlc][:maximum][:millisatoshis],
|
26
|
+
min_htlc_msat: policy[:htlc][:minimum][:millisatoshis]
|
26
27
|
}
|
27
28
|
}
|
28
29
|
|
@@ -34,30 +35,40 @@ module Lighstorm
|
|
34
35
|
grpc_request[:params][:fee_rate_ppm] = params[:rate][:parts_per_million]
|
35
36
|
end
|
36
37
|
|
37
|
-
if params[:base] && params[:base][:
|
38
|
-
if (params[:base][:
|
39
|
-
raise Errors::NegativeNotAllowedError, "fee base can't be negative: #{params[:base][:
|
38
|
+
if params[:base] && params[:base][:millisatoshis]
|
39
|
+
if (params[:base][:millisatoshis]).negative?
|
40
|
+
raise Errors::NegativeNotAllowedError, "fee base can't be negative: #{params[:base][:millisatoshis]}"
|
40
41
|
end
|
41
42
|
|
42
|
-
grpc_request[:params][:base_fee_msat] = params[:base][:
|
43
|
+
grpc_request[:params][:base_fee_msat] = params[:base][:millisatoshis]
|
43
44
|
end
|
44
45
|
|
46
|
+
grpc_request
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.call(grpc_request)
|
50
|
+
Lighstorm::Ports::GRPC.send(grpc_request[:service]).send(
|
51
|
+
grpc_request[:method], grpc_request[:params]
|
52
|
+
).to_h
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.dispatch(grpc_request, &vcr)
|
56
|
+
vcr.nil? ? call(grpc_request) : vcr.call(-> { call(grpc_request) }, :dispatch)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.perform(policy, transaction, params, preview: false, &vcr)
|
60
|
+
grpc_request = prepare(policy.to_h, transaction.to_h, params)
|
61
|
+
|
45
62
|
return grpc_request if preview
|
46
63
|
|
47
|
-
response =
|
48
|
-
:fake
|
49
|
-
else
|
50
|
-
LND.instance.middleware("lightning.#{grpc_request[:method]}") do
|
51
|
-
LND.instance.client.lightning.send(grpc_request[:method], grpc_request[:params])
|
52
|
-
end
|
53
|
-
end
|
64
|
+
response = dispatch(grpc_request, &vcr)
|
54
65
|
|
55
|
-
raise UpdateChannelPolicyError.new(nil, response) unless
|
66
|
+
raise UpdateChannelPolicyError.new(nil, response) unless response[:failed_updates].empty?
|
56
67
|
|
57
68
|
token = SecureRandom.hex
|
58
69
|
policy.fee.prepare_token!(token)
|
59
70
|
policy.fee.base = {
|
60
|
-
value: Models::Satoshis.new(
|
71
|
+
value: Models::Satoshis.new(millisatoshis: grpc_request[:params][:base_fee_msat]),
|
61
72
|
token: token
|
62
73
|
}
|
63
74
|
|
@@ -68,7 +79,7 @@ module Lighstorm
|
|
68
79
|
token: token
|
69
80
|
}
|
70
81
|
|
71
|
-
response
|
82
|
+
Action::Output.new({ response: response, result: policy })
|
72
83
|
end
|
73
84
|
end
|
74
85
|
end
|
@@ -36,7 +36,7 @@ module Lighstorm
|
|
36
36
|
last_at: nil,
|
37
37
|
analysis: {
|
38
38
|
count: 0,
|
39
|
-
sums: { amount: {
|
39
|
+
sums: { amount: { millisatoshis: 0 }, fee: { millisatoshis: 0 } }
|
40
40
|
},
|
41
41
|
channel: nil
|
42
42
|
}
|
@@ -47,8 +47,8 @@ module Lighstorm
|
|
47
47
|
group[:channel] = forward[direction][:channel] if group[:channel].nil?
|
48
48
|
|
49
49
|
group[:analysis][:count] += 1
|
50
|
-
group[:analysis][:sums][:amount][:
|
51
|
-
group[:analysis][:sums][:fee][:
|
50
|
+
group[:analysis][:sums][:amount][:millisatoshis] += forward[:in][:amount][:millisatoshis]
|
51
|
+
group[:analysis][:sums][:fee][:millisatoshis] += forward[:fee][:millisatoshis]
|
52
52
|
end
|
53
53
|
|
54
54
|
group[:_key] = _key(group)
|