Skip to content

Commit 8710d3f

Browse files
show raw spec type names in contract info
1 parent 40b9e16 commit 8710d3f

1 file changed

Lines changed: 5 additions & 37 deletions

File tree

cmd/soroban-cli/src/commands/contract/info/interface.rs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,51 +65,19 @@ impl Cmd {
6565
}
6666
};
6767

68-
// Contract specs may name user-defined types by their fully qualified
69-
// path (e.g. `my_contract::inner::State`). Those names are noisy and,
70-
// because `::` is not a valid identifier, the Rust and JSON renderers
71-
// below cannot use them as-is. Reduce them to short names for display,
72-
// reporting what changed. The `XdrBase64` output is the canonical
73-
// on-chain spec, so it is left untouched.
74-
let reduced = soroban_spec::reduce::reduce(&spec);
75-
if !matches!(self.output, InfoOutput::XdrBase64) {
76-
for rename in reduced.renames().filter(|r| r.renamed()) {
77-
print.infoln(format!(
78-
"Reduced type name {} to {}",
79-
String::from_utf8_lossy(&rename.from),
80-
String::from_utf8_lossy(&rename.to),
81-
));
82-
}
83-
let collisions: Vec<_> = reduced.renames().filter(|r| r.collision()).collect();
84-
if !collisions.is_empty() {
85-
use std::fmt::Write as _;
86-
let mut msg = String::from(
87-
"Reduced type names collided and were disambiguated with a numeric suffix:",
88-
);
89-
for rename in collisions {
90-
let _ = write!(
91-
msg,
92-
"\n {} -> {}",
93-
String::from_utf8_lossy(&rename.from),
94-
String::from_utf8_lossy(&rename.to),
95-
);
96-
}
97-
print.warnln(msg);
98-
}
99-
}
100-
let reduced_spec: Vec<_> = reduced.into_entries().collect();
101-
68+
// Type names in the spec are already reduced to simple names during
69+
// `contract build`, so show the spec as it is stored in the contract.
10270
let res = match self.output {
10371
InfoOutput::XdrBase64 => base64,
104-
InfoOutput::Json => serde_json::to_string(&reduced_spec)?,
105-
InfoOutput::JsonFormatted => serde_json::to_string_pretty(&reduced_spec)?,
72+
InfoOutput::Json => serde_json::to_string(&spec)?,
73+
InfoOutput::JsonFormatted => serde_json::to_string_pretty(&spec)?,
10674
// soroban_spec_rust drops doc strings entirely (rustdocs can execute
10775
// code) and routes every spec name through `format_ident!`, which
10876
// rejects non-identifier bytes. If a future revision starts
10977
// emitting spec strings as `Literal::string` or rustdocs, this
11078
// path becomes a terminal-escape-injection vector and must be
11179
// sanitized before printing.
112-
InfoOutput::Rust => soroban_spec_rust::generate_without_file(&reduced_spec)?
80+
InfoOutput::Rust => soroban_spec_rust::generate_without_file(&spec)?
11381
.to_formatted_string()
11482
.expect("Unexpected spec format error"),
11583
};

0 commit comments

Comments
 (0)