lighstorm 0.0.15 → 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.lock +1 -1
- 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/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 +74 -68
- 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/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
|
data/models/transaction.rb
DELETED
@@ -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
|