glueby 0.10.2 → 0.11.0

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: 71dfd0cca2e922f07b29b4839be2f7cff8c71f587ff043bb05eee6d8cac3435e
4
- data.tar.gz: f3b4b8864d75be7eccad66c402bb56693949ade3c7dfa1b21e3f5abc5c6391b5
3
+ metadata.gz: 0350a6b7d6a1bc1302c0374313c72ecb5283a5388c394a57c6bf7da8f789a815
4
+ data.tar.gz: 991b08a0950fedc906916fb1b984440721601781417e0c504051192dbf548dec
5
5
  SHA512:
6
- metadata.gz: 831aaf50ea027c47450ad167721b441a6253b9c439d1608179f7c0bf9244eaa5cc8bc5a1fc916b31411616389e4750ecdda9cda0497479b6810e8fba134a0fd8
7
- data.tar.gz: 4f078178c9874c00e1ce36e11c13b7813972880ecfc3f7c8ee686040012b6e8ce0038376f2ec808027a99c3beb377e7a5e7493c2f78577533ed11403cd2928e9
6
+ metadata.gz: 46a31cd67ccd59ffa7aee4231ae4f5946957e1403e2ef8b8cd7eeb313bbf607a198523b3ebf72c824dc2957666b40d7537b0784f82a7fb23de633ca3932aa789
7
+ data.tar.gz: 15176048dd26fef955e04c9fc56259d58499880b0d4aae8ece4c286a78dfa8c567e5c62f78e19ca11b74d1b7f1b6408a3190f38fe979c6ab6f4246474fd415e1
@@ -11,7 +11,6 @@ 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
14
  validate :validate_prev
16
15
 
17
16
  class << self
@@ -77,9 +76,12 @@ module Glueby
77
76
  # @return true if tapyrus transactions were broadcasted and the timestamp was updated successfully, otherwise false.
78
77
  def save_with_broadcast(fee_estimator: Glueby::Contract::FixedFeeEstimator.new, utxo_provider: nil)
79
78
  save_with_broadcast!(fee_estimator: fee_estimator, utxo_provider: utxo_provider)
80
- rescue Errors::FailedToBroadcast, Errors::PrevTimestampNotFound, Errors::PrevTimestampIsNotTrackable => e
79
+ rescue Errors::FailedToBroadcast => e
81
80
  logger.error("failed to broadcast (id=#{id}, reason=#{e.message})")
82
81
  false
82
+ rescue Errors::ArgumentError => e
83
+ logger.info("failed to broadcast by argument error (id=#{id}, reason=#{e.message})")
84
+ false
83
85
  end
84
86
 
85
87
  # Broadcast and save timestamp, and it raises errors
@@ -89,7 +91,9 @@ module Glueby
89
91
  # @raise [Glueby::Contract::Errors::FailedToBroadcast] If the broadcasting is failure
90
92
  # @raise [Glueby::Contract::Errors::PrevTimestampNotFound] If it is not available that the timestamp record which correspond with the prev_id attribute
91
93
  # @raise [Glueby::Contract::Errors::PrevTimestampIsNotTrackable] If the timestamp record by prev_id is not trackable
94
+ # @raise [Glueby::Contract::Errors::PrevTimestampAlreadyUpdated] If the previous timestamp was already updated
92
95
  def save_with_broadcast!(fee_estimator: Glueby::Contract::FixedFeeEstimator.new, utxo_provider: nil)
96
+ validate_prev!
93
97
  utxo_provider = Glueby::UtxoProvider.new if !utxo_provider && Glueby.configuration.use_utxo_provider?
94
98
 
95
99
  funding_tx, tx, p2c_address, payment_base = create_txs(fee_estimator, utxo_provider)
@@ -104,7 +108,7 @@ module Glueby
104
108
  wallet.internal_wallet.broadcast(tx) do |tx|
105
109
  assign_attributes(txid: tx.txid, status: :unconfirmed, p2c_address: p2c_address, payment_base: payment_base)
106
110
  @tx = tx
107
- save!
111
+ save!(validate: false) # The validation is already executed at head of #save_with_broadcast!
108
112
 
109
113
  if update_trackable?
110
114
  prev.latest = false
@@ -114,8 +118,7 @@ module Glueby
114
118
  end
115
119
  logger.info("timestamp tx was broadcasted (id=#{id}, txid=#{tx.txid})")
116
120
  true
117
- rescue ActiveRecord::RecordInvalid,
118
- Tapyrus::RPC::Error,
121
+ rescue Tapyrus::RPC::Error,
119
122
  Internal::Wallet::Errors::WalletAlreadyLoaded,
120
123
  Internal::Wallet::Errors::WalletNotFound,
121
124
  Errors::InsufficientFunds => e
@@ -133,8 +136,6 @@ module Glueby
133
136
  builder = builder_class.new(wallet, fee_estimator)
134
137
 
135
138
  if builder.instance_of?(Contract::Timestamp::TxBuilder::UpdatingTrackable)
136
- validate_prev!
137
-
138
139
  builder.set_prev_timestamp_info(
139
140
  timestamp_utxo: prev.utxo,
140
141
  payment_base: prev.payment_base,
@@ -174,9 +175,7 @@ module Glueby
174
175
  def validate_prev
175
176
  validate_prev!
176
177
  true
177
- rescue Errors::PrevTimestampNotFound,
178
- Errors::PrevTimestampIsNotTrackable,
179
- Errors::UnnecessaryPrevTimestamp
178
+ rescue Errors::ArgumentError
180
179
  false
181
180
  end
182
181
 
@@ -200,6 +199,12 @@ module Glueby
200
199
  errors.add(:prev_id, message)
201
200
  raise Errors::PrevTimestampIsNotTrackable, message
202
201
  end
202
+
203
+ if new_record? && self.class.where(prev_id: prev_id).exists?
204
+ message = "The previous timestamp(id: #{prev_id}) was already updated"
205
+ errors.add(:prev_id, message)
206
+ raise Errors::PrevTimestampAlreadyUpdated, message
207
+ end
203
208
  end
204
209
  end
205
210
  end
@@ -18,6 +18,7 @@ module Glueby
18
18
  class PrevTimestampNotFound < ArgumentError; end
19
19
  class PrevTimestampIsNotTrackable < ArgumentError; end
20
20
  class UnnecessaryPrevTimestamp < ArgumentError; end
21
+ class PrevTimestampAlreadyUpdated < ArgumentError; end
21
22
  end
22
23
  end
23
24
  end
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.10.2"
2
+ VERSION = "0.11.0"
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.2
4
+ version: 0.11.0
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-02 00:00:00.000000000 Z
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus