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

Increase Safety when introspecting transaction inputs #6405

Merged
merged 17 commits into from
Aug 16, 2024
Merged

Conversation

bitzoic
Copy link
Member

@bitzoic bitzoic commented Aug 8, 2024

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:
let my_predicate_address: Address = predicate_address();

After

let my_predicate_address: Address = predicate_address().unwrap();
  • input_type() now returns an Option<Input>.
    Before:
let my_input_type: Input = input_type(0);

After:

let my_input_type: Input = input_type(0).unwrap();
  • input_predicate_data() now returns an Option<T>.
    Before:
let my_data: u64 = input_predicate_data::<u64>(0);

After:

let my_data: u64 = input_predicate_data::<u64>(0).unwrap();
  • input_predicate() now returns an Option<Bytes>.
    Before:
let my_input_predicate: Bytes = input_predicate(0);

After:

let my_input_predicate: Bytes = input_predicate(0).unwrap();
  • input_message_sender() now returns an Option<Address>.
    Before:
let my_message_sender: Address = input_message_sender(0);

After:

let my_message_sender: Address = input_message_sender(0).unwrap();
  • input_message_recipient() now returns an Option<Address>.
    Before:
let my_message_recipient: Address = input_message_recipient(0);

After:

let my_message_recipient: Address = input_message_recipient(0).unwrap();
  • input_message_data_length() now returns an Option<u64>.
    Before:
let my_message_data_length: u64 = input_message_data_length(0);

After:

let my_message_data_length: u64 = input_message_data_length(0).unwrap();
  • input_message_data() now returns an Option<Bytes>.
    Before:
let my_input_message_data: Bytes = input_message_data(0);

After:

let my_input_message_data: Bytes = input_message_data(0).unwrap();
  • input_pointer() now returns an Option<raw_ptr> and is private
    Before:
let my_input_pointer: u64 = input_pointer(0);

After:

let my_input_pointer: raw_ptr = input_pointer(0).unwrap();
  • input_message_nonce() now returns an Option<b256>
    Before:
let my_message_nonce: b256 = input_message_nonce(0);

After:

let my_message_nonce: b256 = input_message_nonce(0).unwrap();

Closes #6216

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@bitzoic bitzoic added lib: std Standard library breaking May cause existing user code to break. Requires a minor or major release. labels Aug 8, 2024
@bitzoic bitzoic self-assigned this Aug 8, 2024
@bitzoic bitzoic linked an issue Aug 8, 2024 that may be closed by this pull request
@bitzoic bitzoic marked this pull request as ready for review August 15, 2024 12:00
@bitzoic bitzoic requested review from a team as code owners August 15, 2024 12:00
K1-R1
K1-R1 previously approved these changes Aug 15, 2024
Copy link
Member

@K1-R1 K1-R1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; just an optional nit

@K1-R1 K1-R1 requested a review from a team August 15, 2024 20:46
@bitzoic bitzoic requested a review from K1-R1 August 16, 2024 08:00
@bitzoic bitzoic enabled auto-merge (squash) August 16, 2024 09:36
@bitzoic bitzoic merged commit 3700e3f into master Aug 16, 2024
35 checks passed
@bitzoic bitzoic deleted the bitzoic-6216 branch August 16, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking May cause existing user code to break. Requires a minor or major release. lib: std Standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Increase Safety When Introspecting Transactions
5 participants