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
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
|
5
|
+
require_relative '../satoshis'
|
6
|
+
require_relative '../../controllers/lightning/invoice/actions/create'
|
7
|
+
require_relative '../../controllers/lightning/invoice/actions/pay'
|
8
|
+
require_relative '../../controllers/lightning/invoice/actions/pay_through_route'
|
9
|
+
|
10
|
+
module Lighstorm
|
11
|
+
module Model
|
12
|
+
module Lightning
|
13
|
+
class Invoice
|
14
|
+
attr_reader :_key, :created_at, :expires_at, :settled_at, :state, :payable, :code
|
15
|
+
|
16
|
+
def initialize(data, components)
|
17
|
+
@data = data
|
18
|
+
@components = components
|
19
|
+
|
20
|
+
@_key = data[:_key]
|
21
|
+
@created_at = data[:created_at]
|
22
|
+
@expires_at = data[:expires_at]
|
23
|
+
@settled_at = data[:settled_at]
|
24
|
+
@state = data[:state]
|
25
|
+
|
26
|
+
@payable = data[:payable]
|
27
|
+
|
28
|
+
@code = data[:code]
|
29
|
+
end
|
30
|
+
|
31
|
+
def payment
|
32
|
+
if payable != 'once' || @data[:payments].size > 1
|
33
|
+
raise InvoiceMayHaveMultiplePaymentsError, "payable: #{payable}, payments: #{@data[:payments].size.size}"
|
34
|
+
end
|
35
|
+
|
36
|
+
@payment ||= payments.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def payments
|
40
|
+
@payments ||= @data[:payments]&.map { |data| Payment.new(data, @components) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def amount
|
44
|
+
@amount ||= @data[:amount] ? Satoshis.new(millisatoshis: @data[:amount][:millisatoshis]) : nil
|
45
|
+
end
|
46
|
+
|
47
|
+
def received
|
48
|
+
@received ||= @data[:received] ? Satoshis.new(millisatoshis: @data[:received][:millisatoshis]) : nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def secret
|
52
|
+
@secret ||= Secret.new(@data[:secret], @components)
|
53
|
+
end
|
54
|
+
|
55
|
+
def description
|
56
|
+
@description ||= Struct.new(:data) do
|
57
|
+
def memo
|
58
|
+
data[:memo]
|
59
|
+
end
|
60
|
+
|
61
|
+
def hash
|
62
|
+
data[:hash]
|
63
|
+
end
|
64
|
+
|
65
|
+
def to_h
|
66
|
+
{ memo: memo, hash: hash }
|
67
|
+
end
|
68
|
+
end.new(@data[:description] || {})
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_h
|
72
|
+
result = {
|
73
|
+
_key: _key,
|
74
|
+
created_at: created_at,
|
75
|
+
expires_at: expires_at,
|
76
|
+
settled_at: settled_at,
|
77
|
+
payable: payable,
|
78
|
+
state: state,
|
79
|
+
code: code,
|
80
|
+
amount: amount&.to_h,
|
81
|
+
received: received&.to_h,
|
82
|
+
description: description.to_h,
|
83
|
+
secret: secret.to_h,
|
84
|
+
payments: payments&.map(&:to_h)
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
def pay(
|
89
|
+
amount: nil, message: nil, route: nil,
|
90
|
+
fee: nil,
|
91
|
+
times_out_in: { seconds: 5 },
|
92
|
+
preview: false
|
93
|
+
)
|
94
|
+
raise MissingComponentsError if @components.nil?
|
95
|
+
|
96
|
+
if route
|
97
|
+
Controller::Lightning::Invoice::PayThroughRoute.perform(
|
98
|
+
@components, self, route: route, preview: preview
|
99
|
+
)
|
100
|
+
else
|
101
|
+
Controller::Lightning::Invoice::Pay.perform(
|
102
|
+
@components,
|
103
|
+
code: code,
|
104
|
+
amount: amount,
|
105
|
+
fee: fee,
|
106
|
+
message: message,
|
107
|
+
times_out_in: times_out_in,
|
108
|
+
preview: preview
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lighstorm
|
4
|
+
module Model
|
5
|
+
module Lightning
|
6
|
+
class Lightning
|
7
|
+
IMPLEMENTATION = 'lnd'
|
8
|
+
|
9
|
+
attr_reader :implementation, :version
|
10
|
+
|
11
|
+
def initialize(node)
|
12
|
+
raise Errors::NotYourNodeError unless node.myself?
|
13
|
+
|
14
|
+
@implementation = IMPLEMENTATION
|
15
|
+
@version = node.data[:platform][:lightning][:version]
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_h
|
19
|
+
{
|
20
|
+
implementation: implementation,
|
21
|
+
version: version
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def dump
|
26
|
+
Marshal.load(
|
27
|
+
Marshal.dump({ implementation: implementation, version: version })
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lightning'
|
4
|
+
|
5
|
+
require_relative '../../../../ports/grpc'
|
6
|
+
require_relative '../../../../adapters/lightning/nodes/node'
|
7
|
+
|
8
|
+
module Lighstorm
|
9
|
+
module Model
|
10
|
+
module Lightning
|
11
|
+
class Platform
|
12
|
+
attr_reader :data
|
13
|
+
|
14
|
+
def initialize(node)
|
15
|
+
@node = node
|
16
|
+
@data = @node.data[:platform]
|
17
|
+
end
|
18
|
+
|
19
|
+
def blockchain
|
20
|
+
@blockchain ||= @data ? @data[:blockchain] : nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def network
|
24
|
+
@network ||= @data ? @data[:network] : nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def lightning
|
28
|
+
@lightning ||= Lightning.new(@node)
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_h
|
32
|
+
response = {
|
33
|
+
blockchain: blockchain,
|
34
|
+
network: network
|
35
|
+
}
|
36
|
+
|
37
|
+
response[:lightning] = lightning.to_h if @node.myself?
|
38
|
+
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
def dump
|
43
|
+
data = Marshal.load(Marshal.dump(@data))
|
44
|
+
data.merge(lightning: lightning.dump) if @node.myself?
|
45
|
+
data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../../controllers/lightning/node/actions/apply_gossip'
|
4
|
+
require_relative '../../../controllers/lightning/node/actions/pay'
|
5
|
+
require_relative '../../../controllers/lightning/channel'
|
6
|
+
require_relative '../../../adapters/lightning/nodes/node'
|
7
|
+
require_relative '../../concerns/protectable'
|
8
|
+
require_relative '../../errors'
|
9
|
+
|
10
|
+
require_relative 'node/platform'
|
11
|
+
|
12
|
+
module Lighstorm
|
13
|
+
module Model
|
14
|
+
module Lightning
|
15
|
+
class Node
|
16
|
+
include Protectable
|
17
|
+
|
18
|
+
attr_reader :data, :_key, :alias, :public_key, :color
|
19
|
+
|
20
|
+
def initialize(data, components)
|
21
|
+
@data = data
|
22
|
+
@components = components
|
23
|
+
|
24
|
+
@_key = @data[:_key]
|
25
|
+
@alias = @data[:alias]
|
26
|
+
@public_key = @data[:public_key]
|
27
|
+
@color = @data[:color]
|
28
|
+
end
|
29
|
+
|
30
|
+
def myself?
|
31
|
+
@data[:myself] == true
|
32
|
+
end
|
33
|
+
|
34
|
+
def platform
|
35
|
+
@platform ||= Platform.new(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
def channels
|
39
|
+
raise Errors::NotYourNodeError unless myself?
|
40
|
+
|
41
|
+
raise MissingComponentsError if @components.nil?
|
42
|
+
|
43
|
+
Controller::Lightning::Channel.mine(@components)
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_h
|
47
|
+
result = {
|
48
|
+
_key: _key,
|
49
|
+
public_key: public_key
|
50
|
+
}
|
51
|
+
|
52
|
+
result[:alias] = @alias unless self.alias.nil?
|
53
|
+
result[:color] = @color unless color.nil?
|
54
|
+
|
55
|
+
result[:platform] = platform.to_h if @data[:platform]
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
|
60
|
+
def dump
|
61
|
+
result = Marshal.load(Marshal.dump(@data))
|
62
|
+
|
63
|
+
result[:platform] = platform.dump if @data[:platform]
|
64
|
+
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def alias=(value)
|
69
|
+
protect!(value)
|
70
|
+
|
71
|
+
@alias = value[:value]
|
72
|
+
|
73
|
+
@data[:alias] = @alias
|
74
|
+
|
75
|
+
self.alias
|
76
|
+
end
|
77
|
+
|
78
|
+
def color=(value)
|
79
|
+
protect!(value)
|
80
|
+
|
81
|
+
@color = value[:value]
|
82
|
+
|
83
|
+
@data[:color] = @color
|
84
|
+
|
85
|
+
color
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.adapt(gossip: nil, dump: nil)
|
89
|
+
raise TooManyArgumentsError, 'you need to pass gossip: or dump:, not both' if !gossip.nil? && !dump.nil?
|
90
|
+
|
91
|
+
raise ArgumentError, 'missing gossip: or dump:' if gossip.nil? && dump.nil?
|
92
|
+
|
93
|
+
if !gossip.nil?
|
94
|
+
new(Adapter::Lightning::Node.subscribe_channel_graph(gossip), nil)
|
95
|
+
elsif !dump.nil?
|
96
|
+
new(dump, nil)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def apply!(gossip:)
|
101
|
+
Controller::Lightning::Node::ApplyGossip.perform(
|
102
|
+
self, gossip
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def send_message(
|
107
|
+
message, amount:, fee: nil, secret: nil,
|
108
|
+
times_out_in: { seconds: 5 }, through: 'amp',
|
109
|
+
preview: false
|
110
|
+
)
|
111
|
+
pay(
|
112
|
+
message: message,
|
113
|
+
amount: amount,
|
114
|
+
fee: fee,
|
115
|
+
secret: secret,
|
116
|
+
times_out_in: times_out_in,
|
117
|
+
through: through,
|
118
|
+
preview: preview
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
def pay(
|
123
|
+
amount:, message: nil, secret: nil,
|
124
|
+
fee: nil,
|
125
|
+
times_out_in: { seconds: 5 }, through: 'amp',
|
126
|
+
preview: false
|
127
|
+
)
|
128
|
+
raise MissingComponentsError if @components.nil?
|
129
|
+
|
130
|
+
Controller::Lightning::Node::Pay.perform(
|
131
|
+
@components,
|
132
|
+
public_key: public_key,
|
133
|
+
amount: amount,
|
134
|
+
fee: fee,
|
135
|
+
through: through,
|
136
|
+
secret: secret,
|
137
|
+
message: message,
|
138
|
+
times_out_in: times_out_in,
|
139
|
+
preview: preview
|
140
|
+
)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../ports/dsl/lighstorm/errors'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Lightning
|
8
|
+
class Rate
|
9
|
+
attr_reader :parts_per_million
|
10
|
+
|
11
|
+
# https://en.wikipedia.org/wiki/Parts-per_notation
|
12
|
+
def initialize(parts_per_million: nil)
|
13
|
+
raise MissingPartsPerMillionError, 'missing parts_per_million' if parts_per_million.nil?
|
14
|
+
|
15
|
+
# TODO
|
16
|
+
@parts_per_million = parts_per_million
|
17
|
+
end
|
18
|
+
|
19
|
+
def ppm
|
20
|
+
@parts_per_million
|
21
|
+
end
|
22
|
+
|
23
|
+
def percentage
|
24
|
+
@percentage ||= @parts_per_million.to_f / 10_000
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
{
|
29
|
+
parts_per_million: @parts_per_million
|
30
|
+
# satoshis: satoshis,
|
31
|
+
# bitcoins: bitcoins
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../controllers/lightning/secret/valid_proof'
|
4
|
+
|
5
|
+
require 'digest'
|
6
|
+
|
7
|
+
module Lighstorm
|
8
|
+
module Model
|
9
|
+
module Lightning
|
10
|
+
class Secret
|
11
|
+
attr_reader :proof, :hash
|
12
|
+
|
13
|
+
def self.generate
|
14
|
+
data = { proof: SecureRandom.hex(32) }
|
15
|
+
data[:hash] = Digest::SHA256.hexdigest([data[:proof]].pack('H*'))
|
16
|
+
data
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(components = nil, &vcr)
|
20
|
+
data = vcr.nil? ? generate : vcr.call(-> { generate })
|
21
|
+
|
22
|
+
Secret.new(data, components)
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(data, components)
|
26
|
+
@data = data
|
27
|
+
@components = components
|
28
|
+
|
29
|
+
@proof = data[:proof]
|
30
|
+
@hash = data[:hash]
|
31
|
+
end
|
32
|
+
|
33
|
+
def preimage
|
34
|
+
@proof
|
35
|
+
end
|
36
|
+
|
37
|
+
def valid_proof?(candidate_proof, &vcr)
|
38
|
+
raise MissingComponentsError if @components.nil?
|
39
|
+
|
40
|
+
return true if proof && proof.size == 64 && candidate_proof == proof
|
41
|
+
|
42
|
+
Controller::Lightning::Secret::ValidProof.data(
|
43
|
+
@components,
|
44
|
+
@hash, candidate_proof, &vcr
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_h
|
49
|
+
{
|
50
|
+
proof: proof,
|
51
|
+
hash: hash
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/models/satoshis.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../lightning/invoice'
|
4
|
+
require_relative '../bitcoin/transaction'
|
5
|
+
|
6
|
+
module Lighstorm
|
7
|
+
module Model
|
8
|
+
module Wallet
|
9
|
+
class Activity
|
10
|
+
attr_reader :direction, :at, :message, :layer, :how, :_key
|
11
|
+
|
12
|
+
def initialize(data)
|
13
|
+
@data = data
|
14
|
+
|
15
|
+
@_key = @data[:_key]
|
16
|
+
@at = @data[:at]
|
17
|
+
@direction = @data[:direction]
|
18
|
+
@layer = @data[:layer]
|
19
|
+
@how = @data[:how]
|
20
|
+
@message = @data[:message]
|
21
|
+
end
|
22
|
+
|
23
|
+
def amount
|
24
|
+
@amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
|
25
|
+
end
|
26
|
+
|
27
|
+
def invoice
|
28
|
+
@invoice ||= @data[:data][:invoice].nil? ? nil : Lightning::Invoice.new(@data[:data][:invoice], nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
def transaction
|
32
|
+
@transaction ||= @data[:data][:transaction].nil? ? nil : Bitcoin::Transaction.new(@data[:data][:transaction])
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_h
|
36
|
+
output = {
|
37
|
+
_key: _key,
|
38
|
+
at: at,
|
39
|
+
direction: direction,
|
40
|
+
layer: layer,
|
41
|
+
how: how,
|
42
|
+
amount: amount.to_h,
|
43
|
+
message: message
|
44
|
+
}
|
45
|
+
|
46
|
+
output[:invoice] = invoice.to_h unless invoice.nil?
|
47
|
+
output[:transaction] = transaction.to_h unless transaction.nil?
|
48
|
+
|
49
|
+
output
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../satoshis'
|
4
|
+
|
5
|
+
module Lighstorm
|
6
|
+
module Model
|
7
|
+
module Wallet
|
8
|
+
class Balance
|
9
|
+
attr_reader :_key, :at
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
|
14
|
+
@_key = @data[:_key]
|
15
|
+
@at = @data[:at]
|
16
|
+
end
|
17
|
+
|
18
|
+
def lightning
|
19
|
+
@lightning ||= Satoshis.new(millisatoshis: @data[:lightning][:millisatoshis])
|
20
|
+
end
|
21
|
+
|
22
|
+
def bitcoin
|
23
|
+
@bitcoin ||= Satoshis.new(millisatoshis: @data[:bitcoin][:millisatoshis])
|
24
|
+
end
|
25
|
+
|
26
|
+
def total
|
27
|
+
@total ||= Satoshis.new(millisatoshis: @data[:total][:millisatoshis])
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
{
|
32
|
+
_key: _key,
|
33
|
+
at: at,
|
34
|
+
lightning: lightning.to_h,
|
35
|
+
bitcoin: bitcoin.to_h,
|
36
|
+
total: total.to_h
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/ports/dsl/lighstorm.rb
CHANGED
@@ -6,29 +6,42 @@ require_relative '../../static/spec'
|
|
6
6
|
|
7
7
|
require_relative '../../models/satoshis'
|
8
8
|
|
9
|
-
require_relative '../../controllers/node'
|
10
|
-
require_relative '../../controllers/channel'
|
11
|
-
require_relative '../../controllers/payment'
|
12
|
-
require_relative '../../controllers/forward'
|
13
|
-
require_relative '../../controllers/invoice'
|
14
|
-
require_relative '../../controllers/activity'
|
15
9
|
require_relative '../../controllers/connection'
|
10
|
+
|
16
11
|
require_relative '../../controllers/wallet'
|
12
|
+
require_relative '../../controllers/wallet/activity'
|
13
|
+
|
14
|
+
require_relative '../../controllers/lightning/node'
|
15
|
+
require_relative '../../controllers/lightning/channel'
|
16
|
+
require_relative '../../controllers/lightning/payment'
|
17
|
+
require_relative '../../controllers/lightning/forward'
|
18
|
+
require_relative '../../controllers/lightning/invoice'
|
19
|
+
|
20
|
+
require_relative '../../controllers/bitcoin/transaction'
|
21
|
+
require_relative '../../controllers/bitcoin/address'
|
17
22
|
|
18
23
|
module Lighstorm
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
Forward = Controllers::Forward
|
23
|
-
Invoice = Controllers::Invoice
|
24
|
-
Activity = Controllers::Activity
|
25
|
-
Connection = Controllers::Connection
|
26
|
-
Wallet = Controllers::Wallet
|
24
|
+
Connection = Controller::Connection
|
25
|
+
|
26
|
+
Wallet = Controller::Wallet
|
27
27
|
|
28
|
-
Satoshis =
|
28
|
+
Satoshis = Model::Satoshis
|
29
|
+
|
30
|
+
module Lightning
|
31
|
+
Node = Controller::Lightning::Node
|
32
|
+
Channel = Controller::Lightning::Channel
|
33
|
+
Invoice = Controller::Lightning::Invoice
|
34
|
+
Payment = Controller::Lightning::Payment
|
35
|
+
Forward = Controller::Lightning::Forward
|
36
|
+
end
|
37
|
+
|
38
|
+
module Bitcoin
|
39
|
+
Address = Controller::Bitcoin::Address
|
40
|
+
Transaction = Controller::Bitcoin::Transaction
|
41
|
+
end
|
29
42
|
|
30
43
|
def self.connect!(...)
|
31
|
-
|
44
|
+
Controller::Connection.connect!(...)
|
32
45
|
end
|
33
46
|
|
34
47
|
def self.inject_middleware!(middleware_lambda)
|
data/static/cache.rb
CHANGED
data/static/spec.rb
CHANGED
@@ -4,7 +4,7 @@ module Lighstorm
|
|
4
4
|
module Static
|
5
5
|
SPEC = {
|
6
6
|
name: 'lighstorm',
|
7
|
-
version: '0.0.
|
7
|
+
version: '0.0.16',
|
8
8
|
author: 'icebaker',
|
9
9
|
summary: 'API for interacting with a Lightning Node.',
|
10
10
|
description: 'Lighstorm is an opinionated abstraction layer on top of the lnd-client for interacting with a Lightning Node.',
|