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
@@ -1,195 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- require_relative '../../ports/grpc'
6
- require_relative '../../adapters/edges/channel'
7
-
8
- require_relative '../nodes/node'
9
- require_relative './channel/accounting'
10
-
11
- require_relative '../../controllers/channel/actions/apply_gossip'
12
- require_relative '../connections/channel_node'
13
- require_relative '../satoshis'
14
-
15
- require_relative '../errors'
16
-
17
- module Lighstorm
18
- module Models
19
- class Channel
20
- attr_reader :data, :_key, :id
21
-
22
- def initialize(data, components)
23
- @data = data
24
- @components = components
25
-
26
- @_key = data[:_key]
27
- @id = data[:id]
28
- end
29
-
30
- def known?
31
- @data[:known] == true
32
- end
33
-
34
- def mine?
35
- ensure_known!
36
-
37
- @data[:mine]
38
- end
39
-
40
- def exposure
41
- ensure_known!
42
-
43
- @data[:exposure]
44
- end
45
-
46
- def opened_at
47
- ensure_mine!
48
-
49
- @data[:opened_at]
50
- end
51
-
52
- def up_at
53
- ensure_mine!
54
-
55
- @data[:up_at]
56
- end
57
-
58
- def active?
59
- ensure_mine!
60
-
61
- @data[:state] == 'active'
62
- end
63
-
64
- def state
65
- ensure_mine!
66
-
67
- @data[:state]
68
- end
69
-
70
- def accounting
71
- ensure_known!
72
-
73
- @accounting ||= @data[:accounting] ? ChannelAccounting.new(@data[:accounting], mine?) : nil
74
- end
75
-
76
- def partners
77
- @partners ||= if @data[:partners]
78
- @data[:partners].map do |data|
79
- ChannelNode.new(data, @components, known? ? mine? : nil, transaction)
80
- end
81
- else
82
- []
83
- end
84
- end
85
-
86
- def myself
87
- ensure_mine!
88
-
89
- @myself ||= partners.find { |partner| partner.node.myself? }
90
- end
91
-
92
- def partner
93
- ensure_mine!
94
-
95
- @partner ||= partners.find { |partner| !partner.node.myself? }
96
- end
97
-
98
- def transaction
99
- Struct.new(:data) do
100
- def funding
101
- Struct.new(:data) do
102
- def id
103
- data[:id]
104
- end
105
-
106
- def index
107
- data[:index]
108
- end
109
-
110
- def to_h
111
- { id: id, index: index }
112
- end
113
- end.new(data[:funding])
114
- end
115
-
116
- def to_h
117
- { funding: funding.to_h }
118
- end
119
- end.new(@data[:transaction])
120
- end
121
-
122
- def to_h
123
- if !known? && partners.size.positive?
124
- { _key: _key, id: id, partners: partners.map(&:to_h) }
125
- elsif !known?
126
- { _key: _key, id: id }
127
- elsif mine?
128
- {
129
- _key: _key,
130
- id: id,
131
- opened_at: opened_at,
132
- up_at: up_at,
133
- state: state,
134
- exposure: exposure,
135
- accounting: accounting.to_h,
136
- partner: partner.to_h,
137
- myself: myself.to_h
138
- }
139
- elsif @data[:accounting]
140
- {
141
- _key: _key,
142
- id: id,
143
- accounting: accounting.to_h,
144
- partners: partners.map(&:to_h)
145
- }
146
- else
147
- {
148
- _key: _key,
149
- id: id,
150
- partners: partners.map(&:to_h)
151
- }
152
- end
153
- end
154
-
155
- def dump
156
- result = Marshal.load(Marshal.dump(@data)).merge(
157
- { partners: partners.map(&:dump) }
158
- )
159
-
160
- result[:accounting] = accounting.dump if known?
161
-
162
- result
163
- end
164
-
165
- def self.adapt(gossip: nil, dump: nil)
166
- raise TooManyArgumentsError, 'you need to pass gossip: or dump:, not both' if !gossip.nil? && !dump.nil?
167
-
168
- raise ArgumentError, 'missing gossip: or dump:' if gossip.nil? && dump.nil?
169
-
170
- if !gossip.nil?
171
- new(Adapter::Channel.subscribe_channel_graph(gossip), nil)
172
- elsif !dump.nil?
173
- new(dump, nil)
174
- end
175
- end
176
-
177
- def apply!(gossip:)
178
- Controllers::Channel::ApplyGossip.perform(
179
- self, gossip
180
- )
181
- end
182
-
183
- private
184
-
185
- def ensure_known!
186
- raise Errors::UnknownChannelError unless known?
187
- end
188
-
189
- def ensure_mine!
190
- ensure_known!
191
- raise Errors::NotYourChannelError if @data[:mine] == false
192
- end
193
- end
194
- end
195
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- require_relative '../satoshis'
6
-
7
- require_relative '../connections/forward_channel'
8
- require_relative 'groups/channel_forwards'
9
-
10
- module Lighstorm
11
- module Models
12
- class Forward
13
- attr_reader :_key, :at
14
-
15
- def initialize(data, components)
16
- @data = data
17
- @components = components
18
-
19
- @_key = data[:_key]
20
- @at = data[:at]
21
- end
22
-
23
- def fee
24
- @fee ||= Satoshis.new(millisatoshis: @data[:fee][:millisatoshis])
25
- end
26
-
27
- def in
28
- @in ||= ForwardChannel.new(@data[:in], @components)
29
- end
30
-
31
- def out
32
- @out ||= ForwardChannel.new(@data[:out], @components)
33
- end
34
-
35
- def to_h
36
- {
37
- _key: _key,
38
- at: at,
39
- fee: {
40
- millisatoshis: fee.millisatoshis,
41
- parts_per_million: fee.parts_per_million(self.in.amount.millisatoshis)
42
- },
43
- in: self.in.to_h,
44
- out: out.to_h
45
- }
46
- end
47
- end
48
- end
49
- end
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lighstorm
4
- module Models
5
- class ChannelForwardsGroup
6
- Analysis = Struct.new(:data) do
7
- def count
8
- data[:count]
9
- end
10
-
11
- def sums
12
- Struct.new(:sums) do
13
- def amount
14
- Satoshis.new(millisatoshis: sums[:amount][:millisatoshis])
15
- end
16
-
17
- def fee
18
- Satoshis.new(millisatoshis: sums[:fee][:millisatoshis])
19
- end
20
-
21
- def to_h
22
- {
23
- amount: amount.to_h,
24
- fee: {
25
- millisatoshis: fee.millisatoshis,
26
- parts_per_million: fee.parts_per_million(amount.millisatoshis)
27
- }
28
- }
29
- end
30
- end.new(data[:sums])
31
- end
32
-
33
- def averages
34
- Struct.new(:data) do
35
- def amount
36
- Satoshis.new(
37
- millisatoshis: data[:sums][:amount][:millisatoshis].to_f / data[:count]
38
- )
39
- end
40
-
41
- def fee
42
- Satoshis.new(
43
- millisatoshis: data[:sums][:fee][:millisatoshis].to_f / data[:count]
44
- )
45
- end
46
-
47
- def to_h
48
- {
49
- amount: amount.to_h,
50
- fee: {
51
- millisatoshis: fee.millisatoshis,
52
- parts_per_million: fee.parts_per_million(amount.millisatoshis)
53
- }
54
- }
55
- end
56
- end.new(data)
57
- end
58
-
59
- def to_h
60
- {
61
- count: count,
62
- sums: sums.to_h,
63
- averages: averages.to_h
64
- }
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../satoshis'
4
- require_relative 'channel_forwards/analysis'
5
-
6
- module Lighstorm
7
- module Models
8
- class ChannelForwardsGroup
9
- attr_reader :_key, :last_at
10
-
11
- def initialize(data, components)
12
- @data = data
13
- @components = components
14
-
15
- @_key = data[:_key]
16
- @last_at = data[:last_at]
17
- end
18
-
19
- def analysis
20
- Analysis.new(@data[:analysis])
21
- end
22
-
23
- def channel
24
- @channel ||= Channel.new(@data[:channel], @components)
25
- end
26
-
27
- def to_h
28
- {
29
- _key: _key,
30
- last_at: last_at,
31
- analysis: analysis.to_h,
32
- channel: channel.to_h
33
- }
34
- end
35
- end
36
- end
37
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
-
5
- require_relative '../satoshis'
6
-
7
- require_relative '../connections/payment_channel'
8
- require_relative '../nodes/node'
9
- require_relative '../invoice'
10
- require_relative '../secret'
11
-
12
- module Lighstorm
13
- module Models
14
- class Payment
15
- attr_reader :_key, :at, :state, :secret, :purpose, :through, :message
16
-
17
- def initialize(data, components)
18
- @data = data
19
- @components = components
20
-
21
- @_key = data[:_key]
22
- @at = data[:at]
23
- @state = data[:state]
24
- @purpose = data[:purpose]
25
- @through = data[:through]
26
- @message = data[:message]
27
- end
28
-
29
- def how
30
- @how ||= spontaneous? ? 'spontaneously' : 'with-invoice'
31
- end
32
-
33
- def invoice
34
- @invoice ||= !spontaneous? && @data[:invoice] ? Invoice.new(@data[:invoice], @components) : nil
35
- end
36
-
37
- def amount
38
- @amount ||= @data[:amount] ? Satoshis.new(millisatoshis: @data[:amount][:millisatoshis]) : nil
39
- end
40
-
41
- def fee
42
- @fee ||= @data[:fee] ? Satoshis.new(millisatoshis: @data[:fee][:millisatoshis]) : nil
43
- end
44
-
45
- def secret
46
- @secret ||= @data[:secret] ? Secret.new(@data[:secret], @components) : nil
47
- end
48
-
49
- def hops
50
- return @hops if @hops
51
- return nil if @data[:hops].nil?
52
-
53
- @data[:hops].last[:is_last] = true
54
- @hops = @data[:hops].map do |hop|
55
- PaymentChannel.new(hop, self)
56
- end
57
- end
58
-
59
- def from
60
- @from ||= @data[:hops].nil? ? nil : hops.first
61
- end
62
-
63
- def to
64
- @to ||= @data[:hops].nil? ? nil : hops.last
65
- end
66
-
67
- def to_h
68
- response = {
69
- _key: _key,
70
- at: at,
71
- state: state,
72
- through: through,
73
- purpose: purpose,
74
- how: how,
75
- message: message,
76
- invoice: invoice&.to_h,
77
- from: from.to_h,
78
- to: to.to_h
79
- }
80
-
81
- response[:secret] = secret.to_h if secret
82
- response[:amount] = amount.to_h if amount
83
- if fee
84
- response[:fee] = {
85
- millisatoshis: fee.millisatoshis,
86
- parts_per_million: fee.parts_per_million(amount.millisatoshis)
87
- }
88
- end
89
-
90
- response[:hops] = hops.map(&:to_h) unless hops.nil?
91
-
92
- response
93
- end
94
-
95
- private
96
-
97
- def spontaneous?
98
- !@data[:invoice] || @data[:invoice][:code].nil?
99
- end
100
- end
101
- end
102
- end
data/models/invoice.rb DELETED
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'satoshis'
4
- require 'securerandom'
5
-
6
- require_relative '../controllers/invoice/actions/create'
7
- require_relative '../controllers/invoice/actions/pay'
8
- require_relative '../controllers/invoice/actions/pay_through_route'
9
-
10
- module Lighstorm
11
- module Models
12
- class Invoice
13
- attr_reader :_key, :created_at, :expires_at, :settled_at, :state, :payable, :code
14
-
15
- def initialize(data, components)
16
- @data = data
17
- @components = components
18
-
19
- @_key = data[:_key]
20
- @created_at = data[:created_at]
21
- @expires_at = data[:expires_at]
22
- @settled_at = data[:settled_at]
23
- @state = data[:state]
24
-
25
- @payable = data[:payable]
26
-
27
- @code = data[:code]
28
- end
29
-
30
- def payment
31
- if payable != 'once' || @data[:payments].size > 1
32
- raise InvoiceMayHaveMultiplePaymentsError, "payable: #{payable}, payments: #{@data[:payments].size.size}"
33
- end
34
-
35
- @payment ||= payments.first
36
- end
37
-
38
- def payments
39
- @payments ||= @data[:payments]&.map { |data| Payment.new(data, @components) }
40
- end
41
-
42
- def amount
43
- @amount ||= @data[:amount] ? Satoshis.new(millisatoshis: @data[:amount][:millisatoshis]) : nil
44
- end
45
-
46
- def received
47
- @received ||= @data[:received] ? Satoshis.new(millisatoshis: @data[:received][:millisatoshis]) : nil
48
- end
49
-
50
- def secret
51
- @secret ||= Secret.new(@data[:secret], @components)
52
- end
53
-
54
- def description
55
- @description ||= Struct.new(:data) do
56
- def memo
57
- data[:memo]
58
- end
59
-
60
- def hash
61
- data[:hash]
62
- end
63
-
64
- def to_h
65
- { memo: memo, hash: hash }
66
- end
67
- end.new(@data[:description] || {})
68
- end
69
-
70
- def to_h
71
- result = {
72
- _key: _key,
73
- created_at: created_at,
74
- expires_at: expires_at,
75
- settled_at: settled_at,
76
- payable: payable,
77
- state: state,
78
- code: code,
79
- amount: amount&.to_h,
80
- received: received&.to_h,
81
- description: description.to_h,
82
- secret: secret.to_h,
83
- payments: payments&.map(&:to_h)
84
- }
85
- end
86
-
87
- def pay(
88
- amount: nil, message: nil, route: nil,
89
- fee: nil,
90
- times_out_in: { seconds: 5 },
91
- preview: false
92
- )
93
- raise MissingComponentsError if @components.nil?
94
-
95
- if route
96
- Controllers::Invoice::PayThroughRoute.perform(
97
- @components, self, route: route, preview: preview
98
- )
99
- else
100
- Controllers::Invoice::Pay.perform(
101
- @components,
102
- code: code,
103
- amount: amount,
104
- fee: fee,
105
- message: message,
106
- times_out_in: times_out_in,
107
- preview: preview
108
- )
109
- end
110
- end
111
- end
112
- end
113
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lighstorm
4
- module Models
5
- class Lightning
6
- IMPLEMENTATION = 'lnd'
7
-
8
- attr_reader :implementation, :version
9
-
10
- def initialize(node)
11
- raise Errors::NotYourNodeError unless node.myself?
12
-
13
- @implementation = IMPLEMENTATION
14
- @version = node.data[:platform][:lightning][:version]
15
- end
16
-
17
- def to_h
18
- {
19
- implementation: implementation,
20
- version: version
21
- }
22
- end
23
-
24
- def dump
25
- Marshal.load(
26
- Marshal.dump({ implementation: implementation, version: version })
27
- )
28
- end
29
- end
30
- end
31
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lightning'
4
-
5
- require_relative '../../..//ports/grpc'
6
- require_relative '../../../adapters/nodes/node'
7
-
8
- module Lighstorm
9
- module Models
10
- class Platform
11
- attr_reader :data
12
-
13
- def initialize(node)
14
- @node = node
15
- @data = @node.data[:platform]
16
- end
17
-
18
- def blockchain
19
- @blockchain ||= @data ? @data[:blockchain] : nil
20
- end
21
-
22
- def network
23
- @network ||= @data ? @data[:network] : nil
24
- end
25
-
26
- def lightning
27
- @lightning ||= Lightning.new(@node)
28
- end
29
-
30
- def to_h
31
- response = {
32
- blockchain: blockchain,
33
- network: network
34
- }
35
-
36
- response[:lightning] = lightning.to_h if @node.myself?
37
-
38
- response
39
- end
40
-
41
- def dump
42
- data = Marshal.load(Marshal.dump(@data))
43
- data.merge(lightning: lightning.dump) if @node.myself?
44
- data
45
- end
46
- end
47
- end
48
- end