mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Serialization with serde.
This commit is contained in:
@@ -24,7 +24,7 @@ pub type HeaderHash = H256;
|
||||
pub type ProofHash = H256;
|
||||
|
||||
/// Unique identifier of a parachain.
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct ParachainId(u64);
|
||||
|
||||
impl From<ParachainId> for u64 {
|
||||
@@ -35,19 +35,23 @@ impl From<u64> for ParachainId {
|
||||
fn from(x: u64) -> Self { ParachainId(x) }
|
||||
}
|
||||
|
||||
/// A wrapper type for parachain block header raw bytes.
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ParachainBlockHeader(pub Vec<u8>);
|
||||
|
||||
/// A parachain block proposal.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct ParachainProposal {
|
||||
/// The ID of the parachain this is a proposal for.
|
||||
pub parachain: ParachainId,
|
||||
/// Parachain block header bytes.
|
||||
pub header: Vec<u8>,
|
||||
pub header: ParachainBlockHeader,
|
||||
/// Hash of data necessary to prove validity of the header.
|
||||
pub proof_hash: ProofHash,
|
||||
}
|
||||
|
||||
/// A relay chain block header.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Header {
|
||||
/// Block parent's hash.
|
||||
pub parent_hash: HeaderHash,
|
||||
@@ -63,8 +67,56 @@ pub struct Header {
|
||||
///
|
||||
/// Included candidates should be sorted by parachain ID, and without duplicate
|
||||
/// IDs.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct Body {
|
||||
/// Parachain proposal blocks.
|
||||
pub para_blocks: Vec<ParachainProposal>,
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use polkadot_serializer as ser;
|
||||
|
||||
#[test]
|
||||
fn test_header_serialization() {
|
||||
assert_eq!(ser::to_string_pretty(&Header {
|
||||
parent_hash: 5.into(),
|
||||
state_root: 3.into(),
|
||||
timestamp: 10,
|
||||
number: 67,
|
||||
}), r#"{
|
||||
"parent_hash": "0x0000000000000000000000000000000000000000000000000000000000000005",
|
||||
"state_root": "0x0000000000000000000000000000000000000000000000000000000000000003",
|
||||
"timestamp": 10,
|
||||
"number": 67
|
||||
}"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_body_serialization() {
|
||||
assert_eq!(ser::to_string_pretty(&Body {
|
||||
para_blocks: vec![
|
||||
ParachainProposal {
|
||||
parachain: 5.into(),
|
||||
header: ParachainBlockHeader(vec![1, 2, 3, 4]),
|
||||
proof_hash: 5.into(),
|
||||
}
|
||||
],
|
||||
}), r#"{
|
||||
"para_blocks": [
|
||||
{
|
||||
"parachain": 5,
|
||||
"header": [
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4
|
||||
],
|
||||
"proof_hash": "0x0000000000000000000000000000000000000000000000000000000000000005"
|
||||
}
|
||||
]
|
||||
}"#);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user