glueby 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 374ec643c65f210f1ecc1f35951ead50b86beaf9298a404a3cd21d0c3b0f1872
4
- data.tar.gz: 3b4c3a5780e06ca072b4b8b08839210a927a67af42a00ad9557926820ffefada
3
+ metadata.gz: 71dfd0cca2e922f07b29b4839be2f7cff8c71f587ff043bb05eee6d8cac3435e
4
+ data.tar.gz: f3b4b8864d75be7eccad66c402bb56693949ade3c7dfa1b21e3f5abc5c6391b5
5
5
  SHA512:
6
- metadata.gz: b101685ebba2023302b266abe49603842d05af674e71e5b6c993539a01587c313033ef927f015de619c28f7e60986e51379cf32aac25a69b80dc903881ae51b3
7
- data.tar.gz: 2e437e7403b573d7018727766da166d64cac78147d95bb355f46284d1cb65a2ba36115d578c7fa29c6d6e488e2fdd9914f504e06c3fe346f962cbb1938700145
6
+ metadata.gz: 831aaf50ea027c47450ad167721b441a6253b9c439d1608179f7c0bf9244eaa5cc8bc5a1fc916b31411616389e4750ecdda9cda0497479b6810e8fba134a0fd8
7
+ data.tar.gz: 4f078178c9874c00e1ce36e11c13b7813972880ecfc3f7c8ee686040012b6e8ce0038376f2ec808027a99c3beb377e7a5e7493c2f78577533ed11403cd2928e9
@@ -11,6 +11,9 @@ module Glueby
11
11
 
12
12
  belongs_to :prev, class_name: 'Glueby::Contract::AR::Timestamp', optional: true
13
13
 
14
+ validates :prev, uniqueness: true, allow_nil: true
15
+ validate :validate_prev
16
+
14
17
  class << self
15
18
  def digest_content(content, digest)
16
19
  case digest&.downcase
@@ -130,17 +133,7 @@ module Glueby
130
133
  builder = builder_class.new(wallet, fee_estimator)
131
134
 
132
135
  if builder.instance_of?(Contract::Timestamp::TxBuilder::UpdatingTrackable)
133
- unless prev
134
- message = "The previous timestamp(id: #{prev_id}) not found."
135
- errors.add(:prev_id, message)
136
- raise Errors::PrevTimestampNotFound, message
137
- end
138
-
139
- unless prev.trackable?
140
- message = "The previous timestamp(id: #{prev_id}) type must be trackable"
141
- errors.add(:prev_id, message)
142
- raise Errors::PrevTimestampIsNotTrackable, message
143
- end
136
+ validate_prev!
144
137
 
145
138
  builder.set_prev_timestamp_info(
146
139
  timestamp_utxo: prev.utxo,
@@ -177,6 +170,37 @@ module Glueby
177
170
  def update_trackable?
178
171
  trackable? && prev_id
179
172
  end
173
+
174
+ def validate_prev
175
+ validate_prev!
176
+ true
177
+ rescue Errors::PrevTimestampNotFound,
178
+ Errors::PrevTimestampIsNotTrackable,
179
+ Errors::UnnecessaryPrevTimestamp
180
+ false
181
+ end
182
+
183
+ def validate_prev!
184
+ if simple? && prev_id
185
+ message = "The previous timestamp(id: #{prev_id}) must be nil in simple timestamp"
186
+ errors.add(:prev_id, message)
187
+ raise Errors::UnnecessaryPrevTimestamp, message
188
+ end
189
+
190
+ return unless update_trackable?
191
+
192
+ unless prev
193
+ message = "The previous timestamp(id: #{prev_id}) not found."
194
+ errors.add(:prev_id, message)
195
+ raise Errors::PrevTimestampNotFound, message
196
+ end
197
+
198
+ unless prev.trackable?
199
+ message = "The previous timestamp(id: #{prev_id}) type must be trackable"
200
+ errors.add(:prev_id, message)
201
+ raise Errors::PrevTimestampIsNotTrackable, message
202
+ end
203
+ end
180
204
  end
181
205
  end
182
206
  end
@@ -17,6 +17,7 @@ module Glueby
17
17
  class UnsupportedDigestType < ArgumentError; end
18
18
  class PrevTimestampNotFound < ArgumentError; end
19
19
  class PrevTimestampIsNotTrackable < ArgumentError; end
20
+ class UnnecessaryPrevTimestamp < ArgumentError; end
20
21
  end
21
22
  end
22
23
  end
@@ -20,7 +20,7 @@ module Glueby
20
20
  tx.inputs.each.with_index do |input, index|
21
21
  script_pubkey = script_for_input(input, prevtxs)
22
22
  next unless script_pubkey
23
- key = Key.key_for_script(script_pubkey)
23
+ key = keys.key_for_script(script_pubkey)
24
24
  next unless key
25
25
  sign_tx_for_p2pkh(tx, index, key, script_pubkey, sighashtype)
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.10.1"
2
+ VERSION = "0.10.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glueby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-01 00:00:00.000000000 Z
11
+ date: 2022-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus