lighstorm 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +7 -7
  4. data/adapters/bitcoin/address.rb +19 -0
  5. data/adapters/bitcoin/transaction.rb +34 -0
  6. data/adapters/lightning/connections/channel_node/fee.rb +28 -0
  7. data/adapters/lightning/connections/channel_node/policy.rb +63 -0
  8. data/adapters/lightning/connections/channel_node.rb +77 -0
  9. data/adapters/lightning/connections/payment_channel.rb +30 -0
  10. data/adapters/lightning/edges/channel.rb +98 -0
  11. data/adapters/lightning/edges/forward.rb +42 -0
  12. data/adapters/lightning/edges/payment/purpose.rb +45 -0
  13. data/adapters/lightning/edges/payment.rb +89 -0
  14. data/adapters/lightning/invoice.rb +186 -0
  15. data/adapters/lightning/nodes/node.rb +113 -0
  16. data/controllers/action.rb +1 -1
  17. data/controllers/bitcoin/address/actions/create.rb +91 -0
  18. data/controllers/bitcoin/address/actions/pay.rb +119 -0
  19. data/controllers/bitcoin/address.rb +24 -0
  20. data/controllers/bitcoin/transaction/all.rb +65 -0
  21. data/controllers/bitcoin/transaction.rb +25 -0
  22. data/controllers/concerns/impersonatable.rb +5 -3
  23. data/controllers/connection.rb +1 -1
  24. data/controllers/lightning/channel/actions/apply_gossip.rb +201 -0
  25. data/controllers/lightning/channel/actions/update_fee.rb +94 -0
  26. data/controllers/lightning/channel/all.rb +85 -0
  27. data/controllers/lightning/channel/find_by_id.rb +155 -0
  28. data/controllers/lightning/channel/mine.rb +116 -0
  29. data/controllers/lightning/channel.rb +43 -0
  30. data/controllers/lightning/forward/all.rb +250 -0
  31. data/controllers/lightning/forward/group_by_channel.rb +91 -0
  32. data/controllers/lightning/forward.rb +36 -0
  33. data/controllers/lightning/invoice/actions/create.rb +90 -0
  34. data/controllers/lightning/invoice/actions/pay.rb +97 -0
  35. data/controllers/lightning/invoice/actions/pay_through_route.rb +73 -0
  36. data/controllers/lightning/invoice/all.rb +82 -0
  37. data/controllers/lightning/invoice/decode.rb +50 -0
  38. data/controllers/lightning/invoice/find_by_code.rb +76 -0
  39. data/controllers/lightning/invoice/find_by_secret_hash.rb +56 -0
  40. data/controllers/lightning/invoice.rb +64 -0
  41. data/controllers/lightning/node/actions/apply_gossip.rb +114 -0
  42. data/controllers/lightning/node/actions/pay.rb +117 -0
  43. data/controllers/lightning/node/all.rb +69 -0
  44. data/controllers/lightning/node/find_by_public_key.rb +55 -0
  45. data/controllers/lightning/node/myself.rb +36 -0
  46. data/controllers/lightning/node.rb +35 -0
  47. data/controllers/lightning/payment/actions/pay.rb +110 -0
  48. data/controllers/lightning/payment/all.rb +439 -0
  49. data/controllers/lightning/payment.rb +37 -0
  50. data/controllers/lightning/secret/valid_proof.rb +60 -0
  51. data/controllers/lightning/secret.rb +16 -0
  52. data/controllers/wallet/activity/all.rb +196 -0
  53. data/controllers/wallet/activity.rb +28 -0
  54. data/controllers/wallet/balance.rb +3 -3
  55. data/controllers/wallet.rb +1 -1
  56. data/docs/README.md +229 -148
  57. data/docs/_coverpage.md +1 -1
  58. data/docs/index.html +1 -1
  59. data/models/bitcoin/address.rb +49 -0
  60. data/models/bitcoin/transaction.rb +41 -0
  61. data/models/concerns/protectable.rb +1 -1
  62. data/models/errors.rb +7 -8
  63. data/models/lightning/connections/channel_node/accounting.rb +27 -0
  64. data/models/lightning/connections/channel_node/fee.rb +82 -0
  65. data/models/lightning/connections/channel_node/htlc/blocks/delta.rb +41 -0
  66. data/models/lightning/connections/channel_node/htlc.rb +88 -0
  67. data/models/lightning/connections/channel_node/policy.rb +41 -0
  68. data/models/lightning/connections/channel_node.rb +86 -0
  69. data/models/lightning/connections/forward_channel.rb +31 -0
  70. data/models/lightning/connections/payment_channel.rb +58 -0
  71. data/models/lightning/edges/channel/accounting.rb +87 -0
  72. data/models/lightning/edges/channel/hop.rb +67 -0
  73. data/models/lightning/edges/channel.rb +197 -0
  74. data/models/lightning/edges/forward.rb +51 -0
  75. data/models/lightning/edges/groups/channel_forwards/analysis.rb +71 -0
  76. data/models/lightning/edges/groups/channel_forwards.rb +39 -0
  77. data/models/lightning/edges/payment.rb +104 -0
  78. data/models/lightning/invoice.rb +115 -0
  79. data/models/lightning/nodes/node/lightning.rb +33 -0
  80. data/models/lightning/nodes/node/platform.rb +50 -0
  81. data/models/lightning/nodes/node.rb +145 -0
  82. data/models/lightning/rate.rb +37 -0
  83. data/models/lightning/secret.rb +57 -0
  84. data/models/satoshis.rb +1 -1
  85. data/models/wallet/activity.rb +54 -0
  86. data/models/wallet/balance.rb +42 -0
  87. data/ports/dsl/lighstorm.rb +29 -16
  88. data/static/cache.rb +2 -0
  89. data/static/spec.rb +1 -1
  90. metadata +74 -68
  91. data/adapters/connections/channel_node/fee.rb +0 -26
  92. data/adapters/connections/channel_node/policy.rb +0 -61
  93. data/adapters/connections/channel_node.rb +0 -75
  94. data/adapters/connections/payment_channel.rb +0 -28
  95. data/adapters/edges/channel.rb +0 -96
  96. data/adapters/edges/forward.rb +0 -40
  97. data/adapters/edges/payment/purpose.rb +0 -43
  98. data/adapters/edges/payment.rb +0 -87
  99. data/adapters/invoice.rb +0 -184
  100. data/adapters/nodes/node.rb +0 -111
  101. data/adapters/transaction.rb +0 -23
  102. data/controllers/activity/all.rb +0 -194
  103. data/controllers/activity.rb +0 -26
  104. data/controllers/channel/actions/apply_gossip.rb +0 -193
  105. data/controllers/channel/actions/update_fee.rb +0 -91
  106. data/controllers/channel/all.rb +0 -83
  107. data/controllers/channel/find_by_id.rb +0 -153
  108. data/controllers/channel/mine.rb +0 -114
  109. data/controllers/channel.rb +0 -41
  110. data/controllers/forward/all.rb +0 -248
  111. data/controllers/forward/group_by_channel.rb +0 -89
  112. data/controllers/forward.rb +0 -34
  113. data/controllers/invoice/actions/create.rb +0 -88
  114. data/controllers/invoice/actions/pay.rb +0 -95
  115. data/controllers/invoice/actions/pay_through_route.rb +0 -71
  116. data/controllers/invoice/all.rb +0 -80
  117. data/controllers/invoice/decode.rb +0 -44
  118. data/controllers/invoice/find_by_code.rb +0 -70
  119. data/controllers/invoice/find_by_secret_hash.rb +0 -54
  120. data/controllers/invoice.rb +0 -62
  121. data/controllers/node/actions/apply_gossip.rb +0 -112
  122. data/controllers/node/actions/pay.rb +0 -115
  123. data/controllers/node/all.rb +0 -67
  124. data/controllers/node/find_by_public_key.rb +0 -53
  125. data/controllers/node/myself.rb +0 -34
  126. data/controllers/node.rb +0 -33
  127. data/controllers/payment/actions/pay.rb +0 -108
  128. data/controllers/payment/all.rb +0 -437
  129. data/controllers/payment.rb +0 -35
  130. data/controllers/secret/valid_proof.rb +0 -58
  131. data/controllers/transaction/all.rb +0 -61
  132. data/controllers/transaction.rb +0 -25
  133. data/models/activity.rb +0 -52
  134. data/models/connections/channel_node/accounting.rb +0 -25
  135. data/models/connections/channel_node/fee.rb +0 -80
  136. data/models/connections/channel_node/htlc/blocks/delta.rb +0 -39
  137. data/models/connections/channel_node/htlc.rb +0 -86
  138. data/models/connections/channel_node/policy.rb +0 -39
  139. data/models/connections/channel_node.rb +0 -84
  140. data/models/connections/forward_channel.rb +0 -29
  141. data/models/connections/payment_channel.rb +0 -56
  142. data/models/edges/channel/accounting.rb +0 -85
  143. data/models/edges/channel/hop.rb +0 -65
  144. data/models/edges/channel.rb +0 -195
  145. data/models/edges/forward.rb +0 -49
  146. data/models/edges/groups/channel_forwards/analysis.rb +0 -69
  147. data/models/edges/groups/channel_forwards.rb +0 -37
  148. data/models/edges/payment.rb +0 -102
  149. data/models/invoice.rb +0 -113
  150. data/models/nodes/node/lightning.rb +0 -31
  151. data/models/nodes/node/platform.rb +0 -48
  152. data/models/nodes/node.rb +0 -143
  153. data/models/rate.rb +0 -35
  154. data/models/secret.rb +0 -55
  155. data/models/transaction.rb +0 -39
  156. data/models/wallet.rb +0 -40
