cat_gateway/db/index/block/txo/
insert_unstaked_txo.rs1use std::sync::Arc;
3
4use cardano_blockchain_types::{Slot, TransactionId, TxnIndex, TxnOutputOffset};
5use scylla::{SerializeRow, Session};
6use tracing::error;
7
8use crate::{
9 db::{
10 index::queries::{PreparedQueries, SizedBatch},
11 types::{DbSlot, DbTransactionId, DbTxnIndex, DbTxnOutputOffset},
12 },
13 settings::cassandra_db,
14};
15
16const INSERT_UNSTAKED_TXO_QUERY: &str = include_str!("./cql/insert_unstaked_txo.cql");
18
19#[derive(SerializeRow, Debug)]
22pub(crate) struct Params {
23 txn_id: DbTransactionId,
25 txo: DbTxnOutputOffset,
27 slot_no: DbSlot,
29 txn_index: DbTxnIndex,
31 address: String,
33 value: num_bigint::BigInt,
35}
36
37impl Params {
38 pub(crate) fn new(
40 txn_id: TransactionId, txo: TxnOutputOffset, slot_no: Slot, txn_index: TxnIndex,
41 address: &str, value: u64,
42 ) -> Self {
43 Self {
44 txn_id: txn_id.into(),
45 txo: txo.into(),
46 slot_no: slot_no.into(),
47 txn_index: txn_index.into(),
48 address: address.to_string(),
49 value: value.into(),
50 }
51 }
52
53 pub(crate) async fn prepare_batch(
55 session: &Arc<Session>, cfg: &cassandra_db::EnvVars,
56 ) -> anyhow::Result<SizedBatch> {
57 PreparedQueries::prepare_batch(
58 session.clone(),
59 INSERT_UNSTAKED_TXO_QUERY,
60 cfg,
61 scylla::statement::Consistency::Any,
62 true,
63 false,
64 )
65 .await
66 .inspect_err(|error| error!(error=%error,"Failed to prepare Unstaked Insert TXO Query."))
67 .map_err(|error| anyhow::anyhow!("{error}\n--\n{INSERT_UNSTAKED_TXO_QUERY}"))
68 }
69}