File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
rust/catalyst-types/src/id_uri Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -163,12 +163,23 @@ impl IdUri {
163163 }
164164
165165 /// Add or change the nonce to a specific value in a Catalyst ID URI.
166+ ///
167+ /// Note, this will not fail, but if the Datetime is < `MIN_NONCE`,
168+ /// or greater than `MAX_NONCE`, it will be clamped into that range.
166169 #[ must_use]
167170 pub fn with_specific_nonce ( self , nonce : DateTime < Utc > ) -> Self {
168- Self {
169- nonce : Some ( nonce) ,
170- ..self
171- }
171+ let secs = nonce. timestamp ( ) ;
172+ let clamped_secs = secs. clamp ( Self :: MIN_NONCE , Self :: MAX_NONCE ) ;
173+
174+ let nonce = {
175+ if clamped_secs == secs {
176+ Some ( nonce)
177+ } else {
178+ DateTime :: < Utc > :: from_timestamp ( clamped_secs, 0 )
179+ }
180+ } ;
181+
182+ Self { nonce, ..self }
172183 }
173184
174185 /// Add or change the nonce in a Catalyst ID URI.
You can’t perform that action at this time.
0 commit comments