From 7e3982d8c9c217ba698bc303ba80e306435cf649 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Tue, 19 Mar 2024 09:40:22 +0900 Subject: [PATCH] Port changes from #178 --- indexer/entity/src/block.rs | 5 +++++ indexer/tasks/src/byron/byron_txs.rs | 5 +++-- indexer/tasks/src/multiera/multiera_metadata.rs | 3 +-- indexer/tasks/src/multiera/multiera_txs.rs | 5 +++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/indexer/entity/src/block.rs b/indexer/entity/src/block.rs index 3516c0c8..fa331513 100644 --- a/indexer/entity/src/block.rs +++ b/indexer/entity/src/block.rs @@ -12,6 +12,11 @@ pub struct Model { pub epoch: i32, pub slot: i32, pub payload: Option>, + /** + * tx_count is useful to skip empty blocks during pagination + * We cache tx_count here even though you can derive this number by doing a join of Block<>Transaction + * Since caching it is a relatively small amount of data for better performance + */ pub tx_count: i32, } diff --git a/indexer/tasks/src/byron/byron_txs.rs b/indexer/tasks/src/byron/byron_txs.rs index 7e30607b..2befec4c 100644 --- a/indexer/tasks/src/byron/byron_txs.rs +++ b/indexer/tasks/src/byron/byron_txs.rs @@ -1,5 +1,6 @@ use crate::{dsl::task_macro::*, era_common::transactions_from_hashes, utils::blake2b256}; use cml_core::serialization::ToBytes; +use cml_crypto::RawBytesEncoding; use cml_multi_era::byron::block::ByronBlock; use cml_multi_era::MultiEraBlock; use entity::sea_orm::Set; @@ -48,7 +49,7 @@ async fn handle_tx( .body .tx_payload .iter() - .map(|tx| <[u8; 32]>::from(tx.byron_tx.hash()).to_vec()) + .map(|tx| tx.byron_tx.hash().to_raw_bytes().to_vec()) .collect::>>(), _ => vec![], }; @@ -70,7 +71,7 @@ async fn handle_tx( }; TransactionActiveModel { - hash: Set(<[u8; 32]>::from(tx.byron_tx.hash()).to_vec()), + hash: Set(tx.byron_tx.hash().to_raw_bytes().to_vec()), block_id: Set(database_block.id), tx_index: Set(idx as i32), payload: Set(tx_payload), diff --git a/indexer/tasks/src/multiera/multiera_metadata.rs b/indexer/tasks/src/multiera/multiera_metadata.rs index 62fb66da..762b3042 100644 --- a/indexer/tasks/src/multiera/multiera_metadata.rs +++ b/indexer/tasks/src/multiera/multiera_metadata.rs @@ -1,5 +1,4 @@ -use cml_chain::auxdata::metadata::Metadata; -use cml_chain::auxdata::AuxiliaryData; +use cml_chain::auxdata::{AuxiliaryData, Metadata}; use cml_core::serialization::Serialize; use std::collections::BTreeMap; diff --git a/indexer/tasks/src/multiera/multiera_txs.rs b/indexer/tasks/src/multiera/multiera_txs.rs index 33fcf10f..3d6f2374 100644 --- a/indexer/tasks/src/multiera/multiera_txs.rs +++ b/indexer/tasks/src/multiera/multiera_txs.rs @@ -1,4 +1,5 @@ use cml_core::serialization::Serialize; +use cml_crypto::RawBytesEncoding; use std::collections::{BTreeSet, HashSet}; use super::multiera_block::MultieraBlockTask; @@ -45,7 +46,7 @@ async fn handle_tx( .1 .transaction_bodies() .iter() - .map(|tx_body| <[u8; 32]>::from(tx_body.hash()).to_vec()) + .map(|tx_body| tx_body.hash().to_raw_bytes().to_vec()) .collect::>() .as_slice(), ) @@ -72,7 +73,7 @@ async fn handle_tx( vec![] }; TransactionActiveModel { - hash: Set(<[u8; 32]>::from(tx.hash()).to_vec()), + hash: Set(tx.hash().to_raw_bytes().to_vec()), block_id: Set(database_block.id), tx_index: Set(idx as i32), payload: Set(tx_payload),