lighstorm 0.0.14 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +7 -7
  4. data/README.md +7 -7
  5. data/adapters/bitcoin/address.rb +19 -0
  6. data/adapters/bitcoin/transaction.rb +34 -0
  7. data/adapters/lightning/connections/channel_node/fee.rb +28 -0
  8. data/adapters/lightning/connections/channel_node/policy.rb +63 -0
  9. data/adapters/lightning/connections/channel_node.rb +77 -0
  10. data/adapters/lightning/connections/payment_channel.rb +30 -0
  11. data/adapters/lightning/edges/channel.rb +98 -0
  12. data/adapters/lightning/edges/forward.rb +42 -0
  13. data/adapters/lightning/edges/payment/purpose.rb +45 -0
  14. data/adapters/lightning/edges/payment.rb +89 -0
  15. data/adapters/lightning/invoice.rb +186 -0
  16. data/adapters/lightning/nodes/node.rb +113 -0
  17. data/controllers/action.rb +1 -1
  18. data/controllers/bitcoin/address/actions/create.rb +91 -0
  19. data/controllers/bitcoin/address/actions/pay.rb +119 -0
  20. data/controllers/bitcoin/address.rb +24 -0
  21. data/controllers/bitcoin/transaction/all.rb +65 -0
  22. data/controllers/bitcoin/transaction.rb +25 -0
  23. data/controllers/concerns/impersonatable.rb +5 -3
  24. data/controllers/connection.rb +1 -1
  25. data/controllers/lightning/channel/actions/apply_gossip.rb +201 -0
  26. data/controllers/lightning/channel/actions/update_fee.rb +94 -0
  27. data/controllers/lightning/channel/all.rb +85 -0
  28. data/controllers/lightning/channel/find_by_id.rb +155 -0
  29. data/controllers/lightning/channel/mine.rb +116 -0
  30. data/controllers/lightning/channel.rb +43 -0
  31. data/controllers/lightning/forward/all.rb +250 -0
  32. data/controllers/lightning/forward/group_by_channel.rb +91 -0
  33. data/controllers/lightning/forward.rb +36 -0
  34. data/controllers/lightning/invoice/actions/create.rb +90 -0
  35. data/controllers/lightning/invoice/actions/pay.rb +97 -0
  36. data/controllers/lightning/invoice/actions/pay_through_route.rb +73 -0
  37. data/controllers/lightning/invoice/all.rb +82 -0
  38. data/controllers/lightning/invoice/decode.rb +50 -0
  39. data/controllers/lightning/invoice/find_by_code.rb +76 -0
  40. data/controllers/lightning/invoice/find_by_secret_hash.rb +56 -0
  41. data/controllers/lightning/invoice.rb +64 -0
  42. data/controllers/lightning/node/actions/apply_gossip.rb +114 -0
  43. data/controllers/lightning/node/actions/pay.rb +117 -0
  44. data/controllers/lightning/node/all.rb +69 -0
  45. data/controllers/lightning/node/find_by_public_key.rb +55 -0
  46. data/controllers/lightning/node/myself.rb +36 -0
  47. data/controllers/lightning/node.rb +35 -0
  48. data/controllers/lightning/payment/actions/pay.rb +110 -0
  49. data/controllers/lightning/payment/all.rb +439 -0
  50. data/controllers/lightning/payment.rb +37 -0
  51. data/controllers/lightning/secret/valid_proof.rb +60 -0
  52. data/controllers/lightning/secret.rb +16 -0
  53. data/controllers/wallet/activity/all.rb +196 -0
  54. data/controllers/wallet/activity.rb +28 -0
  55. data/controllers/wallet/balance.rb +3 -3
  56. data/controllers/wallet.rb +1 -1
  57. data/docs/README.md +229 -148
  58. data/docs/_coverpage.md +1 -1
  59. data/docs/index.html +1 -1
  60. data/lighstorm.gemspec +1 -1
  61. data/models/bitcoin/address.rb +49 -0
  62. data/models/bitcoin/transaction.rb +41 -0
  63. data/models/concerns/protectable.rb +1 -1
  64. data/models/errors.rb +7 -8
  65. data/models/lightning/connections/channel_node/accounting.rb +27 -0
  66. data/models/lightning/connections/channel_node/fee.rb +82 -0
  67. data/models/lightning/connections/channel_node/htlc/blocks/delta.rb +41 -0
  68. data/models/lightning/connections/channel_node/htlc.rb +88 -0
  69. data/models/lightning/connections/channel_node/policy.rb +41 -0
  70. data/models/lightning/connections/channel_node.rb +86 -0
  71. data/models/lightning/connections/forward_channel.rb +31 -0
  72. data/models/lightning/connections/payment_channel.rb +58 -0
  73. data/models/lightning/edges/channel/accounting.rb +87 -0
  74. data/models/lightning/edges/channel/hop.rb +67 -0
  75. data/models/lightning/edges/channel.rb +197 -0
  76. data/models/lightning/edges/forward.rb +51 -0
  77. data/models/lightning/edges/groups/channel_forwards/analysis.rb +71 -0
  78. data/models/lightning/edges/groups/channel_forwards.rb +39 -0
  79. data/models/lightning/edges/payment.rb +104 -0
  80. data/models/lightning/invoice.rb +115 -0
  81. data/models/lightning/nodes/node/lightning.rb +33 -0
  82. data/models/lightning/nodes/node/platform.rb +50 -0
  83. data/models/lightning/nodes/node.rb +145 -0
  84. data/models/lightning/rate.rb +37 -0
  85. data/models/lightning/secret.rb +57 -0
  86. data/models/satoshis.rb +1 -1
  87. data/models/wallet/activity.rb +54 -0
  88. data/models/wallet/balance.rb +42 -0
  89. data/ports/dsl/lighstorm.rb +29 -16
  90. data/static/cache.rb +2 -0
  91. data/static/spec.rb +1 -1
  92. metadata +76 -70
  93. data/adapters/connections/channel_node/fee.rb +0 -26
  94. data/adapters/connections/channel_node/policy.rb +0 -61
  95. data/adapters/connections/channel_node.rb +0 -75
  96. data/adapters/connections/payment_channel.rb +0 -28
  97. data/adapters/edges/channel.rb +0 -96
  98. data/adapters/edges/forward.rb +0 -40
  99. data/adapters/edges/payment/purpose.rb +0 -43
  100. data/adapters/edges/payment.rb +0 -87
  101. data/adapters/invoice.rb +0 -184
  102. data/adapters/nodes/node.rb +0 -111
  103. data/adapters/transaction.rb +0 -23
  104. data/controllers/activity/all.rb +0 -194
  105. data/controllers/activity.rb +0 -26
  106. data/controllers/channel/actions/apply_gossip.rb +0 -193
  107. data/controllers/channel/actions/update_fee.rb +0 -91
  108. data/controllers/channel/all.rb +0 -83
  109. data/controllers/channel/find_by_id.rb +0 -153
  110. data/controllers/channel/mine.rb +0 -114
  111. data/controllers/channel.rb +0 -41
  112. data/controllers/forward/all.rb +0 -248
  113. data/controllers/forward/group_by_channel.rb +0 -89
  114. data/controllers/forward.rb +0 -34
  115. data/controllers/invoice/actions/create.rb +0 -88
  116. data/controllers/invoice/actions/pay.rb +0 -95
  117. data/controllers/invoice/actions/pay_through_route.rb +0 -71
  118. data/controllers/invoice/all.rb +0 -80
  119. data/controllers/invoice/decode.rb +0 -44
  120. data/controllers/invoice/find_by_code.rb +0 -70
  121. data/controllers/invoice/find_by_secret_hash.rb +0 -54
  122. data/controllers/invoice.rb +0 -62
  123. data/controllers/node/actions/apply_gossip.rb +0 -112
  124. data/controllers/node/actions/pay.rb +0 -115
  125. data/controllers/node/all.rb +0 -67
  126. data/controllers/node/find_by_public_key.rb +0 -53
  127. data/controllers/node/myself.rb +0 -34
  128. data/controllers/node.rb +0 -33
  129. data/controllers/payment/actions/pay.rb +0 -108
  130. data/controllers/payment/all.rb +0 -437
  131. data/controllers/payment.rb +0 -35
  132. data/controllers/secret/valid_proof.rb +0 -58
  133. data/controllers/transaction/all.rb +0 -61
  134. data/controllers/transaction.rb +0 -25
  135. data/models/activity.rb +0 -52
  136. data/models/connections/channel_node/accounting.rb +0 -25
  137. data/models/connections/channel_node/fee.rb +0 -80
  138. data/models/connections/channel_node/htlc/blocks/delta.rb +0 -39
  139. data/models/connections/channel_node/htlc.rb +0 -86
  140. data/models/connections/channel_node/policy.rb +0 -39
  141. data/models/connections/channel_node.rb +0 -84
  142. data/models/connections/forward_channel.rb +0 -29
  143. data/models/connections/payment_channel.rb +0 -56
  144. data/models/edges/channel/accounting.rb +0 -85
  145. data/models/edges/channel/hop.rb +0 -65
  146. data/models/edges/channel.rb +0 -195
  147. data/models/edges/forward.rb +0 -49
  148. data/models/edges/groups/channel_forwards/analysis.rb +0 -69
  149. data/models/edges/groups/channel_forwards.rb +0 -37
  150. data/models/edges/payment.rb +0 -102
  151. data/models/invoice.rb +0 -113
  152. data/models/nodes/node/lightning.rb +0 -31
  153. data/models/nodes/node/platform.rb +0 -48
  154. data/models/nodes/node.rb +0 -143
  155. data/models/rate.rb +0 -35
  156. data/models/secret.rb +0 -55
  157. data/models/transaction.rb +0 -39
  158. data/models/wallet.rb +0 -40
data/docs/_coverpage.md CHANGED
@@ -8,7 +8,7 @@
8
8
  - Built for maximum **reliability**.
9
9
  - Optimized for programmer **happiness**.
10
10
 
11
- 0.0.14
11
+ 0.0.16
12
12
 
13
13
  ⚠️ _Warning: Early-stage, breaking changes are expected._
14
14
 
data/docs/index.html CHANGED
@@ -18,7 +18,7 @@
18
18
  <script>
19
19
  window.$docsify = {
20
20
  coverpage: true,
21
- name: 'Lighstorm 0.0.14',
21
+ name: 'Lighstorm 0.0.16',
22
22
  repo: 'https://github.com/icebaker/lighstorm'
23
23
  }
24
24
  </script>
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.7'
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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lighstorm
4
- module Models
4
+ module Model
5
5
  module Protectable
6
6
  def prepare_token!(token)
7
7
  @token = token
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 MissingGossipHandlerError < LighstormError; end
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 UpdateChannelPolicyError < RequestError; end
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