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

fix: ABI generation #146

Merged
merged 2 commits into from
Oct 2, 2024
Merged

fix: ABI generation #146

merged 2 commits into from
Oct 2, 2024

Conversation

mitinarseny
Copy link
Collaborator

@mitinarseny mitinarseny commented Oct 2, 2024

This PR fixes an issue when ABI generation fails due to absence of #[derive(JsonSchema)]

cargo near build
# ...
• Generating ABI
 │ error[E0277]: the trait bound `PermissionedAccounts: JsonSchema` is not satisfied
 │     |
 │ 18  | #[access_control(role_type(Role))]| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 │     | || the trait `JsonSchema` is not implemented for `PermissionedAccounts`| required by a bound introduced by this call
 │     |
 │     = help: the following other types implement trait `JsonSchema`:
 │               &'a T
 │               &'a mut T
                ()
 │               (T0, T1)
 │               (T0, T1, T2)
 │               (T0, T1, T2, T3)
 │               (T0, T1, T2, T3, T4)
 │               (T0, T1, T2, T3, T4, T5)
 │             and 185 others
 │ note: required by a bound in `SchemaGenerator::subschema_for`
 │    --> /Users/mitinarseny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/schemars-0.8.21/src/gen.rs:221:38
 │     |
 │ 221 |     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
 │     |                                      ^^^^^^^^^^ required by this bound in `SchemaGenerator::subschema_for`
 │     = note: this error originates in the attribute macro `access_control` (in Nightly builds, run with -Z macro-backtrace for more info)
 │ 
 │ For more information about this error, try `rustc --explain E0277`.
 │ error: could not compile `defuse-contract` (lib) due to 1 previous error

Basically, in order to properly handle ABI generation via cargo near, you're literally forced to use #[near(serializers = [json])], as its expanded version depends on near-sdk/abi feature, so you can think of expanded version as:

#[derive(::near_sdk::serde::Deserialize, ::near_sdk::serde::Serialize)]
#[serde(crate = "::near_sdk::serde")]
#[cfg_attr(all(feature = "near_sdk/abi", not(target_arch = "wasm32")), derive(::near_sdk::schemars::JsonSchema))]
#[cfg_attr(all(feature = "near_sdk/abi", not(target_arch = "wasm32")), schemars(crate = "::near_sdk::schemars"))]

@mitinarseny mitinarseny requested a review from karim-en October 2, 2024 08:16
@mitinarseny mitinarseny marked this pull request as ready for review October 2, 2024 08:16
@mitinarseny mitinarseny requested a review from aleksuss October 2, 2024 08:19
@aleksuss
Copy link
Collaborator

aleksuss commented Oct 2, 2024

Maybe other types should be reworked as well?

@mitinarseny
Copy link
Collaborator Author

Maybe other types should be reworked as well?

As I checked, these are the only types exposed in ABI. All other custom types in this crate are needed for events, which are not included in ABI

Copy link
Collaborator

@aleksuss aleksuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mitinarseny mitinarseny merged commit e6e4b07 into master Oct 2, 2024
2 checks passed
@mitinarseny mitinarseny deleted the fix/abi branch October 2, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants