Skip to content

Commit b52de13

Browse files
committed
handle globals separately when emitting JSON ABI to solidity
1 parent 86afff2 commit b52de13

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

crates/json-abi/src/to_sol.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ impl JsonAbi {
220220
out.pop(); // trailing newline
221221

222222
out.push('}');
223+
if !its.globals.is_empty() {
224+
out.push('\n');
225+
fmt!(its.globals);
226+
}
223227
}
224228
}
225229

@@ -228,13 +232,20 @@ struct InternalTypes<'a> {
228232
name: &'a str,
229233
this_its: BTreeSet<It<'a>>,
230234
other: BTreeMap<&'a String, BTreeSet<It<'a>>>,
235+
globals: BTreeSet<It<'a>>,
231236
enums_as_udvt: bool,
232237
}
233238

234239
impl<'a> InternalTypes<'a> {
235240
#[allow(clippy::missing_const_for_fn)]
236241
fn new(name: &'a str, enums_as_udvt: bool) -> Self {
237-
Self { name, this_its: BTreeSet::new(), other: BTreeMap::new(), enums_as_udvt }
242+
Self {
243+
name,
244+
this_its: BTreeSet::new(),
245+
other: BTreeMap::new(),
246+
globals: BTreeSet::new(),
247+
enums_as_udvt,
248+
}
238249
}
239250

240251
fn visit_abi(&mut self, abi: &'a JsonAbi) {
@@ -313,7 +324,7 @@ impl<'a> InternalTypes<'a> {
313324
self.other.entry(contract).or_default().insert(it);
314325
}
315326
} else {
316-
self.this_its.insert(it);
327+
self.globals.insert(it);
317328
}
318329
}
319330
}

0 commit comments

Comments
 (0)