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 Format and Update WASM Path #1642

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion cmd/crates/soroban-spec-typescript/src/boilerplate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ mod test {
use super::*;

const EXAMPLE_WASM: &[u8] = include_bytes!(
"../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm"
"../../../../target/wasm32-unknown-unknown/test-wasms/deps/test_custom_types.wasm"
);

fn init(root: impl AsRef<Path>) -> std::io::Result<Project> {
Expand Down
31 changes: 11 additions & 20 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,29 +156,20 @@ 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()?,
}
}
// 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(())
}

// The start method remains unchanged
fn start(&self) -> Result<rpc::EventStart, Error> {
let start = match (self.start_ledger, self.cursor.clone()) {
(Some(start), _) => rpc::EventStart::Ledger(start),
Expand Down
10 changes: 2 additions & 8 deletions cmd/soroban-cli/src/log/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use tracing::{debug, info, span, Level};

use crate::xdr;
use xdr::WriteXdr;

pub fn events(events: &[xdr::DiagnosticEvent]) {
for (i, event) in events.iter().enumerate() {
Expand All @@ -15,20 +14,16 @@ pub fn events(events: &[xdr::DiagnosticEvent]) {

let _enter = span.enter();

let xdr = event.to_xdr_base64(xdr::Limits::none()).unwrap();
let json = serde_json::to_string(event).unwrap();
if span.metadata().unwrap().level() == &Level::INFO {
info!("{i}: {xdr} {json}");
info!("{i}: {event:#?}");
} else {
debug!("{i}: {xdr} {json}");
debug!("{i}: {event:#?}");
}
}
}

fn is_contract_event(event: &xdr::DiagnosticEvent) -> bool {
matches!(event.event.type_, xdr::ContractEventType::Contract)
}

fn is_log_event(event: &xdr::DiagnosticEvent) -> bool {
match &event.event.body {
xdr::ContractEventBody::V0(xdr::ContractEventV0 { topics, .. })
Expand All @@ -40,7 +35,6 @@ fn is_log_event(event: &xdr::DiagnosticEvent) -> bool {
xdr::ContractEventBody::V0(_) => false,
}
}

fn str_to_sc_symbol(s: &str) -> xdr::ScSymbol {
let inner: xdr::StringM<32> = s.try_into().unwrap();
xdr::ScSymbol(inner)
Expand Down