Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render Stellar Events as JSON Instead of Rust Debug Forma #1659

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,16 @@ impl Cmd {

let response = self.run_against_rpc_server(None, None).await?;

for event in &response.events {
match self.output {
// Should we pretty-print the JSON like we're doing here or just
// dump an event in raw JSON on each line? The latter is easier
// to consume programmatically.
OutputFormat::Json => {
println!(
"{}",
serde_json::to_string_pretty(&event).map_err(|e| {
Error::InvalidJson {
debug: format!("{event:#?}"),
error: e,
}
})?,
);
}
OutputFormat::Plain => println!("{event}"),
OutputFormat::Pretty => event.pretty_print()?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hope of the issue was to address that "Events in pretty print mode print as Rust debug format," and same in the plain mode too I think. The intent is to fix that, rather than return only JSON. So each topic and the value should print as JSON, but the rest of the format should stay the same.

See:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sure, thank you for letting me know, i'll fix that as soon as possible

}
}
// Convert the entire response to JSON
let json_response =
serde_json::to_string_pretty(&response).map_err(|e| Error::InvalidJson {
debug: format!("{response:#?}"),
error: e,
})?;

// Print the JSON response
println!("{}", json_response);

Ok(())
}

Expand Down
Loading