Skip to content

Commit ee89e7e

Browse files
deuszxma2bd
authored andcommitted
Custom Debug impl for CreateAndCall request (#4632)
## Motivation Before this PR the derived `Debug` implementation prints whole `Vec<u8>` bytes: ``` 2025-09-23T12:21:27.8588391Z "{\"CreateAndCall\":[[0,97,115,109,1,0,0,0,1,226,1,31,96,2,127,127,0,96,3,127,127 .... ``` ## Proposal Custom impl that prints the lengths. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. - These changes should be backported to the latest `testnet` branch ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 0738016 commit ee89e7e

File tree

1 file changed

+39
-2
lines changed
  • examples/create-and-call/src

1 file changed

+39
-2
lines changed

examples/create-and-call/src/lib.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
/*! ABI of the Create and Call Example Application that does not use GraphQL */
55

6+
use std::fmt::Debug;
7+
68
use linera_sdk::linera_base_types::{ContractAbi, ServiceAbi};
79
use serde::{Deserialize, Serialize};
810

@@ -18,13 +20,48 @@ impl ServiceAbi for CreateAndCallAbi {
1820
type QueryResponse = u64;
1921
}
2022

21-
#[derive(Debug, Serialize, Deserialize)]
23+
#[derive(Serialize, Deserialize)]
2224
pub enum CreateAndCallRequest {
2325
Query,
2426
CreateAndCall(Vec<u8>, Vec<u8>, u64, u64),
2527
}
2628

27-
#[derive(Debug, Serialize, Deserialize)]
29+
#[derive(Serialize, Deserialize)]
2830
pub enum CreateAndCallOperation {
2931
CreateAndCall(Vec<u8>, Vec<u8>, u64, u64),
3032
}
33+
34+
impl Debug for CreateAndCallRequest {
35+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
36+
match self {
37+
CreateAndCallRequest::Query => write!(f, "CreateAndCallRequest::Query"),
38+
CreateAndCallRequest::CreateAndCall(code, calldata, initial_value, increment) => {
39+
write!(
40+
f,
41+
"CreateAndCallRequest::CreateAndCall(code: <{} bytes>, calldata: <{} bytes>, initial value: {}, increment: {})",
42+
code.len(),
43+
calldata.len(),
44+
initial_value,
45+
increment
46+
)
47+
}
48+
}
49+
}
50+
}
51+
52+
impl Debug for CreateAndCallOperation {
53+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54+
match self {
55+
CreateAndCallOperation::CreateAndCall(code, calldata, initial_value, increment) => {
56+
write!(
57+
f,
58+
"CreateAndCall(code: <{} bytes>, calldata: <{} bytes>, initial_value: {}, increment: {})",
59+
code.len(),
60+
calldata.len(),
61+
initial_value,
62+
increment
63+
)
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)