Skip to content

Commit

Permalink
hotfix: mmr_id to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Jul 26, 2024
1 parent 95ffe6d commit aea1559
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions crates/primitives/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
pub mmr_root: String,
pub mmr_size: u64,
Expand Down Expand Up @@ -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<String>,
pub mmr_root: String,
pub mmr_size: u64,
Expand Down
15 changes: 2 additions & 13 deletions crates/primitives/src/processed_types/mmr.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -24,21 +24,10 @@ impl MMRMeta {
}
}

impl From<MMRMeta> 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,
Expand Down
12 changes: 12 additions & 0 deletions crates/primitives/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit aea1559

Please sign in to comment.