Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e committed Dec 16, 2024
2 parents 4675e3f + 6e1b2c9 commit 542d272
Show file tree
Hide file tree
Showing 30 changed files with 2,244 additions and 419 deletions.
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

0 comments on commit 542d272

Please sign in to comment.