Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase Safety when introspecting transaction inputs (#6405)
## Description When using the `inputs.sw` library of the std-lib, if a bad input was given to the functions or a transaction did not exist, the functions would revert. Instead, they now return options so error may be caught. ## Fixes - `input_pointer` now returns a pointer over a `u64` and is private. ## Breaking There are a number of breaking changes in function return types. - `predicate_address()` now returns an `Option<Address>`. Before: ```sway let my_predicate_address: Address = predicate_address(); ``` After ```sway let my_predicate_address: Address = predicate_address().unwrap(); ``` - `input_type()` now returns an `Option<Input>`. Before: ```sway let my_input_type: Input = input_type(0); ``` After: ```sway let my_input_type: Input = input_type(0).unwrap(); ``` - `input_predicate_data()` now returns an `Option<T>`. Before: ```sway let my_data: u64 = input_predicate_data::<u64>(0); ``` After: ```sway let my_data: u64 = input_predicate_data::<u64>(0).unwrap(); ``` - `input_predicate()` now returns an `Option<Bytes>`. Before: ```sway let my_input_predicate: Bytes = input_predicate(0); ``` After: ```sway let my_input_predicate: Bytes = input_predicate(0).unwrap(); ``` - `input_message_sender()` now returns an `Option<Address>`. Before: ```sway let my_message_sender: Address = input_message_sender(0); ``` After: ```sway let my_message_sender: Address = input_message_sender(0).unwrap(); ``` - `input_message_recipient()` now returns an `Option<Address>`. Before: ```sway let my_message_recipient: Address = input_message_recipient(0); ``` After: ```sway let my_message_recipient: Address = input_message_recipient(0).unwrap(); ``` - `input_message_data_length()` now returns an `Option<u64>`. Before: ```sway let my_message_data_length: u64 = input_message_data_length(0); ``` After: ```sway let my_message_data_length: u64 = input_message_data_length(0).unwrap(); ``` - `input_message_data()` now returns an `Option<Bytes>`. Before: ```sway let my_input_message_data: Bytes = input_message_data(0); ``` After: ```sway let my_input_message_data: Bytes = input_message_data(0).unwrap(); ``` - `input_pointer()` now returns an `Option<raw_ptr>` and is private Before: ```sway let my_input_pointer: u64 = input_pointer(0); ``` After: ```sway let my_input_pointer: raw_ptr = input_pointer(0).unwrap(); ``` - `input_message_nonce()` now returns an `Option<b256>` Before: ```sway let my_message_nonce: b256 = input_message_nonce(0); ``` After: ```sway let my_message_nonce: b256 = input_message_nonce(0).unwrap(); ``` Closes #6216 ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: K1-R1 <77465250+K1-R1@users.noreply.github.com>
- Loading branch information