data/models/nodes/node.rb DELETED
@@ -1,143 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../../controllers/node/actions/apply_gossip'
4
- require_relative '../../controllers/node/actions/pay'
5
- require_relative '../../controllers/channel'
6
- require_relative '../../adapters/nodes/node'
7
- require_relative '../concerns/protectable'
8
- require_relative '../errors'
9
-
10
- require_relative 'node/platform'
11
-
12
- module Lighstorm
13
- module Models
14
- class Node
15
- include Protectable
16
-
17
- attr_reader :data, :_key, :alias, :public_key, :color
18
-
19
- def initialize(data, components)
20
- @data = data
21
- @components = components
22
-
23
- @_key = @data[:_key]
24
- @alias = @data[:alias]
25
- @public_key = @data[:public_key]
26
- @color = @data[:color]
27
- end
28
-
29
- def myself?
30
- @data[:myself] == true
31
- end
32
-
33
- def platform
34
- @platform ||= Platform.new(self)
35
- end
36
-
37
- def channels
38
- raise Errors::NotYourNodeError unless myself?
39
-
40
- raise MissingComponentsError if @components.nil?
41
-
42
- Controllers::Channel.mine(@components)
43
- end
44
-
45
- def to_h
46
- result = {
47
- _key: _key,
48
- public_key: public_key
49
- }
50
-
51
- result[:alias] = @alias unless self.alias.nil?
52
- result[:color] = @color unless color.nil?
53
-
54
- result[:platform] = platform.to_h if @data[:platform]
55
-
56
- result
57
- end
58
-
59
- def dump
60
- result = Marshal.load(Marshal.dump(@data))
61
-
62
- result[:platform] = platform.dump if @data[:platform]
63
-
64
- result
65
- end
66
-
67
- def alias=(value)
68
- protect!(value)
69
-
70
- @alias = value[:value]
71
-
72
- @data[:alias] = @alias
73
-
74
- self.alias
75
- end
76
-
77
- def color=(value)
78
- protect!(value)
79
-
80
- @color = value[:value]
81
-
82
- @data[:color] = @color
83
-
84
- color
85
- end
86
-
87
- def self.adapt(gossip: nil, dump: nil)
88
- raise TooManyArgumentsError, 'you need to pass gossip: or dump:, not both' if !gossip.nil? && !dump.nil?
89
-
90
- raise ArgumentError, 'missing gossip: or dump:' if gossip.nil? && dump.nil?
91
-
92
- if !gossip.nil?
93
- new(Adapter::Node.subscribe_channel_graph(gossip), nil)
94
- elsif !dump.nil?
95
- new(dump, nil)
96
- end
97
- end
98
-
99
- def apply!(gossip:)
100
- Controllers::Node::ApplyGossip.perform(
101
- self, gossip
102
- )
103
- end
104
-
105
- def send_message(
106
- message, amount:, fee: nil, secret: nil,
107
- times_out_in: { seconds: 5 }, through: 'amp',
108
- preview: false
109
- )
110
- pay(
111
- message: message,
112
- amount: amount,
113
- fee: fee,
114
- secret: secret,
115
- times_out_in: times_out_in,
116
- through: through,
117
- preview: preview
118
- )
119
- end
120
-
121
- def pay(
122
- amount:, message: nil, secret: nil,
123
- fee: nil,
124
- times_out_in: { seconds: 5 }, through: 'amp',
125
- preview: false
126
- )
127
- raise MissingComponentsError if @components.nil?
128
-
129
- Controllers::Node::Pay.perform(
130
- @components,
131
- public_key: public_key,
132
- amount: amount,
133
- fee: fee,
134
- through: through,
135
- secret: secret,
136
- message: message,
137
- times_out_in: times_out_in,
138
- preview: preview
139
- )
140
- end
141
- end
142
- end
143
- end
data/models/rate.rb DELETED
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../ports/dsl/lighstorm/errors'
4
-
5
- module Lighstorm
6
- module Models
7
- class Rate
8
- attr_reader :parts_per_million
9
-
10
- # https://en.wikipedia.org/wiki/Parts-per_notation
11
- def initialize(parts_per_million: nil)
12
- raise MissingPartsPerMillionError, 'missing parts_per_million' if parts_per_million.nil?
13
-
14
- # TODO
15
- @parts_per_million = parts_per_million
16
- end
17
-
18
- def ppm
19
- @parts_per_million
20
- end
21
-
22
- def percentage
23
- @percentage ||= @parts_per_million.to_f / 10_000
24
- end
25
-
26
- def to_h
27
- {
28
- parts_per_million: @parts_per_million
29
- # satoshis: satoshis,
30
- # bitcoins: bitcoins
31
- }
32
- end
33
- end
34
- end
35
- end
data/models/secret.rb DELETED
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../controllers/secret/valid_proof'
4
-
5
- require 'digest'
6
-
7
- module Lighstorm
8
- module Models
9
- class Secret
10
- attr_reader :preimage, :hash
11
-
12
- def self.generate
13
- data = { preimage: SecureRandom.hex(32) }
14
- data[:hash] = Digest::SHA256.hexdigest([data[:preimage]].pack('H*'))
15
- data
16
- end
17
-
18
- def self.create(components = nil, &vcr)
19
- data = vcr.nil? ? generate : vcr.call(-> { generate })
20
-
21
- Secret.new(data, components)
22
- end
23
-
24
- def initialize(data, components)
25
- @data = data
26
- @components = components
27
-
28
- @preimage = data[:preimage]
29
- @hash = data[:hash]
30
- end
31
-
32
- def proof
33
- @preimage
34
- end
35
-
36
- def valid_proof?(candidate_preimage, &vcr)
37
- raise MissingComponentsError if @components.nil?
38
-
39
- return true if candidate_preimage == preimage
40
-
41
- Controllers::Secret::ValidProof.data(
42
- @components,
43
- @hash, candidate_preimage, &vcr
44
- )
45
- end
46
-
47
- def to_h
48
- {
49
- preimage: preimage,
50
- hash: hash
51
- }
52
- end
53
- end
54
- end
55
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './satoshis'
4
-
5
- module Lighstorm
6
- module Models
7
- class Transaction
8
- attr_reader :_key, :at, :hash, :label
9
-
10
- def initialize(data)
11
- @data = data
12
-
13
- @_key = @data[:_key]
14
- @at = @data[:at]
15
- @hash = @data[:hash]
16
- @label = @data[:label]
17
- end
18
-
19
- def amount
20
- @amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
21
- end
22
-
23
- def fee
24
- @fee ||= Satoshis.new(millisatoshis: @data[:fee][:millisatoshis])
25
- end
26
-
27
- def to_h
28
- {
29
- _key: _key,
30
- at: at,
31
- hash: hash,
32
- amount: amount.to_h,
33
- fee: fee.to_h,
34
- label: label
35
- }
36
- end
37
- end
38
- end
39
- end
data/models/wallet.rb DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative './satoshis'
4
-
5
- module Lighstorm
6
- module Models
7
- class Wallet
8
- attr_reader :_key, :at
9
-
10
- def initialize(data)
11
- @data = data
12
-
13
- @_key = @data[:_key]
14
- @at = @data[:at]
15
- end
16
-
17
- def lightning
18
- @lightning ||= Satoshis.new(millisatoshis: @data[:lightning][:millisatoshis])
19
- end
20
-
21
- def bitcoin
22
- @bitcoin ||= Satoshis.new(millisatoshis: @data[:bitcoin][:millisatoshis])
23
- end
24
-
25
- def total
26
- @total ||= Satoshis.new(millisatoshis: @data[:total][:millisatoshis])
27
- end
28
-
29
- def to_h
30
- {
31
- _key: _key,
32
- at: at,
33
- lightning: lightning.to_h,
34
- bitcoin: bitcoin.to_h,
35
- total: total.to_h
36
- }
37
- end
38
- end
39
- end
40
- end