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 ee9fbfc commit 5476984
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 @@ -50,6 +50,11 @@ pub fn felt_to_bytes32(felt: FieldElement) -> FixedBytes<32> {
B256::from(felt_bytes)
}

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")
}

pub fn default_increment() -> u64 {
1
}
Expand Down Expand Up @@ -144,4 +149,11 @@ mod tests {
let bytes32 = felt_to_bytes32(felt);
assert_eq!(bytes32, felt.to_bytes_be());
}

#[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 5476984

Please sign in to comment.