Skip to content

Commit

Permalink
feat(gprimitives): serialize actor id as hex
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit committed Jan 17, 2025
1 parent 6ce236b commit 0214707
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ethexe/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository.workspace = true
tokio = { workspace = true }
anyhow.workspace = true
futures.workspace = true
gprimitives = { workspace = true, features = ["serde"] }
gprimitives = { workspace = true, features = ["serde", "ethexe"] }
ethexe-db.workspace = true
ethexe-processor.workspace = true
tower = { workspace = true, features = ["util"] }
Expand Down
5 changes: 4 additions & 1 deletion gprimitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ rust-version.workspace = true
[dependencies]
derive_more.workspace = true
primitive-types = { workspace = true, features = ["scale-info", "rustc-hex"] }
parity-scale-codec = { workspace = true, features = ["derive"], optional = true }
parity-scale-codec = { workspace = true, features = [
"derive",
], optional = true }
scale-info = { workspace = true, features = ["derive"], optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
hex.workspace = true
Expand All @@ -22,3 +24,4 @@ gear-ss58.workspace = true
[features]
codec = ["parity-scale-codec", "scale-info"]
serde = ["dep:serde", "primitive-types/serde_no_std"]
ethexe = []
13 changes: 12 additions & 1 deletion gprimitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl FromStr for ActorId {
}
}

#[cfg(feature = "serde")]
#[cfg(all(feature = "serde", not(feature = "ethexe")))]
impl Serialize for ActorId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -239,6 +239,17 @@ impl Serialize for ActorId {
}
}

#[cfg(all(feature = "serde", feature = "ethexe"))]
impl Serialize for ActorId {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let id: H160 = self.to_address_lossy();
id.serialize(serializer)
}
}

#[cfg(feature = "serde")]
impl<'de> Deserialize<'de> for ActorId {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
Expand Down

0 comments on commit 0214707

Please sign in to comment.