glueby 0.10.0 → 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
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
|
@@ -9,7 +9,9 @@ module Glueby
|
|
9
9
|
|
10
10
|
attr_reader :tx
|
11
11
|
|
12
|
-
belongs_to :prev, class_name: 'Glueby::Contract::AR::Timestamp'
|
12
|
+
belongs_to :prev, class_name: 'Glueby::Contract::AR::Timestamp', optional: true
|
13
|
+
|
14
|
+
validate :validate_prev
|
13
15
|
|
14
16
|
class << self
|
15
17
|
def digest_content(content, digest)
|
@@ -74,9 +76,12 @@ module Glueby
|
|
74
76
|
# @return true if tapyrus transactions were broadcasted and the timestamp was updated successfully, otherwise false.
|
75
77
|
def save_with_broadcast(fee_estimator: Glueby::Contract::FixedFeeEstimator.new, utxo_provider: nil)
|
76
78
|
save_with_broadcast!(fee_estimator: fee_estimator, utxo_provider: utxo_provider)
|
77
|
-
rescue Errors::FailedToBroadcast
|
79
|
+
rescue Errors::FailedToBroadcast => e
|
78
80
|
logger.error("failed to broadcast (id=#{id}, reason=#{e.message})")
|
79
81
|
false
|
82
|
+
rescue Errors::ArgumentError => e
|
83
|
+
logger.info("failed to broadcast by argument error (id=#{id}, reason=#{e.message})")
|
84
|
+
false
|
80
85
|
end
|
81
86
|
|
82
87
|
# Broadcast and save timestamp, and it raises errors
|
@@ -86,7 +91,9 @@ module Glueby
|
|
86
91
|
# @raise [Glueby::Contract::Errors::FailedToBroadcast] If the broadcasting is failure
|
87
92
|
# @raise [Glueby::Contract::Errors::PrevTimestampNotFound] If it is not available that the timestamp record which correspond with the prev_id attribute
|
88
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
|
89
95
|
def save_with_broadcast!(fee_estimator: Glueby::Contract::FixedFeeEstimator.new, utxo_provider: nil)
|
96
|
+
validate_prev!
|
90
97
|
utxo_provider = Glueby::UtxoProvider.new if !utxo_provider && Glueby.configuration.use_utxo_provider?
|
91
98
|
|
92
99
|
funding_tx, tx, p2c_address, payment_base = create_txs(fee_estimator, utxo_provider)
|
@@ -101,7 +108,7 @@ module Glueby
|
|
101
108
|
wallet.internal_wallet.broadcast(tx) do |tx|
|
102
109
|
assign_attributes(txid: tx.txid, status: :unconfirmed, p2c_address: p2c_address, payment_base: payment_base)
|
103
110
|
@tx = tx
|
104
|
-
save!
|
111
|
+
save!(validate: false) # The validation is already executed at head of #save_with_broadcast!
|
105
112
|
|
106
113
|
if update_trackable?
|
107
114
|
prev.latest = false
|
@@ -111,8 +118,7 @@ module Glueby
|
|
111
118
|
end
|
112
119
|
logger.info("timestamp tx was broadcasted (id=#{id}, txid=#{tx.txid})")
|
113
120
|
true
|
114
|
-
rescue
|
115
|
-
Tapyrus::RPC::Error,
|
121
|
+
rescue Tapyrus::RPC::Error,
|
116
122
|
Internal::Wallet::Errors::WalletAlreadyLoaded,
|
117
123
|
Internal::Wallet::Errors::WalletNotFound,
|
118
124
|
Errors::InsufficientFunds => e
|
@@ -130,18 +136,6 @@ module Glueby
|
|
130
136
|
builder = builder_class.new(wallet, fee_estimator)
|
131
137
|
|
132
138
|
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
|
144
|
-
|
145
139
|
builder.set_prev_timestamp_info(
|
146
140
|
timestamp_utxo: prev.utxo,
|
147
141
|
payment_base: prev.payment_base,
|
@@ -177,6 +171,41 @@ module Glueby
|
|
177
171
|
def update_trackable?
|
178
172
|
trackable? && prev_id
|
179
173
|
end
|
174
|
+
|
175
|
+
def validate_prev
|
176
|
+
validate_prev!
|
177
|
+
true
|
178
|
+
rescue Errors::ArgumentError
|
179
|
+
false
|
180
|
+
end
|
181
|
+
|
182
|
+
def validate_prev!
|
183
|
+
if simple? && prev_id
|
184
|
+
message = "The previous timestamp(id: #{prev_id}) must be nil in simple timestamp"
|
185
|
+
errors.add(:prev_id, message)
|
186
|
+
raise Errors::UnnecessaryPrevTimestamp, message
|
187
|
+
end
|
188
|
+
|
189
|
+
return unless update_trackable?
|
190
|
+
|
191
|
+
unless prev
|
192
|
+
message = "The previous timestamp(id: #{prev_id}) not found."
|
193
|
+
errors.add(:prev_id, message)
|
194
|
+
raise Errors::PrevTimestampNotFound, message
|
195
|
+
end
|
196
|
+
|
197
|
+
unless prev.trackable?
|
198
|
+
message = "The previous timestamp(id: #{prev_id}) type must be trackable"
|
199
|
+
errors.add(:prev_id, message)
|
200
|
+
raise Errors::PrevTimestampIsNotTrackable, message
|
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
|
208
|
+
end
|
180
209
|
end
|
181
210
|
end
|
182
211
|
end
|
@@ -17,6 +17,8 @@ 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
|
21
|
+
class PrevTimestampAlreadyUpdated < ArgumentError; end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
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 =
|
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
|
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-
|
11
|
+
date: 2022-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tapyrus
|