Skip to content

Commit 49e73af

Browse files
committed
fix: resolve topic_id packing issues
1 parent b69ad8d commit 49e73af

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

core/src/abi.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::HashSet, fs, iter::Map, path::Path};
1+
use std::{collections::HashSet, fs, path::Path};
22

33
use ethers::{
44
types::{ValueOrArray, H256},
@@ -178,12 +178,33 @@ pub enum ReadAbiError {
178178

179179
impl ABIItem {
180180
pub fn format_event_signature(&self) -> Result<String, ParamTypeError> {
181-
let formatted_inputs = self
182-
.inputs
183-
.iter()
184-
.map(|component| component.format_param_type())
185-
.collect::<Result<Vec<_>, _>>()?;
186-
Ok(formatted_inputs.join(","))
181+
let name = &self.name;
182+
let params = self.inputs.iter()
183+
.map(Self::format_param_type)
184+
.collect::<Result<Vec<_>, _>>()?
185+
.join(",");
186+
187+
Ok(format!("{}({})", name, params))
188+
}
189+
190+
fn format_param_type(input: &ABIInput) -> Result<String, ParamTypeError> {
191+
let base_type = input.type_.split('[').next().unwrap_or(&input.type_);
192+
let array_suffix = input.type_.strip_prefix(base_type).unwrap_or("");
193+
194+
let type_str = match base_type {
195+
"tuple" => {
196+
let inner = input.components.as_ref()
197+
.ok_or(ParamTypeError::MissingComponents)?
198+
.iter()
199+
.map(Self::format_param_type)
200+
.collect::<Result<Vec<_>, _>>()?
201+
.join(",");
202+
format!("({})", inner)
203+
},
204+
_ => base_type.to_string(),
205+
};
206+
207+
Ok(format!("{}{}", type_str, array_suffix))
187208
}
188209

189210
pub fn extract_event_names_and_signatures_from_abi(
@@ -193,6 +214,7 @@ impl ABIItem {
193214
for item in abi_json.into_iter() {
194215
if item.type_ == "event" {
195216
let signature = item.format_event_signature()?;
217+
// println!("signature {}", signature);
196218
events.push(EventInfo::new(item, signature));
197219
}
198220
}
@@ -275,13 +297,12 @@ impl EventInfo {
275297
}
276298

277299
pub fn topic_id(&self) -> H256 {
278-
let event_signature = format!("{}({})", self.name, self.signature);
300+
let event_signature = self.signature.clone();
279301
H256::from_slice(&keccak256(event_signature))
280302
}
281303

282304
pub fn topic_id_as_hex_string(&self) -> String {
283-
let event_signature = format!("{}({})", self.name, self.signature);
284-
Map::collect(keccak256(event_signature).iter().map(|byte| format!("{:02x}", byte)))
305+
format!("0x{:x}", self.topic_id())
285306
}
286307

287308
pub fn struct_result(&self) -> &str {

core/src/generator/events_bindings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ fn build_pub_contract_fn(
422422
}
423423
Some(value) => match value {
424424
ValueOrArray::Value(address) => {
425-
let address = format!("{}", address);
425+
let address = format!("{:?}", address);
426426
Code::new(format!(
427427
r#"pub fn {contract_name}_contract(network: &str) -> {abi_gen_name}<Arc<Provider<RetryClient<Http>>>> {{
428428
let address: Address = "{address}".parse().expect("Invalid address");

documentation/docs/pages/docs/changelog.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ github branch - https://github.com/joshstevens19/rindexer/tree/release/0.10.0
3939
-------------------------------------------------
4040
- fix: dependency events not being applied to the correct contract
4141
- fix: resolve defining environment variables in contract address fields in the yaml
42+
- fix: resolve topic_id packing issues
4243

4344
## 0.9.0-beta - 19th September 2024
4445

0 commit comments

Comments
 (0)