Skip to content

Commit

Permalink
fix: ensure composite inners are resolved to known types (#45)
Browse files Browse the repository at this point in the history
* fix: ensure composite inners are resolved to known types

* fix: fix clippy

* chore: use dojoengine patch until new account API is supported
  • Loading branch information
glihm authored Jul 25, 2024
1 parent 5cb2490 commit 3aec6d1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ url.workspace = true
tokio = { version = "1.15.0", features = ["full"], optional = true }

[patch.crates-io]
# Remove this patch once the following PR is merged: <https://github.com/xJonathanLEI/starknet-rs/pull/615>
# To enable std feature on `starknet-types-core`.
starknet-core = { git = "https://github.com/kariy/starknet-rs", rev = "fffe8e9" }
# Remove this patch once starknet-rs and types-core new revs in
# <https://github.com/cartridge-gg/cainome/pull/44> are supported by Dojo.
starknet-core = { git = "https://github.com/dojoengine/starknet-rs", branch = "fix/include-patch" }

[features]
default = []
Expand Down
25 changes: 25 additions & 0 deletions crates/parser/src/abi/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,31 @@ impl AbiParser {
}
}

// Can be a very huge copy here. Need an other way to do that in the loop
// above here.
let filtered = tokens_filtered.clone();

// So now once it's filtered, we may actually iterate again on the tokens
// to resolve all structs/enums inners that may reference existing types.
for (name, tokens) in tokens_filtered.iter_mut() {
if let Token::Composite(ref mut composite) = tokens {
for inner in &mut composite.inners {
if let Token::Composite(ref mut inner_composite) = inner.token {
if inner_composite.r#type == CompositeType::Unknown {
inner.token = filtered
.get(&inner.token.type_path())
.unwrap_or_else(|| panic!("In composite {} the inner token type for {} is expected to exist: {}",
name,
inner.name,
inner.token.type_path()
))
.clone();
}
}
}
}
}

tokens_filtered
}
}

0 comments on commit 3aec6d1

Please sign in to comment.