Skip to content

Commit 916682c

Browse files
committed
feat(cat-gateway): impl Query for Cip36ForVoteKeyInsert
1 parent b3ba600 commit 916682c

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//! Insert CIP36 Registration Query
22
3-
use std::sync::Arc;
3+
use std::{fmt, sync::Arc};
44

55
use cardano_blockchain_types::{Cip36, Slot, TxnIndex, VotingPubKey};
66
use scylla::{SerializeRow, Session};
77
use tracing::error;
88

99
use crate::{
1010
db::{
11-
index::queries::{PreparedQueries, SizedBatch},
11+
index::queries::{PreparedQueries, Query, QueryKind, SizedBatch},
1212
types::{DbSlot, DbTxnIndex},
1313
},
1414
settings::cassandra_db,
@@ -20,7 +20,7 @@ const INSERT_CIP36_REGISTRATION_FOR_VOTE_KEY_QUERY: &str =
2020

2121
/// Insert CIP-36 Registration Invalid Query Parameters
2222
#[derive(SerializeRow, Debug)]
23-
pub(crate) struct Params {
23+
pub(crate) struct Cip36ForVoteKeyInsert {
2424
/// Voting Public Key
2525
vote_key: Vec<u8>,
2626
/// Full Stake Address (not hashed, 32 byte ED25519 Public key).
@@ -33,12 +33,29 @@ pub(crate) struct Params {
3333
valid: bool,
3434
}
3535

36-
impl Params {
36+
impl Query for Cip36ForVoteKeyInsert {
37+
/// Prepare Batch of Insert TXI Index Data Queries
38+
async fn prepare_query(
39+
session: &Arc<Session>, cfg: &cassandra_db::EnvVars,
40+
) -> anyhow::Result<QueryKind> {
41+
Self::prepare_batch(session, cfg)
42+
.await
43+
.map(QueryKind::Batch)
44+
}
45+
}
46+
47+
impl fmt::Display for Cip36ForVoteKeyInsert {
48+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49+
write!(f, "{INSERT_CIP36_REGISTRATION_FOR_VOTE_KEY_QUERY}")
50+
}
51+
}
52+
53+
impl Cip36ForVoteKeyInsert {
3754
/// Create a new Insert Query.
3855
pub fn new(
3956
vote_key: &VotingPubKey, slot_no: Slot, txn_index: TxnIndex, cip36: &Cip36, valid: bool,
4057
) -> Self {
41-
Params {
58+
Cip36ForVoteKeyInsert {
4259
vote_key: vote_key
4360
.voting_pk()
4461
.map(|k| k.to_bytes().to_vec())

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) struct Cip36InsertQuery {
2626
/// Stake Registration Data captured during indexing.
2727
invalid: Vec<insert_cip36_invalid::Cip36InvalidInsert>,
2828
/// Stake Registration Data captured during indexing.
29-
for_vote_key: Vec<insert_cip36_for_vote_key::Params>,
29+
for_vote_key: Vec<insert_cip36_for_vote_key::Cip36ForVoteKeyInsert>,
3030
/// Stake Registration Data captured during indexing.
3131
stake_regs: Vec<certs::StakeRegistrationInsertQuery>,
3232
}
@@ -50,7 +50,7 @@ impl Cip36InsertQuery {
5050
let insert_cip36_invalid_batch =
5151
insert_cip36_invalid::Cip36InvalidInsert::prepare_batch(session, cfg).await;
5252
let insert_cip36_for_vote_key_addr_batch =
53-
insert_cip36_for_vote_key::Params::prepare_batch(session, cfg).await;
53+
insert_cip36_for_vote_key::Cip36ForVoteKeyInsert::prepare_batch(session, cfg).await;
5454
// Its a hack of inserting `stake_regs` during the indexing CIP 36 registrations.
5555
// Its done because some of the CIP 36 registrations contains some stake addresses which
5656
// are not actually some how registered using cardano certs.
@@ -86,7 +86,7 @@ impl Cip36InsertQuery {
8686
voting_key, slot_no, index, &cip36,
8787
));
8888
self.for_vote_key
89-
.push(insert_cip36_for_vote_key::Params::new(
89+
.push(insert_cip36_for_vote_key::Cip36ForVoteKeyInsert::new(
9090
voting_key, slot_no, index, &cip36, true,
9191
));
9292
self.stake_regs
@@ -120,10 +120,11 @@ impl Cip36InsertQuery {
120120
index,
121121
&cip36,
122122
));
123-
self.for_vote_key
124-
.push(insert_cip36_for_vote_key::Params::new(
123+
self.for_vote_key.push(
124+
insert_cip36_for_vote_key::Cip36ForVoteKeyInsert::new(
125125
voting_key, slot_no, index, &cip36, false,
126-
));
126+
),
127+
);
127128
}
128129
}
129130

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ use crate::{
4949
db::index::{
5050
block::{
5151
certs::StakeRegistrationInsertQuery,
52-
cip36::{insert_cip36::Cip36Insert, insert_cip36_invalid::Cip36InvalidInsert},
52+
cip36::{
53+
insert_cip36::Cip36Insert, insert_cip36_for_vote_key::Cip36ForVoteKeyInsert,
54+
insert_cip36_invalid::Cip36InvalidInsert,
55+
},
5356
},
5457
queries::rbac::{
5558
get_catalyst_id_from_stake_address, get_catalyst_id_from_transaction_id,
@@ -246,7 +249,8 @@ async fn prepare_queries(
246249
TxoUnstakedAssetInsert,
247250
StakeRegistrationInsertQuery,
248251
Cip36Insert,
249-
Cip36InvalidInsert
252+
Cip36InvalidInsert,
253+
Cip36ForVoteKeyInsert
250254
);
251255
Ok(queries)
252256
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,14 @@ async fn test_cip36_registration_for_vote_key() {
321321

322322
// data
323323
let data = vec![
324-
cip36::insert_cip36_for_vote_key::Params::new(
324+
cip36::insert_cip36_for_vote_key::Cip36ForVoteKeyInsert::new(
325325
&voting_pub_key(0),
326326
0.into(),
327327
0.into(),
328328
&test_utils::cip_36_1(),
329329
false,
330330
),
331-
cip36::insert_cip36_for_vote_key::Params::new(
331+
cip36::insert_cip36_for_vote_key::Cip36ForVoteKeyInsert::new(
332332
&voting_pub_key(1),
333333
1.into(),
334334
1.into(),

0 commit comments

Comments
 (0)