Add sync logic to handshake message

This commit is contained in:
NicolasCantu 2025-06-03 18:15:18 +02:00 committed by Sosthene
parent 684b71e00c
commit 92c777dbef

View File

@ -18,6 +18,7 @@ pub enum AnkFlag {
Cipher, Cipher,
Commit, Commit,
Handshake, Handshake,
Sync,
Unknown, Unknown,
} }
@ -29,6 +30,7 @@ impl From<&str> for AnkFlag {
"Cipher" => Self::Cipher, "Cipher" => Self::Cipher,
"Commit" => Self::Commit, "Commit" => Self::Commit,
"Handshake" => Self::Handshake, "Handshake" => Self::Handshake,
"Sync" => Self::Sync,
_ => Self::Unknown, _ => Self::Unknown,
} }
} }
@ -48,6 +50,7 @@ impl AnkFlag {
2 => Self::Cipher, 2 => Self::Cipher,
3 => Self::Commit, 3 => Self::Commit,
4 => Self::Handshake, 4 => Self::Handshake,
5 => Self::Sync,
_ => Self::Unknown, _ => Self::Unknown,
} }
} }
@ -59,6 +62,7 @@ impl AnkFlag {
Self::Cipher => "Cipher", Self::Cipher => "Cipher",
Self::Commit => "Commit", Self::Commit => "Commit",
Self::Handshake => "Handshake", Self::Handshake => "Handshake",
Self::Sync => "Sync",
Self::Unknown => "Unknown", Self::Unknown => "Unknown",
} }
} }
@ -164,6 +168,7 @@ pub struct HandshakeMessage {
pub sp_address: String, pub sp_address: String,
pub peers_list: OutPointMemberMap, pub peers_list: OutPointMemberMap,
pub processes_list: OutPointProcessMap, pub processes_list: OutPointProcessMap,
// pub chain_tip: u64,
} }
impl HandshakeMessage { impl HandshakeMessage {
@ -172,6 +177,36 @@ impl HandshakeMessage {
sp_address, sp_address,
peers_list, peers_list,
processes_list, processes_list,
// chain_tip,
}
}
pub fn to_string(&self) -> String {
serde_json::to_string(self).unwrap()
}
}
#[derive(Debug, Serialize, Deserialize, Tsify)]
pub enum SyncMessageContent {
Tweaks,
WholeBlocks,
Headers,
}
#[derive(Debug, Serialize, Deserialize, Tsify)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct SyncMessage {
start: u32,
end: u32,
content: SyncMessageContent,
}
impl SyncMessage {
pub fn new(start: u32, end: u32, content: SyncMessageContent) -> Self {
Self {
start,
end,
content,
} }
} }