use own type MantleMsgId

This commit is contained in:
Sergio Chouhy
2026-01-29 15:21:15 -03:00
parent 476dc50482
commit de54744893
8 changed files with 13 additions and 40 deletions
-1
View File
@@ -17,6 +17,5 @@ log.workspace = true
hex.workspace = true
borsh.workspace = true
base64.workspace = true
logos-blockchain-core.workspace = true
url.workspace = true
logos-blockchain-common-http-client.workspace = true
+3 -23
View File
@@ -1,10 +1,10 @@
use borsh::{BorshDeserialize, BorshSerialize};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use sha2::{Digest, Sha256, digest::FixedOutput};
use crate::transaction::EncodedTransaction;
pub type HashType = [u8; 32];
pub type MantleMsgId = [u8; 32];
#[derive(Debug, Clone)]
/// Our own hasher.
@@ -50,11 +50,7 @@ pub struct Block {
pub header: BlockHeader,
pub body: BlockBody,
pub bedrock_status: BedrockStatus,
#[borsh(
serialize_with = "borsh_msg_id::serialize",
deserialize_with = "borsh_msg_id::deserialize"
)]
pub bedrock_parent_id: MsgId,
pub bedrock_parent_id: MantleMsgId,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
@@ -69,7 +65,7 @@ impl HashableBlockData {
pub fn into_pending_block(
self,
signing_key: &nssa::PrivateKey,
bedrock_parent_id: MsgId,
bedrock_parent_id: MantleMsgId,
) -> Block {
let data_bytes = borsh::to_vec(&self).unwrap();
let signature = nssa::Signature::new(signing_key, &data_bytes);
@@ -106,22 +102,6 @@ impl From<Block> for HashableBlockData {
}
}
mod borsh_msg_id {
use std::io::{Read, Write};
use logos_blockchain_core::mantle::ops::channel::MsgId;
pub fn serialize<W: Write>(v: &MsgId, w: &mut W) -> std::io::Result<()> {
w.write_all(v.as_ref())
}
pub fn deserialize<R: Read>(r: &mut R) -> std::io::Result<MsgId> {
let mut buf = [0u8; 32];
r.read_exact(&mut buf)?;
Ok(MsgId::from(buf))
}
}
#[cfg(test)]
mod tests {
use crate::{block::HashableBlockData, test_utils};
+1 -3
View File
@@ -1,5 +1,3 @@
use logos_blockchain_core::mantle::ops::channel::MsgId;
use crate::{
block::{Block, HashableBlockData},
transaction::{EncodedTransaction, NSSATransaction},
@@ -32,7 +30,7 @@ pub fn produce_dummy_block(
transactions,
};
block_data.into_pending_block(&sequencer_sign_key_for_testing(), MsgId::from([0; 32]))
block_data.into_pending_block(&sequencer_sign_key_for_testing(), [0; 32])
}
pub fn produce_dummy_empty_transaction() -> EncodedTransaction {