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

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6b83658
script decoding works for gas fwd and wo gas fwd for single calls
segfault-magnet Oct 21, 2024
160d790
can now debug script data for single and multi contract calls
segfault-magnet Oct 23, 2024
02cab44
wip
segfault-magnet Oct 24, 2024
99a47e7
decoding configurables from premade scripts works for loader scripts
segfault-magnet Oct 28, 2024
a240068
cover more edge cases, wip
segfault-magnet Oct 29, 2024
a158e67
tests for missing data
segfault-magnet Oct 29, 2024
1a25250
test for invalid utf-8
segfault-magnet Oct 29, 2024
7f6c3fc
test for missing blob id when decoding loader script
segfault-magnet Oct 30, 2024
81bb930
more tests for edge cases
segfault-magnet Oct 30, 2024
c3b157b
reuse contract call data in call utils to dry up code
segfault-magnet Oct 30, 2024
7e6e1b8
remove unwraps from runtime decoder
segfault-magnet Oct 30, 2024
65b1174
refactoring
segfault-magnet Oct 31, 2024
7c11b08
wasm test
segfault-magnet Nov 1, 2024
712603d
separate into modules
segfault-magnet Nov 1, 2024
49774b5
rename
segfault-magnet Nov 1, 2024
6a3e950
wip
segfault-magnet Nov 1, 2024
55e3c91
decode fixed
segfault-magnet Nov 11, 2024
7fd5792
Merge remote-tracking branch 'origin/master' into feat/script_analyzing
segfault-magnet Nov 11, 2024
f7d1a7b
rename into abi formatter
segfault-magnet Nov 11, 2024
33cc27d
no need for extra struct
segfault-magnet Nov 11, 2024
80a35cf
wip
segfault-magnet Nov 11, 2024
f61533e
Merge remote-tracking branch 'origin/master' into feat/script_analyzing
segfault-magnet Nov 12, 2024
0f13383
tests passing
segfault-magnet Nov 12, 2024
43110e5
rename
segfault-magnet Nov 13, 2024
57550ef
remove redundant pub crate
segfault-magnet Nov 13, 2024
d5a1c66
avoid breaking changes
segfault-magnet Nov 13, 2024
07bb9c3
cleanup data section offset calculation
segfault-magnet Nov 13, 2024
b6c1e75
move to helper functions
segfault-magnet Nov 13, 2024
0d3dc46
rename
segfault-magnet Nov 13, 2024
83ef45d
cleanup
segfault-magnet Nov 13, 2024
3ed26a7
move logic into associated function
segfault-magnet Nov 13, 2024
d93460e
convert to named struct
segfault-magnet Nov 13, 2024
c1991f8
wasm friendly imports
segfault-magnet Nov 13, 2024
033036d
fix compile
segfault-magnet Nov 14, 2024
ae8e1fa
fix loader no data section
segfault-magnet Nov 14, 2024
87cd1b0
refactoring
segfault-magnet Nov 14, 2024
838b6dd
add docs
segfault-magnet Nov 14, 2024
a78d89a
fix forc warnings
segfault-magnet Nov 14, 2024
38cb60b
fix import
segfault-magnet Nov 14, 2024
f6e4c27
fix cargo clippy
segfault-magnet Nov 14, 2024
471b130
fix more clippy
segfault-magnet Nov 14, 2024
5f6c766
fix typos
segfault-magnet Nov 19, 2024
f383b79
clippy
segfault-magnet Nov 19, 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.7.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