glueby 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/glueby/contract/active_record/timestamp.rb +15 -10
- data/lib/glueby/contract/errors.rb +1 -0
- data/lib/glueby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0350a6b7d6a1bc1302c0374313c72ecb5283a5388c394a57c6bf7da8f789a815
|
4
|
+
data.tar.gz: 991b08a0950fedc906916fb1b984440721601781417e0c504051192dbf548dec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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::
|
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
|
data/lib/glueby/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2022-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|