Skip to content

Commit 8fa47ec

Browse files
committed
chore: correct visitor impl
1 parent a4f491d commit 8fa47ec

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

crates/tx-cache/src/types.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
577577
where
578578
S: SeqAccess<'de>,
579579
{
580-
// We consider this a complete request if we have no txn hash.
580+
// We consider this a complete request if we have no elements in the sequence.
581581
let Some(txn_hash) = seq.next_element()? else {
582582
// We consider this a complete request if we have no txn hash.
583583
return Ok(PaginationParams::new(None));
@@ -630,9 +630,19 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
630630
}
631631
}
632632

633-
// We consider this a complete request if we have no txn hash.
634-
let Some(txn_hash) = txn_hash else {
635-
return Ok(PaginationParams::new(None));
633+
// We consider this a complete request if we have no txn hash and no other fields are present.
634+
let txn_hash = match txn_hash {
635+
Some(hash) => hash,
636+
None => {
637+
if score.is_some() || global_transaction_score_key.is_some() {
638+
return Err(serde::de::Error::invalid_length(
639+
score.is_some() as usize
640+
+ global_transaction_score_key.is_some() as usize,
641+
&self,
642+
));
643+
}
644+
return Ok(PaginationParams::new(None));
645+
}
636646
};
637647

638648
// For all other items, we require a score and a global transaction score key.
@@ -712,9 +722,8 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
712722
where
713723
S: SeqAccess<'de>,
714724
{
715-
// We consider this a complete request if we have no txn hash.
725+
// We consider this a complete request if we have no elements in the sequence.
716726
let Some(id) = seq.next_element()? else {
717-
// We consider this a complete request if we have no txn hash.
718727
return Ok(PaginationParams::new(None));
719728
};
720729

@@ -765,17 +774,22 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
765774
}
766775
}
767776

768-
// We consider this a complete request if we have no txn hash.
777+
// We consider this a complete request if we have no id and no other fields are present.
769778
let Some(id) = id else {
779+
if score.is_some() || global_bundle_score_key.is_some() {
780+
return Err(serde::de::Error::invalid_length(
781+
score.is_some() as usize
782+
+ global_bundle_score_key.is_some() as usize,
783+
&self,
784+
));
785+
}
770786
return Ok(PaginationParams::new(None));
771787
};
772788

773-
// For all other items, we require a score and a global transaction score key.
789+
// For all other items, we require a score and a global bundle score key.
774790
let score = score.ok_or_else(|| serde::de::Error::missing_field("score"))?;
775-
let global_bundle_score_key = global_bundle_score_key.ok_or_else(|| {
776-
serde::de::Error::missing_field("globalTransactionScoreKey")
777-
})?;
778-
791+
let global_bundle_score_key = global_bundle_score_key
792+
.ok_or_else(|| serde::de::Error::missing_field("globalBundleScoreKey"))?;
779793
Ok(PaginationParams::new(Some(BundleKey {
780794
id,
781795
score,

0 commit comments

Comments
 (0)