forked from FuelLabs/fuels-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes FuelLabs#562 Adds 2 methods for parsing and fetching receipt logs. logs_with_type::<T>() returns all logs of type T. fetch_logs() returns a vector containing all logs as Strings. Co-authored-by: Halil Beglerović <[email protected]> Co-authored-by: Mohammad Fawaz <[email protected]> Co-authored-by: Ahmed Sagdati <[email protected]>
- Loading branch information
1 parent
450e9ae
commit 204b138
Showing
16 changed files
with
485 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Logs | ||
|
||
Whenever you log a value within a contract method, the resulting log entry is added to the log receipt and the variable type is recorded in the contract's ABI. The SDK lets you parse those values into Rust types. | ||
|
||
Consider the following contract method: | ||
|
||
```rust,ignore | ||
{{#include ../../../packages/fuels/tests/test_projects/logged_types/src/main.sw:produce_logs}} | ||
``` | ||
|
||
You can access the logged values in Rust by calling `logs_with_type::<T>` from a contract instance, where `T` is the type of the logged variables you want to retrieve. The result will be a `Vec<T>`: | ||
|
||
```rust,ignore | ||
{{#include ../../../packages/fuels/tests/harness.rs:produce_logs}} | ||
``` | ||
|
||
You can also get a vector of all the logged values as strings using `fetch_logs()`: | ||
|
||
```rust, ignore | ||
{{#include ../../../packages/fuels/tests/harness.rs:fetch_logs}} | ||
``` | ||
|
||
Due to possible performance hits, it is not recommended to use `fetch_logs()` outside of a debugging scenario. | ||
|
||
> **Note:** To bind logged values in the SDK, you need to build your contract by supplying a feature flag: `forc build --generate-logged-types`. This is temporary and the flag won't be needed in the future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.