Skip to content

Commit 726181b

Browse files
committed
refactoring: use string for JSON data
1 parent 89e7a56 commit 726181b

File tree

8 files changed

+28
-41
lines changed

8 files changed

+28
-41
lines changed

crates/iota-grpc-api/proto/common.proto

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ message BcsData {
1010
bytes data = 1;
1111
}
1212

13-
// JSON-serialized data container
14-
message JsonData {
15-
bytes data = 1;
16-
}
17-
1813
// 32-byte address type for IOTA addresses, object IDs, package IDs, etc.
1914
message Address {
2015
bytes address = 1;

crates/iota-grpc-api/proto/read.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ message ObjectDataOptions {
3030
}
3131

3232
message GetObjectResponse {
33-
optional iota.grpc.common.JsonData json_data = 1; // JSON-serialized IotaObjectData (success)
34-
optional iota.grpc.common.JsonData json_error = 2; // JSON-serialized IotaObjectResponseError (error)
33+
optional string json_data = 1; // JSON-serialized IotaObjectData (success)
34+
optional string json_error = 2; // JSON-serialized IotaObjectResponseError (error)
3535
}

crates/iota-grpc-api/proto/transaction.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ message TransactionStreamRequest {
1919

2020
// Transaction data
2121
message Transaction {
22-
iota.grpc.common.JsonData json_data = 1; // JSON-serialized IotaTransactionBlockEffects
22+
string json_data = 1; // JSON-serialized IotaTransactionBlockEffects
2323
}
2424

2525
// Rich transaction filter that supports gRPC transaction filtering

crates/iota-grpc-api/proto/write.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ enum ExecuteTransactionRequestType {
4646
}
4747

4848
message ExecuteTransactionResponse {
49-
iota.grpc.common.JsonData json_data = 1; // JSON-serialized IotaTransactionBlockResponse
49+
string json_data = 1; // JSON-serialized IotaTransactionBlockResponse
5050
}

crates/iota-grpc-api/src/client/read.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,17 @@ impl ReadClient {
6767
response: &crate::read::GetObjectResponse,
6868
) -> Result<IotaObjectResponse, Status> {
6969
// Check for success data first
70-
if let Some(data_wrapper) = &response.json_data {
70+
if let Some(json_data) = &response.json_data {
7171
// Deserialize success data
72-
let object_data: IotaObjectData =
73-
serde_json::from_slice(&data_wrapper.data).map_err(|e| {
74-
Status::internal(format!("Failed to deserialize object data from JSON: {e}"))
75-
})?;
72+
let object_data: IotaObjectData = serde_json::from_str(json_data).map_err(|e| {
73+
Status::internal(format!("Failed to deserialize object data from JSON: {e}"))
74+
})?;
7675
Ok(IotaObjectResponse::new_with_data(object_data))
77-
} else if let Some(error_wrapper) = &response.json_error {
76+
} else if let Some(json_error) = &response.json_error {
7877
// Deserialize error
79-
let error: IotaObjectResponseError = serde_json::from_slice(&error_wrapper.data)
80-
.map_err(|e| {
81-
Status::internal(format!("Failed to deserialize error from JSON: {e}"))
82-
})?;
78+
let error: IotaObjectResponseError = serde_json::from_str(json_error).map_err(|e| {
79+
Status::internal(format!("Failed to deserialize error from JSON: {e}"))
80+
})?;
8381
Ok(IotaObjectResponse::new_with_error(error))
8482
} else {
8583
Err(Status::internal("Response contains neither data nor error"))

crates/iota-grpc-api/src/read_service.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,19 @@ impl ReadService for ReadGrpcService {
110110
})?;
111111

112112
return Ok(Response::new(GetObjectResponse {
113-
json_data: Some(crate::common::JsonData {
114-
data: serde_json::to_vec(&data).map_err(|e| {
115-
Status::internal(format!(
116-
"Failed to serialize object data: {e}"
117-
))
118-
})?,
119-
}),
120-
json_error: Some(crate::common::JsonData {
121-
data: serde_json::to_vec(&IotaObjectResponseError::Display {
113+
json_data: Some(serde_json::to_string(&data).map_err(|e| {
114+
Status::internal(format!(
115+
"Failed to serialize object data: {e}"
116+
))
117+
})?),
118+
json_error: Some(
119+
serde_json::to_string(&IotaObjectResponseError::Display {
122120
error: "Failed to compute display fields".to_string(),
123121
})
124122
.map_err(|e| {
125123
Status::internal(format!("Failed to serialize error: {e}"))
126124
})?,
127-
}),
125+
),
128126
}));
129127
}
130128
}
@@ -159,23 +157,23 @@ impl ReadService for ReadGrpcService {
159157

160158
/// Serialize success data to JSON (matches IotaObjectResponse::new_with_data)
161159
fn serialize_data_to_json(data: IotaObjectData) -> Result<GetObjectResponse, Status> {
162-
let json_data = serde_json::to_vec(&data)
160+
let json_data = serde_json::to_string(&data)
163161
.map_err(|e| Status::internal(format!("Failed to serialize object data to JSON: {e}")))?;
164162

165163
Ok(GetObjectResponse {
166-
json_data: Some(crate::common::JsonData { data: json_data }),
164+
json_data: Some(json_data),
167165
json_error: None,
168166
})
169167
}
170168

171169
/// Serialize error to JSON (matches IotaObjectResponse::new_with_error)
172170
fn serialize_error_to_json(error: IotaObjectResponseError) -> Result<GetObjectResponse, Status> {
173-
let error_data = serde_json::to_vec(&error)
171+
let json_error = serde_json::to_string(&error)
174172
.map_err(|e| Status::internal(format!("Failed to serialize error to JSON: {e}")))?;
175173

176174
Ok(GetObjectResponse {
177175
json_data: None,
178-
json_error: Some(crate::common::JsonData { data: error_data }),
176+
json_error: Some(json_error),
179177
})
180178
}
181179

crates/iota-grpc-api/src/transaction_service.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,9 @@ fn parse_iota_address(
255255
impl From<&iota_json_rpc_types::IotaTransactionBlockEffects> for Transaction {
256256
fn from(effects: &iota_json_rpc_types::IotaTransactionBlockEffects) -> Self {
257257
// Serialize JSON-RPC effects directly to JSON
258-
let data = serde_json::to_vec(effects)
258+
let json_data = serde_json::to_string(effects)
259259
.expect("IotaTransactionBlockEffects should always serialize to JSON");
260260

261-
Transaction {
262-
json_data: Some(crate::common::JsonData { data }),
263-
}
261+
Transaction { json_data }
264262
}
265263
}

crates/iota-grpc-api/src/write_service.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,10 @@ impl WriteGrpcService {
136136
fn serialize_response_to_json(
137137
response: &IotaTransactionBlockResponse,
138138
) -> Result<ExecuteTransactionResponse, Status> {
139-
let data = serde_json::to_vec(response)
139+
let json_data = serde_json::to_string(response)
140140
.map_err(|e| Status::internal(format!("Failed to serialize response to JSON: {e}")))?;
141141

142-
Ok(ExecuteTransactionResponse {
143-
json_data: Some(crate::common::JsonData { data }),
144-
})
142+
Ok(ExecuteTransactionResponse { json_data })
145143
}
146144

147145
async fn handle_post_orchestration(

0 commit comments

Comments
 (0)