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

feat: script transaction human readable formatting #1542

Merged
merged 49 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
397e703
read cargo toml instead of running cargo metadata
segfault-magnet Dec 5, 2024
be68fc5
script decoding works for gas fwd and wo gas fwd for single calls
segfault-magnet Oct 21, 2024
01723fc
can now debug script data for single and multi contract calls
segfault-magnet Oct 23, 2024
963dcff
wip
segfault-magnet Oct 24, 2024
7f6d611
decoding configurables from premade scripts works for loader scripts
segfault-magnet Oct 28, 2024
21cabe9
cover more edge cases, wip
segfault-magnet Oct 29, 2024
196e3a2
tests for missing data
segfault-magnet Oct 29, 2024
2b542ad
test for invalid utf-8
segfault-magnet Oct 29, 2024
0d3dee9
test for missing blob id when decoding loader script
segfault-magnet Oct 30, 2024
d07362f
more tests for edge cases
segfault-magnet Oct 30, 2024
c85e606
reuse contract call data in call utils to dry up code
segfault-magnet Oct 30, 2024
00fa464
remove unwraps from runtime decoder
segfault-magnet Oct 30, 2024
77aa755
refactoring
segfault-magnet Oct 31, 2024
d2db4ca
wasm test
segfault-magnet Nov 1, 2024
81aae8f
separate into modules
segfault-magnet Nov 1, 2024
17a3e6d
rename
segfault-magnet Nov 1, 2024
fd68428
wip
segfault-magnet Nov 1, 2024
71f00b0
decode fixed
segfault-magnet Nov 11, 2024
e302285
rename into abi formatter
segfault-magnet Nov 11, 2024
249f3e0
no need for extra struct
segfault-magnet Nov 11, 2024
6fc6f22
wip
segfault-magnet Nov 11, 2024
866e684
tests passing
segfault-magnet Nov 12, 2024
f1a766f
rename
segfault-magnet Nov 13, 2024
7428fe0
remove redundant pub crate
segfault-magnet Nov 13, 2024
cf9559d
avoid breaking changes
segfault-magnet Nov 13, 2024
0ffcb7c
cleanup data section offset calculation
segfault-magnet Nov 13, 2024
e60815f
move to helper functions
segfault-magnet Nov 13, 2024
d2d0df9
rename
segfault-magnet Nov 13, 2024
77ccc55
cleanup
segfault-magnet Nov 13, 2024
4d1ccc2
move logic into associated function
segfault-magnet Nov 13, 2024
100923a
convert to named struct
segfault-magnet Nov 13, 2024
c9a8a65
wasm friendly imports
segfault-magnet Nov 13, 2024
c3c574d
fix compile
segfault-magnet Nov 14, 2024
5955316
fix loader no data section
segfault-magnet Nov 14, 2024
06a780f
refactoring
segfault-magnet Nov 14, 2024
b90f7cc
add docs
segfault-magnet Nov 14, 2024
32484ef
fix forc warnings
segfault-magnet Nov 14, 2024
54a9b51
fix import
segfault-magnet Nov 14, 2024
4de405d
fix cargo clippy
segfault-magnet Nov 14, 2024
943352e
fix more clippy
segfault-magnet Nov 14, 2024
e8efb24
fix typos
segfault-magnet Nov 19, 2024
77caf1e
clippy
segfault-magnet Nov 19, 2024
c425d96
fix test
segfault-magnet Nov 27, 2024
af4e8d6
Merge branch 'master' into feat/script_analyzing
segfault-magnet Dec 5, 2024
556c09a
Merge branch 'master' into feat/script_analyzing
hal3e Dec 8, 2024
5f2ac71
fix test
segfault-magnet Dec 9, 2024
98581f5
Merge branch 'master' into feat/script_analyzing
segfault-magnet Dec 11, 2024
5cda5ff
Merge branch 'master' into feat/script_analyzing
segfault-magnet Dec 11, 2024
d1a0b95
Merge branch 'master' into feat/script_analyzing
segfault-magnet Dec 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bytes = { version = "1.5.0", default-features = false }
chrono = "0.4.31"
cynic = { version = "2.2", default-features = false }
elliptic-curve = { version = "0.13.8", default-features = false }
test-case = { version = "3.3", default-features = false }
eth-keystore = "0.5.0"
flate2 = { version = "1.0", default-features = false }
fuel-abi-types = "0.8.0"
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- [Transfer all assets](./cookbook/transfer-all-assets.md)
- [Debugging](./debugging/index.md)
- [The Function selector](./debugging/function-selector.md)
- [Decoding script transactions](./debugging/decoding-script-transactions.md)
- [Glossary](./glossary.md)
- [Contributing](./contributing/CONTRIBUTING.md)
- [Integration tests structure](./contributing/tests-structure.md)
Expand Down
24 changes: 24 additions & 0 deletions docs/src/debugging/decoding-script-transactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Decoding script transactions

The SDK offers some tools that can help you make fuel script transactions more
human readable. You can determine whether the script transaction is:

* calling a contract method(s),
* is a loader script and you can see the blob id
* is neither of the above

In the case of contract call(s), if you have the ABI file, you can also decode
the arguments to the function by making use of the `AbiFormatter`:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:decoding_script_transactions}}
```

prints:

```text
The script called: initialize_counter(42)
```

The `AbiFormatter` can also decode configurables, refer to the rust docs for
more information.
17 changes: 11 additions & 6 deletions e2e/sway/scripts/script_struct/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
script;

configurable {
MY_STRUCT: MyStruct = MyStruct {
number: 10,
boolean: true,
},
A_NUMBER: u64 = 11,
}

struct MyStruct {
number: u64,
boolean: bool,
}

fn main(my_struct: MyStruct) -> u64 {
if my_struct.boolean {
my_struct.number
} else {
0
}
fn main(arg: MyStruct) -> u64 {
let _calc = MY_STRUCT.number + A_NUMBER;
if arg.boolean { arg.number } else { 0 }
}
8 changes: 8 additions & 0 deletions e2e/sway/types/contracts/nested_structs/src/main.sw
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ struct MemoryAddress {

abi MyContract {
fn get_struct() -> AllStruct;
#[payable]
fn check_struct_integrity(arg: AllStruct) -> bool;
#[payable]
fn i_am_called_differently(_arg1: AllStruct, _arg2: MemoryAddress);
fn nested_struct_with_reserved_keyword_substring(call_data: CallData) -> CallData;
}

Expand All @@ -38,10 +41,15 @@ impl MyContract for Contract {
},
}
}

#[payable]
fn check_struct_integrity(arg: AllStruct) -> bool {
arg.some_struct.field == 12345u32 && arg.some_struct.field_2 == true
}

#[payable]
fn i_am_called_differently(_arg1: AllStruct, _arg2: MemoryAddress) {}

fn nested_struct_with_reserved_keyword_substring(call_data: CallData) -> CallData {
call_data
}
Expand Down
Loading
Loading