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/docs/_coverpage.md
CHANGED
data/docs/index.html
CHANGED
data/lighstorm.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.require_paths = ['ports/dsl']
|
33
33
|
|
34
34
|
spec.add_dependency 'dotenv', '~> 2.8', '>= 2.8.1'
|
35
|
-
spec.add_dependency 'lnd-client', '~> 0.0.
|
35
|
+
spec.add_dependency 'lnd-client', '~> 0.0.9'
|
36
36
|
spec.add_dependency 'zache', '~> 0.12.0'
|
37
37
|
|
38
38
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../controllers/bitcoin/address/actions/pay'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Bitcoin
|
8
|
+
class Address
|
9
|
+
attr_reader :_key, :created_at, :code
|
10
|
+
|
11
|
+
def initialize(data, components)
|
12
|
+
@data = data
|
13
|
+
@components = components
|
14
|
+
|
15
|
+
@_key = @data[:_key]
|
16
|
+
@created_at = @data[:created_at]
|
17
|
+
@code = @data[:code]
|
18
|
+
end
|
19
|
+
|
20
|
+
def pay(
|
21
|
+
amount:, fee:,
|
22
|
+
description: nil, required_confirmations: 6,
|
23
|
+
preview: false, &vcr
|
24
|
+
)
|
25
|
+
Controller::Bitcoin::Address::Pay.perform(
|
26
|
+
@components,
|
27
|
+
address_code: code,
|
28
|
+
amount: amount, fee: fee, description: description,
|
29
|
+
required_confirmations: required_confirmations,
|
30
|
+
preview: preview,
|
31
|
+
&vcr
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h
|
36
|
+
if created_at || _key
|
37
|
+
{
|
38
|
+
_key: _key,
|
39
|
+
created_at: created_at,
|
40
|
+
code: code
|
41
|
+
}
|
42
|
+
else
|
43
|
+
{ code: code }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../satoshis'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Bitcoin
|
8
|
+
class Transaction
|
9
|
+
attr_reader :_key, :at, :hash, :description
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
|
14
|
+
@_key = @data[:_key]
|
15
|
+
@at = @data[:at]
|
16
|
+
@hash = @data[:hash]
|
17
|
+
@description = @data[:description]
|
18
|
+
end
|
19
|
+
|
20
|
+
def amount
|
21
|
+
@amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
|
22
|
+
end
|
23
|
+
|
24
|
+
def fee
|
25
|
+
@fee ||= Satoshis.new(millisatoshis: @data[:fee][:millisatoshis])
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_h
|
29
|
+
{
|
30
|
+
_key: _key,
|
31
|
+
at: at,
|
32
|
+
hash: hash,
|
33
|
+
amount: amount.to_h,
|
34
|
+
fee: fee.to_h,
|
35
|
+
description: description
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/models/errors.rb
CHANGED
@@ -14,22 +14,21 @@ module Lighstorm
|
|
14
14
|
|
15
15
|
class ToDoError < LighstormError; end
|
16
16
|
|
17
|
-
class MissingComponentsError < LighstormError; end
|
18
17
|
class ArgumentError < LighstormError; end
|
19
|
-
class TooManyArgumentsError < LighstormError; end
|
20
18
|
class IncoherentGossipError < LighstormError; end
|
21
|
-
class
|
19
|
+
class InvoiceMayHaveMultiplePaymentsError < LighstormError; end
|
20
|
+
class MissingComponentsError < LighstormError; end
|
22
21
|
class MissingCredentialsError < LighstormError; end
|
22
|
+
class MissingGossipHandlerError < LighstormError; end
|
23
23
|
class MissingPartsPerMillionError < LighstormError; end
|
24
24
|
class MissingTTLError < LighstormError; end
|
25
25
|
class NegativeNotAllowedError < LighstormError; end
|
26
26
|
class NotYourChannelError < LighstormError; end
|
27
27
|
class NotYourNodeError < LighstormError; end
|
28
28
|
class OperationNotAllowedError < LighstormError; end
|
29
|
+
class TooManyArgumentsError < LighstormError; end
|
29
30
|
class UnknownChannelError < LighstormError; end
|
30
31
|
|
31
|
-
class InvoiceMayHaveMultiplePaymentsError < LighstormError; end
|
32
|
-
|
33
32
|
class RequestError < LighstormError
|
34
33
|
attr_reader :request, :response, :result, :grpc
|
35
34
|
|
@@ -53,15 +52,15 @@ module Lighstorm
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
class
|
57
|
-
|
55
|
+
class AmountBelowDustLimitError < RequestError; end
|
58
56
|
class NoInvoiceFoundError < RequestError; end
|
57
|
+
class UpdateChannelPolicyError < RequestError; end
|
59
58
|
|
60
59
|
class PaymentError < RequestError; end
|
61
60
|
|
62
|
-
class NoRouteFoundError < PaymentError; end
|
63
61
|
class AlreadyPaidError < PaymentError; end
|
64
62
|
class AmountForNonZeroError < PaymentError; end
|
65
63
|
class MissingMillisatoshisError < PaymentError; end
|
64
|
+
class NoRouteFoundError < PaymentError; end
|
66
65
|
end
|
67
66
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../satoshis'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Lightning
|
8
|
+
class ChannelNodeAccounting
|
9
|
+
def initialize(data)
|
10
|
+
@data = data
|
11
|
+
end
|
12
|
+
|
13
|
+
def balance
|
14
|
+
@balance ||= Satoshis.new(millisatoshis: @data[:balance][:millisatoshis])
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{ balance: balance.to_h }
|
19
|
+
end
|
20
|
+
|
21
|
+
def dump
|
22
|
+
Marshal.load(Marshal.dump(@data))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
require_relative '../../../satoshis'
|
6
|
+
require_relative '../../rate'
|
7
|
+
require_relative '../../../concerns/protectable'
|
8
|
+
|
9
|
+
require_relative '../../../../controllers/lightning/channel/actions/update_fee'
|
10
|
+
|
11
|
+
module Lighstorm
|
12
|
+
module Model
|
13
|
+
module Lightning
|
14
|
+
class Fee
|
15
|
+
include Protectable
|
16
|
+
|
17
|
+
def initialize(policy, components, data)
|
18
|
+
@policy = policy
|
19
|
+
@components = components
|
20
|
+
@data = data
|
21
|
+
end
|
22
|
+
|
23
|
+
def base
|
24
|
+
return nil unless @data[:base]
|
25
|
+
|
26
|
+
@base ||= Satoshis.new(millisatoshis: @data[:base][:millisatoshis])
|
27
|
+
end
|
28
|
+
|
29
|
+
def rate
|
30
|
+
return nil unless @data[:rate]
|
31
|
+
|
32
|
+
@rate ||= Rate.new(parts_per_million: @data[:rate][:parts_per_million])
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h
|
36
|
+
result = {}
|
37
|
+
|
38
|
+
result[:base] = base.to_h if @data[:base]
|
39
|
+
result[:rate] = rate.to_h if @data[:rate]
|
40
|
+
|
41
|
+
return nil if result.empty?
|
42
|
+
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
def dump
|
47
|
+
Marshal.load(Marshal.dump(@data))
|
48
|
+
end
|
49
|
+
|
50
|
+
def update(params, preview: false, &vcr)
|
51
|
+
raise MissingComponentsError if @components.nil?
|
52
|
+
|
53
|
+
Controller::Lightning::Channel::UpdateFee.perform(
|
54
|
+
@components,
|
55
|
+
@policy, @policy.transaction, params,
|
56
|
+
preview: preview, &vcr
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def base=(value)
|
61
|
+
protect!(value)
|
62
|
+
|
63
|
+
@base = value[:value]
|
64
|
+
|
65
|
+
@data[:base] = { millisatoshis: @base.millisatoshis }
|
66
|
+
|
67
|
+
base
|
68
|
+
end
|
69
|
+
|
70
|
+
def rate=(value)
|
71
|
+
protect!(value)
|
72
|
+
|
73
|
+
@rate = value[:value]
|
74
|
+
|
75
|
+
@data[:rate] = { parts_per_million: @rate.parts_per_million }
|
76
|
+
|
77
|
+
rate
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../../../concerns/protectable'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Lightning
|
8
|
+
class BlocksDelta
|
9
|
+
include Protectable
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def minimum
|
16
|
+
@minimum ||= @data[:minimum]
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_h
|
20
|
+
{
|
21
|
+
minimum: minimum
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def dump
|
26
|
+
Marshal.load(Marshal.dump(@data))
|
27
|
+
end
|
28
|
+
|
29
|
+
def minimum=(value)
|
30
|
+
protect!(value)
|
31
|
+
|
32
|
+
@minimum = value[:value]
|
33
|
+
|
34
|
+
@data[:minimum] = @minimum
|
35
|
+
|
36
|
+
minimum
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../satoshis'
|
4
|
+
require_relative '../../rate'
|
5
|
+
require_relative '../../../concerns/protectable'
|
6
|
+
require_relative 'htlc/blocks/delta'
|
7
|
+
|
8
|
+
module Lighstorm
|
9
|
+
module Model
|
10
|
+
module Lightning
|
11
|
+
class HTLC
|
12
|
+
include Protectable
|
13
|
+
|
14
|
+
def initialize(data)
|
15
|
+
@data = data
|
16
|
+
end
|
17
|
+
|
18
|
+
def minimum
|
19
|
+
@minimum ||= if @data[:minimum]
|
20
|
+
Satoshis.new(
|
21
|
+
millisatoshis: @data[:minimum][:millisatoshis]
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def maximum
|
27
|
+
@maximum ||= if @data[:maximum]
|
28
|
+
Satoshis.new(
|
29
|
+
millisatoshis: @data[:maximum][:millisatoshis]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def blocks
|
35
|
+
@blocks ||= Struct.new(:data) do
|
36
|
+
def delta
|
37
|
+
@delta ||= BlocksDelta.new(data[:delta] || {})
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump
|
41
|
+
{ delta: delta.dump }
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_h
|
45
|
+
{ delta: delta.to_h }
|
46
|
+
end
|
47
|
+
end.new(@data[:blocks] || {})
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_h
|
51
|
+
{
|
52
|
+
minimum: minimum.to_h,
|
53
|
+
maximum: maximum.to_h,
|
54
|
+
blocks: blocks.to_h
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
def dump
|
59
|
+
result = Marshal.load(Marshal.dump(@data))
|
60
|
+
|
61
|
+
result = result.merge({ blocks: blocks.dump }) if @data[:blocks]
|
62
|
+
|
63
|
+
result
|
64
|
+
end
|
65
|
+
|
66
|
+
def minimum=(value)
|
67
|
+
protect!(value)
|
68
|
+
|
69
|
+
@minimum = value[:value]
|
70
|
+
|
71
|
+
@data[:minimum] = { millisatoshis: @minimum.millisatoshis }
|
72
|
+
|
73
|
+
minimum
|
74
|
+
end
|
75
|
+
|
76
|
+
def maximum=(value)
|
77
|
+
protect!(value)
|
78
|
+
|
79
|
+
@maximum = value[:value]
|
80
|
+
|
81
|
+
@data[:maximum] = { millisatoshis: @maximum.millisatoshis }
|
82
|
+
|
83
|
+
maximum
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'fee'
|
4
|
+
require_relative 'htlc'
|
5
|
+
|
6
|
+
module Lighstorm
|
7
|
+
module Model
|
8
|
+
module Lightning
|
9
|
+
class Policy
|
10
|
+
attr_reader :transaction
|
11
|
+
|
12
|
+
def initialize(data, components, transaction)
|
13
|
+
@data = data
|
14
|
+
@components = components
|
15
|
+
@transaction = transaction
|
16
|
+
end
|
17
|
+
|
18
|
+
def fee
|
19
|
+
@fee ||= Fee.new(self, @components, @data ? @data[:fee] : {})
|
20
|
+
end
|
21
|
+
|
22
|
+
def htlc
|
23
|
+
@htlc ||= HTLC.new(@data ? @data[:htlc] : {})
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_h
|
27
|
+
{ fee: fee.to_h, htlc: htlc.to_h }
|
28
|
+
end
|
29
|
+
|
30
|
+
def dump
|
31
|
+
result = Marshal.load(Marshal.dump(@data))
|
32
|
+
|
33
|
+
result = result.merge({ fee: fee.dump }) if @data && @data[:fee]
|
34
|
+
result = result.merge({ htlc: htlc.dump }) if @data && @data[:htlc]
|
35
|
+
|
36
|
+
result
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'channel_node/policy'
|
4
|
+
require_relative 'channel_node/accounting'
|
5
|
+
|
6
|
+
require_relative '../nodes/node'
|
7
|
+
require_relative '../../errors'
|
8
|
+
|
9
|
+
module Lighstorm
|
10
|
+
module Model
|
11
|
+
module Lightning
|
12
|
+
class ChannelNode
|
13
|
+
include Protectable
|
14
|
+
|
15
|
+
attr_reader :state
|
16
|
+
|
17
|
+
def initialize(data, components, is_mine, transaction)
|
18
|
+
@data = data
|
19
|
+
@components = components
|
20
|
+
@state = data[:state]
|
21
|
+
@initiator = data[:initiator]
|
22
|
+
@is_mine = is_mine
|
23
|
+
@transaction = transaction
|
24
|
+
end
|
25
|
+
|
26
|
+
def active?
|
27
|
+
state == 'active'
|
28
|
+
end
|
29
|
+
|
30
|
+
def initiator?
|
31
|
+
@initiator
|
32
|
+
end
|
33
|
+
|
34
|
+
def node
|
35
|
+
@node ||= Node.new(@data[:node], @components)
|
36
|
+
end
|
37
|
+
|
38
|
+
def policy
|
39
|
+
@policy ||= Policy.new(@data[:policy], @components, @transaction)
|
40
|
+
end
|
41
|
+
|
42
|
+
def accounting
|
43
|
+
raise Errors::NotYourChannelError unless @is_mine
|
44
|
+
|
45
|
+
@accounting ||= @data[:accounting] ? ChannelNodeAccounting.new(@data[:accounting]) : nil
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_h
|
49
|
+
restult = {
|
50
|
+
state: state,
|
51
|
+
initiator: @initiator,
|
52
|
+
node: node.to_h
|
53
|
+
}
|
54
|
+
|
55
|
+
restult[:accounting] = accounting.to_h if @is_mine
|
56
|
+
restult[:policy] = policy.to_h if @data[:policy]
|
57
|
+
|
58
|
+
restult
|
59
|
+
end
|
60
|
+
|
61
|
+
def dump
|
62
|
+
result = Marshal.load(Marshal.dump(@data)).merge(
|
63
|
+
{
|
64
|
+
node: node.dump,
|
65
|
+
policy: policy.dump
|
66
|
+
}
|
67
|
+
)
|
68
|
+
|
69
|
+
result[:accounting] = accounting.dump if @is_mine
|
70
|
+
result.delete(:policy) if result[:policy].nil?
|
71
|
+
|
72
|
+
result
|
73
|
+
end
|
74
|
+
|
75
|
+
def state=(value)
|
76
|
+
protect!(value)
|
77
|
+
|
78
|
+
@state = value[:value]
|
79
|
+
@data[:state] = @state
|
80
|
+
|
81
|
+
state
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../edges/channel'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Lightning
|
8
|
+
class ForwardChannel
|
9
|
+
def initialize(data, components)
|
10
|
+
@data = data
|
11
|
+
@components = components
|
12
|
+
end
|
13
|
+
|
14
|
+
def amount
|
15
|
+
@amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
|
16
|
+
end
|
17
|
+
|
18
|
+
def channel
|
19
|
+
@channel ||= Channel.new(@data[:channel], @components)
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
{
|
24
|
+
amount: amount.to_h,
|
25
|
+
channel: channel.to_h
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../edges/channel/hop'
|
4
|
+
require_relative '../nodes/node'
|
5
|
+
|
6
|
+
module Lighstorm
|
7
|
+
module Model
|
8
|
+
module Lightning
|
9
|
+
class PaymentChannel
|
10
|
+
attr_reader :hop
|
11
|
+
|
12
|
+
def initialize(data, payment)
|
13
|
+
@data = data
|
14
|
+
|
15
|
+
@hop = data[:hop]
|
16
|
+
@payment = payment
|
17
|
+
end
|
18
|
+
|
19
|
+
def first?
|
20
|
+
@hop == 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def last?
|
24
|
+
@data[:is_last] == true
|
25
|
+
end
|
26
|
+
|
27
|
+
def amount
|
28
|
+
@amount ||= @data[:amount] ? Satoshis.new(millisatoshis: @data[:amount][:millisatoshis]) : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def fee
|
32
|
+
@fee ||= @data[:fee] ? Satoshis.new(millisatoshis: @data[:fee][:millisatoshis]) : nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def channel
|
36
|
+
@channel ||= HopChannel.new(@data, @payment)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_h
|
40
|
+
result = {
|
41
|
+
hop: hop,
|
42
|
+
channel: channel.to_h
|
43
|
+
}
|
44
|
+
|
45
|
+
result[:amount] = amount.to_h if amount
|
46
|
+
if fee
|
47
|
+
result[:fee] = {
|
48
|
+
millisatoshis: fee.millisatoshis,
|
49
|
+
parts_per_million: fee.parts_per_million(amount.millisatoshis)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
result
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|