Skip to content

Commit b3ba600

Browse files
committed
feat(cat-gateway): impl Query for Cip36InvalidInsert
1 parent 6aea30e commit b3ba600

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

catalyst-gateway/bin/src/db/index/block/cip36/insert_cip36_invalid.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Insert CIP36 Registration Query (Invalid Records)
22
3-
use std::{fmt::Debug, sync::Arc};
3+
use std::{fmt, sync::Arc};
44

55
use cardano_blockchain_types::{Cip36, Slot, TxnIndex, VotingPubKey};
66
use pallas::ledger::addresses::Address;
@@ -9,7 +9,7 @@ use tracing::error;
99

1010
use crate::{
1111
db::{
12-
index::queries::{PreparedQueries, SizedBatch},
12+
index::queries::{PreparedQueries, Query, QueryKind, SizedBatch},
1313
types::{DbSlot, DbTxnIndex},
1414
},
1515
settings::cassandra_db,
@@ -21,7 +21,7 @@ const INSERT_CIP36_REGISTRATION_INVALID_QUERY: &str =
2121

2222
/// Insert CIP-36 Registration Invalid Query Parameters
2323
#[derive(SerializeRow, Clone)]
24-
pub(crate) struct Params {
24+
pub(crate) struct Cip36InvalidInsert {
2525
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
2626
stake_public_key: Vec<u8>,
2727
/// Slot Number the cert is in.
@@ -46,13 +46,24 @@ pub(crate) struct Params {
4646
problem_report: String,
4747
}
4848

49-
impl Debug for Params {
50-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
49+
impl Query for Cip36InvalidInsert {
50+
/// Prepare Batch of Insert TXI Index Data Queries
51+
async fn prepare_query(
52+
session: &Arc<Session>, cfg: &cassandra_db::EnvVars,
53+
) -> anyhow::Result<QueryKind> {
54+
Self::prepare_batch(session, cfg)
55+
.await
56+
.map(QueryKind::Batch)
57+
}
58+
}
59+
60+
impl fmt::Debug for Cip36InvalidInsert {
61+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5162
let cip36 = match self.cip36 {
5263
MaybeUnset::Unset => "UNSET",
5364
MaybeUnset::Set(v) => &format!("{v:?}"),
5465
};
55-
f.debug_struct("Params")
66+
f.debug_struct("Cip36InvalidInsert")
5667
.field("stake_public_key", &self.stake_public_key)
5768
.field("slot_no", &self.slot_no)
5869
.field("txn_index", &self.txn_index)
@@ -68,7 +79,13 @@ impl Debug for Params {
6879
}
6980
}
7081

71-
impl Params {
82+
impl fmt::Display for Cip36InvalidInsert {
83+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
84+
write!(f, "{INSERT_CIP36_REGISTRATION_INVALID_QUERY}")
85+
}
86+
}
87+
88+
impl Cip36InvalidInsert {
7289
/// Create a new Insert Query.
7390
pub fn new(
7491
vote_key: Option<&VotingPubKey>, slot_no: Slot, txn_index: TxnIndex, cip36: &Cip36,
@@ -89,7 +106,7 @@ impl Params {
89106
String::new()
90107
});
91108

92-
Params {
109+
Cip36InvalidInsert {
93110
stake_public_key,
94111
slot_no: slot_no.into(),
95112
txn_index: txn_index.into(),

catalyst-gateway/bin/src/db/index/block/cip36/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) struct Cip36InsertQuery {
2424
/// Stake Registration Data captured during indexing.
2525
registrations: Vec<insert_cip36::Cip36Insert>,
2626
/// Stake Registration Data captured during indexing.
27-
invalid: Vec<insert_cip36_invalid::Params>,
27+
invalid: Vec<insert_cip36_invalid::Cip36InvalidInsert>,
2828
/// Stake Registration Data captured during indexing.
2929
for_vote_key: Vec<insert_cip36_for_vote_key::Params>,
3030
/// Stake Registration Data captured during indexing.
@@ -48,7 +48,7 @@ impl Cip36InsertQuery {
4848
) -> anyhow::Result<(SizedBatch, SizedBatch, SizedBatch)> {
4949
let insert_cip36_batch = insert_cip36::Cip36Insert::prepare_batch(session, cfg).await;
5050
let insert_cip36_invalid_batch =
51-
insert_cip36_invalid::Params::prepare_batch(session, cfg).await;
51+
insert_cip36_invalid::Cip36InvalidInsert::prepare_batch(session, cfg).await;
5252
let insert_cip36_for_vote_key_addr_batch =
5353
insert_cip36_for_vote_key::Params::prepare_batch(session, cfg).await;
5454
// Its a hack of inserting `stake_regs` during the indexing CIP 36 registrations.
@@ -107,17 +107,19 @@ impl Cip36InsertQuery {
107107
// Cannot index an invalid CIP36, if there is no stake public key.
108108
if let Some(stake_pk) = cip36.stake_pk() {
109109
if cip36.voting_pks().is_empty() {
110-
self.invalid.push(insert_cip36_invalid::Params::new(
111-
None, slot_no, index, &cip36,
112-
));
110+
self.invalid
111+
.push(insert_cip36_invalid::Cip36InvalidInsert::new(
112+
None, slot_no, index, &cip36,
113+
));
113114
} else {
114115
for voting_key in cip36.voting_pks() {
115-
self.invalid.push(insert_cip36_invalid::Params::new(
116-
Some(voting_key),
117-
slot_no,
118-
index,
119-
&cip36,
120-
));
116+
self.invalid
117+
.push(insert_cip36_invalid::Cip36InvalidInsert::new(
118+
Some(voting_key),
119+
slot_no,
120+
index,
121+
&cip36,
122+
));
121123
self.for_vote_key
122124
.push(insert_cip36_for_vote_key::Params::new(
123125
voting_key, slot_no, index, &cip36, false,

catalyst-gateway/bin/src/db/index/queries/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ use super::block::{
4747
};
4848
use crate::{
4949
db::index::{
50-
block::{certs::StakeRegistrationInsertQuery, cip36::insert_cip36::Cip36Insert},
50+
block::{
51+
certs::StakeRegistrationInsertQuery,
52+
cip36::{insert_cip36::Cip36Insert, insert_cip36_invalid::Cip36InvalidInsert},
53+
},
5154
queries::rbac::{
5255
get_catalyst_id_from_stake_address, get_catalyst_id_from_transaction_id,
5356
get_rbac_invalid_registrations, get_rbac_registrations,
@@ -242,7 +245,8 @@ async fn prepare_queries(
242245
TxoUnstakedInsert,
243246
TxoUnstakedAssetInsert,
244247
StakeRegistrationInsertQuery,
245-
Cip36Insert
248+
Cip36Insert,
249+
Cip36InvalidInsert
246250
);
247251
Ok(queries)
248252
}

catalyst-gateway/bin/src/db/index/tests/scylla_purge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,13 @@ async fn test_cip36_registration_invalid() {
392392

393393
// data
394394
let data = vec![
395-
cip36::insert_cip36_invalid::Params::new(
395+
cip36::insert_cip36_invalid::Cip36InvalidInsert::new(
396396
Some(&voting_pub_key(0)),
397397
0.into(),
398398
0.into(),
399399
&test_utils::cip_36_1(),
400400
),
401-
cip36::insert_cip36_invalid::Params::new(
401+
cip36::insert_cip36_invalid::Cip36InvalidInsert::new(
402402
Some(&voting_pub_key(1)),
403403
1.into(),
404404
1.into(),

0 commit comments

Comments
 (0)