diff --git a/crates/primitives/src/block/header.rs b/crates/primitives/src/block/header.rs index bbf0d5ab..249ce349 100644 --- a/crates/primitives/src/block/header.rs +++ b/crates/primitives/src/block/header.rs @@ -439,7 +439,7 @@ pub struct MMRDataFromIndexer { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct MMRMetaFromIndexer { - pub mmr_id: u64, + pub mmr_id: String, pub mmr_peaks: Vec, pub mmr_root: String, pub mmr_size: u64, @@ -470,7 +470,7 @@ pub struct MMRDataFromNewIndexer { #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct MMRMetaFromNewIndexer { - pub mmr_id: u64, + pub mmr_id: String, pub mmr_peaks: Vec, pub mmr_root: String, pub mmr_size: u64, diff --git a/crates/primitives/src/processed_types/mmr.rs b/crates/primitives/src/processed_types/mmr.rs index a0b8fbe5..31454007 100644 --- a/crates/primitives/src/processed_types/mmr.rs +++ b/crates/primitives/src/processed_types/mmr.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -use crate::block::header::MMRMetaFromNewIndexer; +use crate::{block::header::MMRMetaFromNewIndexer, utils::hex_string_to_uint}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct MMRMeta { @@ -24,21 +24,10 @@ impl MMRMeta { } } -impl From for MMRMetaFromNewIndexer { - fn from(val: MMRMeta) -> Self { - MMRMetaFromNewIndexer { - mmr_id: val.id, - mmr_root: val.root, - mmr_size: val.size, - mmr_peaks: val.peaks, - } - } -} - impl MMRMeta { pub fn from_indexer(val: MMRMetaFromNewIndexer, chain_id: u64) -> Self { MMRMeta { - id: val.mmr_id, + id: hex_string_to_uint(&val.mmr_id), root: val.mmr_root, size: val.mmr_size, peaks: val.mmr_peaks, diff --git a/crates/primitives/src/utils.rs b/crates/primitives/src/utils.rs index fe2eddbd..e6a1711e 100644 --- a/crates/primitives/src/utils.rs +++ b/crates/primitives/src/utils.rs @@ -44,6 +44,11 @@ pub fn tx_index_to_tx_key(tx_index: u64) -> String { format!("0x{}", hex::encode(binding)) } +pub fn hex_string_to_uint(hex_string: &str) -> u64 { + let hex_string = hex_string.trim_start_matches("0x"); + u64::from_str_radix(hex_string, 16).expect("Cannot convert hex string to uint") +} + #[cfg(test)] mod tests { use super::*; @@ -122,4 +127,11 @@ mod tests { assert_eq!(tx_key, expected_tx_key); } + + #[test] + fn test_hex_string_to_uint() { + let hex_string = "0x1b"; + let result = hex_string_to_uint(hex_string); + assert_eq!(result, 27); + } }