Skip to content

Commit ad594e5

Browse files
committed
chore: rename PaginationParams to CursorPayload`
1 parent c9ca389 commit ad594e5

File tree

1 file changed

+37
-47
lines changed

1 file changed

+37
-47
lines changed

crates/tx-cache/src/types.rs

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -464,15 +464,15 @@ pub struct OrderKey {
464464
pub id: B256,
465465
}
466466

467-
/// A query for pagination.
467+
/// A deserialization helper for cursors keys.
468468
#[derive(Clone, Debug, Serialize)]
469-
pub struct PaginationParams<C: Serialize + for<'a> Deserialize<'a>> {
470-
/// The cursor to start from.
469+
pub struct CursorPayload<C: Serialize + for<'a> Deserialize<'a>> {
470+
// The cursor key.
471471
#[serde(flatten)]
472472
cursor: Option<C>,
473473
}
474474

475-
impl<C: Serialize + for<'a> Deserialize<'a>> PaginationParams<C> {
475+
impl<C: Serialize + for<'a> Deserialize<'a>> CursorPayload<C> {
476476
/// Creates a new instance of [`PaginationParams`].
477477
pub const fn new(cursor: Option<C>) -> Self {
478478
Self { cursor }
@@ -489,7 +489,7 @@ impl<C: Serialize + for<'a> Deserialize<'a>> PaginationParams<C> {
489489
}
490490
}
491491

492-
impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
492+
impl<'de> Deserialize<'de> for CursorPayload<TxKey> {
493493
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
494494
where
495495
D: Deserializer<'de>,
@@ -537,20 +537,20 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
537537
struct TxKeyVisitor;
538538

539539
impl<'de> Visitor<'de> for TxKeyVisitor {
540-
type Value = PaginationParams<TxKey>;
540+
type Value = CursorPayload<TxKey>;
541541

542542
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
543543
formatter.write_str("a PaginationParams<TxKey>")
544544
}
545545

546-
fn visit_seq<S>(self, mut seq: S) -> Result<PaginationParams<TxKey>, S::Error>
546+
fn visit_seq<S>(self, mut seq: S) -> Result<CursorPayload<TxKey>, S::Error>
547547
where
548548
S: SeqAccess<'de>,
549549
{
550550
// We consider this a complete request if we have no elements in the sequence.
551551
let Some(txn_hash) = seq.next_element()? else {
552552
// We consider this a complete request if we have no txn hash.
553-
return Ok(PaginationParams::new(None));
553+
return Ok(CursorPayload::new(None));
554554
};
555555

556556
// For all other items, we require a score and a global transaction score key.
@@ -560,14 +560,14 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
560560
let global_transaction_score_key = seq
561561
.next_element()?
562562
.ok_or_else(|| serde::de::Error::invalid_length(2, &self))?;
563-
Ok(PaginationParams::new(Some(TxKey {
563+
Ok(CursorPayload::new(Some(TxKey {
564564
txn_hash,
565565
score,
566566
global_transaction_score_key,
567567
})))
568568
}
569569

570-
fn visit_map<M>(self, mut map: M) -> Result<PaginationParams<TxKey>, M::Error>
570+
fn visit_map<M>(self, mut map: M) -> Result<CursorPayload<TxKey>, M::Error>
571571
where
572572
M: MapAccess<'de>,
573573
{
@@ -611,7 +611,7 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
611611
&self,
612612
));
613613
}
614-
return Ok(PaginationParams::new(None));
614+
return Ok(CursorPayload::new(None));
615615
}
616616
};
617617

@@ -620,7 +620,7 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
620620
let global_transaction_score_key = global_transaction_score_key
621621
.ok_or_else(|| serde::de::Error::missing_field("globalTransactionScoreKey"))?;
622622

623-
Ok(PaginationParams::new(Some(TxKey {
623+
Ok(CursorPayload::new(Some(TxKey {
624624
txn_hash,
625625
score,
626626
global_transaction_score_key,
@@ -633,7 +633,7 @@ impl<'de> Deserialize<'de> for PaginationParams<TxKey> {
633633
}
634634
}
635635

636-
impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
636+
impl<'de> Deserialize<'de> for CursorPayload<BundleKey> {
637637
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
638638
where
639639
D: Deserializer<'de>,
@@ -682,19 +682,19 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
682682
struct BundleKeyVisitor;
683683

684684
impl<'de> Visitor<'de> for BundleKeyVisitor {
685-
type Value = PaginationParams<BundleKey>;
685+
type Value = CursorPayload<BundleKey>;
686686

687687
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
688688
formatter.write_str("a PaginationParams<BundleKey>")
689689
}
690690

691-
fn visit_seq<S>(self, mut seq: S) -> Result<PaginationParams<BundleKey>, S::Error>
691+
fn visit_seq<S>(self, mut seq: S) -> Result<CursorPayload<BundleKey>, S::Error>
692692
where
693693
S: SeqAccess<'de>,
694694
{
695695
// We consider this a complete request if we have no elements in the sequence.
696696
let Some(id) = seq.next_element()? else {
697-
return Ok(PaginationParams::new(None));
697+
return Ok(CursorPayload::new(None));
698698
};
699699

700700
// For all other items, we require a score and a global transaction score key.
@@ -704,14 +704,10 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
704704
let global_bundle_score_key = seq
705705
.next_element()?
706706
.ok_or_else(|| serde::de::Error::invalid_length(2, &self))?;
707-
Ok(PaginationParams::new(Some(BundleKey {
708-
id,
709-
score,
710-
global_bundle_score_key,
711-
})))
707+
Ok(CursorPayload::new(Some(BundleKey { id, score, global_bundle_score_key })))
712708
}
713709

714-
fn visit_map<M>(self, mut map: M) -> Result<PaginationParams<BundleKey>, M::Error>
710+
fn visit_map<M>(self, mut map: M) -> Result<CursorPayload<BundleKey>, M::Error>
715711
where
716712
M: MapAccess<'de>,
717713
{
@@ -753,18 +749,14 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
753749
&self,
754750
));
755751
}
756-
return Ok(PaginationParams::new(None));
752+
return Ok(CursorPayload::new(None));
757753
};
758754

759755
// For all other items, we require a score and a global bundle score key.
760756
let score = score.ok_or_else(|| serde::de::Error::missing_field("score"))?;
761757
let global_bundle_score_key = global_bundle_score_key
762758
.ok_or_else(|| serde::de::Error::missing_field("globalBundleScoreKey"))?;
763-
Ok(PaginationParams::new(Some(BundleKey {
764-
id,
765-
score,
766-
global_bundle_score_key,
767-
})))
759+
Ok(CursorPayload::new(Some(BundleKey { id, score, global_bundle_score_key })))
768760
}
769761
}
770762

@@ -774,7 +766,7 @@ impl<'de> Deserialize<'de> for PaginationParams<BundleKey> {
774766
}
775767
}
776768

777-
impl<'de> Deserialize<'de> for PaginationParams<OrderKey> {
769+
impl<'de> Deserialize<'de> for CursorPayload<OrderKey> {
778770
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
779771
where
780772
D: Deserializer<'de>,
@@ -819,24 +811,24 @@ impl<'de> Deserialize<'de> for PaginationParams<OrderKey> {
819811
struct OrderKeyVisitor;
820812

821813
impl<'de> Visitor<'de> for OrderKeyVisitor {
822-
type Value = PaginationParams<OrderKey>;
814+
type Value = CursorPayload<OrderKey>;
823815

824816
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
825817
formatter.write_str("a PaginationParams<OrderKey>")
826818
}
827819

828-
fn visit_seq<S>(self, mut seq: S) -> Result<PaginationParams<OrderKey>, S::Error>
820+
fn visit_seq<S>(self, mut seq: S) -> Result<CursorPayload<OrderKey>, S::Error>
829821
where
830822
S: SeqAccess<'de>,
831823
{
832824
let Some(id) = seq.next_element()? else {
833-
return Ok(PaginationParams::new(None));
825+
return Ok(CursorPayload::new(None));
834826
};
835827

836-
Ok(PaginationParams::new(Some(OrderKey { id })))
828+
Ok(CursorPayload::new(Some(OrderKey { id })))
837829
}
838830

839-
fn visit_map<M>(self, mut map: M) -> Result<PaginationParams<OrderKey>, M::Error>
831+
fn visit_map<M>(self, mut map: M) -> Result<CursorPayload<OrderKey>, M::Error>
840832
where
841833
M: MapAccess<'de>,
842834
{
@@ -854,10 +846,10 @@ impl<'de> Deserialize<'de> for PaginationParams<OrderKey> {
854846
}
855847

856848
let Some(id) = id else {
857-
return Ok(PaginationParams::new(None));
849+
return Ok(CursorPayload::new(None));
858850
};
859851

860-
Ok(PaginationParams::new(Some(OrderKey { id })))
852+
Ok(CursorPayload::new(Some(OrderKey { id })))
861853
}
862854
}
863855

@@ -899,24 +891,22 @@ mod tests {
899891
let serialized = serde_urlencoded::to_string(&tx_key).unwrap();
900892
assert_eq!(serialized, "txnHash=0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&score=100&globalTransactionScoreKey=gtsk");
901893

902-
let deserialized =
903-
serde_urlencoded::from_str::<PaginationParams<TxKey>>(&serialized).unwrap();
894+
let deserialized = serde_urlencoded::from_str::<CursorPayload<TxKey>>(&serialized).unwrap();
904895
assert_eq!(deserialized.cursor().unwrap(), &tx_key);
905896

906897
let partial_query_string = "score=100&globalTransactionScoreKey=gtsk";
907898
let partial_params =
908-
serde_urlencoded::from_str::<PaginationParams<TxKey>>(partial_query_string);
899+
serde_urlencoded::from_str::<CursorPayload<TxKey>>(partial_query_string);
909900
assert!(partial_params.is_err());
910901

911902
let partial_query_string =
912903
"txnHash=0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&score=100";
913904
let partial_params =
914-
serde_urlencoded::from_str::<PaginationParams<TxKey>>(partial_query_string);
905+
serde_urlencoded::from_str::<CursorPayload<TxKey>>(partial_query_string);
915906
assert!(partial_params.is_err());
916907

917908
let empty_query_string = "";
918-
let empty_params =
919-
serde_urlencoded::from_str::<PaginationParams<TxKey>>(empty_query_string);
909+
let empty_params = serde_urlencoded::from_str::<CursorPayload<TxKey>>(empty_query_string);
920910
assert!(empty_params.is_ok());
921911
assert!(empty_params.unwrap().cursor().is_none());
922912
}
@@ -937,22 +927,22 @@ mod tests {
937927
);
938928

939929
let deserialized =
940-
serde_urlencoded::from_str::<PaginationParams<BundleKey>>(&serialized).unwrap();
930+
serde_urlencoded::from_str::<CursorPayload<BundleKey>>(&serialized).unwrap();
941931
assert_eq!(deserialized.cursor().unwrap(), &bundle_key);
942932

943933
let partial_query_string = "score=100&globalBundleScoreKey=gbsk";
944934
let partial_params =
945-
serde_urlencoded::from_str::<PaginationParams<BundleKey>>(partial_query_string);
935+
serde_urlencoded::from_str::<CursorPayload<BundleKey>>(partial_query_string);
946936
assert!(partial_params.is_err());
947937

948938
let partial_query_string = "id=5932d4bb-58d9-41a9-851d-8dd7f04ccc33&score=100";
949939
let partial_params =
950-
serde_urlencoded::from_str::<PaginationParams<BundleKey>>(partial_query_string);
940+
serde_urlencoded::from_str::<CursorPayload<BundleKey>>(partial_query_string);
951941
assert!(partial_params.is_err());
952942

953943
let empty_query_string = "";
954944
let empty_params =
955-
serde_urlencoded::from_str::<PaginationParams<BundleKey>>(empty_query_string);
945+
serde_urlencoded::from_str::<CursorPayload<BundleKey>>(empty_query_string);
956946
assert!(empty_params.is_ok());
957947
assert!(empty_params.unwrap().cursor().is_none());
958948
}
@@ -967,7 +957,7 @@ mod tests {
967957
);
968958

969959
let deserialized =
970-
serde_urlencoded::from_str::<PaginationParams<OrderKey>>(&serialized).unwrap();
960+
serde_urlencoded::from_str::<CursorPayload<OrderKey>>(&serialized).unwrap();
971961
assert_eq!(deserialized.cursor().unwrap(), &order_key);
972962
}
973963
}

0 commit comments

Comments
 (0)