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

Parse logged types #582

Merged
merged 47 commits into from
Oct 3, 2022
Merged

Parse logged types #582

merged 47 commits into from
Oct 3, 2022

Conversation

MujkicA
Copy link
Contributor

@MujkicA MujkicA commented Sep 20, 2022

Closes #562

This PR adds _logs_with_type::<T>() to the existing contract instance methods. It requires receipts and returns a Vec<T> containing all the logged values of type T.
It also adds _print_logs() for outputting all the logged values to stdout.

The feature flag --generate-logged-types is added to the build test script so that we can test, but needs to be removed as soon as forc starts generating logged types without it.

As mentioned in the issue, ABI support for logging generic types is limited. However, it is likely that once added, it will work on the SDK side with little to no changes.
Another future upgrade we can expect is to further filter the logs based on the name of the logged variables once they are included in the ABI.

I will add the follow-up issues once we agree on the changes.

@MujkicA MujkicA added the enhancement New feature or request label Sep 20, 2022
@MujkicA MujkicA self-assigned this Sep 20, 2022
@MujkicA MujkicA marked this pull request as draft September 20, 2022 12:23
@MujkicA MujkicA requested a review from a team September 20, 2022 15:28
@MujkicA MujkicA marked this pull request as ready for review September 20, 2022 15:42
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels/tests/harness.rs Outdated Show resolved Hide resolved
packages/fuels/tests/harness.rs Show resolved Hide resolved
hal3e
hal3e previously approved these changes Sep 21, 2022
Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

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

Good work!

Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
MujkicA and others added 3 commits September 27, 2022 17:06
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Co-authored-by: Mohammad Fawaz <mohammadfawaz89@gmail.com>
Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

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

Great work!

docs/src/calling-contracts/logs.md Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
docs/src/calling-contracts/logs.md Outdated Show resolved Hide resolved
docs/src/calling-contracts/logs.md Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
MujkicA and others added 8 commits September 28, 2022 14:58
Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
Co-authored-by: Halil Beglerović <hal3e.git@gmail.com>
docs/src/calling-contracts/logs.md Outdated Show resolved Hide resolved
packages/fuels-core/src/code_gen/abigen.rs Outdated Show resolved Hide resolved
MujkicA and others added 3 commits October 3, 2022 14:44
segfault-magnet
segfault-magnet previously approved these changes Oct 3, 2022
Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

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

This looks amazing. I have one issue with the semantics, though. Whenever I call something with print in it, I expect it to automatically print something to stdout/stderr.

print_logs() doesn't print anything; it returns a Vec<String>. The name/behavior is misleading.

I propose we rename print_logs() to fetch_logs()/get_logs()/resolve_logs() and keep the same behavior (return a Vec<String> and let the user decide what to do with it.)


Ok(())
}

Copy link
Member

Choose a reason for hiding this comment

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

Excellent tests!

Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

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

Looking good :shipit:

@MujkicA MujkicA merged commit 204b138 into master Oct 3, 2022
@MujkicA MujkicA deleted the ahmedm/logged-types branch October 3, 2022 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse logged types
6 participants