Skip to content

Commit

Permalink
Add and remove "0x" prefix during marshal and unmarshal respectively
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Feb 18, 2025
1 parent 7378fc0 commit 9208fca
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions anchor/network/src/handshake/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl NodeInfo {
fn marshal(&self) -> Result<Vec<u8>, Error> {
let mut entries = vec![
"".to_string(), // formerly forkVersion, now deprecated
self.network_id.clone(), // network id
format!("0x{}", self.network_id.clone()), // network id
];

if let Some(meta) = &self.metadata {
Expand All @@ -78,7 +78,9 @@ impl NodeInfo {
return Err(Validation("node info must have at least 2 entries".into()));
}
// skip ser.entries[0]: old forkVersion
let network_id = ser.entries[1].clone();
let network_id = ser.entries[1].clone().strip_prefix("0x")
.ok_or_else(|| Validation("network id must be prefixed with 0x".into()))?.to_string();

let metadata = if ser.entries.len() >= 3 {
let meta = serde_json::from_slice(ser.entries[2].as_bytes())?;
Some(meta)
Expand Down

0 comments on commit 9208fca

Please sign in to comment.