Skip to content

Commit 8cda1c7

Browse files
author
Adrian Nagy
committed
fix(graphql): Call to/from encodings instead of calling serde
1 parent 06cc95b commit 8cda1c7

File tree

2 files changed

+7
-69
lines changed

2 files changed

+7
-69
lines changed

mina-p2p-messages/src/v2/manual.rs

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,11 +1006,6 @@ impl MinaBaseSignedCommandStableV2 {
10061006
}
10071007

10081008
/// TODO(adonagy): implement the base64 conversions similarly to the base58check ones (versioned/not versioned)
1009-
#[derive(Debug, Clone)]
1010-
pub struct MinaBaseZkappCommandTStableV1WireStableV1Base64(
1011-
pub MinaBaseZkappCommandTStableV1WireStableV1,
1012-
);
1013-
10141009
impl MinaBaseZkappCommandTStableV1WireStableV1 {
10151010
pub fn to_base64(&self) -> Result<String, conv::Error> {
10161011
const ZKAPP_VERSION_TAG: u8 = 1;
@@ -1034,51 +1029,6 @@ impl MinaBaseZkappCommandTStableV1WireStableV1 {
10341029
}
10351030
}
10361031

1037-
impl From<MinaBaseZkappCommandTStableV1WireStableV1>
1038-
for MinaBaseZkappCommandTStableV1WireStableV1Base64
1039-
{
1040-
fn from(value: MinaBaseZkappCommandTStableV1WireStableV1) -> Self {
1041-
Self(value)
1042-
}
1043-
}
1044-
1045-
impl Serialize for MinaBaseZkappCommandTStableV1WireStableV1Base64 {
1046-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1047-
where
1048-
S: serde::ser::Serializer,
1049-
{
1050-
if serializer.is_human_readable() {
1051-
let base64_data = self.0.to_base64().map_err(serde::ser::Error::custom)?;
1052-
serializer.serialize_str(&base64_data)
1053-
} else {
1054-
self.0.serialize(serializer)
1055-
}
1056-
}
1057-
}
1058-
1059-
impl<'de> Deserialize<'de> for MinaBaseZkappCommandTStableV1WireStableV1Base64 {
1060-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1061-
where
1062-
D: serde::Deserializer<'de>,
1063-
{
1064-
let deserialised = if deserializer.is_human_readable() {
1065-
use base64::{engine::general_purpose::STANDARD_NO_PAD, Engine as _};
1066-
let base64_data = String::deserialize(deserializer)?;
1067-
STANDARD_NO_PAD
1068-
.decode(&base64_data)
1069-
.map_err(|e| serde::de::Error::custom(format!("Error deserializing zkapp: {e}")))?
1070-
} else {
1071-
Deserialize::deserialize(deserializer)?
1072-
};
1073-
1074-
let res =
1075-
MinaBaseZkappCommandTStableV1WireStableV1::binprot_read(&mut deserialised.as_slice())
1076-
.map_err(|e| serde::de::Error::custom(format!("Error deserializing zkapp: {e}")))?;
1077-
1078-
Ok(Self(res))
1079-
}
1080-
}
1081-
10821032
impl Serialize for ConsensusBodyReferenceStableV1 {
10831033
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
10841034
where
@@ -1721,8 +1671,7 @@ mod test {
17211671
use binprot::BinProtRead;
17221672

17231673
use crate::v2::{
1724-
MinaBaseVerificationKeyWireStableV1, MinaBaseZkappCommandTStableV1WireStableV1,
1725-
MinaBaseZkappCommandTStableV1WireStableV1Base64,
1674+
MinaBaseVerificationKeyWireStableV1, MinaBaseZkappCommandTStableV1WireStableV1
17261675
};
17271676

17281677
#[test]
@@ -1732,12 +1681,8 @@ mod test {
17321681
let zkapp =
17331682
MinaBaseZkappCommandTStableV1WireStableV1::binprot_read(&mut bytes.as_slice()).unwrap();
17341683

1735-
let zkapp_id = MinaBaseZkappCommandTStableV1WireStableV1Base64::from(zkapp);
1736-
1737-
let zkapp_id_string = serde_json::to_string_pretty(&zkapp_id).unwrap();
1738-
let zkapp_id_string = zkapp_id_string.trim_matches('"');
1739-
1740-
assert_eq!(expexcted, zkapp_id_string);
1684+
let zkapp_id = zkapp.to_base64().unwrap();
1685+
assert_eq!(expexcted, zkapp_id);
17411686
}
17421687

17431688
#[test]
@@ -1748,7 +1693,7 @@ mod test {
17481693

17491694
let decoded = STANDARD.decode(verification_key_encoded).unwrap();
17501695
let verification_key =
1751-
MinaBaseVerificationKeyWireStableV1::binprot_read(&mut decoded.as_slice()).unwrap();
1752-
println!("{:?}", verification_key);
1696+
MinaBaseVerificationKeyWireStableV1::binprot_read(&mut decoded.as_slice());
1697+
assert!(verification_key.is_ok());
17531698
}
17541699
}

node/native/src/graphql/block.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use juniper::GraphQLObject;
2-
use mina_p2p_messages::v2::MinaBaseZkappCommandTStableV1WireStableV1Base64;
32
use openmina_core::block::AppliedBlock;
43

54
use crate::graphql::zkapp::{GraphQLFailureReason, GraphQLFeePayer, GraphQLZkappCommand};
@@ -172,15 +171,9 @@ impl TryFrom<mina_p2p_messages::v2::StagedLedgerDiffDiffDiffStableV2> for GraphQ
172171
Ok(Some(GraphQLZkapp {
173172
hash: zkapp.hash()?.to_string(),
174173
failure_reason,
175-
id: serde_json::to_string_pretty(
176-
&MinaBaseZkappCommandTStableV1WireStableV1Base64::from(zkapp.clone()),
177-
)?
178-
.trim_matches('"')
179-
.to_string(),
174+
id: zkapp.to_base64()?,
180175
zkapp_command: GraphQLZkappCommand {
181-
memo: serde_json::to_string_pretty(&zkapp.memo)?
182-
.trim_matches('"')
183-
.to_string(),
176+
memo: zkapp.memo.to_base58check(),
184177
account_updates,
185178
fee_payer: GraphQLFeePayer::from(zkapp.fee_payer),
186179
},

0 commit comments

Comments
 (0)