lighstorm 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'digest'
4
- require_relative 'satoshis'
5
-
6
- module Lighstorm
7
- module Models
8
- class PaymentRequest
9
- attr_reader :_key, :code, :address
10
-
11
- def initialize(data)
12
- @data = data
13
-
14
- @_key = data[:_key] || Digest::SHA256.hexdigest(
15
- data[:code] || "#{data[:amount][:millisatoshis]}#{Time.now}"
16
- )
17
-
18
- @code = data[:code]
19
-
20
- @address = data[:address]
21
- end
22
-
23
- def amount
24
- @amount ||= Satoshis.new(millisatoshis: @data[:amount][:millisatoshis])
25
- end
26
-
27
- def description
28
- @description ||= Struct.new(:data) do
29
- def memo
30
- data[:memo]
31
- end
32
-
33
- def hash
34
- data[:hash]
35
- end
36
-
37
- def to_h
38
- { memo: memo, hash: hash }
39
- end
40
- end.new(@data[:description] || {})
41
- end
42
-
43
- def secret
44
- @secret ||= Struct.new(:data) do
45
- def preimage
46
- data[:preimage]
47
- end
48
-
49
- def hash
50
- data[:hash]
51
- end
52
-
53
- def to_h
54
- # Don't expose 'secret' by default: Security
55
- { hash: hash }
56
- end
57
- end.new(@data[:secret] || {})
58
- end
59
-
60
- def to_h
61
- # Don't expose 'address' by default: Privacy
62
- {
63
- _key: _key,
64
- code: code,
65
- amount: amount.to_h,
66
- description: description.to_h,
67
- secret: secret.to_h
68
- }
69
- end
70
- end
71
- end
72
- end