cat_gateway/db/index/block/txo/
insert_txo_asset.rs1use std::sync::Arc;
4
5use cardano_blockchain_types::{Slot, StakeAddress, TxnIndex, TxnOutputOffset};
6use scylla::{SerializeRow, Session};
7use tracing::error;
8
9use crate::{
10 db::{
11 index::queries::{PreparedQueries, SizedBatch},
12 types::{DbSlot, DbStakeAddress, DbTxnIndex, DbTxnOutputOffset},
13 },
14 settings::cassandra_db,
15};
16
17const INSERT_TXO_ASSET_QUERY: &str = include_str!("./cql/insert_txo_asset.cql");
19
20#[derive(SerializeRow, Debug)]
23pub(crate) struct Params {
24 stake_address: DbStakeAddress,
26 slot_no: DbSlot,
28 txn_index: DbTxnIndex,
30 txo: DbTxnOutputOffset,
32 policy_id: Vec<u8>,
34 asset_name: Vec<u8>,
36 value: num_bigint::BigInt,
38}
39
40impl Params {
41 #[allow(clippy::too_many_arguments)]
46 pub(crate) fn new(
47 stake_address: StakeAddress, slot_no: Slot, txn_index: TxnIndex, txo: TxnOutputOffset,
48 policy_id: &[u8], asset_name: &[u8], value: i128,
49 ) -> Self {
50 Self {
51 stake_address: stake_address.into(),
52 slot_no: slot_no.into(),
53 txn_index: txn_index.into(),
54 txo: txo.into(),
55 policy_id: policy_id.to_vec(),
56 asset_name: asset_name.to_vec(),
57 value: value.into(),
58 }
59 }
60
61 pub(crate) async fn prepare_batch(
63 session: &Arc<Session>, cfg: &cassandra_db::EnvVars,
64 ) -> anyhow::Result<SizedBatch> {
65 PreparedQueries::prepare_batch(
66 session.clone(),
67 INSERT_TXO_ASSET_QUERY,
68 cfg,
69 scylla::statement::Consistency::Any,
70 true,
71 false,
72 )
73 .await
74 .inspect_err(|error| error!(error=%error,"Failed to prepare Insert TXO Asset Query."))
75 .map_err(|error| anyhow::anyhow!("{error}\n--\n{INSERT_TXO_ASSET_QUERY}"))
76 }
77}