├── .editorconfig ├── .env.example ├── .github ├── CODEOWNERS ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── ci.yml │ ├── docs.yml │ ├── gh-pages.yml │ ├── repo-plan.toml │ └── scripts │ └── verify_tag.sh ├── .gitignore ├── .markdownlint.yaml ├── .markdownlintignore ├── Cargo.toml ├── LICENSE ├── README.md ├── SECURITY.md ├── _typos.toml ├── ci_checks.sh ├── docs ├── .spellcheck.yml ├── book.toml ├── spell-check-custom-words.txt ├── src │ ├── SUMMARY.md │ ├── abigen │ │ ├── index.md │ │ ├── the-abigen-macro.md │ │ └── the-json-abi-file.md │ ├── accounts.md │ ├── calling-contracts │ │ ├── call-params.md │ │ ├── call-response.md │ │ ├── calls-with-different-wallets.md │ │ ├── cost-estimation.md │ │ ├── custom-asset-transfer.md │ │ ├── custom-inputs-outputs.md │ │ ├── index.md │ │ ├── logs.md │ │ ├── low-level-calls.md │ │ ├── multicalls.md │ │ ├── other-contracts.md │ │ ├── simulation.md │ │ ├── tx-dependency-estimation.md │ │ ├── tx-policies.md │ │ └── variable-outputs.md │ ├── cli │ │ ├── fuels-abi-cli.md │ │ └── index.md │ ├── codec │ │ ├── decoding.md │ │ ├── encoding.md │ │ └── index.md │ ├── connecting │ │ ├── external-node.md │ │ ├── index.md │ │ ├── querying.md │ │ ├── retrying.md │ │ ├── rocksdb.md │ │ └── short-lived.md │ ├── contributing │ │ ├── CONTRIBUTING.md │ │ └── tests-structure.md │ ├── cookbook │ │ ├── custom-chain.md │ │ ├── deposit-and-withdraw.md │ │ ├── index.md │ │ └── transfer-all-assets.md │ ├── custom-transactions │ │ ├── custom-calls.md │ │ ├── index.md │ │ └── transaction-builders.md │ ├── debugging │ │ ├── decoding-script-transactions.md │ │ ├── function-selector.md │ │ └── index.md │ ├── deploying │ │ ├── configurable-constants.md │ │ ├── index.md │ │ ├── interacting-with-contracts.md │ │ ├── large_contracts.md │ │ ├── storage-slots.md │ │ └── the-fuelvm-binary-file.md │ ├── getting-started.md │ ├── glossary.md │ ├── index.md │ ├── predicates │ │ ├── index.md │ │ └── send-spend-predicate.md │ ├── preuploading-code.md │ ├── reference.md │ ├── running-scripts.md │ ├── testing │ │ ├── basics.md │ │ ├── chains.md │ │ ├── index.md │ │ └── the-setup-program-test-macro.md │ ├── types │ │ ├── B512.md │ │ ├── address.md │ │ ├── asset-id.md │ │ ├── bits256.md │ │ ├── bytes.md │ │ ├── bytes32.md │ │ ├── contract-id.md │ │ ├── conversion.md │ │ ├── custom_types.md │ │ ├── evm_address.md │ │ ├── index.md │ │ ├── string.md │ │ └── vectors.md │ └── wallets │ │ ├── access.md │ │ ├── checking-balances-and-coins.md │ │ ├── fake_signer.md │ │ ├── index.md │ │ ├── keystore.md │ │ ├── kms.md │ │ ├── private_key_signer.md │ │ ├── signing.md │ │ └── test-wallets.md └── theme │ └── highlight.js ├── e2e ├── Cargo.toml ├── Forc.toml ├── assets │ └── precompiled_sway │ │ └── legacy_format_simple_contract.bin ├── build.rs ├── src │ ├── aws_kms.rs │ ├── e2e_helpers.rs │ └── lib.rs ├── sway │ ├── abi │ │ ├── simple_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── wasm_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── wasm_predicate │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ ├── bindings │ │ ├── sharing_types │ │ │ ├── contract_a │ │ │ │ ├── Forc.toml │ │ │ │ └── src │ │ │ │ │ └── main.sw │ │ │ ├── contract_b │ │ │ │ ├── Forc.toml │ │ │ │ └── src │ │ │ │ │ └── main.sw │ │ │ └── shared_lib │ │ │ │ ├── Forc.toml │ │ │ │ └── src │ │ │ │ └── lib.sw │ │ ├── simple_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── type_paths │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ ├── another_lib.sw │ │ │ ├── contract_a_types.sw │ │ │ └── main.sw │ ├── contracts │ │ ├── asserts │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── auth_testing_abi │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── auth_testing_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── block_timestamp │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── configurables │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── contract_test │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── huge_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── large_return_data │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── lib_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── lib_contract_abi │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── lib_contract_caller │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── library_test │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── liquidity_pool │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── low_level_caller │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── msg_methods │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── multiple_read_calls │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── needs_custom_decoder │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── payable_annotation │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── proxy │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── revert_transaction_error │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── storage │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── token_ops │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── transaction_block_height │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── tx_input_output │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── var_outputs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ ├── logs │ │ ├── contract_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── contract_logs_abi │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── contract_revert_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── contract_with_contract_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_heap_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_revert_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── script_with_contract_logs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ ├── predicates │ │ ├── basic_predicate │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_blobs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_configurables │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_tx_input_output │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_witnesses │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── signatures │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── swap │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ ├── scripts │ │ ├── arguments │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── basic_script │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── empty │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── require_from_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── reverting │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_array │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_asserts │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_blobs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_configurables │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_enum │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_needs_custom_decoder │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_proxy │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_struct │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── script_tx_input_output │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── transfer_script │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ └── types │ │ ├── contracts │ │ ├── b256 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── b512 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── bytes │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── call_empty_return │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── complex_types_contract │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── contract_output_test │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── empty_arguments │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── enum_as_input │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── enum_encoding │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── enum_inside_struct │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── evm_address │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── generics │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── heap_type_in_enums │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── heap_types │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── identity │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── native_types │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── nested_structs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── options │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── raw_slice │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── results │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── std_lib_string │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── str_in_array │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── string_slice │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── tuples │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── two_structs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── type_inside_enum │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── u128 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── u256 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── vector_output │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── vectors │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ ├── data_structures.sw │ │ │ ├── eq_impls.sw │ │ │ ├── main.sw │ │ │ └── utils.sw │ │ ├── predicates │ │ ├── address │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── enums │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_b256 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_bytes │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_bytes_hash │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_generics │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_raw_slice │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_std_lib_string │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_string_slice │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_tuples │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_u128 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_u256 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_vector │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── predicate_vectors │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ ├── structs │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ │ └── main.sw │ │ └── u64 │ │ │ ├── Forc.toml │ │ │ └── src │ │ │ └── main.sw │ │ └── scripts │ │ ├── options_results │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_b256 │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_bytes │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_generics │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_heap_types │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_raw_slice │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_std_lib_string │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_string_slice │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_tuples │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_u128 │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ ├── script_u256 │ │ ├── Forc.toml │ │ └── src │ │ │ └── main.sw │ │ └── script_vectors │ │ ├── Forc.toml │ │ └── src │ │ ├── data_structures.sw │ │ ├── eq_impls.sw │ │ ├── main.sw │ │ └── utils.sw └── tests │ ├── aws.rs │ ├── binary_format.rs │ ├── bindings.rs │ ├── configurables.rs │ ├── contracts.rs │ ├── debug_utils.rs │ ├── from_token.rs │ ├── imports.rs │ ├── logs.rs │ ├── predicates.rs │ ├── providers.rs │ ├── scripts.rs │ ├── storage.rs │ ├── types_contracts.rs │ ├── types_predicates.rs │ ├── types_scripts.rs │ └── wallets.rs ├── examples ├── codec │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── contracts │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── cookbook │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── debugging │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── macros │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── predicates │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── providers │ ├── Cargo.toml │ └── src │ │ └── lib.rs ├── rust_bindings │ ├── Cargo.toml │ └── src │ │ ├── abi.json │ │ ├── lib.rs │ │ └── rust_bindings_formatted.rs ├── types │ ├── Cargo.toml │ └── src │ │ └── lib.rs └── wallets │ ├── Cargo.toml │ └── src │ └── lib.rs ├── packages ├── fuels-accounts │ ├── Cargo.toml │ └── src │ │ ├── account.rs │ │ ├── accounts_utils.rs │ │ ├── coin_cache.rs │ │ ├── keystore.rs │ │ ├── lib.rs │ │ ├── predicate.rs │ │ ├── provider.rs │ │ ├── provider │ │ ├── cache.rs │ │ ├── retry_util.rs │ │ ├── retryable_client.rs │ │ ├── supported_fuel_core_version.rs │ │ └── supported_versions.rs │ │ ├── schema │ │ └── schema.sdl │ │ ├── signers.rs │ │ ├── signers │ │ ├── fake.rs │ │ ├── kms.rs │ │ ├── kms │ │ │ ├── aws.rs │ │ │ └── google.rs │ │ └── private_key.rs │ │ └── wallet.rs ├── fuels-code-gen │ ├── Cargo.toml │ └── src │ │ ├── error.rs │ │ ├── lib.rs │ │ ├── program_bindings.rs │ │ ├── program_bindings │ │ ├── abigen.rs │ │ ├── abigen │ │ │ ├── abigen_target.rs │ │ │ ├── bindings.rs │ │ │ ├── bindings │ │ │ │ ├── contract.rs │ │ │ │ ├── function_generator.rs │ │ │ │ ├── predicate.rs │ │ │ │ ├── script.rs │ │ │ │ └── utils.rs │ │ │ ├── configurables.rs │ │ │ └── logs.rs │ │ ├── custom_types.rs │ │ ├── custom_types │ │ │ ├── enums.rs │ │ │ ├── structs.rs │ │ │ └── utils.rs │ │ ├── generated_code.rs │ │ ├── resolved_type.rs │ │ └── utils.rs │ │ └── utils.rs ├── fuels-core │ ├── Cargo.toml │ └── src │ │ ├── codec.rs │ │ ├── codec │ │ ├── abi_decoder.rs │ │ ├── abi_decoder │ │ │ ├── bounded_decoder.rs │ │ │ └── decode_as_debug_str.rs │ │ ├── abi_encoder.rs │ │ ├── abi_encoder │ │ │ └── bounded_encoder.rs │ │ ├── abi_formatter.rs │ │ ├── function_selector.rs │ │ ├── logs.rs │ │ └── utils.rs │ │ ├── lib.rs │ │ ├── traits.rs │ │ ├── traits │ │ ├── parameterize.rs │ │ ├── signer.rs │ │ └── tokenizable.rs │ │ ├── types.rs │ │ ├── types │ │ ├── checksum_address.rs │ │ ├── core.rs │ │ ├── core │ │ │ ├── bits.rs │ │ │ ├── bytes.rs │ │ │ ├── identity.rs │ │ │ ├── raw_slice.rs │ │ │ ├── sized_ascii_string.rs │ │ │ └── u256.rs │ │ ├── dry_runner.rs │ │ ├── errors.rs │ │ ├── param_types.rs │ │ ├── param_types │ │ │ ├── from_type_application.rs │ │ │ └── param_type.rs │ │ ├── token.rs │ │ ├── transaction_builders.rs │ │ ├── transaction_builders │ │ │ ├── blob.rs │ │ │ └── script_tx_estimator.rs │ │ ├── tx_response.rs │ │ ├── tx_status.rs │ │ ├── wrappers.rs │ │ └── wrappers │ │ │ ├── block.rs │ │ │ ├── chain_info.rs │ │ │ ├── coin.rs │ │ │ ├── coin_type.rs │ │ │ ├── coin_type_id.rs │ │ │ ├── input.rs │ │ │ ├── message.rs │ │ │ ├── message_proof.rs │ │ │ ├── node_info.rs │ │ │ ├── transaction.rs │ │ │ └── transaction_response.rs │ │ ├── utils.rs │ │ └── utils │ │ ├── constants.rs │ │ └── offsets.rs ├── fuels-macros │ ├── .gitignore │ ├── Cargo.toml │ ├── src │ │ ├── abigen.rs │ │ ├── abigen │ │ │ └── parsing.rs │ │ ├── derive.rs │ │ ├── derive │ │ │ ├── parameterize.rs │ │ │ ├── tokenizable.rs │ │ │ ├── try_from.rs │ │ │ └── utils.rs │ │ ├── lib.rs │ │ ├── parse_utils.rs │ │ ├── parse_utils │ │ │ ├── command.rs │ │ │ ├── unique_lit_strs.rs │ │ │ └── unique_name_values.rs │ │ ├── setup_program_test.rs │ │ └── setup_program_test │ │ │ ├── code_gen.rs │ │ │ ├── parsing.rs │ │ │ └── parsing │ │ │ ├── command_parser.rs │ │ │ ├── commands.rs │ │ │ ├── commands │ │ │ ├── abigen.rs │ │ │ ├── deploy_contract.rs │ │ │ ├── initialize_wallet.rs │ │ │ ├── load_script.rs │ │ │ └── set_options.rs │ │ │ └── validations.rs │ └── tests │ │ ├── macro_usage.rs │ │ └── ui │ │ ├── abigen │ │ ├── duplicate_attribute.rs │ │ ├── duplicate_attribute.stderr │ │ ├── invalid_abi_path.rs │ │ ├── invalid_abi_path.stderr │ │ ├── invalid_abi_value.rs │ │ ├── invalid_abi_value.stderr │ │ ├── invalid_name_value.rs │ │ ├── invalid_name_value.stderr │ │ ├── invalid_program_type.rs │ │ ├── invalid_program_type.stderr │ │ ├── malformed_abi.rs │ │ ├── malformed_abi.stderr │ │ ├── missing_abi_attribute.rs │ │ ├── missing_abi_attribute.stderr │ │ ├── missing_name_attr.rs │ │ ├── missing_name_attr.stderr │ │ ├── unrecognized_attribute.rs │ │ └── unrecognized_attribute.stderr │ │ ├── derive │ │ ├── parameterize │ │ │ ├── attribute_must_be_named_value.rs │ │ │ ├── attribute_must_be_named_value.stderr │ │ │ ├── only_generic_types_are_supported.rs │ │ │ ├── only_generic_types_are_supported.stderr │ │ │ ├── only_one_variant_element_supported.rs │ │ │ ├── only_one_variant_element_supported.stderr │ │ │ ├── struct_like_enum_variants_not_supported.rs │ │ │ ├── struct_like_enum_variants_not_supported.stderr │ │ │ ├── tuple_like_structs_not_supported.rs │ │ │ └── tuple_like_structs_not_supported.stderr │ │ └── tokenizable │ │ │ ├── attribute_must_be_named_value.stderr │ │ │ ├── only_generic_types_are_supported.rs │ │ │ ├── only_generic_types_are_supported.stderr │ │ │ ├── only_one_variant_element_supported.rs │ │ │ ├── only_one_variant_element_supported.stderr │ │ │ ├── struct_like_enum_variants_not_supported.rs │ │ │ ├── struct_like_enum_variants_not_supported.stderr │ │ │ ├── tuple_like_structs_not_supported.rs │ │ │ └── tuple_like_structs_not_supported.stderr │ │ └── setup_program_test │ │ ├── abigen_command_is_missing.rs │ │ ├── abigen_command_is_missing.stderr │ │ ├── duplicate_wallet_command.rs │ │ ├── duplicate_wallet_command.stderr │ │ ├── duplicate_wallet_names.rs │ │ ├── duplicate_wallet_names.stderr │ │ ├── invalid_path.rs │ │ ├── invalid_path.stderr │ │ ├── invalid_project_path.rs │ │ ├── invalid_project_path.stderr │ │ ├── unknown_command.rs │ │ ├── unknown_command.stderr │ │ ├── unknown_contract.rs │ │ ├── unknown_contract.stderr │ │ ├── unknown_options_key.rs │ │ ├── unknown_options_key.stderr │ │ ├── unknown_options_value.rs │ │ └── unknown_options_value.stderr ├── fuels-programs │ ├── Cargo.toml │ └── src │ │ ├── assembly.rs │ │ ├── assembly │ │ ├── contract_call.rs │ │ ├── cursor.rs │ │ └── script_and_predicate_loader.rs │ │ ├── calls.rs │ │ ├── calls │ │ ├── call_handler.rs │ │ ├── contract_call.rs │ │ ├── receipt_parser.rs │ │ ├── script_call.rs │ │ ├── traits.rs │ │ ├── traits │ │ │ ├── contract_dep_configurator.rs │ │ │ ├── response_parser.rs │ │ │ └── transaction_tuner.rs │ │ └── utils.rs │ │ ├── contract.rs │ │ ├── contract │ │ ├── loader.rs │ │ ├── regular.rs │ │ └── storage.rs │ │ ├── debug.rs │ │ ├── executable.rs │ │ ├── lib.rs │ │ ├── responses.rs │ │ ├── responses │ │ ├── call.rs │ │ └── submit.rs │ │ └── utils.rs ├── fuels-test-helpers │ ├── Cargo.toml │ └── src │ │ ├── accounts.rs │ │ ├── fuel_bin_service.rs │ │ ├── lib.rs │ │ ├── node_types.rs │ │ ├── service.rs │ │ ├── utils.rs │ │ └── wallets_config.rs └── fuels │ ├── Cargo.toml │ └── src │ └── lib.rs ├── rustfmt.toml ├── scripts ├── change-log │ ├── Cargo.toml │ └── src │ │ ├── adapters.rs │ │ ├── adapters │ │ └── octocrab.rs │ │ ├── domain.rs │ │ ├── domain │ │ ├── changelog.rs │ │ └── models.rs │ │ ├── lib.rs │ │ ├── main.rs │ │ ├── ports.rs │ │ └── ports │ │ └── github.rs ├── check-docs │ ├── Cargo.toml │ ├── src │ │ ├── lib.rs │ │ └── main.rs │ └── tests │ │ ├── harness.rs │ │ └── test_data │ │ ├── docs │ │ └── src │ │ │ ├── SUMMARY.md │ │ │ ├── test-not-there.md │ │ │ └── test.md │ │ ├── test_anchor_data.rs │ │ └── test_include_data.md ├── fuel-core-version │ ├── Cargo.toml │ └── src │ │ └── main.rs └── versions-replacer │ ├── Cargo.toml │ └── src │ ├── lib.rs │ ├── main.rs │ ├── metadata.rs │ └── replace.rs └── wasm-tests ├── .cargo └── config.toml ├── Cargo.toml └── src └── lib.rs /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.toml] 2 | indent_style = space 3 | indent_size = 2 4 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | GITHUB_TOKEN= 2 | GITHUB_REPOSITORY_OWNER= 3 | GITHUB_REPOSITORY_NAME= 4 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @FuelLabs/client 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Release notes 8 | 9 | 14 | 15 | In this release, we: 16 | 17 | - Did this and that 18 | 19 | # Summary 20 | 21 | 26 | 27 | # Breaking Changes 28 | 29 | 35 | 36 | # Checklist 37 | 38 | - [ ] All **changes** are **covered** by **tests** (or not applicable) 39 | - [ ] All **changes** are **documented** (or not applicable) 40 | - [ ] I **reviewed** the **entire PR** myself (preferably, on GH UI) 41 | - [ ] I **described** all **Breaking Changes** (or there's none) 42 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Docs 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | test: 13 | uses: FuelLabs/github-actions/.github/workflows/mdbook-docs.yml@master 14 | with: 15 | docs-src-path: "docs/src" 16 | pre-command: 'cargo run --package versions-replacer -- ./docs --manifest-path ./Cargo.toml --filename-regex "\.md$"' 17 | spellcheck-config-path: 'docs/.spellcheck.yml' 18 | -------------------------------------------------------------------------------- /.github/workflows/repo-plan.toml: -------------------------------------------------------------------------------- 1 | [current-repo] 2 | name = "fuels-rs" 3 | owner = "FuelLabs" 4 | 5 | [repo.fuels-rs.details] 6 | name = "fuels-rs" 7 | owner = "FuelLabs" 8 | 9 | [repo.fuel-core.details] 10 | name = "fuel-core" 11 | owner = "FuelLabs" 12 | 13 | [repo.fuels-rs] 14 | dependencies = ["fuel-core"] 15 | -------------------------------------------------------------------------------- /.github/workflows/scripts/verify_tag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | err() { 5 | echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2; 6 | } 7 | 8 | status() { 9 | WIDTH=12 10 | printf "\e[32m\e[1m%${WIDTH}s\e[0m %s\n" "$1" "$2" 11 | } 12 | 13 | REF=$1 14 | MANIFEST=$2 15 | 16 | if [ -z "$REF" ]; then 17 | err "Expected ref to be set" 18 | exit 1 19 | fi 20 | 21 | if [ -z "$MANIFEST" ]; then 22 | err "Expected manifest to be set" 23 | exit 1 24 | fi 25 | 26 | # strip preceding 'v' if it exists on tag 27 | REF=${REF/#v} 28 | TOML_VERSION=$(cat $MANIFEST | dasel -r toml -w plain 'workspace.package.version') 29 | 30 | if [ "$TOML_VERSION" != "$REF" ]; then 31 | err "Crate version $TOML_VERSION, doesn't match tag version $REF" 32 | exit 1 33 | else 34 | status "Crate version matches tag $TOML_VERSION" 35 | fi 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | target/ 4 | 5 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 6 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 7 | Cargo.lock 8 | 9 | # These are backup files generated by rustfmt 10 | **/*.rs.bk 11 | 12 | # Don't add the generated MDBook artifacts 13 | docs/book/ 14 | 15 | # Don't add Forc lock files 16 | **/Forc.lock 17 | 18 | # Don't add out/ files from test Sway projects. 19 | e2e/sway/**/out/ 20 | e2e/sway/**/.gitignore 21 | 22 | .env 23 | 24 | output_changelog.md 25 | -------------------------------------------------------------------------------- /.markdownlint.yaml: -------------------------------------------------------------------------------- 1 | "default": true # Default state for all rules 2 | "MD013": false # Disable rule for line length 3 | "MD033": false # Disable rule banning inline HTML -------------------------------------------------------------------------------- /.markdownlintignore: -------------------------------------------------------------------------------- 1 | README.md 2 | scripts/check-docs -------------------------------------------------------------------------------- /_typos.toml: -------------------------------------------------------------------------------- 1 | [files] 2 | extend-exclude = ["packages/fuels-accounts/src/schema/schema.sdl"] -------------------------------------------------------------------------------- /ci_checks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Requires installed: 4 | # The latest version of the `forc`,`forc-fmt` and `fuel-core`. 5 | # `cargo install fuel-core-bin --git https://github.com/FuelLabs/fuel-core --tag v0.18.1 --locked` 6 | # `cargo install forc --git https://github.com/FuelLabs/sway --tag v0.38.0 --locked` 7 | # `cargo install forc-fmt --git https://github.com/FuelLabs/sway --tag v0.38.0 --locked` 8 | # Note, if you need a custom branch, you can replace `--tag {RELEASE}` with the `--branch {BRANCH_NAME}`. 9 | 10 | cargo fmt --all -- --check && 11 | forc fmt --check && 12 | forc build --release --terse && 13 | cargo clippy --all-targets && 14 | forc build --release --terse && 15 | cargo clippy --all-targets --all-features && 16 | cargo test --all-targets --all-features && 17 | cargo test --all-targets --all-features --workspace && 18 | cargo test --all-targets --workspace && 19 | cargo run --bin check-docs && 20 | cargo doc |& grep -A 6 "warning: unresolved link to" 21 | -------------------------------------------------------------------------------- /docs/.spellcheck.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | - name: SPCheck 3 | aspell: 4 | lang: en 5 | dictionary: 6 | encoding: utf-8 7 | wordlists: 8 | - docs/spell-check-custom-words.txt 9 | pipeline: 10 | - pyspelling.filters.context: 11 | context_visible_first: true 12 | escapes: \\[\\`~] 13 | delimiters: 14 | # Ignore all code blocks 15 | - open: '(?s)^(?P *`{3,}\s*(\w+\s*,?\s*)+.*?)$' 16 | close: '^( *`{3,})$' 17 | - pyspelling.filters.markdown: 18 | markdown_extensions: 19 | - pymdownx.superfences: 20 | - pyspelling.filters.html: 21 | comments: false 22 | ignores: 23 | - code 24 | - pre 25 | sources: 26 | - 'docs/*.md' 27 | - 'docs/src/*.md' 28 | - 'docs/src/**/*.md' 29 | default_encoding: utf-8 30 | -------------------------------------------------------------------------------- /docs/book.toml: -------------------------------------------------------------------------------- 1 | [book] 2 | authors = ["Fuel Labs "] 3 | language = "en" 4 | multilingual = false 5 | src = "src" 6 | title = "The Fuel Rust SDK" 7 | 8 | [output.html] 9 | git-repository-url = "https://github.com/FuelLabs/fuels-rs" 10 | 11 | [rust] 12 | edition = "2021" 13 | -------------------------------------------------------------------------------- /docs/src/abigen/index.md: -------------------------------------------------------------------------------- 1 | # Generating bindings with abigen 2 | 3 | You might have noticed this snippet in the previous sections: 4 | 5 | ```rust,ignore 6 | {{#include ../../../examples/contracts/src/lib.rs:abigen_example}} 7 | ``` 8 | 9 | 10 | 11 | The SDK lets you transform ABI methods of a smart contract, specified as JSON objects (which you can get from [Forc](https://github.com/FuelLabs/sway/tree/master/forc)), into Rust structs and methods that are type-checked at compile time. 12 | In order to call your contracts, scripts or predicates, you first need to generate the Rust bindings for them. 13 | 14 | 15 | The following subsections contain more details about the `abigen!` syntax and the code generated from it. 16 | -------------------------------------------------------------------------------- /docs/src/abigen/the-json-abi-file.md: -------------------------------------------------------------------------------- 1 | # The JSON ABI file 2 | 3 | 4 | 5 | Whether you want to deploy or connect to a pre-existing smart contract, the JSON ABI file is extremely important: it's what tells the SDK about the [ABI methods](https://docs.fuel.network/guides/quickstart/building-a-smart-contract/#abi) in your smart contracts. 6 | 7 | 8 | For the same example Sway code as above: 9 | 10 | ```Rust 11 | contract; 12 | 13 | abi MyContract { 14 | fn test_function() -> bool; 15 | } 16 | 17 | impl MyContract for Contract { 18 | fn test_function() -> bool { 19 | true 20 | } 21 | } 22 | ``` 23 | 24 | The JSON ABI file looks like this: 25 | 26 | ```json 27 | $ cat out/release/my-test-abi.json 28 | [ 29 | { 30 | "type": "function", 31 | "inputs": [], 32 | "name": "test_function", 33 | "outputs": [ 34 | { 35 | "name": "", 36 | "type": "bool", 37 | "components": null 38 | } 39 | ] 40 | } 41 | ] 42 | ``` 43 | 44 | The Fuel Rust SDK will take this file as input and generate equivalent methods (and custom types if applicable) that you can call from your Rust code. 45 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/calls-with-different-wallets.md: -------------------------------------------------------------------------------- 1 | # Calls with different wallets 2 | 3 | 4 | 5 | You can use the `with_account()` method on an existing contract instance as a shorthand for creating a new instance connected to the provided wallet. This lets you make contracts calls with different wallets in a chain like fashion. 6 | 7 | 8 | ```rust,ignore 9 | {{#include ../../../examples/contracts/src/lib.rs:connect_wallet}} 10 | ``` 11 | 12 | > **Note:** connecting a different wallet to an existing instance ignores its set provider in favor of the provider used to deploy the contract. If you have two wallets connected to separate providers (each communicating with a separate fuel-core), the one assigned to the deploying wallet will also be used for contract calls. This behavior is only relevant if multiple providers (i.e. fuel-core instances) are present and can otherwise be ignored. 13 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/cost-estimation.md: -------------------------------------------------------------------------------- 1 | # Estimating contract call cost 2 | 3 | With the function `estimate_transaction_cost(tolerance: Option, block_horizon: Option)` provided by `CallHandler`, you can get a cost estimation for a specific call. The return type, `TransactionCost`, is a struct that contains relevant information for the estimation: 4 | 5 | ```rust,ignore 6 | {{#include ../../../packages/fuels-accounts/src/provider.rs:transaction_cost}} 7 | ``` 8 | 9 | > **Note** `script_gas` refers to the part of the gas spent on the script execution. 10 | 11 | Below are examples that show how to get the estimated transaction cost from single and multi call transactions. 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/contracts/src/lib.rs:contract_call_cost_estimation}} 15 | ``` 16 | 17 | ```rust,ignore 18 | {{#include ../../../examples/contracts/src/lib.rs:multi_call_cost_estimation}} 19 | ``` 20 | 21 | The transaction cost estimation can be used to set the gas limit for an actual call, or to show the user the estimated cost. 22 | 23 | > **Note** The same estimation interface is available for scripts. 24 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/custom-asset-transfer.md: -------------------------------------------------------------------------------- 1 | # Custom asset transfer 2 | 3 | 4 | 5 | The SDK provides the option to transfer assets within the same transaction, when making a contract call. By using `add_custom_asset()` you specify the asset ID, the amount, and the destination address: 6 | 7 | 8 | ```rust,ignore 9 | {{#include ../../../examples/contracts/src/lib.rs:add_custom_assets}} 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/custom-inputs-outputs.md: -------------------------------------------------------------------------------- 1 | # Custom inputs and outputs 2 | 3 | If you need to add specific inputs and outputs to contract calls, you can use the `with_inputs` and `with_outputs` methods. 4 | 5 | ```rust,ignore 6 | {{#include ../../../examples/contracts/src/lib.rs:add_custom_inputs_outputs}} 7 | ``` 8 | 9 | > **Note:** if custom inputs include coins that need to be signed, use the `add_signer` method to add the appropriate signer. 10 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/index.md: -------------------------------------------------------------------------------- 1 | # Calling contracts 2 | 3 | Once you've deployed your contract, as seen in the previous sections, you'll likely want to: 4 | 5 | 1. Call contract methods; 6 | 2. Configure call parameters and transaction policies; 7 | 3. Forward coins and gas in your contract calls; 8 | 4. Read and interpret returned values and logs. 9 | 10 | Here's an example. Suppose your Sway contract has two ABI methods called `initialize_counter(u64)` and `increment_counter(u64)`. Once you've deployed it the contract, you can call these methods like this: 11 | 12 | ```rust,ignore 13 | {{#include ../../../examples/contracts/src/lib.rs:use_deployed_contract}} 14 | ``` 15 | 16 | The example above uses all the default configurations and performs a simple contract call. 17 | 18 | Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows: 19 | 20 | ```rust,ignore 21 | {{#include ../../../examples/contracts/src/lib.rs:submit_response_contract}} 22 | ``` 23 | 24 | Next, we'll see how we can further configure the many different parameters in a contract call. 25 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/logs.md: -------------------------------------------------------------------------------- 1 | # Logs 2 | 3 | Whenever you log a value within a contract method, the resulting log entry is added to the log receipt and the variable type is recorded in the contract's ABI. The SDK lets you parse those values into Rust types. 4 | 5 | Consider the following contract method: 6 | 7 | ```rust,ignore 8 | {{#include ../../../e2e/sway/logs/contract_logs/src/main.sw:produce_logs}} 9 | ``` 10 | 11 | You can access the logged values in Rust by calling `decode_logs_with_type::` from a `CallResponse`, where `T` is the type of the logged variables you want to retrieve. The result will be a `Vec`: 12 | 13 | ```rust,ignore 14 | {{#include ../../../e2e/tests/logs.rs:produce_logs}} 15 | ``` 16 | 17 | You can use the `decode_logs()` function to retrieve a `LogResult` struct containing a `results` field that is a vector of `Result` values representing the success or failure of decoding each log. 18 | 19 | ```rust, ignore 20 | {{#include ../../../e2e/tests/logs.rs:decode_logs}} 21 | ``` 22 | 23 | Due to possible performance hits, it is not recommended to use `decode_logs()` outside of a debugging scenario. 24 | 25 | > **Note:** String slices cannot be logged directly. Use the `__to_str_array()` function to convert it to a `str[N]` first. 26 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/other-contracts.md: -------------------------------------------------------------------------------- 1 | # Calling other contracts 2 | 3 | If your contract method is calling other contracts you will have to add the appropriate `Inputs` and `Outputs` to your transaction. For your convenience, the `CallHandler` provides methods that prepare those inputs and outputs for you. You have two methods that you can use: `with_contracts(&[&contract_instance, ...])` and `with_contract_ids(&[&contract_id, ...])`. 4 | 5 | `with_contracts(&[&contract_instance, ...])` requires contract instances that were created using the `abigen` macro. When setting the external contracts with this method, logs and require revert errors originating from the external contract can be propagated and decoded by the calling contract. 6 | 7 | ```rust,ignore 8 | {{#include ../../../e2e/tests/contracts.rs:external_contract}} 9 | ``` 10 | 11 | If however, you do not need to decode logs or you do not have a contract instance that was generated using the `abigen` macro you can use `with_contract_ids(&[&contract_id, ...])` and provide the required contract ids. 12 | 13 | ```rust,ignore 14 | {{#include ../../../e2e/tests/contracts.rs:external_contract_ids}} 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/src/calling-contracts/simulation.md: -------------------------------------------------------------------------------- 1 | # Simulating calls 2 | 3 | Sometimes you want to simulate a call to a contract without changing the state of the blockchain. This can be achieved by calling `.simulate` instead of `.call` and passing in the desired execution context: 4 | 5 | * `.simulate(Execution::realistic())` simulates the transaction in a manner that closely resembles a real call. You need a wallet with base assets to cover the transaction cost, even though no funds will be consumed. This is useful for validating that a real call would succeed if made at that moment. It allows you to debug issues with your contract without spending gas. 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/contracts/src/lib.rs:simulate}} 9 | ``` 10 | 11 | * `.simulate(Execution::state_read_only())` disables many validations, adds fake gas, extra variable outputs, blank witnesses, etc., enabling you to read state even with an account that has no funds. 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/contracts/src/lib.rs:simulate_read_state}} 15 | ``` 16 | 17 | If the node supports historical execution (the node is using `rocksdb` and the `historical_execution` flag has been set), then both execution types can be chained with `at_height` to simulate the call at a specific block height. 18 | 19 | ```rust,ignore 20 | {{#include ../../../examples/contracts/src/lib.rs:simulate_read_state_at_height}} 21 | ``` 22 | -------------------------------------------------------------------------------- /docs/src/cli/index.md: -------------------------------------------------------------------------------- 1 | # `fuels-rs` Rust Workspaces 2 | 3 | This section gives you a little overview of the role and function of every workspace in the `fuels-rs` repository. 4 | 5 | - [`fuels-abi-cli`](./fuels-abi-cli.md) 6 | -------------------------------------------------------------------------------- /docs/src/codec/encoding.md: -------------------------------------------------------------------------------- 1 | # Encoding 2 | 3 | Be sure to read the [prerequisites](./index.md#prerequisites-for-decodingencoding) to encoding. 4 | 5 | Encoding is done via the [`ABIEncoder`](https://docs.rs/fuels/latest/fuels/core/codec/struct.ABIEncoder.html): 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/codec/src/lib.rs:encoding_example}} 9 | ``` 10 | 11 | There is also a shortcut-macro that can encode multiple types which implement [`Tokenizable`](https://docs.rs/fuels/latest/fuels/core/traits/trait.Tokenizable.html): 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/codec/src/lib.rs:encoding_example_w_macro}} 15 | ``` 16 | 17 | ## Configuring the encoder 18 | 19 | The encoder can be configured to limit its resource expenditure: 20 | 21 | ```rust,ignore 22 | {{#include ../../../examples/codec/src/lib.rs:configuring_the_encoder}} 23 | ``` 24 | 25 | The default values for the `EncoderConfig` are: 26 | 27 | ```rust,ignore 28 | {{#include ../../../packages/fuels-core/src/codec/abi_encoder.rs:default_encoder_config}} 29 | ``` 30 | 31 | ## Configuring the encoder for contract/script calls 32 | 33 | You can also configure the encoder used to encode the arguments of the contract method: 34 | 35 | ```rust,ignore 36 | {{#include ../../../examples/contracts/src/lib.rs:contract_encoder_config}} 37 | ``` 38 | 39 | The same method is available for script calls. 40 | -------------------------------------------------------------------------------- /docs/src/connecting/index.md: -------------------------------------------------------------------------------- 1 | # Connecting to a Fuel node 2 | 3 | 4 | 5 | At a high level, you can use the Fuel Rust SDK to build Rust-based applications that can run computations on the Fuel Virtual Machine through interactions with smart contracts written in Sway. 6 | 7 | For this interaction to work, the SDK must be able to communicate with a `fuel-core` node; you have two options at your disposal: 8 | 9 | 1. Use the testnet or run a Fuel node (using `fuel-core`) and instantiate a provider that points to that node's IP and port. 10 | 2. Use the SDK's native `launch_provider_and_get_wallet()` that runs a short-lived test Fuel node; 11 | 12 | The second option is ideal for smart contract testing, as you can quickly spin up and tear down nodes between specific test cases. 13 | 14 | For application building, you should use the first option. 15 | 16 | -------------------------------------------------------------------------------- /docs/src/connecting/rocksdb.md: -------------------------------------------------------------------------------- 1 | # RocksDB 2 | 3 | RocksDB enables the preservation of the blockchain's state locally, facilitating its future utilization. 4 | 5 | To create or use a local database, follow these instructions: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/cookbook/src/lib.rs:create_or_use_rocksdb}} 9 | ``` 10 | 11 | > Note: If the specified database does not exist, a new database will be created at that path. To utilize the code snippets above, either the `fuel-core` binary must be present, or both the `fuel-core-lib` and `rocksdb` features need to be enabled. 12 | -------------------------------------------------------------------------------- /docs/src/contributing/tests-structure.md: -------------------------------------------------------------------------------- 1 | # Integration tests structure in `fuels-rs` 2 | 3 | The integration tests of `fuels-rs` cover almost all aspects of the SDK and have grown significantly as more functionality was added. To make the tests and associated `Sway` projects more manageable they were split into several categories. A category consist of a `.rs` file for the tests and, if needed, a separate directory for the `Sway` projects. 4 | 5 | Currently have the following structure: 6 | 7 | ```shell 8 | . 9 | ├─ bindings/ 10 | ├─ contracts/ 11 | ├─ logs/ 12 | ├─ predicates/ 13 | ├─ storage/ 14 | ├─ types/ 15 | ├─ bindings.rs 16 | ├─ contracts.rs 17 | ├─ from_token.rs 18 | ├─ logs.rs 19 | ├─ predicates.rs 20 | ├─ providers.rs 21 | ├─ scripts.rs 22 | ├─ storage.rs 23 | ├─ types.rs 24 | └─ wallets.rs 25 | ``` 26 | 27 | Even though test organization is subjective, please consider these guidelines before adding a new category: 28 | 29 | - Add a new category when creating a new section in the `Fuels Rust SDK` book - e.g. `Types` 30 | - Add a new category if there are more than 3 test and more than 100 lines of code and they form a group of tests - e.g. `storage.rs` 31 | 32 | Otherwise, we recommend putting the integration test inside the existing categories above. 33 | -------------------------------------------------------------------------------- /docs/src/cookbook/custom-chain.md: -------------------------------------------------------------------------------- 1 | # Custom chain 2 | 3 | This example demonstrates how to start a short-lived Fuel node with custom consensus parameters for the underlying chain. 4 | 5 | First, we have to import `ConsensusParameters` and `ChainConfig`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/cookbook/src/lib.rs:custom_chain_import}} 9 | ``` 10 | 11 | Next, we can define some values for the consensus parameters: 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/cookbook/src/lib.rs:custom_chain_consensus}} 15 | ``` 16 | 17 | Before we can start a node, we probably also want to define some genesis coins and assign them to an address: 18 | 19 | ```rust,ignore 20 | {{#include ../../../examples/cookbook/src/lib.rs:custom_chain_coins}} 21 | ``` 22 | 23 | Finally, we call `setup_test_provider()`, which starts a node with the given configurations and returns a 24 | provider attached to that node: 25 | 26 | ```rust,ignore 27 | {{#include ../../../examples/cookbook/src/lib.rs:custom_chain_provider}} 28 | ``` 29 | -------------------------------------------------------------------------------- /docs/src/cookbook/index.md: -------------------------------------------------------------------------------- 1 | # Cookbook 2 | 3 | This section covers more advanced use cases that can be satisfied by combining various features of the Rust SDK. As such, it assumes that you have already made yourself familiar with the previous chapters of this book. 4 | 5 | > **Note** This section is still a work in progress and more recipes may be added in the future. 6 | -------------------------------------------------------------------------------- /docs/src/custom-transactions/custom-calls.md: -------------------------------------------------------------------------------- 1 | # Custom contract and script calls 2 | 3 | When preparing a contract call via `CallHandler`, the Rust SDK uses a transaction builder in the background. You can fetch this builder and customize it before submitting it to the network. After the transaction is executed successfully, you can use the corresponding `CallHandler` to generate a [call response](../calling-contracts/call-response.md). The call response can be used to decode return values and logs. Below are examples for both contract and script calls. 4 | 5 | ## Custom contract call 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/contracts/src/lib.rs:contract_call_tb}} 9 | ``` 10 | 11 | ## Custom script call 12 | 13 | ```rust,ignore 14 | {{#include ../../../e2e/tests/scripts.rs:script_call_tb}} 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/src/custom-transactions/index.md: -------------------------------------------------------------------------------- 1 | # Custom transactions 2 | 3 | Until now, we have used helpers to create transactions, send them with a provider, and parse the results. However, sometimes we must make custom transactions with specific inputs, outputs, witnesses, etc. In the next chapter, we will show how to use the Rust SDKs transaction builders to accomplish this. 4 | -------------------------------------------------------------------------------- /docs/src/debugging/decoding-script-transactions.md: -------------------------------------------------------------------------------- 1 | # Decoding script transactions 2 | 3 | The SDK offers some tools that can help you make fuel script transactions more 4 | human readable. You can determine whether the script transaction is: 5 | 6 | * calling a contract method(s), 7 | * is a loader script and you can see the blob id 8 | * is neither of the above 9 | 10 | In the case of contract call(s), if you have the ABI file, you can also decode 11 | the arguments to the function by making use of the `AbiFormatter`: 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/contracts/src/lib.rs:decoding_script_transactions}} 15 | ``` 16 | 17 | prints: 18 | 19 | ```text 20 | The script called: initialize_counter(42) 21 | ``` 22 | 23 | The `AbiFormatter` can also decode configurables, refer to the rust docs for 24 | more information. 25 | -------------------------------------------------------------------------------- /docs/src/debugging/function-selector.md: -------------------------------------------------------------------------------- 1 | # Function selector 2 | 3 | Whenever you call a contract method the SDK will generate a function selector according to the fuel specs which will be 4 | used by the node to identify which method we wish to execute. 5 | 6 | If, for whatever reason, you wish to generate the function selector yourself you can do so: 7 | 8 | ```rust,ignore 9 | {{#include ../../../examples/debugging/src/lib.rs:example_fn_selector}} 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/src/debugging/index.md: -------------------------------------------------------------------------------- 1 | # Debugging 2 | 3 | > **note** This section is still a work in progress. 4 | 5 | - [The Function Selector](./function-selector.md) 6 | -------------------------------------------------------------------------------- /docs/src/deploying/configurable-constants.md: -------------------------------------------------------------------------------- 1 | # Configurable constants 2 | 3 | In Sway, you can define `configurable` constants which can be changed during the contract deployment in the SDK. Here is an example how the constants are defined. 4 | 5 | ```rust,ignore 6 | {{#include ../../../e2e/sway/contracts/configurables/src/main.sw}} 7 | ``` 8 | 9 | Each of the configurable constants will get a dedicated `with` method in the SDK. For example, the constant `STR_4` will get the `with_STR_4` method which accepts the same type as defined in the contract code. Below is an example where we chain several `with` methods and deploy the contract with the new constants. 10 | 11 | ```rust,ignore 12 | {{#include ../../../e2e/tests/configurables.rs:contract_configurables}} 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/src/deploying/interacting-with-contracts.md: -------------------------------------------------------------------------------- 1 | # Interacting with contracts 2 | 3 | If you already have a deployed contract and want to call its methods using the SDK, but without deploying it again, all you need is the contract ID of your deployed contract. You can skip the whole deployment setup and call `::new(contract_id, wallet)` directly. For example: 4 | 5 | ```rust,ignore 6 | {{#include ../../../examples/contracts/src/lib.rs:deployed_contracts}} 7 | ``` 8 | -------------------------------------------------------------------------------- /docs/src/deploying/storage-slots.md: -------------------------------------------------------------------------------- 1 | # Overriding storage slots 2 | 3 | If you use storage in your contract, the default storage values will be generated in a JSON file (e.g. `my_contract-storage_slots.json`) by the Sway compiler. These are loaded automatically for you when you load a contract binary. If you wish to override some of the defaults, you need to provide the corresponding storage slots manually: 4 | 5 | ```rust,ignore 6 | {{#include ../../../examples/contracts/src/lib.rs:storage_slots_override}} 7 | ``` 8 | 9 | If you don't have the slot storage file (`my_contract-storage_slots.json` example from above) for some reason, or you don't wish to load any of the default values, you can disable the auto-loading of storage slots: 10 | 11 | ```rust,ignore 12 | {{#include ../../../examples/contracts/src/lib.rs:storage_slots_disable_autoload}} 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/src/glossary.md: -------------------------------------------------------------------------------- 1 | # Glossary 2 | 3 | ## Contract 4 | 5 | 6 | 7 | 8 | A contract, in the SDK, is an abstraction that represents a connection to a specific smart contract deployed on the Fuel Network. This contract instance can be used as a regular Rust object, with methods attached to it that reflect those in its smart contract equivalent. 9 | 10 | 11 | 12 | ## Provider 13 | 14 | 15 | 16 | 17 | A Provider is a struct that provides an abstraction for a connection to a Fuel node. It provides read-only access to the node. You can use this provider as-is or through the wallet. 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/src/index.md: -------------------------------------------------------------------------------- 1 | # The Fuel Rust SDK 2 | 3 | 4 | 5 | The Fuel Rust SDK can be used for a variety of things, including: 6 | 7 | - Compiling, deploying, and testing [Sway](https://github.com/FuelLabs/sway) contracts 8 | - Using the testnet or running a local Fuel node 9 | - Crafting and signing transactions with hand-crafted scripts or contract calls 10 | - Generating type-safe Rust bindings of contract ABI methods 11 | 12 | 13 | This book is an overview of the different things one can achieve using the Rust SDK, and how to implement them. Keep in mind that both the SDK and the documentation are works-in-progress! 14 | -------------------------------------------------------------------------------- /docs/src/reference.md: -------------------------------------------------------------------------------- 1 | # API Reference 2 | 3 | For a more in-depth look at the APIs provided by the Fuel Rust SDK, head over to the [official documentation](https://docs.rs/fuels/latest/fuels/). In the actual Rust docs, you can see the most up-to-date information about the API, which is synced with the code as it changes. 4 | -------------------------------------------------------------------------------- /docs/src/testing/chains.md: -------------------------------------------------------------------------------- 1 | # Increasing the block height 2 | 3 | You can use `produce_blocks` to help achieve an arbitrary block height; this is useful when you want to do any testing regarding transaction maturity. 4 | 5 | > **Note**: For the `produce_blocks` API to work, it is imperative to have `manual_blocks_enabled = true` in the config for the running node. See example below. 6 | 7 | ```rust,ignore 8 | {{#include ../../../e2e/tests/providers.rs:use_produce_blocks_to_increase_block_height}} 9 | ``` 10 | 11 | You can also set a custom block time as the second, optional argument. Here is an example: 12 | 13 | ```rust,ignore 14 | {{#include ../../../e2e/tests/providers.rs:use_produce_blocks_custom_time}} 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/src/testing/index.md: -------------------------------------------------------------------------------- 1 | # `fuels-rs` Testing 2 | 3 | > **note** This section is still a work in progress. 4 | 5 | - [Testing Basics](./basics.md) 6 | - [`setup_program_test!` Macro](./the-setup-program-test-macro.md) 7 | - [Tweaking the Blockchain](./chains.md) 8 | -------------------------------------------------------------------------------- /docs/src/types/B512.md: -------------------------------------------------------------------------------- 1 | # `B512` 2 | 3 | In the Rust SDK, the `B512` definition matches the Sway standard library type with the same name and will be converted accordingly when interacting with contracts: 4 | 5 | ```rust,ignore 6 | {{#include ../../../packages/fuels-core/src/types/core/bits.rs:b512}} 7 | ``` 8 | 9 | Here's an example: 10 | 11 | ```rust,ignore 12 | {{#include ../../../e2e/tests/types_contracts.rs:b512_example}} 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/src/types/address.md: -------------------------------------------------------------------------------- 1 | # `Address` 2 | 3 | Like `Bytes32`, `Address` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Address.html)). 4 | 5 | These are the main ways of creating an `Address`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/types/src/lib.rs:address}} 9 | ``` 10 | -------------------------------------------------------------------------------- /docs/src/types/asset-id.md: -------------------------------------------------------------------------------- 1 | # `AssetId` 2 | 3 | Like `Bytes32`, `AssetId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/0.49.0/fuel_types/struct.AssetId.html)). 4 | 5 | These are the main ways of creating an `AssetId`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/types/src/lib.rs:asset_id}} 9 | ``` 10 | -------------------------------------------------------------------------------- /docs/src/types/bits256.md: -------------------------------------------------------------------------------- 1 | # `Bits256` 2 | 3 | In Fuel, a type called `b256` represents hashes and holds a 256-bit value. The Rust SDK represents `b256` as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, you must pass a `Bits256([u8; 32])` when calling it from the SDK. 4 | 5 | Here's an example: 6 | 7 | ```rust,ignore 8 | {{#include ../../../e2e/tests/types_contracts.rs:256_arg}} 9 | ``` 10 | 11 | If you have a hexadecimal value as a string and wish to convert it to `Bits256`, you may do so with `from_hex_str`: 12 | 13 | ```rust,ignore 14 | {{#include ../../../packages/fuels-core/src/types/core/bits.rs:from_hex_str}} 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/src/types/bytes.md: -------------------------------------------------------------------------------- 1 | # `Bytes` 2 | 3 | In Fuel, a type called `Bytes` represents a collection of tightly-packed bytes. The Rust SDK represents `Bytes` as `Bytes(Vec)`. Here's an example of using `Bytes` in a contract call: 4 | 5 | ```rust,ignore 6 | {{#include ../../../e2e/tests/types_contracts.rs:bytes_arg}} 7 | ``` 8 | 9 | If you have a hexadecimal value as a string and wish to convert it to `Bytes`, you may do so with `from_hex_str`: 10 | 11 | ```rust,ignore 12 | {{#include ../../../packages/fuels-core/src/types/core/bytes.rs:bytes_from_hex_str}} 13 | ``` 14 | -------------------------------------------------------------------------------- /docs/src/types/bytes32.md: -------------------------------------------------------------------------------- 1 | # `Bytes32` 2 | 3 | In Sway and the FuelVM, `Bytes32` represents hashes. They hold a 256-bit (32-byte) value. `Bytes32` is a wrapper on a 32-sized slice of `u8`: `pub struct Bytes32([u8; 32]);`. 4 | 5 | These are the main ways of creating a `Bytes32`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/types/src/lib.rs:bytes32}} 9 | ``` 10 | 11 | `Bytes32` also implements the `fmt` module's `Debug`, `Display`, `LowerHex` and `UpperHex` traits. For example, you can get the display and hex representations with: 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/types/src/lib.rs:bytes32_format}} 15 | ``` 16 | 17 | For a full list of implemented methods and traits, see the [fuel-types documentation](https://docs.rs/fuel-types/latest/fuel_types/struct.Bytes32.html). 18 | 19 | > **Note:** In Fuel, there's a special type called `b256`, which is similar to `Bytes32`; also used to represent hashes, and it holds a 256-bit value. In Rust, through the SDK, this is represented as `Bits256(value)` where `value` is a `[u8; 32]`. If your contract method takes a `b256` as input, all you need to do is pass a `Bits256([u8; 32])` when calling it from the SDK. 20 | -------------------------------------------------------------------------------- /docs/src/types/contract-id.md: -------------------------------------------------------------------------------- 1 | # `ContractId` 2 | 3 | Like `Bytes32`, `ContractId` is a wrapper on `[u8; 32]` with similar methods and implements the same traits (see [fuel-types documentation](https://docs.rs/fuel-types/0.49.0/fuel_types/struct.ContractId.html)). 4 | 5 | These are the main ways of creating a `ContractId`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../examples/types/src/lib.rs:contract_id}} 9 | ``` 10 | -------------------------------------------------------------------------------- /docs/src/types/evm_address.md: -------------------------------------------------------------------------------- 1 | # `EvmAddress` 2 | 3 | In the Rust SDK, Ethereum Virtual Machine (EVM) addresses can be represented with the `EvmAddress` type. Its definition matches with the Sway standard library type with the same name and will be converted accordingly when interacting with contracts: 4 | 5 | ```rust,ignore 6 | {{#include ../../../packages/fuels-core/src/types/core/bits.rs:evm_address}} 7 | ``` 8 | 9 | Here's an example: 10 | 11 | ```rust,ignore 12 | {{#include ../../../e2e/tests/types_contracts.rs:evm_address_arg}} 13 | ``` 14 | 15 | > **Note:** when creating an `EvmAddress` from `Bits256`, the first 12 bytes will be cleared because an EVM address is only 20 bytes long. 16 | -------------------------------------------------------------------------------- /docs/src/types/index.md: -------------------------------------------------------------------------------- 1 | # Types 2 | 3 | The FuelVM and Sway have many internal types. These types have equivalents in the SDK. This section discusses these types, how to use them, and how to convert them. 4 | -------------------------------------------------------------------------------- /docs/src/types/string.md: -------------------------------------------------------------------------------- 1 | # `String` 2 | 3 | The Rust SDK represents Fuel's `String`s as `SizedAsciiString`, where the generic parameter `LEN` is the length of a given string. This abstraction is necessary because all strings in Fuel and Sway are statically-sized, i.e., you must know the size of the string beforehand. 4 | 5 | Here's how you can create a simple string using `SizedAsciiString`: 6 | 7 | ```rust,ignore 8 | {{#include ../../../packages/fuels-core/src/types/core/sized_ascii_string.rs:string_simple_example}} 9 | ``` 10 | 11 | To make working with `SizedAsciiString`s easier, you can use `try_into()` to convert from Rust's `String` to `SizedAsciiString`, and you can use `into()` to convert from `SizedAsciiString` to Rust's `String`. Here are a few examples: 12 | 13 | ```rust,ignore 14 | {{#include ../../../packages/fuels-core/src/types/core/sized_ascii_string.rs:conversion}} 15 | ``` 16 | 17 | If your contract's method takes and returns, for instance, a Sway's `str[23]`. When using the SDK, this method will take and return a `SizedAsciiString<23>`. 18 | -------------------------------------------------------------------------------- /docs/src/types/vectors.md: -------------------------------------------------------------------------------- 1 | # Vectors 2 | 3 | ## Passing in vectors 4 | 5 | You can pass a Rust `std::vec::Vec` into your contract method transparently. The following code calls a Sway contract method which accepts a `Vec>`. 6 | 7 | ```rust,ignore 8 | {{#include ../../../e2e/tests/types_contracts.rs:passing_in_vec}} 9 | ``` 10 | 11 | You can use a vector just like you would use any other type -- e.g. a `[Vec; 2]` or a `SomeStruct>` etc. 12 | 13 | ## Returning vectors 14 | 15 | Returning vectors from contract methods is supported transparently, with the caveat that you cannot have them nested inside another type. This limitation is temporary. 16 | 17 | ```rust,ignore 18 | {{#include ../../../e2e/tests/types_contracts.rs:returning_vec}} 19 | ``` 20 | 21 | > **Note: you can still interact with contracts containing methods that return vectors nested inside another type, just not interact with the methods themselves** 22 | -------------------------------------------------------------------------------- /docs/src/wallets/fake_signer.md: -------------------------------------------------------------------------------- 1 | # Fake signer (impersonating another account) 2 | 3 | To facilitate account impersonation, the Rust SDK provides the `FakeSigner`. We can use it to simulate ownership of assets held by an account with a given address. This also implies that we can impersonate contract calls from that address. A wallet with a `FakeSigner` will only succeed in unlocking assets if the network is set up with `utxo_validation = false`. 4 | 5 | ```rust,ignore 6 | {{#include ../../../examples/contracts/src/lib.rs:utxo_validation_off}} 7 | ``` 8 | 9 | ```rust,ignore 10 | {{#include ../../../examples/contracts/src/lib.rs:utxo_validation_off_node_start}} 11 | ``` 12 | 13 | ```rust,ignore 14 | {{#include ../../../examples/contracts/src/lib.rs:contract_call_impersonation}} 15 | ``` 16 | -------------------------------------------------------------------------------- /docs/src/wallets/keystore.md: -------------------------------------------------------------------------------- 1 | # Encrypting and Storing Keys 2 | 3 | The code below shows how to: 4 | 5 | - Encrypt and store your key using a master password. 6 | - Ensure that the key can be retrieved later with the proper credentials. 7 | 8 | ```rust,ignore 9 | {{#include ../../../examples/wallets/src/lib.rs:create_and_store_mnemonic_key}} 10 | ``` 11 | -------------------------------------------------------------------------------- /docs/src/wallets/kms.md: -------------------------------------------------------------------------------- 1 | # Using KMS Wallets 2 | 3 | Key Management Service (KMS) is a robust and secure solution for managing cryptographic keys for your Fuel wallets. Instead of keeping private keys on your local system, KMS Wallets leverage secure infrastructure to handle both key storage and signing operations. 4 | 5 | The SDK provides signers for AWS and Google KMS. 6 | 7 | Below is an example of how to initialize a wallet with a AWS KMS signer: 8 | 9 | ```rust,ignore 10 | {{#include ../../../e2e/tests/aws.rs:use_kms_wallet}} 11 | ``` 12 | -------------------------------------------------------------------------------- /e2e/assets/precompiled_sway/legacy_format_simple_contract.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/fuels-rs/e510eab463c190600bd8b5f004bd5544b3ffc8cd/e2e/assets/precompiled_sway/legacy_format_simple_contract.bin -------------------------------------------------------------------------------- /e2e/src/e2e_helpers.rs: -------------------------------------------------------------------------------- 1 | use fuels::types::errors::Result; 2 | 3 | use crate::aws_kms::{AwsKms, AwsKmsProcess}; 4 | 5 | pub async fn start_aws_kms(logs: bool) -> Result { 6 | AwsKms::default().with_show_logs(logs).start().await 7 | } 8 | -------------------------------------------------------------------------------- /e2e/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod aws_kms; 2 | pub mod e2e_helpers; 3 | -------------------------------------------------------------------------------- /e2e/sway/abi/simple_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "simple_contract" 6 | -------------------------------------------------------------------------------- /e2e/sway/abi/simple_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi SimpleContract { 4 | fn takes_u32_returns_bool(arg: u32) -> bool; 5 | } 6 | 7 | impl SimpleContract for Contract { 8 | fn takes_u32_returns_bool(_arg: u32) -> bool { 9 | true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/sway/abi/wasm_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "wasm_contract" 6 | -------------------------------------------------------------------------------- /e2e/sway/abi/wasm_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | enum SomeEnum { 4 | V1: (), 5 | V2: T, 6 | } 7 | 8 | #[allow(dead_code)] 9 | struct SomeStruct { 10 | a: u32, 11 | b: bool, 12 | } 13 | 14 | abi TestContract { 15 | fn test_function(arg: SomeEnum); 16 | } 17 | 18 | impl TestContract for Contract { 19 | fn test_function(_arg: SomeEnum) {} 20 | } 21 | -------------------------------------------------------------------------------- /e2e/sway/abi/wasm_predicate/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "wasm_predicate" 6 | -------------------------------------------------------------------------------- /e2e/sway/abi/wasm_predicate/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | configurable { 4 | U64: u64 = 128, 5 | } 6 | 7 | fn main(val: u64) -> bool { 8 | val == U64 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/bindings/sharing_types/contract_a/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_a" 6 | 7 | [dependencies] 8 | shared_lib = { path = "../shared_lib" } 9 | -------------------------------------------------------------------------------- /e2e/sway/bindings/sharing_types/contract_b/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_b" 6 | 7 | [dependencies] 8 | shared_lib = { path = "../shared_lib" } 9 | -------------------------------------------------------------------------------- /e2e/sway/bindings/sharing_types/shared_lib/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "lib.sw" 4 | license = "Apache-2.0" 5 | name = "shared_lib" 6 | -------------------------------------------------------------------------------- /e2e/sway/bindings/sharing_types/shared_lib/src/lib.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub struct SharedStruct1 { 4 | a: T, 5 | } 6 | 7 | pub struct SharedStruct2 { 8 | a: u32, 9 | b: SharedStruct1, 10 | } 11 | 12 | #[allow(dead_code)] 13 | pub enum SharedEnum { 14 | a: u64, 15 | b: SharedStruct2, 16 | } 17 | -------------------------------------------------------------------------------- /e2e/sway/bindings/simple_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "simple_contract" 6 | -------------------------------------------------------------------------------- /e2e/sway/bindings/simple_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn takes_int_returns_bool(arg: u32) -> bool; 5 | } 6 | 7 | impl MyContract for Contract { 8 | fn takes_int_returns_bool(arg: u32) -> bool { 9 | arg == 32u32 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/sway/bindings/type_paths/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "type_paths" 6 | -------------------------------------------------------------------------------- /e2e/sway/bindings/type_paths/src/another_lib.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub struct VeryCommonNameStruct { 4 | pub field_a: u32, 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/bindings/type_paths/src/contract_a_types.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub struct VeryCommonNameStruct { 4 | another_field: u32, 5 | } 6 | 7 | pub struct AWrapper { 8 | field: VeryCommonNameStruct, 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/bindings/type_paths/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | mod contract_a_types; 4 | mod another_lib; 5 | 6 | use contract_a_types::AWrapper; 7 | use another_lib::VeryCommonNameStruct; 8 | 9 | abi MyContract { 10 | fn test_function(arg: AWrapper) -> VeryCommonNameStruct; 11 | } 12 | 13 | impl MyContract for Contract { 14 | fn test_function(_arg: AWrapper) -> VeryCommonNameStruct { 15 | VeryCommonNameStruct { field_a: 10u32 } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /e2e/sway/contracts/asserts/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "asserts" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/auth_testing_abi/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "auth_testing_abi" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/auth_testing_abi/src/main.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | abi AuthTesting { 4 | fn is_caller_external() -> bool; 5 | fn check_msg_sender(expected_id: Address) -> bool; 6 | } 7 | -------------------------------------------------------------------------------- /e2e/sway/contracts/auth_testing_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "auth_testing_contract" 6 | 7 | [dependencies] 8 | auth_testing_abi = { path = "../auth_testing_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/contracts/auth_testing_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::auth::{AuthError, caller_is_external, msg_sender}; 4 | use auth_testing_abi::*; 5 | 6 | impl AuthTesting for Contract { 7 | fn is_caller_external() -> bool { 8 | caller_is_external() 9 | } 10 | 11 | fn check_msg_sender(expected_id: Address) -> bool { 12 | let result: Result = msg_sender(); 13 | let mut ret = false; 14 | if result.is_err() { 15 | ret = false; 16 | } else { 17 | let unwrapped = result.unwrap(); 18 | if let Identity::Address(v) = unwrapped { 19 | assert(v == expected_id); 20 | ret = true; 21 | } else { 22 | ret = false; 23 | } 24 | }; 25 | 26 | ret 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /e2e/sway/contracts/block_timestamp/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "block_timestamp" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/block_timestamp/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::block::timestamp; 4 | 5 | abi MyContract { 6 | fn return_timestamp() -> u64; 7 | } 8 | 9 | impl MyContract for Contract { 10 | fn return_timestamp() -> u64 { 11 | timestamp() 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /e2e/sway/contracts/configurables/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "configurables" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/contract_test/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_test" 6 | 7 | [dependencies] 8 | increment_abi = { path = "../library_test", package = "library_test" } 9 | -------------------------------------------------------------------------------- /e2e/sway/contracts/huge_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "huge_contract" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/contracts/huge_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn something() -> u64; 5 | #[storage(write)] 6 | fn write_some_u64(some: u64); 7 | #[storage(read)] 8 | fn read_some_u64() -> u64; 9 | } 10 | 11 | storage { 12 | some_u64: u64 = 42, 13 | } 14 | 15 | impl MyContract for Contract { 16 | fn something() -> u64 { 17 | asm() { 18 | blob i450000; 19 | } 20 | 1001 21 | } 22 | 23 | #[storage(write)] 24 | fn write_some_u64(some: u64) { 25 | storage.some_u64.write(some); 26 | } 27 | 28 | #[storage(read)] 29 | fn read_some_u64() -> u64 { 30 | storage.some_u64.read() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /e2e/sway/contracts/large_return_data/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "large_return_data" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/lib_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "lib_contract" 6 | 7 | [dependencies] 8 | lib_contract_abi = { path = "../lib_contract_abi/", package = "lib_contract_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/contracts/lib_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use lib_contract_abi::LibContract; 4 | 5 | impl LibContract for Contract { 6 | fn increment(value: u64) -> u64 { 7 | value + 1 8 | } 9 | 10 | fn require() -> () { 11 | require(false, __to_str_array("require from contract")); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /e2e/sway/contracts/lib_contract_abi/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "lib_contract_abi" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/lib_contract_abi/src/main.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | abi LibContract { 4 | fn increment(value: u64) -> u64; 5 | fn require(); 6 | } 7 | -------------------------------------------------------------------------------- /e2e/sway/contracts/lib_contract_caller/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "lib_contract_caller" 6 | 7 | [dependencies] 8 | lib_contract = { path = "../lib_contract_abi/", package = "lib_contract_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/contracts/library_test/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "library_test" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/library_test/src/main.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | abi Incrementor { 4 | fn initialize(gas: u64, amt: u64, coin: b256, initial_value: u64) -> u64; 5 | fn increment(gas: u64, amt: u64, coin: b256, initial_value: u64) -> u64; 6 | } 7 | -------------------------------------------------------------------------------- /e2e/sway/contracts/liquidity_pool/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "liquidity_pool" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/liquidity_pool/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{asset::{mint_to, transfer}, call_frames::msg_asset_id, context::msg_amount}; 4 | abi LiquidityPool { 5 | #[payable] 6 | fn deposit(recipient: Identity); 7 | #[payable] 8 | fn withdraw(recipient: Identity); 9 | } 10 | const BASE_TOKEN: AssetId = AssetId::from(0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c); 11 | impl LiquidityPool for Contract { 12 | #[payable] 13 | fn deposit(recipient: Identity) { 14 | assert(BASE_TOKEN == msg_asset_id()); 15 | assert(0 < msg_amount()); 16 | // Mint two times the amount. 17 | let amount_to_mint = msg_amount() * 2; 18 | // Mint some LP token based upon the amount of the base token. 19 | mint_to(recipient, b256::zero(), amount_to_mint); 20 | } 21 | #[payable] 22 | fn withdraw(recipient: Identity) { 23 | assert(0 < msg_amount()); 24 | // Amount to withdraw. 25 | let amount_to_transfer = msg_amount() / 2; 26 | // Transfer base token to recipient. 27 | transfer(recipient, BASE_TOKEN, amount_to_transfer); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /e2e/sway/contracts/low_level_caller/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "low_level_caller" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/low_level_caller/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{ 4 | bytes::Bytes, 5 | constants::ZERO_B256, 6 | low_level_call::{ 7 | call_with_function_selector, 8 | CallParams, 9 | }, 10 | }; 11 | 12 | abi MyCallerContract { 13 | fn call_low_level_call( 14 | target: ContractId, 15 | function_selector: Bytes, 16 | calldata: Bytes, 17 | ); 18 | } 19 | 20 | impl MyCallerContract for Contract { 21 | // ANCHOR: low_level_call_contract 22 | fn call_low_level_call( 23 | target: ContractId, 24 | function_selector: Bytes, 25 | calldata: Bytes, 26 | ) { 27 | let call_params = CallParams { 28 | coins: 0, 29 | asset_id: AssetId::from(ZERO_B256), 30 | gas: 10_000, 31 | }; 32 | 33 | call_with_function_selector(target, function_selector, calldata, call_params); 34 | } 35 | // ANCHOR_END: low_level_call_contract 36 | } 37 | -------------------------------------------------------------------------------- /e2e/sway/contracts/msg_methods/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "msg_methods" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/msg_methods/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::auth::msg_sender; 4 | 5 | abi FuelTest { 6 | #[payable] 7 | fn message_sender() -> Identity; 8 | } 9 | 10 | impl FuelTest for Contract { 11 | #[payable] 12 | fn message_sender() -> Identity { 13 | msg_sender().unwrap() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/sway/contracts/multiple_read_calls/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "multiple_read_calls" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/multiple_read_calls/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::storage_api::{read, write}; 4 | 5 | abi MyContract { 6 | #[storage(write)] 7 | fn store(input: u64); 8 | #[storage(read)] 9 | fn read() -> u64; 10 | } 11 | 12 | const COUNTER_KEY = 0x0000000000000000000000000000000000000000000000000000000000000000; 13 | 14 | impl MyContract for Contract { 15 | #[storage(write)] 16 | fn store(input: u64) { 17 | write(COUNTER_KEY, 0, input); 18 | } 19 | 20 | #[storage(read)] 21 | fn read() -> u64 { 22 | read::(COUNTER_KEY, 0).unwrap_or(0) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /e2e/sway/contracts/needs_custom_decoder/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "needs_custom_decoder" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/contracts/needs_custom_decoder/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | impl AbiEncode for [u8; 1000] { 4 | fn abi_encode(self, buffer: Buffer) -> Buffer { 5 | let mut buffer = buffer; 6 | let mut i = 0; 7 | while i < 1000 { 8 | buffer = self[i].abi_encode(buffer); 9 | i += 1; 10 | }; 11 | 12 | buffer 13 | } 14 | } 15 | 16 | abi MyContract { 17 | fn i_return_a_1k_el_array() -> [u8; 1000]; 18 | fn i_log_a_1k_el_array(); 19 | } 20 | 21 | impl MyContract for Contract { 22 | fn i_log_a_1k_el_array() { 23 | let arr: [u8; 1000] = [0; 1000]; 24 | log(arr); 25 | } 26 | 27 | fn i_return_a_1k_el_array() -> [u8; 1000] { 28 | [0; 1000] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/contracts/payable_annotation/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "payable_annotation" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/payable_annotation/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi TestContract { 4 | #[payable] 5 | fn payable() -> u64; 6 | fn non_payable() -> u64; 7 | } 8 | 9 | impl TestContract for Contract { 10 | #[payable] 11 | fn payable() -> u64 { 12 | 42 13 | } 14 | 15 | fn non_payable() -> u64 { 16 | 42 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /e2e/sway/contracts/proxy/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "proxy" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/contracts/proxy/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::execution::run_external; 4 | 5 | abi Proxy { 6 | #[storage(write)] 7 | fn set_target_contract(id: ContractId); 8 | 9 | // methods of the `huge_contract` in our e2e sway contracts 10 | #[storage(read)] 11 | fn something() -> u64; 12 | 13 | #[storage(read)] 14 | fn write_some_u64(some: u64); 15 | 16 | #[storage(read)] 17 | fn read_some_u64() -> u64; 18 | } 19 | 20 | storage { 21 | target_contract: Option = None, 22 | } 23 | 24 | impl Proxy for Contract { 25 | #[storage(write)] 26 | fn set_target_contract(id: ContractId) { 27 | storage.target_contract.write(Some(id)); 28 | } 29 | 30 | #[storage(read)] 31 | fn something() -> u64 { 32 | let target = storage.target_contract.read().unwrap(); 33 | run_external(target) 34 | } 35 | 36 | #[storage(read)] 37 | fn write_some_u64(_some: u64) { 38 | let target = storage.target_contract.read().unwrap(); 39 | run_external(target) 40 | } 41 | 42 | #[storage(read)] 43 | fn read_some_u64() -> u64 { 44 | let target = storage.target_contract.read().unwrap(); 45 | run_external(target) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /e2e/sway/contracts/revert_transaction_error/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "revert_transaction_error" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/revert_transaction_error/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn make_transaction_fail(fail: bool) -> u64; 5 | } 6 | 7 | impl MyContract for Contract { 8 | fn make_transaction_fail(fail: bool) -> u64 { 9 | if fail { 10 | revert(128); 11 | } 12 | 13 | 42 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/sway/contracts/storage/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "storage" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/storage/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::storage_api::read; 4 | 5 | storage { 6 | x: u64 = 64, 7 | y: b256 = 0x0101010101010101010101010101010101010101010101010101010101010101, 8 | } 9 | 10 | abi MyContract { 11 | #[storage(write)] 12 | fn set_storage(x: u64, y: b256); 13 | #[storage(read)] 14 | fn get_value_b256(key: b256) -> b256; 15 | #[storage(read)] 16 | fn get_value_u64(key: b256) -> u64; 17 | } 18 | 19 | impl MyContract for Contract { 20 | #[storage(write)] 21 | fn set_storage(x: u64, y: b256) { 22 | storage.x.write(x); 23 | storage.y.write(y); 24 | } 25 | 26 | #[storage(read)] 27 | fn get_value_b256(key: b256) -> b256 { 28 | read::(key, 0).unwrap() 29 | } 30 | 31 | #[storage(read)] 32 | fn get_value_u64(key: b256) -> u64 { 33 | read::(key, 0).unwrap() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /e2e/sway/contracts/token_ops/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "token_ops" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/transaction_block_height/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "transaction_block_height" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/transaction_block_height/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn get_current_height() -> u32; 5 | fn calling_this_will_produce_a_block(); 6 | } 7 | 8 | impl MyContract for Contract { 9 | fn get_current_height() -> u32 { 10 | std::block::height() 11 | } 12 | 13 | fn calling_this_will_produce_a_block() {} 14 | } 15 | -------------------------------------------------------------------------------- /e2e/sway/contracts/tx_input_output/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "tx_input_output" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/tx_input_output/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::{inputs::*, outputs::*}; 4 | 5 | configurable { 6 | ASSET_ID: AssetId = AssetId::zero(), 7 | OWNER: Address = Address::zero(), 8 | } 9 | 10 | abi TxContractTest { 11 | fn check_input(index: u64); 12 | fn check_output_is_change(index: u64); 13 | } 14 | 15 | impl TxContractTest for Contract { 16 | fn check_input(index: u64) { 17 | // Checks if coin and maybe returns owner 18 | if let Some(owner) = input_coin_owner(index) { 19 | require(owner == OWNER, "wrong owner"); 20 | 21 | let asset_id = input_asset_id(index).unwrap(); 22 | require(asset_id == ASSET_ID, "wrong asset id"); 23 | } else { 24 | revert_with_log("input is not a coin"); 25 | } 26 | } 27 | 28 | fn check_output_is_change(index: u64) { 29 | if let Some(Output::Change) = output_type(index) { 30 | let asset_to = output_asset_to(index).unwrap(); 31 | require(asset_to == OWNER, "wrong change address"); 32 | } else { 33 | revert_with_log("output is not change"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /e2e/sway/contracts/var_outputs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "var_outputs" 6 | -------------------------------------------------------------------------------- /e2e/sway/contracts/var_outputs/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn mint(coins: u64, recipient: Identity); 5 | } 6 | 7 | impl MyContract for Contract { 8 | fn mint(coins: u64, recipient: Identity) { 9 | let mut counter = 0; 10 | while counter < coins { 11 | counter += 1; 12 | std::asset::mint_to(recipient, b256::zero(), 1); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_logs" 6 | 7 | [dependencies] 8 | contract_logs_abi = { path = "../contract_logs_abi/", package = "contract_logs_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_logs_abi/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_logs_abi" 6 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_logs_abi/src/main.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | use std::logging::log; 4 | 5 | abi ContractLogs { 6 | fn produce_logs_values(); 7 | fn produce_logs_variables(); 8 | fn produce_logs_custom_types(); 9 | fn produce_logs_generic_types(); 10 | fn produce_multiple_logs(); 11 | fn produce_bad_logs(); 12 | fn produce_string_slice_log(); 13 | fn produce_string_log(); 14 | fn produce_bytes_log(); 15 | fn produce_raw_slice_log(); 16 | fn produce_vec_log(); 17 | 18 | fn produce_panic(); 19 | fn produce_panic_with_error(); 20 | } 21 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_revert_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_revert_logs" 6 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_with_contract_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_with_contract_logs" 6 | 7 | [dependencies] 8 | library = { path = "../contract_logs_abi/", package = "contract_logs_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/logs/contract_with_contract_logs/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::logging::log; 4 | use library::ContractLogs; 5 | 6 | abi ContractCaller { 7 | fn logs_from_external_contract(contract_id: ContractId) -> (); 8 | fn panic_from_external_contract(contract_id: ContractId) -> (); 9 | fn panic_error_from_external_contract(contract_id: ContractId) -> (); 10 | } 11 | 12 | impl ContractCaller for Contract { 13 | fn logs_from_external_contract(contract_id: ContractId) { 14 | // Call contract with `contract_id` and make some logs 15 | let contract_instance = abi(ContractLogs, contract_id.into()); 16 | contract_instance.produce_logs_values(); 17 | } 18 | 19 | fn panic_from_external_contract(contract_id: ContractId) { 20 | // Call contract with `contract_id` and make some logs 21 | let contract_instance = abi(ContractLogs, contract_id.into()); 22 | contract_instance.produce_panic(); 23 | } 24 | 25 | fn panic_error_from_external_contract(contract_id: ContractId) { 26 | // Call contract with `contract_id` and make some logs 27 | let contract_instance = abi(ContractLogs, contract_id.into()); 28 | contract_instance.produce_panic_with_error(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_heap_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_heap_logs" 6 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_heap_logs/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::{logging::log, string::String}; 4 | 5 | #[allow(dead_code)] 6 | enum EnumWithGeneric { 7 | VariantOne: D, 8 | VariantTwo: (), 9 | } 10 | 11 | fn main() { 12 | // String slice 13 | log("fuel"); 14 | 15 | // String 16 | log(String::from_ascii_str("fuel")); 17 | 18 | // Bytes 19 | log(String::from_ascii_str("fuel").as_bytes()); 20 | 21 | // RawSlice 22 | log(String::from_ascii_str("fuel").as_raw_slice()); 23 | 24 | // Vector 25 | let mut v = Vec::new(); 26 | v.push(1u16); 27 | v.push(2u16); 28 | v.push(3u16); 29 | 30 | let some_enum = EnumWithGeneric::VariantOne(v); 31 | let other_enum = EnumWithGeneric::VariantTwo; 32 | 33 | let mut v1 = Vec::new(); 34 | v1.push(some_enum); 35 | v1.push(other_enum); 36 | v1.push(some_enum); 37 | 38 | let mut v2 = Vec::new(); 39 | v2.push(v1); 40 | v2.push(v1); 41 | 42 | let mut v3 = Vec::new(); 43 | v3.push(v2); 44 | 45 | log(v3); 46 | } 47 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_logs" 6 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_revert_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_revert_logs" 6 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_with_contract_logs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_with_contract_logs" 6 | 7 | [dependencies] 8 | library = { path = "../contract_logs_abi/", package = "contract_logs_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/logs/script_with_contract_logs/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::logging::log; 4 | use library::ContractLogs; 5 | 6 | #[allow(dead_code)] 7 | enum MatchEnum { 8 | Logs: (), 9 | Panic: (), 10 | PanicError: (), 11 | } 12 | 13 | fn main(contract_id: ContractId, match_enum: MatchEnum) { 14 | let contract_instance = abi(ContractLogs, contract_id.into()); 15 | match match_enum { 16 | MatchEnum::Logs => { 17 | contract_instance.produce_logs_values(); 18 | 19 | let f: bool = true; 20 | let u: u64 = 42; 21 | let e: str[4] = __to_str_array("Fuel"); 22 | let l: [u8; 3] = [1u8, 2u8, 3u8]; 23 | log(f); 24 | log(u); 25 | log(e); 26 | log(l); 27 | } 28 | MatchEnum::Panic => { 29 | contract_instance.produce_panic(); 30 | } 31 | MatchEnum::PanicError => { 32 | contract_instance.produce_panic_with_error(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /e2e/sway/predicates/basic_predicate/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "basic_predicate" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/basic_predicate/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(a: u32, b: u64) -> bool { 4 | b == a.as_u64() 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_blobs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_blobs" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_blobs/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | configurable { 4 | SECRET_NUMBER: u64 = 9000, 5 | } 6 | 7 | fn main(arg1: u8, arg2: u8) -> bool { 8 | arg1 == 1 && arg2 == 19 && SECRET_NUMBER == 10001 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_configurables/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_configurables" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_tx_input_output/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_tx_input_output" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_tx_input_output/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::{inputs::*, outputs::*}; 4 | 5 | configurable { 6 | ASSET_ID: AssetId = AssetId::zero(), 7 | OWNER: Address = Address::zero(), 8 | } 9 | 10 | fn main(input_index: u64, output_index: u64) -> bool { 11 | // Checks if coin and maybe returns owner 12 | let input_ok = if let Some(owner) = input_coin_owner(input_index) { 13 | let is_owner = owner == OWNER; 14 | 15 | let asset_id = input_asset_id(input_index).unwrap(); 16 | 17 | is_owner && asset_id == ASSET_ID 18 | } else { 19 | false 20 | }; 21 | 22 | let output_ok = if let Some(Output::Change) = output_type(output_index) { 23 | let asset_to = output_asset_to(output_index).unwrap(); 24 | asset_to == OWNER 25 | } else { 26 | false 27 | }; 28 | 29 | input_ok && output_ok 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_witnesses/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_witnesses" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/predicate_witnesses/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::tx::tx_witness_data; 4 | 5 | fn main(witness_index: u64, witness_index2: u64) -> bool { 6 | let witness: u8 = tx_witness_data(witness_index).unwrap(); 7 | let witness2: u64 = tx_witness_data(witness_index2).unwrap(); 8 | 9 | witness == 64 && witness2 == 4096 10 | } 11 | -------------------------------------------------------------------------------- /e2e/sway/predicates/signatures/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "signatures" 6 | -------------------------------------------------------------------------------- /e2e/sway/predicates/signatures/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::{ 4 | b512::B512, 5 | crypto::{ 6 | message::Message, 7 | secp256k1::Secp256k1, 8 | }, 9 | inputs::input_predicate_data, 10 | }; 11 | 12 | fn extract_public_key_and_match(signature: B512, expected_public_key: b256) -> u64 { 13 | let signature = Secp256k1::from(signature); 14 | 15 | if let Result::Ok(pub_key_sig) = signature.address(Message::from(b256::zero())) 16 | { 17 | if pub_key_sig == Address::from(expected_public_key) { 18 | return 1; 19 | } 20 | } 21 | 22 | 0 23 | } 24 | 25 | fn main(signatures: [B512; 3]) -> bool { 26 | let public_keys = [ 27 | 0xd58573593432a30a800f97ad32f877425c223a9e427ab557aab5d5bb89156db0, 28 | 0x14df7c7e4e662db31fe2763b1734a3d680e7b743516319a49baaa22b2032a857, 29 | 0x3ff494fb136978c3125844625dad6baf6e87cdb1328c8a51f35bda5afe72425c, 30 | ]; 31 | 32 | let mut matched_keys = 0; 33 | 34 | matched_keys = extract_public_key_and_match(signatures[0], public_keys[0]); 35 | matched_keys = matched_keys + extract_public_key_and_match(signatures[1], public_keys[1]); 36 | matched_keys = matched_keys + extract_public_key_and_match(signatures[2], public_keys[2]); 37 | 38 | matched_keys > 1 39 | } 40 | -------------------------------------------------------------------------------- /e2e/sway/predicates/swap/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "swap" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/predicates/swap/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::outputs::{Output, output_amount, output_asset_id, output_asset_to}; 4 | fn main() -> bool { 5 | let receiver = Address::from(0x09c0b2d1a486c439a87bcba6b46a7a1a23f3897cc83a94521a96da5c23bc58db); 6 | let ask_amount = 100; 7 | let output_index = 0; 8 | let to = Address::from(output_asset_to(output_index).unwrap()); 9 | let asset_id = output_asset_id(output_index).unwrap(); 10 | let amount = output_amount(output_index).unwrap(); 11 | (to == receiver) && (amount == ask_amount) && (asset_id == AssetId::zero()) 12 | } 13 | -------------------------------------------------------------------------------- /e2e/sway/scripts/arguments/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "arguments" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/arguments/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | struct Bimbam { 4 | val: u64, 5 | } 6 | 7 | struct SugarySnack { 8 | twix: u64, 9 | mars: u64, 10 | } 11 | 12 | fn main(bim: Bimbam, bam: SugarySnack) -> Bimbam { 13 | let val = bam.twix + bim.val + (bam.mars * 2); 14 | Bimbam { val: val } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/sway/scripts/basic_script/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "basic_script" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/basic_script/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | /// Compares a to b and returns a `str[5]` 4 | fn main(a: u64, b: u32) -> str[5] { 5 | if a < b.as_u64() { 6 | let my_string: str[5] = __to_str_array("hello"); 7 | my_string 8 | } else { 9 | let my_string: str[5] = __to_str_array("heyoo"); 10 | my_string 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /e2e/sway/scripts/empty/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "empty" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/scripts/empty/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main() {} 4 | -------------------------------------------------------------------------------- /e2e/sway/scripts/require_from_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "require_from_contract" 6 | 7 | [dependencies] 8 | library = { path = "../../contracts/lib_contract_abi", package = "lib_contract_abi" } 9 | -------------------------------------------------------------------------------- /e2e/sway/scripts/require_from_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use library::LibContract; 4 | 5 | fn main(contract_id: ContractId) { 6 | let contract_instance = abi(LibContract, contract_id.into()); 7 | contract_instance.require(); 8 | } 9 | -------------------------------------------------------------------------------- /e2e/sway/scripts/reverting/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "reverting" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/reverting/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main() { 4 | assert(false) 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_array/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_array" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_array/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main(foo: [u64; 4]) -> u64 { 4 | foo[0] + foo[1] + foo[2] + foo[3] 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_asserts/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_asserts" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_blobs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_blobs" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_blobs/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | configurable { 4 | SECRET_NUMBER: u64 = 9000, 5 | } 6 | 7 | enum MyEnum { 8 | A: u64, 9 | B: u8, 10 | C: (), 11 | } 12 | 13 | struct MyStruct { 14 | field_a: MyEnum, 15 | field_b: b256, 16 | } 17 | 18 | fn main(arg1: MyStruct) -> u64 { 19 | assert_eq(SECRET_NUMBER, 10001); 20 | 21 | match arg1.field_a { 22 | MyEnum::B(value) => { 23 | assert_eq(value, 99); 24 | } 25 | _ => { 26 | assert(false) 27 | } 28 | } 29 | 30 | assert_eq( 31 | arg1.field_b, 32 | 0x1111111111111111111111111111111111111111111111111111111111111111, 33 | ); 34 | 35 | return SECRET_NUMBER; 36 | } 37 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_configurables/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_configurables" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_configurables/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | #[allow(dead_code)] 4 | enum EnumWithGeneric { 5 | VariantOne: D, 6 | VariantTwo: (), 7 | } 8 | 9 | struct StructWithGeneric { 10 | field_1: D, 11 | field_2: u64, 12 | } 13 | 14 | configurable { 15 | BOOL: bool = true, 16 | U8: u8 = 8, 17 | U16: u16 = 16, 18 | U32: u32 = 32, 19 | U64: u64 = 63, 20 | U256: u256 = 0x0000000000000000000000000000000000000000000000000000000000000008u256, 21 | B256: b256 = 0x0101010101010101010101010101010101010101010101010101010101010101, 22 | STR_4: str[4] = __to_str_array("fuel"), 23 | TUPLE: (u8, bool) = (8, true), 24 | ARRAY: [u32; 3] = [253, 254, 255], 25 | STRUCT: StructWithGeneric = StructWithGeneric { 26 | field_1: 8, 27 | field_2: 16, 28 | }, 29 | ENUM: EnumWithGeneric = EnumWithGeneric::VariantOne(true), 30 | } 31 | //U128: u128 = 128, //TODO: add once https://github.com/FuelLabs/sway/issues/5356 is done 32 | 33 | fn main() -> (bool, u8, u16, u32, u64, u256, b256, str[4], (u8, bool), [u32; 3], StructWithGeneric, EnumWithGeneric) { 34 | (BOOL, U8, U16, U32, U64, U256, B256, STR_4, TUPLE, ARRAY, STRUCT, ENUM) 35 | } 36 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_enum/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_enum" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_enum/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | #[allow(dead_code)] 4 | enum MyEnum { 5 | One: (), 6 | Two: (), 7 | Three: (), 8 | } 9 | 10 | fn main(my_enum: MyEnum) -> u64 { 11 | match my_enum { 12 | MyEnum::One => 1, 13 | MyEnum::Two => 2, 14 | MyEnum::Three => 3, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_needs_custom_decoder/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_needs_custom_decoder" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_needs_custom_decoder/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | impl AbiEncode for [u8; 1000] { 4 | #[allow(dead_code)] 5 | fn abi_encode(self, buffer: Buffer) -> Buffer { 6 | let mut buffer = buffer; 7 | let mut i = 0; 8 | while i < 1000 { 9 | buffer = self[i].abi_encode(buffer); 10 | i += 1; 11 | }; 12 | 13 | buffer 14 | } 15 | } 16 | 17 | fn main(log_instead_of_return: bool) -> Option<[u8; 1000]> { 18 | let arr: [u8; 1000] = [0; 1000]; 19 | 20 | if log_instead_of_return { 21 | log(arr); 22 | 23 | return None; 24 | } 25 | 26 | Some(arr) 27 | } 28 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_proxy/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_proxy" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_proxy/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | abi Proxy { 4 | #[storage(write)] 5 | fn set_target_contract(id: ContractId); 6 | 7 | // methods of the `huge_contract` in our e2e sway contracts 8 | #[storage(read)] 9 | fn something() -> u64; 10 | 11 | #[storage(read)] 12 | fn write_some_u64(some: u64); 13 | 14 | #[storage(read)] 15 | fn read_some_u64() -> u64; 16 | } 17 | 18 | fn main(proxy_contract_id: ContractId) -> bool { 19 | let proxy_instance = abi(Proxy, proxy_contract_id.into()); 20 | let _ = proxy_instance.something(); 21 | proxy_instance.write_some_u64(10001); 22 | let read_u_64 = proxy_instance.read_some_u64(); 23 | return read_u_64 == 10001; 24 | } 25 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_struct/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_struct" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_struct/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | configurable { 4 | MY_STRUCT: MyStruct = MyStruct { 5 | number: 10, 6 | boolean: true, 7 | }, 8 | A_NUMBER: u64 = 11, 9 | } 10 | 11 | struct MyStruct { 12 | number: u64, 13 | boolean: bool, 14 | } 15 | 16 | fn main(arg: MyStruct) -> u64 { 17 | let _calc = MY_STRUCT.number + A_NUMBER; 18 | if arg.boolean { arg.number } else { 0 } 19 | } 20 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_tx_input_output/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_tx_input_output" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/script_tx_input_output/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::{inputs::*, outputs::*}; 4 | 5 | configurable { 6 | ASSET_ID: AssetId = AssetId::zero(), 7 | OWNER: Address = Address::zero(), 8 | } 9 | 10 | fn main(input_index: u64, output_index: u64) { 11 | // Checks if coin and maybe returns owner 12 | if let Some(owner) = input_coin_owner(input_index) { 13 | require(owner == OWNER, "wrong owner"); 14 | 15 | let asset_id = input_asset_id(input_index).unwrap(); 16 | require(asset_id == ASSET_ID, "wrong asset id"); 17 | } else { 18 | revert_with_log("input is not a coin"); 19 | } 20 | 21 | if let Some(Output::Change) = output_type(output_index) { 22 | let asset_to = output_asset_to(output_index).unwrap(); 23 | require(asset_to == OWNER, "wrong change address"); 24 | } else { 25 | revert_with_log("output is not change"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /e2e/sway/scripts/transfer_script/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "transfer_script" 6 | -------------------------------------------------------------------------------- /e2e/sway/scripts/transfer_script/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::asset::transfer; 4 | 5 | fn main(amount: u64, asset: AssetId, receiver: Identity) -> () { 6 | transfer(receiver, asset, amount); 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/b256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "b256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/b256/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi MyContract { 4 | fn b256_as_output() -> b256; 5 | fn b256_as_input(foo: b256) -> bool; 6 | } 7 | 8 | impl MyContract for Contract { 9 | fn b256_as_output() -> b256 { 10 | 0x0202020202020202020202020202020202020202020202020202020202020202 11 | } 12 | 13 | fn b256_as_input(foo: b256) -> bool { 14 | foo == 0x0101010101010101010101010101010101010101010101010101010101010101 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/b512/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "b512" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/b512/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::b512::B512; 4 | 5 | const HI_BITS = 0xbd0c9b8792876713afa8bff383eebf31c43437823ed761cc3600d0016de5110c; 6 | const LO_BITS = 0x44ac566bd156b4fc71a4a4cb2655d3dd360c695edb17dc3b64d611e122fea23d; 7 | const LO_BITS2 = 0x54ac566bd156b4fc71a4a4cb2655d3dd360c695edb17dc3b64d611e122fea23d; 8 | 9 | abi MyContract { 10 | fn b512_as_output() -> B512; 11 | fn b512_as_input(b512: B512) -> bool; 12 | } 13 | 14 | impl MyContract for Contract { 15 | fn b512_as_output() -> B512 { 16 | B512::from((HI_BITS, LO_BITS)) 17 | } 18 | 19 | fn b512_as_input(b512: B512) -> bool { 20 | let expected_b512 = B512::from((HI_BITS, LO_BITS2)); 21 | 22 | b512 == expected_b512 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/bytes/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "bytes" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/call_empty_return/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "call_empty_return" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/call_empty_return/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::storage_api::write; 4 | 5 | abi TestContract { 6 | #[storage(write)] 7 | fn store_value(val: u64); 8 | } 9 | 10 | const COUNTER_KEY = 0x0000000000000000000000000000000000000000000000000000000000000000; 11 | 12 | impl TestContract for Contract { 13 | #[storage(write)] 14 | fn store_value(val: u64) { 15 | write(COUNTER_KEY, 0, val); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/complex_types_contract/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "complex_types_contract" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/complex_types_contract/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::storage::storage_api::{read, write}; 4 | 5 | struct EmptyStruct {} 6 | 7 | #[allow(dead_code)] 8 | struct CounterConfig { 9 | dummy: bool, 10 | initial_value: u64, 11 | } 12 | 13 | abi TestContract { 14 | #[storage(write)] 15 | fn initialize_counter(config: CounterConfig) -> u64; 16 | #[storage(read, write)] 17 | fn increment_counter(amount: u64) -> u64; 18 | fn get_empty_struct() -> EmptyStruct; 19 | fn input_empty_struct(es: EmptyStruct) -> bool; 20 | } 21 | 22 | const COUNTER_KEY = 0x0000000000000000000000000000000000000000000000000000000000000000; 23 | 24 | impl TestContract for Contract { 25 | #[storage(write)] 26 | fn initialize_counter(config: CounterConfig) -> u64 { 27 | let value = config.initial_value; 28 | write(COUNTER_KEY, 0, value); 29 | value 30 | } 31 | 32 | #[storage(read, write)] 33 | fn increment_counter(amount: u64) -> u64 { 34 | let value = read::(COUNTER_KEY, 0).unwrap_or(0) + amount; 35 | write(COUNTER_KEY, 0, value); 36 | value 37 | } 38 | 39 | fn get_empty_struct() -> EmptyStruct { 40 | EmptyStruct {} 41 | } 42 | 43 | fn input_empty_struct(es: EmptyStruct) -> bool { 44 | let EmptyStruct {} = es; 45 | 46 | true 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/contract_output_test/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "contract_output_test" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/contract_output_test/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | struct MyStruct { 4 | foo: u8, 5 | bar: bool, 6 | } 7 | 8 | abi TestContract { 9 | fn is_even(value: u64) -> bool; 10 | fn return_my_string(value: str[4]) -> str[4]; 11 | fn return_my_struct(value: MyStruct) -> MyStruct; 12 | } 13 | 14 | impl TestContract for Contract { 15 | fn is_even(value: u64) -> bool { 16 | if (value / 2) * 2 == value { 17 | true 18 | } else { 19 | false 20 | } 21 | } 22 | 23 | fn return_my_string(value: str[4]) -> str[4] { 24 | value 25 | } 26 | 27 | fn return_my_struct(value: MyStruct) -> MyStruct { 28 | value 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/empty_arguments/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "empty_arguments" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/empty_arguments/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi TestContract { 4 | fn method_with_empty_argument() -> u64; 5 | } 6 | 7 | impl TestContract for Contract { 8 | fn method_with_empty_argument() -> u64 { 9 | 63 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/enum_as_input/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "enum_as_input" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/enum_encoding/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "enum_encoding" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/enum_inside_struct/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "enum_inside_struct" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/enum_inside_struct/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | #[allow(dead_code)] 4 | enum Shaker { 5 | Cosmopolitan: u64, 6 | Mojito: u64, 7 | } 8 | 9 | struct Cocktail { 10 | the_thing_you_mix_in: Shaker, 11 | glass: u64, 12 | } 13 | 14 | abi TestContract { 15 | fn return_enum_inside_struct(a: u64) -> Cocktail; 16 | fn take_enum_inside_struct(c: Cocktail) -> u64; 17 | } 18 | 19 | impl TestContract for Contract { 20 | fn return_enum_inside_struct(a: u64) -> Cocktail { 21 | Cocktail { 22 | the_thing_you_mix_in: Shaker::Mojito(a), 23 | glass: 333, 24 | } 25 | } 26 | 27 | fn take_enum_inside_struct(c: Cocktail) -> u64 { 28 | c.glass 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/evm_address/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "evm_address" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/evm_address/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::vm::evm::evm_address::EvmAddress; 4 | 5 | abi EvmTest { 6 | fn evm_address_as_input(evm_addr: EvmAddress) -> bool; 7 | fn evm_address_from_literal() -> EvmAddress; 8 | fn evm_address_from_argument(raw_address: b256) -> EvmAddress; 9 | } 10 | 11 | impl EvmTest for Contract { 12 | fn evm_address_as_input(evm_addr: EvmAddress) -> bool { 13 | let evm_addr2 = EvmAddress::from(0x1616060606060606060606060606060606060606060606060606060606060606); 14 | 15 | evm_addr == evm_addr2 16 | } 17 | 18 | fn evm_address_from_literal() -> EvmAddress { 19 | EvmAddress::from(0x0606060606060606060606060606060606060606060606060606060606060606) 20 | } 21 | 22 | fn evm_address_from_argument(raw_address: b256) -> EvmAddress { 23 | EvmAddress::from(raw_address) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/generics/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "generics" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/heap_type_in_enums/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "heap_type_in_enums" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/heap_types/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "heap_types" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/heap_types/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::bytes::Bytes; 4 | use std::string::String; 5 | 6 | #[allow(dead_code)] 7 | struct StructGenerics { 8 | one: T, 9 | two: K, 10 | three: U, 11 | } 12 | 13 | #[allow(dead_code)] 14 | enum EnumGeneric { 15 | One: H, 16 | Two: I, 17 | } 18 | 19 | abi HeapTypesContract { 20 | fn nested_heap_types() -> EnumGeneric>, String>; 21 | } 22 | 23 | impl HeapTypesContract for Contract { 24 | fn nested_heap_types() -> EnumGeneric>, String> { 25 | let mut some_vec = Vec::new(); 26 | some_vec.push(2u8); 27 | some_vec.push(4u8); 28 | some_vec.push(8u8); 29 | 30 | let struct_generics = StructGenerics { 31 | one: Bytes::from(some_vec), 32 | two: String::from_ascii_str("fuel"), 33 | three: some_vec.as_raw_slice(), 34 | }; 35 | 36 | let mut enum_vec = Vec::new(); 37 | enum_vec.push(struct_generics); 38 | enum_vec.push(struct_generics); 39 | 40 | EnumGeneric::One(enum_vec) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/identity/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "identity" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/native_types/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "native_types" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/native_types/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | struct User { 4 | address: Address, 5 | weight: u64, 6 | } 7 | 8 | abi MyContract { 9 | fn wrapped_address(user: User) -> User; 10 | fn unwrapped_address(addr: Address) -> Address; 11 | } 12 | 13 | impl MyContract for Contract { 14 | fn wrapped_address(user: User) -> User { 15 | user 16 | } 17 | 18 | fn unwrapped_address(addr: Address) -> Address { 19 | addr 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/nested_structs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "nested_structs" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/options/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "options" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/raw_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "raw_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/results/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "results" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/std_lib_string/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "std_lib_string" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/std_lib_string/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::string::String; 4 | use std::assert::assert_eq; 5 | use std::bytes::Bytes; 6 | 7 | abi MyContract { 8 | fn return_dynamic_string() -> String; 9 | fn accepts_dynamic_string(s: String); 10 | fn echoes_dynamic_string(s: String) -> String; 11 | } 12 | 13 | impl MyContract for Contract { 14 | fn return_dynamic_string() -> String { 15 | String::from_ascii_str("Hello World") 16 | } 17 | 18 | fn accepts_dynamic_string(string: String) { 19 | assert_eq(string, String::from_ascii_str("Hello World")); 20 | } 21 | 22 | fn echoes_dynamic_string(string: String) -> String { 23 | string 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/str_in_array/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "str_in_array" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/str_in_array/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi TestContract { 4 | fn take_array_string_shuffle(a: [str[3]; 3]) -> [str[3]; 3]; 5 | fn take_array_string_return_single(a: [str[3]; 3]) -> [str[3]; 1]; 6 | fn take_array_string_return_single_element(a: [str[3]; 3]) -> str[3]; 7 | } 8 | 9 | impl TestContract for Contract { 10 | fn take_array_string_shuffle(a: [str[3]; 3]) -> [str[3]; 3] { 11 | [a[2], a[0], a[1]] 12 | } 13 | 14 | fn take_array_string_return_single(a: [str[3]; 3]) -> [str[3]; 1] { 15 | [a[0]] 16 | } 17 | 18 | fn take_array_string_return_single_element(a: [str[3]; 3]) -> str[3] { 19 | a[1] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/string_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "string_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/string_slice/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | abi RawSliceContract { 4 | fn handles_str(input: str) -> str; 5 | } 6 | 7 | impl RawSliceContract for Contract { 8 | fn handles_str(input: str) -> str { 9 | assert_eq(input, "contract-input"); 10 | 11 | "contract-return" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/tuples/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "tuples" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/two_structs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "two_structs" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/two_structs/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | pub struct StructOne { 4 | foo: u64, 5 | } 6 | 7 | pub struct StructTwo { 8 | bar: u64, 9 | } 10 | 11 | abi MyTest { 12 | fn something(input: StructOne) -> u64; 13 | fn something_else(input: StructTwo) -> u64; 14 | } 15 | 16 | impl MyTest for Contract { 17 | fn something(input: StructOne) -> u64 { 18 | let v = input.foo; 19 | v + 1 20 | } 21 | fn something_else(input: StructTwo) -> u64 { 22 | let v = input.bar; 23 | v - 1 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/type_inside_enum/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "type_inside_enum" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/u128/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "u128" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/u128/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | use std::u128::U128; 4 | 5 | #[allow(dead_code)] 6 | enum SomeEnum { 7 | A: bool, 8 | B: T, 9 | } 10 | 11 | abi MyContract { 12 | fn u128_sum_and_ret(some_u128: U128) -> U128; 13 | fn u128_in_enum_input(some_enum: SomeEnum); 14 | fn u128_in_enum_output() -> SomeEnum; 15 | } 16 | 17 | impl MyContract for Contract { 18 | fn u128_sum_and_ret(arg: U128) -> U128 { 19 | arg + U128::from((3, 4)) 20 | } 21 | 22 | fn u128_in_enum_input(some_enum: SomeEnum) { 23 | if let SomeEnum::B(some_u128) = some_enum { 24 | let expected_u128 = U128::from((3, 3)); 25 | require( 26 | some_u128 == expected_u128, 27 | "given u128 didn't match the expected u128", 28 | ); 29 | } else { 30 | require(false, "enum was not of variant B: u128"); 31 | } 32 | } 33 | 34 | fn u128_in_enum_output() -> SomeEnum { 35 | SomeEnum::B(U128::from((4, 4))) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/u256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "u256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/u256/src/main.sw: -------------------------------------------------------------------------------- 1 | contract; 2 | 3 | #[allow(dead_code)] 4 | enum SomeEnum { 5 | A: bool, 6 | B: T, 7 | } 8 | 9 | abi MyContract { 10 | fn u256_sum_and_ret(some_u256: u256) -> u256; 11 | fn u256_in_enum_output() -> SomeEnum; 12 | fn u256_in_enum_input(some_enum: SomeEnum); 13 | } 14 | 15 | impl MyContract for Contract { 16 | fn u256_sum_and_ret(arg: u256) -> u256 { 17 | arg + 0x0000000000000003000000000000000400000000000000050000000000000006u256 18 | } 19 | 20 | fn u256_in_enum_output() -> SomeEnum { 21 | SomeEnum::B(0x0000000000000001000000000000000200000000000000030000000000000004u256) 22 | } 23 | 24 | fn u256_in_enum_input(some_enum: SomeEnum) { 25 | if let SomeEnum::B(some_u256) = some_enum { 26 | require( 27 | some_u256 == 0x0000000000000002000000000000000300000000000000040000000000000005u256, 28 | "given u256 didn't match the expected u256", 29 | ); 30 | } else { 31 | require(false, "enum was not of variant B: u256"); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/vector_output/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "vector_output" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/vectors/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "vectors" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/vectors/src/data_structures.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub struct SomeStruct { 4 | pub a: T, 5 | } 6 | 7 | pub enum SomeEnum { 8 | a: T, 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/types/contracts/vectors/src/utils.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub fn vec_from(vals: [u32; 3]) -> Vec { 4 | let mut vec = Vec::new(); 5 | vec.push(vals[0]); 6 | vec.push(vals[1]); 7 | vec.push(vals[2]); 8 | vec 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/address/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "address" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/address/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(input: Address) -> bool { 4 | let expected_addr = Address::from(0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a); 5 | 6 | input == expected_addr 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/enums/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "enums" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/enums/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | #[allow(dead_code)] 4 | enum TestEnum { 5 | A: u64, 6 | B: bool, 7 | } 8 | 9 | #[allow(dead_code)] 10 | enum AnotherTestEnum { 11 | A: u64, 12 | B: u64, 13 | } 14 | 15 | fn main(test_enum: TestEnum, test_enum2: AnotherTestEnum) -> bool { 16 | if let TestEnum::A(a) = test_enum { 17 | if let AnotherTestEnum::B(b) = test_enum2 { 18 | return a == b; 19 | } 20 | } 21 | 22 | false 23 | } 24 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_b256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_b256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_b256/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(foo: b256) -> bool { 4 | foo == 0x0101010101010101010101010101010101010101010101010101010101010101 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_bytes/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_bytes" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_bytes/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::bytes::Bytes; 4 | 5 | #[allow(dead_code)] 6 | enum SomeEnum { 7 | First: bool, 8 | Second: T, 9 | } 10 | 11 | struct Wrapper { 12 | inner: T, 13 | inner_enum: SomeEnum, 14 | } 15 | 16 | fn expected_bytes() -> Bytes { 17 | let mut bytes = Bytes::new(); 18 | 19 | bytes.push(40u8); 20 | bytes.push(41u8); 21 | bytes.push(42u8); 22 | 23 | bytes 24 | } 25 | 26 | fn valid_bytes(bytes: Bytes) -> bool { 27 | bytes == expected_bytes() 28 | } 29 | 30 | fn valid_vec(arg: Vec) -> bool { 31 | if arg.len() != 2 { 32 | return false; 33 | } 34 | 35 | valid_bytes(arg.get(0).unwrap()) && valid_bytes(arg.get(1).unwrap()) 36 | } 37 | 38 | fn main(wrapper: Wrapper>) -> bool { 39 | if let SomeEnum::Second(enum_bytes) = wrapper.inner_enum { 40 | valid_bytes(enum_bytes) && valid_vec(wrapper.inner) 41 | } else { 42 | false 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_bytes_hash/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_bytes_hash" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_bytes_hash/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::bytes::Bytes; 4 | use std::hash::{Hash, sha256}; 5 | 6 | fn main(bytes: Bytes, hash: b256) -> bool { 7 | sha256(bytes) == hash 8 | } 9 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_generics/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_generics" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_generics/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | struct GenericStruct { 4 | value: U, 5 | } 6 | 7 | #[allow(dead_code)] 8 | enum GenericEnum { 9 | Generic: GenericStruct, 10 | AnotherGeneric: V, 11 | } 12 | 13 | fn main( 14 | generic_struct: GenericStruct, 15 | generic_enum: GenericEnum, 16 | ) -> bool { 17 | if let GenericEnum::Generic(other_struct) = generic_enum { 18 | return other_struct.value == generic_struct.value.as_u16(); 19 | } 20 | 21 | false 22 | } 23 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_raw_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_raw_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_raw_slice/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | #[allow(dead_code)] 4 | enum SomeEnum { 5 | First: bool, 6 | Second: T, 7 | } 8 | 9 | struct Wrapper { 10 | inner: T, 11 | inner_enum: SomeEnum, 12 | } 13 | 14 | fn valid_raw_slice(slice: raw_slice) -> bool { 15 | let vec: Vec = Vec::from(slice); 16 | vec.len() == 3 && vec.get(0).unwrap() == 40 && vec.get(1).unwrap() == 41 && vec.get(2).unwrap() == 42 17 | } 18 | 19 | fn valid_vec(vec: Vec) -> bool { 20 | vec.len() == 2 && valid_raw_slice(vec.get(0).unwrap()) && valid_raw_slice(vec.get(1).unwrap()) 21 | } 22 | 23 | fn main(wrapper: Wrapper>) -> bool { 24 | if let SomeEnum::Second(enum_raw_slice) = wrapper.inner_enum 25 | { 26 | valid_raw_slice(enum_raw_slice) && valid_vec(wrapper.inner) 27 | } else { 28 | false 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_std_lib_string/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_std_lib_string" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_std_lib_string/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::string::String; 4 | 5 | fn main(_arg_0: u64, _arg_1: u64, string: String) -> bool { 6 | string == String::from_ascii_str("Hello World") 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_string_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_string_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_string_slice/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(input: str) -> bool { 4 | input == "predicate-input" 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_tuples/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_tuples" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_tuples/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | struct TestStruct { 4 | value: u32, 5 | } 6 | 7 | #[allow(dead_code)] 8 | enum TestEnum { 9 | Value: u64, 10 | OtherValue: u32, 11 | } 12 | 13 | fn main(input_tuple: (u64, TestStruct, TestEnum), number: u64) -> bool { 14 | let (u64_number, test_struct, test_enum) = input_tuple; 15 | 16 | if let TestEnum::Value(enum_value) = test_enum { 17 | return u64_number == 16 && test_struct.value == 32u32 && enum_value == 64 && number == 128; 18 | } 19 | 20 | false 21 | } 22 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_u128/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_u128" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_u128/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | use std::u128::U128; 4 | 5 | fn main(arg: U128) -> bool { 6 | arg == U128::from((8, 2)) 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_u256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_u256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_u256/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(arg: u256) -> bool { 4 | arg == 0x000000000000000a000000000000000b000000000000000c000000000000000du256 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_vector/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_vector" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_vector/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(a: u32, b: u64, c: Vec) -> bool { 4 | let number: u64 = c.get(2).unwrap(); 5 | number == (b + a.as_u64()) 6 | } 7 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/predicate_vectors/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "predicate_vectors" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/structs/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "structs" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/structs/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | struct TestStruct { 4 | value: u64, 5 | } 6 | 7 | struct AnotherTestStruct { 8 | value: u64, 9 | number: u64, 10 | } 11 | 12 | fn main(test_struct: TestStruct, test_struct2: AnotherTestStruct) -> bool { 13 | test_struct.value == (test_struct2.value + test_struct2.number) 14 | } 15 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/u64/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "u64" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/predicates/u64/src/main.sw: -------------------------------------------------------------------------------- 1 | predicate; 2 | 3 | fn main(a: u64) -> bool { 4 | a == 32768 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/options_results/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "options_results" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/options_results/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | pub enum TestError { 4 | ZimZam: str[5], 5 | } 6 | 7 | fn main(bim: Option, _bam: Option) -> Result, TestError> { 8 | if let Option::Some(42) = bim { 9 | Result::Ok(Option::Some(true)) 10 | } else if let Option::Some(_) = bim { 11 | Result::Ok(Option::None) 12 | } else { 13 | Result::Err(TestError::ZimZam(__to_str_array("error"))) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_b256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_b256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_b256/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main(foo: b256) -> b256 { 4 | assert_eq( 5 | foo, 6 | 0x0101010101010101010101010101010101010101010101010101010101010101, 7 | ); 8 | 9 | 0x0202020202020202020202020202020202020202020202020202020202020202 10 | } 11 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_bytes/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_bytes" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_bytes/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::bytes::Bytes; 4 | 5 | #[allow(dead_code)] 6 | enum SomeEnum { 7 | First: bool, 8 | Second: T, 9 | } 10 | 11 | struct Wrapper { 12 | inner: T, 13 | inner_enum: SomeEnum, 14 | } 15 | 16 | fn expected_bytes() -> Bytes { 17 | let mut bytes = Bytes::new(); 18 | 19 | bytes.push(40u8); 20 | bytes.push(41u8); 21 | bytes.push(42u8); 22 | 23 | bytes 24 | } 25 | 26 | fn main(_arg: u64, wrapper: Wrapper>) { 27 | if let SomeEnum::Second(enum_bytes) = wrapper.inner_enum { 28 | require( 29 | enum_bytes == expected_bytes(), 30 | "wrapper.inner_enum didn't carry the expected bytes", 31 | ) 32 | } else { 33 | require(false, "enum was not of variant Second"); 34 | } 35 | 36 | let inner_vec = wrapper.inner; 37 | require( 38 | inner_vec 39 | .len() == 2, 40 | "Expected wrapper.inner vector to have 2 elements", 41 | ); 42 | require( 43 | inner_vec 44 | .get(0) 45 | .unwrap() == expected_bytes(), 46 | "wrapper.inner[0] didn't match expectation", 47 | ); 48 | require( 49 | inner_vec 50 | .get(1) 51 | .unwrap() == expected_bytes(), 52 | "wrapper.inner[1] didn't match expectation", 53 | ); 54 | } 55 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_generics/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_generics" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_generics/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | struct GenericBimbam { 4 | val: U, 5 | } 6 | 7 | #[allow(dead_code)] 8 | struct GenericSnack { 9 | twix: GenericBimbam, 10 | mars: V, 11 | } 12 | 13 | fn main( 14 | bim: GenericBimbam, 15 | bam: GenericSnack, 16 | ) -> (GenericSnack, GenericBimbam) { 17 | ( 18 | GenericSnack { 19 | twix: GenericBimbam { 20 | val: bam.mars.as_u64(), 21 | }, 22 | mars: 2u32 * bim.val.as_u32(), 23 | }, 24 | GenericBimbam { val: 255u8 }, 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_heap_types/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_heap_types" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_heap_types/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::bytes::Bytes; 4 | use std::string::String; 5 | 6 | #[allow(dead_code)] 7 | struct StructGenerics { 8 | one: T, 9 | two: K, 10 | three: U, 11 | } 12 | 13 | #[allow(dead_code)] 14 | enum EnumGeneric { 15 | One: H, 16 | Two: I, 17 | } 18 | 19 | fn main() -> EnumGeneric>>, String> { 20 | let mut some_vec = Vec::new(); 21 | some_vec.push(2u8); 22 | some_vec.push(4u8); 23 | some_vec.push(8u8); 24 | 25 | let struct_generics = StructGenerics { 26 | one: Bytes::from(some_vec), 27 | two: String::from_ascii_str("fuel"), 28 | three: some_vec, 29 | }; 30 | 31 | let mut enum_vec = Vec::new(); 32 | enum_vec.push(struct_generics); 33 | enum_vec.push(struct_generics); 34 | 35 | EnumGeneric::One(enum_vec) 36 | } 37 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_raw_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_raw_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_std_lib_string/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_std_lib_string" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_std_lib_string/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::string::String; 4 | 5 | fn main(string: String) -> String { 6 | assert_eq(string, String::from_ascii_str("script-input")); 7 | 8 | String::from_ascii_str("script-return") 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_string_slice/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_string_slice" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_string_slice/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main(input: str) -> str { 4 | assert_eq(input, "script-input"); 5 | 6 | "script-return" 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_tuples/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_tuples" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_tuples/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | #[allow(dead_code)] 4 | struct Bim { 5 | bim: u64, 6 | } 7 | 8 | #[allow(dead_code)] 9 | struct Bam { 10 | bam: str[5], 11 | } 12 | 13 | #[allow(dead_code)] 14 | struct Boum { 15 | boum: bool, 16 | } 17 | 18 | fn main(_my_tuple: (Bim, Bam, Boum), _zim: Bam) -> ((Boum, Bim, Bam), u64) { 19 | ( 20 | ( 21 | Boum { boum: true }, 22 | Bim { bim: 193817 }, 23 | Bam { 24 | bam: __to_str_array("hello"), 25 | }, 26 | ), 27 | 42242, 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_u128/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_u128" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_u128/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | use std::u128::U128; 4 | 5 | fn main(arg: U128) -> U128 { 6 | arg + U128::from((8, 2)) 7 | } 8 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_u256/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_u256" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_u256/src/main.sw: -------------------------------------------------------------------------------- 1 | script; 2 | 3 | fn main(arg: u256) -> u256 { 4 | arg + 0x0000000000000006000000000000000700000000000000080000000000000009u256 5 | } 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_vectors/Forc.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | authors = ["Fuel Labs "] 3 | entry = "main.sw" 4 | license = "Apache-2.0" 5 | name = "script_vectors" 6 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_vectors/src/data_structures.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub struct SomeStruct { 4 | pub a: T, 5 | } 6 | 7 | pub enum SomeEnum { 8 | a: T, 9 | } 10 | -------------------------------------------------------------------------------- /e2e/sway/types/scripts/script_vectors/src/utils.sw: -------------------------------------------------------------------------------- 1 | library; 2 | 3 | pub fn vec_from(vals: [u32; 3]) -> Vec { 4 | let mut vec = Vec::new(); 5 | vec.push(vals[0]); 6 | vec.push(vals[1]); 7 | vec.push(vals[2]); 8 | vec 9 | } 10 | -------------------------------------------------------------------------------- /e2e/tests/from_token.rs: -------------------------------------------------------------------------------- 1 | use fuels::{core::traits::Tokenizable, prelude::*, types::Token}; 2 | 3 | #[tokio::test] 4 | async fn create_struct_from_decoded_tokens() -> Result<()> { 5 | abigen!(Contract( 6 | name = "SimpleContract", 7 | abi = "e2e/sway/types/contracts/nested_structs/out/release/nested_structs-abi.json" 8 | )); 9 | 10 | let u32_token = Token::U32(10); 11 | let bool_token = Token::Bool(true); 12 | let struct_from_tokens = SomeStruct::from_token(Token::Struct(vec![u32_token, bool_token]))?; 13 | 14 | assert_eq!(10, struct_from_tokens.field); 15 | assert!(struct_from_tokens.field_2); 16 | 17 | Ok(()) 18 | } 19 | 20 | #[tokio::test] 21 | async fn create_nested_struct_from_decoded_tokens() -> Result<()> { 22 | abigen!(Contract( 23 | name = "SimpleContract", 24 | abi = "e2e/sway/types/contracts/nested_structs/out/release/nested_structs-abi.json" 25 | )); 26 | 27 | let u32_token = Token::U32(10); 28 | let bool_token = Token::Bool(true); 29 | let inner_struct_token = Token::Struct(vec![u32_token, bool_token]); 30 | 31 | let nested_struct_from_tokens = AllStruct::from_token(Token::Struct(vec![inner_struct_token]))?; 32 | 33 | assert_eq!(10, nested_struct_from_tokens.some_struct.field); 34 | assert!(nested_struct_from_tokens.some_struct.field_2); 35 | 36 | Ok(()) 37 | } 38 | -------------------------------------------------------------------------------- /e2e/tests/imports.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod tests { 3 | #[test] 4 | fn provides_output_type() { 5 | // test exists because we've excluded fuel_tx::Output twice 6 | #[allow(unused_imports)] 7 | use fuels::types::output::Output; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /examples/codec/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-codec" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK codec examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | tokio = { workspace = true, features = ["full"] } 15 | -------------------------------------------------------------------------------- /examples/contracts/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-contracts" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK contract examples." 11 | 12 | [dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | rand = { workspace = true, features = ["default"] } 15 | tokio = { workspace = true, features = ["full"] } 16 | tempfile = { workspace = true } 17 | 18 | [features] 19 | fuel-core-lib = ["fuels/fuel-core-lib"] 20 | rocksdb = ["fuels/rocksdb"] 21 | -------------------------------------------------------------------------------- /examples/cookbook/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-cookbook" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK cookbook examples." 11 | 12 | [dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | rand = { workspace = true } 15 | tokio = { workspace = true, features = ["full"] } 16 | 17 | [features] 18 | rocksdb = ["fuels/rocksdb"] 19 | fuel-core-lib = ["fuels/fuel-core-lib"] 20 | -------------------------------------------------------------------------------- /examples/debugging/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-debugging" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK debugging examples." 11 | 12 | [dev-dependencies] 13 | fuel-abi-types = { workspace = true } 14 | fuels = { workspace = true, features = ["default"] } 15 | rand = { workspace = true } 16 | serde_json = { workspace = true } 17 | tokio = { workspace = true, features = ["full"] } 18 | -------------------------------------------------------------------------------- /examples/macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-macros" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK macro examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | tokio = { workspace = true, features = ["full"] } 15 | -------------------------------------------------------------------------------- /examples/predicates/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-predicates" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK predicate examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | rand = { workspace = true } 15 | tokio = { workspace = true, features = ["full"] } 16 | -------------------------------------------------------------------------------- /examples/providers/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-providers" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK provider examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | rand = { workspace = true } 15 | tokio = { workspace = true, features = ["full"] } 16 | -------------------------------------------------------------------------------- /examples/rust_bindings/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-rust-bindings" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK examples for Rust-native bindings" 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | fuels-code-gen = { workspace = true } 15 | fuels-macros = { workspace = true } 16 | proc-macro2 = { workspace = true } 17 | rand = { workspace = true } 18 | tokio = { workspace = true, features = ["full"] } 19 | -------------------------------------------------------------------------------- /examples/rust_bindings/src/abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "programType": "contract", 3 | "specVersion": "1", 4 | "encodingVersion": "1", 5 | "concreteTypes": [ 6 | { 7 | "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", 8 | "type": "u64" 9 | } 10 | ], 11 | "functions": [ 12 | { 13 | "inputs": [ 14 | { 15 | "name": "value", 16 | "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" 17 | } 18 | ], 19 | "name": "initialize_counter", 20 | "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" 21 | }, 22 | { 23 | "inputs": [ 24 | { 25 | "name": "value", 26 | "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" 27 | } 28 | ], 29 | "name": "increment_counter", 30 | "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" 31 | } 32 | ], 33 | "metadataTypes": [] 34 | } 35 | -------------------------------------------------------------------------------- /examples/types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-types" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK types examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default"] } 14 | rand = { workspace = true } 15 | tokio = { workspace = true, features = ["full"] } 16 | -------------------------------------------------------------------------------- /examples/wallets/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-example-wallets" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | description = "Fuel Rust SDK wallet examples." 11 | 12 | [dev-dependencies] 13 | fuels = { workspace = true, features = ["default", "accounts-keystore"] } 14 | rand = { workspace = true } 15 | tokio = { workspace = true, features = ["full"] } 16 | -------------------------------------------------------------------------------- /packages/fuels-accounts/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "std")] 2 | mod account; 3 | #[cfg(feature = "std")] 4 | mod accounts_utils; 5 | #[cfg(all(feature = "std", feature = "keystore"))] 6 | pub mod keystore; 7 | #[cfg(feature = "std")] 8 | pub mod provider; 9 | #[cfg(feature = "std")] 10 | pub mod wallet; 11 | 12 | #[cfg(feature = "std")] 13 | pub use account::*; 14 | 15 | #[cfg(feature = "coin-cache")] 16 | mod coin_cache; 17 | 18 | pub mod predicate; 19 | pub mod signers; 20 | #[cfg(test)] 21 | mod test { 22 | #[test] 23 | fn sdl_is_the_same_as_from_fuel() { 24 | let file_sdl = include_str!("./schema/schema.sdl"); 25 | 26 | let core_sdl = String::from_utf8(fuel_core_client::SCHEMA_SDL.to_vec()).unwrap(); 27 | 28 | assert_eq!(file_sdl, &core_sdl); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/fuels-accounts/src/provider/supported_fuel_core_version.rs: -------------------------------------------------------------------------------- 1 | pub const SUPPORTED_FUEL_CORE_VERSION: semver::Version = semver::Version::new(0, 43, 2); 2 | -------------------------------------------------------------------------------- /packages/fuels-accounts/src/signers.rs: -------------------------------------------------------------------------------- 1 | pub mod derivation { 2 | pub const BIP44_PURPOSE: &str = "44'"; 3 | pub const COIN_TYPE: &str = "1179993420'"; 4 | pub const DEFAULT_DERIVATION_PATH: &str = "m/44'/1179993420'/0'/0/0"; 5 | } 6 | 7 | #[cfg(any(feature = "signer-aws-kms", feature = "signer-google-kms"))] 8 | pub mod kms; 9 | 10 | pub mod fake; 11 | pub mod private_key; 12 | -------------------------------------------------------------------------------- /packages/fuels-accounts/src/signers/fake.rs: -------------------------------------------------------------------------------- 1 | use async_trait::async_trait; 2 | use fuel_crypto::{Message, Signature}; 3 | use fuels_core::{ 4 | traits::Signer, 5 | types::{Address, errors::Result}, 6 | }; 7 | 8 | use super::private_key::PrivateKeySigner; 9 | 10 | #[derive(Clone, Debug, PartialEq, Eq)] 11 | pub struct FakeSigner { 12 | address: Address, 13 | } 14 | 15 | impl From for FakeSigner { 16 | fn from(signer: PrivateKeySigner) -> Self { 17 | Self { 18 | address: signer.address(), 19 | } 20 | } 21 | } 22 | 23 | impl FakeSigner { 24 | pub fn new(address: Address) -> Self { 25 | Self { address } 26 | } 27 | } 28 | 29 | #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] 30 | #[cfg_attr(not(target_arch = "wasm32"), async_trait)] 31 | impl Signer for FakeSigner { 32 | async fn sign(&self, _message: Message) -> Result { 33 | Ok(Signature::default()) 34 | } 35 | 36 | fn address(&self) -> Address { 37 | self.address 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-code-gen" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | rust-version = { workspace = true } 10 | description = "Used for code generation in the Fuel Rust SDK" 11 | 12 | [dependencies] 13 | Inflector = { workspace = true } 14 | fuel-abi-types = { workspace = true } 15 | itertools = { workspace = true } 16 | proc-macro2 = { workspace = true } 17 | quote = { workspace = true } 18 | regex = { workspace = true } 19 | serde_json = { workspace = true } 20 | syn = { workspace = true } 21 | 22 | [dev-dependencies] 23 | pretty_assertions = { workspace = true, features = ["alloc"] } 24 | 25 | [package.metadata.cargo-machete] 26 | ignored = ["Inflector"] 27 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/src/error.rs: -------------------------------------------------------------------------------- 1 | use std::{ 2 | fmt::{Debug, Display, Formatter}, 3 | io, 4 | }; 5 | 6 | pub struct Error(pub String); 7 | 8 | impl Error { 9 | pub fn combine>(self, err: T) -> Self { 10 | error!("{} {}", self.0, err.into().0) 11 | } 12 | } 13 | 14 | #[macro_export] 15 | macro_rules! error { 16 | ($fmt_str: literal $(,$arg: expr)*) => {$crate::error::Error(format!($fmt_str,$($arg),*))} 17 | } 18 | 19 | pub use error; 20 | 21 | pub type Result = std::result::Result; 22 | 23 | impl Debug for Error { 24 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 25 | write!(f, "{:?}", self.0) 26 | } 27 | } 28 | 29 | impl Display for Error { 30 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { 31 | write!(f, "{}", self.0) 32 | } 33 | } 34 | 35 | impl std::error::Error for Error {} 36 | 37 | macro_rules! impl_from { 38 | ($($err_type:ty),*) => { 39 | $( 40 | impl From<$err_type> for self::Error { 41 | fn from(err: $err_type) -> Self { 42 | Self(err.to_string()) 43 | } 44 | } 45 | )* 46 | } 47 | } 48 | 49 | impl_from!( 50 | serde_json::Error, 51 | io::Error, 52 | proc_macro2::LexError, 53 | fuel_abi_types::error::Error 54 | ); 55 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub use program_bindings::*; 2 | 3 | pub mod error; 4 | mod program_bindings; 5 | pub mod utils; 6 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/src/program_bindings.rs: -------------------------------------------------------------------------------- 1 | mod abigen; 2 | mod custom_types; 3 | mod generated_code; 4 | mod resolved_type; 5 | mod utils; 6 | 7 | pub use abigen::{Abi, Abigen, AbigenTarget, ProgramType}; 8 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/src/program_bindings/abigen/bindings.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | error::Result, 3 | program_bindings::{ 4 | abigen::{ 5 | ProgramType, 6 | abigen_target::AbigenTarget, 7 | bindings::{ 8 | contract::contract_bindings, predicate::predicate_bindings, script::script_bindings, 9 | }, 10 | }, 11 | generated_code::GeneratedCode, 12 | }, 13 | utils::ident, 14 | }; 15 | 16 | mod contract; 17 | mod function_generator; 18 | mod predicate; 19 | mod script; 20 | mod utils; 21 | 22 | pub(crate) fn generate_bindings(target: AbigenTarget, no_std: bool) -> Result { 23 | let bindings_generator = match target.program_type { 24 | ProgramType::Script => script_bindings, 25 | ProgramType::Contract => contract_bindings, 26 | ProgramType::Predicate => predicate_bindings, 27 | }; 28 | 29 | let name = ident(&target.name); 30 | let abi = target.source.abi; 31 | bindings_generator(&name, abi, no_std) 32 | } 33 | -------------------------------------------------------------------------------- /packages/fuels-code-gen/src/utils.rs: -------------------------------------------------------------------------------- 1 | pub use fuel_abi_types::utils::{TypePath, ident, safe_ident}; 2 | -------------------------------------------------------------------------------- /packages/fuels-core/src/codec/function_selector.rs: -------------------------------------------------------------------------------- 1 | pub fn encode_fn_selector(name: &str) -> Vec { 2 | let bytes = name.as_bytes().to_vec(); 3 | let len = bytes.len() as u64; 4 | 5 | [len.to_be_bytes().to_vec(), bytes].concat() 6 | } 7 | 8 | /// This uses the default `EncoderConfig` configuration. 9 | #[macro_export] 10 | macro_rules! calldata { 11 | ( $($arg: expr),* ) => { 12 | ::fuels::core::codec::ABIEncoder::default().encode(&[$(::fuels::core::traits::Tokenizable::into_token($arg)),*]) 13 | } 14 | } 15 | 16 | pub use calldata; 17 | -------------------------------------------------------------------------------- /packages/fuels-core/src/traits.rs: -------------------------------------------------------------------------------- 1 | mod parameterize; 2 | mod signer; 3 | mod tokenizable; 4 | 5 | pub use parameterize::*; 6 | pub use signer::*; 7 | pub use tokenizable::*; 8 | -------------------------------------------------------------------------------- /packages/fuels-core/src/traits/signer.rs: -------------------------------------------------------------------------------- 1 | use async_trait::async_trait; 2 | use auto_impl::auto_impl; 3 | use fuel_crypto::{Message, Signature}; 4 | 5 | use crate::types::{Address, errors::Result}; 6 | 7 | /// Trait for signing transactions and messages 8 | /// 9 | /// Implement this trait to support different signing modes, e.g. hardware wallet, hosted etc. 10 | #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] 11 | #[cfg_attr(not(target_arch = "wasm32"), async_trait)] 12 | #[auto_impl(&, Box, Rc, Arc)] 13 | pub trait Signer { 14 | async fn sign(&self, message: Message) -> Result; 15 | fn address(&self) -> Address; 16 | } 17 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/core.rs: -------------------------------------------------------------------------------- 1 | pub use bits::*; 2 | pub use bytes::*; 3 | pub use identity::*; 4 | pub use raw_slice::*; 5 | pub use sized_ascii_string::*; 6 | pub use u256::*; 7 | 8 | mod bits; 9 | mod bytes; 10 | mod identity; 11 | mod raw_slice; 12 | mod sized_ascii_string; 13 | mod u256; 14 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/core/raw_slice.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, PartialEq, Clone, Eq)] 2 | pub struct RawSlice(pub Vec); 3 | 4 | impl From for Vec { 5 | fn from(raw_slice: RawSlice) -> Vec { 6 | raw_slice.0 7 | } 8 | } 9 | 10 | impl PartialEq> for RawSlice { 11 | fn eq(&self, other: &Vec) -> bool { 12 | self.0 == *other 13 | } 14 | } 15 | 16 | impl PartialEq for Vec { 17 | fn eq(&self, other: &RawSlice) -> bool { 18 | *self == other.0 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/param_types.rs: -------------------------------------------------------------------------------- 1 | mod from_type_application; 2 | mod param_type; 3 | 4 | pub use param_type::*; 5 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/tx_response.rs: -------------------------------------------------------------------------------- 1 | use fuel_tx::TxId; 2 | 3 | use super::tx_status::Success; 4 | 5 | #[derive(Clone, Debug)] 6 | pub struct TxResponse { 7 | pub tx_status: Success, 8 | pub tx_id: TxId, 9 | } 10 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/wrappers.rs: -------------------------------------------------------------------------------- 1 | pub mod block; 2 | pub mod chain_info; 3 | pub mod coin; 4 | pub mod coin_type; 5 | pub mod coin_type_id; 6 | pub mod input; 7 | pub mod message; 8 | pub mod message_proof; 9 | pub mod node_info; 10 | pub mod transaction; 11 | pub mod transaction_response; 12 | pub mod output { 13 | pub use fuel_tx::Output; 14 | } 15 | #[cfg(feature = "std")] 16 | pub mod gas_price { 17 | pub use fuel_core_client::client::types::gas_price::{EstimateGasPrice, LatestGasPrice}; 18 | } 19 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/wrappers/chain_info.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "std")] 2 | 3 | use fuel_core_client::client::types::chain_info::ChainInfo as ClientChainInfo; 4 | use fuel_tx::ConsensusParameters; 5 | 6 | use crate::types::block::Block; 7 | 8 | #[derive(Debug)] 9 | pub struct ChainInfo { 10 | pub da_height: u64, 11 | pub name: String, 12 | pub latest_block: Block, 13 | pub consensus_parameters: ConsensusParameters, 14 | } 15 | 16 | impl From for ChainInfo { 17 | fn from(client_chain_info: ClientChainInfo) -> Self { 18 | Self { 19 | da_height: client_chain_info.da_height, 20 | name: client_chain_info.name, 21 | latest_block: client_chain_info.latest_block.into(), 22 | consensus_parameters: client_chain_info.consensus_parameters, 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/wrappers/coin.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "std")] 2 | 3 | use fuel_core_chain_config::CoinConfig; 4 | use fuel_core_client::client::types::{ 5 | coins::Coin as ClientCoin, 6 | primitives::{AssetId, UtxoId}, 7 | }; 8 | 9 | use crate::types::Address; 10 | 11 | #[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] 12 | pub struct Coin { 13 | pub amount: u64, 14 | pub asset_id: AssetId, 15 | pub utxo_id: UtxoId, 16 | pub owner: Address, 17 | } 18 | 19 | impl From for Coin { 20 | fn from(coin: ClientCoin) -> Self { 21 | Self { 22 | amount: coin.amount, 23 | asset_id: coin.asset_id, 24 | utxo_id: coin.utxo_id, 25 | owner: coin.owner, 26 | } 27 | } 28 | } 29 | 30 | impl From for CoinConfig { 31 | fn from(coin: Coin) -> CoinConfig { 32 | Self { 33 | tx_id: *coin.utxo_id.tx_id(), 34 | output_index: coin.utxo_id.output_index(), 35 | owner: coin.owner, 36 | amount: coin.amount, 37 | asset_id: coin.asset_id, 38 | ..Default::default() 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/wrappers/coin_type_id.rs: -------------------------------------------------------------------------------- 1 | use fuel_tx::UtxoId; 2 | use fuel_types::Nonce; 3 | 4 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] 5 | pub enum CoinTypeId { 6 | UtxoId(UtxoId), 7 | Nonce(Nonce), 8 | } 9 | -------------------------------------------------------------------------------- /packages/fuels-core/src/types/wrappers/node_info.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "std")] 2 | 3 | use fuel_core_client::client::types::node_info::NodeInfo as ClientNodeInfo; 4 | 5 | #[derive(Debug, Clone)] 6 | pub struct NodeInfo { 7 | pub utxo_validation: bool, 8 | pub vm_backtrace: bool, 9 | pub max_tx: u64, 10 | pub max_depth: u64, 11 | pub node_version: String, 12 | } 13 | 14 | impl From for NodeInfo { 15 | fn from(client_node_info: ClientNodeInfo) -> Self { 16 | Self { 17 | utxo_validation: client_node_info.utxo_validation, 18 | vm_backtrace: client_node_info.vm_backtrace, 19 | max_tx: client_node_info.max_tx, 20 | max_depth: client_node_info.max_depth, 21 | node_version: client_node_info.node_version, 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/fuels-core/src/utils/constants.rs: -------------------------------------------------------------------------------- 1 | use fuel_tx::Word; 2 | 3 | pub const ENUM_DISCRIMINANT_BYTE_WIDTH: usize = 8; 4 | pub const WORD_SIZE: usize = core::mem::size_of::(); 5 | 6 | // ANCHOR: default_call_parameters 7 | pub const DEFAULT_CALL_PARAMS_AMOUNT: u64 = 0; 8 | // ANCHOR_END: default_call_parameters 9 | 10 | pub const DEFAULT_GAS_ESTIMATION_TOLERANCE: f64 = 0.2; 11 | pub const DEFAULT_GAS_ESTIMATION_BLOCK_HORIZON: u32 = 5; 12 | 13 | // The size of a signature inside a transaction `Witness` 14 | pub const WITNESS_STATIC_SIZE: usize = 8; 15 | const SIGNATURE_SIZE: usize = 64; 16 | pub const SIGNATURE_WITNESS_SIZE: usize = WITNESS_STATIC_SIZE + SIGNATURE_SIZE; 17 | -------------------------------------------------------------------------------- /packages/fuels-macros/.gitignore: -------------------------------------------------------------------------------- 1 | # This folder is generated whenever a UI test fails, so we don't want to track its content. 2 | wip/* 3 | -------------------------------------------------------------------------------- /packages/fuels-macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-macros" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | rust-version = { workspace = true } 10 | description = "Fuel Rust SDK macros to generate types from ABI." 11 | 12 | [lib] 13 | proc-macro = true 14 | 15 | [dependencies] 16 | fuels-code-gen = { workspace = true } 17 | itertools = { workspace = true } 18 | proc-macro2 = { workspace = true } 19 | quote = { workspace = true } 20 | syn = { workspace = true, features = ["extra-traits"] } 21 | 22 | [dev-dependencies] 23 | trybuild = { workspace = true } 24 | 25 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/abigen.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use parsing::MacroAbigenTargets; 2 | 3 | mod parsing; 4 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/derive.rs: -------------------------------------------------------------------------------- 1 | pub mod parameterize; 2 | pub mod tokenizable; 3 | pub mod try_from; 4 | mod utils; 5 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/setup_program_test.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use code_gen::generate_setup_program_test_code; 2 | pub(crate) use parsing::TestProgramCommands; 3 | 4 | mod code_gen; 5 | mod parsing; 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/setup_program_test/parsing.rs: -------------------------------------------------------------------------------- 1 | pub(crate) use commands::{ 2 | AbigenCommand, BuildProfile, DeployContractCommand, InitializeWalletCommand, LoadScriptCommand, 3 | SetOptionsCommand, TestProgramCommands, 4 | }; 5 | 6 | mod command_parser; 7 | mod commands; 8 | mod validations; 9 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/setup_program_test/parsing/commands/deploy_contract.rs: -------------------------------------------------------------------------------- 1 | use std::convert::TryFrom; 2 | 3 | use syn::{Error, Lit, LitStr}; 4 | 5 | use crate::parse_utils::{Command, UniqueNameValues}; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct DeployContractCommand { 9 | pub name: String, 10 | pub contract: LitStr, 11 | pub wallet: String, 12 | pub random_salt: bool, 13 | } 14 | 15 | impl TryFrom for DeployContractCommand { 16 | type Error = Error; 17 | 18 | fn try_from(command: Command) -> Result { 19 | let name_values = UniqueNameValues::new(command.contents)?; 20 | name_values.validate_has_no_other_names(&["name", "contract", "wallet", "random_salt"])?; 21 | 22 | let name = name_values.get_as_lit_str("name")?.value(); 23 | let contract = name_values.get_as_lit_str("contract")?.clone(); 24 | let wallet = name_values.get_as_lit_str("wallet")?.value(); 25 | let random_salt = name_values.try_get("random_salt").is_none_or(|opt| { 26 | let Lit::Bool(b) = opt else { return true }; 27 | b.value() 28 | }); 29 | 30 | Ok(Self { 31 | name, 32 | contract, 33 | wallet, 34 | random_salt, 35 | }) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/setup_program_test/parsing/commands/initialize_wallet.rs: -------------------------------------------------------------------------------- 1 | use std::convert::TryFrom; 2 | 3 | use proc_macro2::Span; 4 | use syn::{Error, LitStr}; 5 | 6 | use crate::parse_utils::{Command, UniqueLitStrs}; 7 | 8 | #[derive(Debug, Clone)] 9 | pub struct InitializeWalletCommand { 10 | pub span: Span, 11 | pub names: Vec, 12 | } 13 | 14 | impl TryFrom for InitializeWalletCommand { 15 | type Error = Error; 16 | 17 | fn try_from(command: Command) -> Result { 18 | let wallets = UniqueLitStrs::new(command.contents)?; 19 | 20 | Ok(Self { 21 | span: command.name.span(), 22 | names: wallets.into_iter().collect(), 23 | }) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/fuels-macros/src/setup_program_test/parsing/commands/load_script.rs: -------------------------------------------------------------------------------- 1 | use std::convert::TryFrom; 2 | 3 | use syn::{Error, LitStr}; 4 | 5 | use crate::parse_utils::{Command, UniqueNameValues}; 6 | 7 | #[derive(Debug, Clone)] 8 | pub struct LoadScriptCommand { 9 | pub name: String, 10 | pub script: LitStr, 11 | pub wallet: String, 12 | } 13 | 14 | impl TryFrom for LoadScriptCommand { 15 | type Error = Error; 16 | 17 | fn try_from(command: Command) -> Result { 18 | let name_values = UniqueNameValues::new(command.contents)?; 19 | name_values.validate_has_no_other_names(&["name", "script", "wallet"])?; 20 | 21 | let name = name_values.get_as_lit_str("name")?.value(); 22 | let script = name_values.get_as_lit_str("script")?.clone(); 23 | let wallet = name_values.get_as_lit_str("wallet")?.value(); 24 | 25 | Ok(Self { 26 | name, 27 | script, 28 | wallet, 29 | }) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/macro_usage.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | mod tests { 3 | #[test] 4 | fn ui() { 5 | let t = trybuild::TestCases::new(); 6 | t.compile_fail("tests/ui/abigen/*.rs"); 7 | t.compile_fail("tests/ui/setup_program_test/*.rs"); 8 | t.compile_fail("tests/ui/derive/*/*.rs"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/duplicate_attribute.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract( 4 | abi = "some-abi.json", 5 | abi = "some-abi2.json", 6 | name = "SomeName", 7 | abi = "some-abi3.json", 8 | )); 9 | 10 | fn main() {} 11 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/duplicate_attribute.stderr: -------------------------------------------------------------------------------- 1 | error: original defined here: 2 | --> tests/ui/abigen/duplicate_attribute.rs:4:5 3 | | 4 | 4 | abi = "some-abi.json", 5 | | ^^^ 6 | 7 | error: duplicate! 8 | --> tests/ui/abigen/duplicate_attribute.rs:5:5 9 | | 10 | 5 | abi = "some-abi2.json", 11 | | ^^^ 12 | 13 | error: duplicate! 14 | --> tests/ui/abigen/duplicate_attribute.rs:7:5 15 | | 16 | 7 | abi = "some-abi3.json", 17 | | ^^^ 18 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_abi_path.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(name = "SomeName", abi = "some_abi.json")); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_abi_path.stderr: -------------------------------------------------------------------------------- 1 | error: failed to read `abi` file with path $WORKSPACE/target/tests/trybuild/fuels-macros/some_abi.json: No such file or directory (os error 2) 2 | --> tests/ui/abigen/invalid_abi_path.rs:3:43 3 | | 4 | 3 | abigen!(Contract(name = "SomeName", abi = "some_abi.json")); 5 | | ^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_abi_value.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(name = "SomeName", abi = true,)); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_abi_value.stderr: -------------------------------------------------------------------------------- 1 | error: expected the attribute 'abi' to have a string value 2 | --> tests/ui/abigen/invalid_abi_value.rs:3:43 3 | | 4 | 3 | abigen!(Contract(name = "SomeName", abi = true,)); 5 | | ^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_name_value.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(name = true, abi = "some-abi.json",)); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_name_value.stderr: -------------------------------------------------------------------------------- 1 | error: expected the attribute 'name' to have a string value 2 | --> tests/ui/abigen/invalid_name_value.rs:3:25 3 | | 4 | 3 | abigen!(Contract(name = true, abi = "some-abi.json",)); 5 | | ^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_program_type.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(SomeInvalidProgramType( 4 | name = "SomeName", 5 | abi = "some-abi.json" 6 | )); 7 | 8 | fn main() {} 9 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/invalid_program_type.stderr: -------------------------------------------------------------------------------- 1 | error: `SomeInvalidProgramType` is not a valid program type. Expected one of: `Script`, `Contract`, `Predicate` 2 | --> tests/ui/abigen/invalid_program_type.rs:3:9 3 | | 4 | 3 | abigen!(SomeInvalidProgramType( 5 | | ^^^^^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/malformed_abi.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(name = "SomeName", abi = r#"{}"#)); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/malformed_abi.stderr: -------------------------------------------------------------------------------- 1 | error: malformed `abi`. Did you use `forc` to create it?: missing field `programType` at line 1 column 2 2 | --> tests/ui/abigen/malformed_abi.rs:3:43 3 | | 4 | 3 | abigen!(Contract(name = "SomeName", abi = r#"{}"#)); 5 | | ^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/missing_abi_attribute.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(name = "SomeName")); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/missing_abi_attribute.stderr: -------------------------------------------------------------------------------- 1 | error: missing attribute 'abi' 2 | --> tests/ui/abigen/missing_abi_attribute.rs:3:18 3 | | 4 | 3 | abigen!(Contract(name = "SomeName")); 5 | | ^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/missing_name_attr.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract(abi = "some-abi.json")); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/missing_name_attr.stderr: -------------------------------------------------------------------------------- 1 | error: missing attribute 'name' 2 | --> tests/ui/abigen/missing_name_attr.rs:3:18 3 | | 4 | 3 | abigen!(Contract(abi = "some-abi.json")); 5 | | ^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/unrecognized_attribute.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::abigen; 2 | 3 | abigen!(Contract( 4 | name = "SomeName", 5 | abi = "some-abi.json", 6 | unknown = "something" 7 | )); 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/abigen/unrecognized_attribute.stderr: -------------------------------------------------------------------------------- 1 | error: attribute 'unknown' not recognized. Expected one of: 'name', 'abi' 2 | --> tests/ui/abigen/unrecognized_attribute.rs:6:5 3 | | 4 | 6 | unknown = "something" 5 | | ^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/attribute_must_be_named_value.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Parameterize; 2 | 3 | #[derive(Parameterize)] 4 | #[FuelsTypesPath] 5 | enum SomeEnum { 6 | A(u8), 7 | } 8 | 9 | #[derive(Parameterize)] 10 | #[FuelsTypesPath = true] 11 | struct SomeStruct {} 12 | 13 | fn main() {} 14 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/attribute_must_be_named_value.stderr: -------------------------------------------------------------------------------- 1 | error: expected name='value' 2 | --> tests/ui/derive/parameterize/attribute_must_be_named_value.rs:4:3 3 | | 4 | 4 | #[FuelsTypesPath] 5 | | ^^^^^^^^^^^^^^ 6 | 7 | error: expected string literal 8 | --> tests/ui/derive/parameterize/attribute_must_be_named_value.rs:10:20 9 | | 10 | 10 | #[FuelsTypesPath = true] 11 | | ^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/only_generic_types_are_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Parameterize; 2 | 3 | #[derive(Parameterize)] 4 | enum SomeEnum { 5 | A, 6 | } 7 | 8 | #[derive(Parameterize)] 9 | enum AnotherEnum<'a> { 10 | A(&'a u64), 11 | } 12 | 13 | #[derive(Parameterize)] 14 | struct SomeStruct {} 15 | 16 | #[derive(Parameterize)] 17 | struct AnotherStruct<'a> { 18 | a: &'a u64, 19 | } 20 | 21 | fn main() {} 22 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/only_generic_types_are_supported.stderr: -------------------------------------------------------------------------------- 1 | error: Const generics not supported 2 | --> tests/ui/derive/parameterize/only_generic_types_are_supported.rs:4:15 3 | | 4 | 4 | enum SomeEnum { 5 | | ^^^^^^^^^^^^^^ 6 | 7 | error: Lifetimes not supported 8 | --> tests/ui/derive/parameterize/only_generic_types_are_supported.rs:9:18 9 | | 10 | 9 | enum AnotherEnum<'a> { 11 | | ^^ 12 | 13 | error: Const generics not supported 14 | --> tests/ui/derive/parameterize/only_generic_types_are_supported.rs:14:19 15 | | 16 | 14 | struct SomeStruct {} 17 | | ^^^^^^^^^^^^^^ 18 | 19 | error: Lifetimes not supported 20 | --> tests/ui/derive/parameterize/only_generic_types_are_supported.rs:17:22 21 | | 22 | 17 | struct AnotherStruct<'a> { 23 | | ^^ 24 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/only_one_variant_element_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Parameterize; 2 | 3 | #[derive(Parameterize)] 4 | enum SomeEnum { 5 | // problem because no elements present 6 | B(), 7 | } 8 | 9 | #[derive(Parameterize)] 10 | enum AnotherEnum { 11 | A(u64, u32), 12 | } 13 | 14 | fn main() {} 15 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/only_one_variant_element_supported.stderr: -------------------------------------------------------------------------------- 1 | error: must have exactly one element 2 | --> tests/ui/derive/parameterize/only_one_variant_element_supported.rs:6:6 3 | | 4 | 6 | B(), 5 | | ^^ 6 | 7 | error: must have exactly one element 8 | --> tests/ui/derive/parameterize/only_one_variant_element_supported.rs:11:6 9 | | 10 | 11 | A(u64, u32), 11 | | ^^^^^^^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/struct_like_enum_variants_not_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Parameterize; 2 | 3 | #[derive(Parameterize)] 4 | enum SomeEnum { 5 | A, 6 | B { something: u64 }, 7 | } 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/struct_like_enum_variants_not_supported.stderr: -------------------------------------------------------------------------------- 1 | error: struct-like enum variants are not supported 2 | --> tests/ui/derive/parameterize/struct_like_enum_variants_not_supported.rs:6:7 3 | | 4 | 6 | B { something: u64 }, 5 | | ^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/tuple_like_structs_not_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Parameterize; 2 | 3 | #[derive(Parameterize)] 4 | struct SomeStruct(pub u64, pub String); 5 | 6 | fn main() {} 7 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/parameterize/tuple_like_structs_not_supported.stderr: -------------------------------------------------------------------------------- 1 | error: Tuple-like structs not supported 2 | --> tests/ui/derive/parameterize/tuple_like_structs_not_supported.rs:4:19 3 | | 4 | 4 | struct SomeStruct(pub u64, pub String); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/attribute_must_be_named_value.stderr: -------------------------------------------------------------------------------- 1 | error: Expected name='value' 2 | --> tests/ui/derive/tokenizable/attribute_must_be_named_value.rs:4:3 3 | | 4 | 4 | #[FuelsTypesPath] 5 | | ^^^^^^^^^^^^^^ 6 | 7 | error: Expected string literal 8 | --> tests/ui/derive/tokenizable/attribute_must_be_named_value.rs:10:20 9 | | 10 | 10 | #[FuelsTypesPath = true] 11 | | ^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/only_generic_types_are_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Tokenizable; 2 | 3 | #[derive(Tokenizable)] 4 | enum SomeEnum { 5 | A, 6 | } 7 | 8 | #[derive(Tokenizable)] 9 | enum AnotherEnum<'a> { 10 | A(&'a u64), 11 | } 12 | 13 | #[derive(Tokenizable)] 14 | struct SomeStruct {} 15 | 16 | #[derive(Tokenizable)] 17 | struct AnotherStruct<'a> { 18 | a: &'a u64, 19 | } 20 | 21 | fn main() {} 22 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/only_generic_types_are_supported.stderr: -------------------------------------------------------------------------------- 1 | error: Const generics not supported 2 | --> tests/ui/derive/tokenizable/only_generic_types_are_supported.rs:4:15 3 | | 4 | 4 | enum SomeEnum { 5 | | ^^^^^^^^^^^^^^ 6 | 7 | error: Lifetimes not supported 8 | --> tests/ui/derive/tokenizable/only_generic_types_are_supported.rs:9:18 9 | | 10 | 9 | enum AnotherEnum<'a> { 11 | | ^^ 12 | 13 | error: Const generics not supported 14 | --> tests/ui/derive/tokenizable/only_generic_types_are_supported.rs:14:19 15 | | 16 | 14 | struct SomeStruct {} 17 | | ^^^^^^^^^^^^^^ 18 | 19 | error: Lifetimes not supported 20 | --> tests/ui/derive/tokenizable/only_generic_types_are_supported.rs:17:22 21 | | 22 | 17 | struct AnotherStruct<'a> { 23 | | ^^ 24 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/only_one_variant_element_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Tokenizable; 2 | 3 | #[derive(Tokenizable)] 4 | enum SomeEnum { 5 | // problem because no elements present 6 | B(), 7 | } 8 | 9 | #[derive(Tokenizable)] 10 | enum AnotherEnum { 11 | A(u64, u32), 12 | } 13 | 14 | fn main() {} 15 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/only_one_variant_element_supported.stderr: -------------------------------------------------------------------------------- 1 | error: tuple-like enum variants must contain exactly one element 2 | --> tests/ui/derive/tokenizable/only_one_variant_element_supported.rs:6:6 3 | | 4 | 6 | B(), 5 | | ^^ 6 | 7 | error: tuple-like enum variants must contain exactly one element 8 | --> tests/ui/derive/tokenizable/only_one_variant_element_supported.rs:11:6 9 | | 10 | 11 | A(u64, u32), 11 | | ^^^^^^^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/struct_like_enum_variants_not_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Tokenizable; 2 | 3 | #[derive(Tokenizable)] 4 | enum SomeEnum { 5 | A, 6 | B { something: u64 }, 7 | } 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/struct_like_enum_variants_not_supported.stderr: -------------------------------------------------------------------------------- 1 | error: struct like enum variants are not supported 2 | --> tests/ui/derive/tokenizable/struct_like_enum_variants_not_supported.rs:6:7 3 | | 4 | 6 | B { something: u64 }, 5 | | ^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/tuple_like_structs_not_supported.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::Tokenizable; 2 | 3 | #[derive(Tokenizable)] 4 | struct SomeStruct(pub u64, pub String); 5 | 6 | fn main() {} 7 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/derive/tokenizable/tuple_like_structs_not_supported.stderr: -------------------------------------------------------------------------------- 1 | error: Tuple-like structs not supported 2 | --> tests/ui/derive/tokenizable/tuple_like_structs_not_supported.rs:4:19 3 | | 4 | 4 | struct SomeStruct(pub u64, pub String); 5 | | ^^^^^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/abigen_command_is_missing.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!(Deploy( 4 | name = "some_instance", 5 | contract = "SomeUnknownContract", 6 | wallet = "some_wallet" 7 | )); 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/abigen_command_is_missing.stderr: -------------------------------------------------------------------------------- 1 | error: Add an `Abigen(..)` command! 2 | --> tests/ui/setup_program_test/abigen_command_is_missing.rs:3:21 3 | | 4 | 3 | setup_program_test!(Deploy( 5 | | ^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/duplicate_wallet_command.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!( 4 | Wallets("wallet1"), 5 | Wallets("wallet2"), 6 | Abigen(Contract(name = "MyContract", project = "some_project")) 7 | ); 8 | 9 | fn main() {} 10 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/duplicate_wallet_command.stderr: -------------------------------------------------------------------------------- 1 | error: Only one `Wallets` command allowed 2 | --> tests/ui/setup_program_test/duplicate_wallet_command.rs:4:5 3 | | 4 | 4 | Wallets("wallet1"), 5 | | ^^^^^^^ 6 | 7 | error: Only one `Wallets` command allowed 8 | --> tests/ui/setup_program_test/duplicate_wallet_command.rs:5:5 9 | | 10 | 5 | Wallets("wallet2"), 11 | | ^^^^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/duplicate_wallet_names.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!( 4 | Wallets("wallet1", "wallet1"), 5 | Abigen(Contract(name = "MyContract", project = "some_project")) 6 | ); 7 | 8 | fn main() {} 9 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/duplicate_wallet_names.stderr: -------------------------------------------------------------------------------- 1 | error: original defined here: 2 | --> tests/ui/setup_program_test/duplicate_wallet_names.rs:4:13 3 | | 4 | 4 | Wallets("wallet1", "wallet1"), 5 | | ^^^^^^^^^ 6 | 7 | error: duplicate! 8 | --> tests/ui/setup_program_test/duplicate_wallet_names.rs:4:24 9 | | 10 | 4 | Wallets("wallet1", "wallet1"), 11 | | ^^^^^^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/invalid_path.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!(Abigen(Contract( 4 | name = "MyContract", 5 | project = "some_project" 6 | ))); 7 | 8 | fn main() {} 9 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/invalid_path.stderr: -------------------------------------------------------------------------------- 1 | error: unable to canonicalize forc project path. Make sure the path is valid! 2 | --> tests/ui/setup_program_test/invalid_path.rs:5:15 3 | | 4 | 5 | project = "some_project" 5 | | ^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/invalid_project_path.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!(Abigen(Contract(name = "MyContract", project = "."))); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/invalid_project_path.stderr: -------------------------------------------------------------------------------- 1 | error: failed to read `abi` file with path $WORKSPACE/target/tests/trybuild/fuels-macros/out/release/fuels-macros-abi.json: No such file or directory (os error 2) 2 | --> tests/ui/setup_program_test/invalid_project_path.rs:3:68 3 | | 4 | 3 | setup_program_test!(Abigen(Contract(name = "MyContract", project = "."))); 5 | | ^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_command.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!( 4 | Abigen(Contract(project = "some_project", name = "SomeContract")), 5 | Deploy( 6 | name = "some_instance", 7 | contract = "SomeContract", 8 | wallet = "some_wallet" 9 | ), 10 | UnknownCommand() 11 | ); 12 | 13 | fn main() {} 14 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_command.stderr: -------------------------------------------------------------------------------- 1 | error: Unrecognized command. Expected one of: 'Options', 'Wallets', 'Abigen', 'Deploy', 'LoadScript' 2 | --> tests/ui/setup_program_test/unknown_command.rs:10:5 3 | | 4 | 10 | UnknownCommand() 5 | | ^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_contract.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!( 4 | Abigen(Contract(project = "some_project", name = "MismatchedName")), 5 | Deploy( 6 | name = "some_instance", 7 | contract = "SomeUnknownContract", 8 | wallet = "some_wallet" 9 | ) 10 | ); 11 | 12 | fn main() {} 13 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_contract.stderr: -------------------------------------------------------------------------------- 1 | error: Contract is unknown 2 | --> tests/ui/setup_program_test/unknown_contract.rs:7:20 3 | | 4 | 7 | contract = "SomeUnknownContract", 5 | | ^^^^^^^^^^^^^^^^^^^^^ 6 | 7 | error: Consider adding: Contract(name="SomeUnknownContract", project=...) 8 | --> tests/ui/setup_program_test/unknown_contract.rs:4:5 9 | | 10 | 4 | Abigen(Contract(project = "some_project", name = "MismatchedName")), 11 | | ^^^^^^ 12 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_options_key.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!(Options(unknown = "debug")); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_options_key.stderr: -------------------------------------------------------------------------------- 1 | error: attribute 'unknown' not recognized. Expected one of: 'profile' 2 | --> tests/ui/setup_program_test/unknown_options_key.rs:3:29 3 | | 4 | 3 | setup_program_test!(Options(unknown = "debug")); 5 | | ^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_options_value.rs: -------------------------------------------------------------------------------- 1 | use fuels_macros::setup_program_test; 2 | 3 | setup_program_test!(Options(profile = "not_a_profile")); 4 | 5 | fn main() {} 6 | -------------------------------------------------------------------------------- /packages/fuels-macros/tests/ui/setup_program_test/unknown_options_value.stderr: -------------------------------------------------------------------------------- 1 | error: invalid build profile option: must be "debug" or "release" 2 | --> tests/ui/setup_program_test/unknown_options_value.rs:3:39 3 | | 4 | 3 | setup_program_test!(Options(profile = "not_a_profile")); 5 | | ^^^^^^^^^^^^^^^ 6 | -------------------------------------------------------------------------------- /packages/fuels-programs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuels-programs" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | repository = { workspace = true } 9 | rust-version = { workspace = true } 10 | description = "Fuel Rust SDK contracts." 11 | 12 | [dependencies] 13 | async-trait = { workspace = true, default-features = false } 14 | fuel-abi-types = { workspace = true } 15 | fuel-asm = { workspace = true } 16 | fuel-tx = { workspace = true } 17 | fuel-types = { workspace = true, features = ["default"] } 18 | fuels-accounts = { workspace = true } 19 | fuels-core = { workspace = true } 20 | itertools = { workspace = true } 21 | rand = { workspace = true } 22 | serde_json = { workspace = true } 23 | tokio = { workspace = true } 24 | 25 | [dev-dependencies] 26 | tempfile = "3.8.1" 27 | test-case = { workspace = true } 28 | 29 | [features] 30 | default = ["std"] 31 | std = ["fuels-core/std", "fuels-accounts/std"] 32 | fault-proving = ["fuels-core/fault-proving", "fuels-accounts/fault-proving"] 33 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/assembly.rs: -------------------------------------------------------------------------------- 1 | pub mod contract_call; 2 | pub mod cursor; 3 | pub mod script_and_predicate_loader; 4 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/calls/traits.rs: -------------------------------------------------------------------------------- 1 | mod contract_dep_configurator; 2 | mod response_parser; 3 | mod transaction_tuner; 4 | 5 | pub use contract_dep_configurator::*; 6 | pub use response_parser::*; 7 | pub use transaction_tuner::*; 8 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/calls/traits/contract_dep_configurator.rs: -------------------------------------------------------------------------------- 1 | use fuels_core::types::ContractId; 2 | 3 | use crate::calls::{ContractCall, ScriptCall, utils::sealed}; 4 | 5 | pub trait ContractDependencyConfigurator: sealed::Sealed { 6 | fn append_external_contract(&mut self, contract_id: ContractId); 7 | fn with_external_contracts(self, external_contracts: Vec) -> Self; 8 | } 9 | 10 | impl ContractDependencyConfigurator for ContractCall { 11 | fn append_external_contract(&mut self, contract_id: ContractId) { 12 | self.external_contracts.push(contract_id) 13 | } 14 | 15 | fn with_external_contracts(self, external_contracts: Vec) -> Self { 16 | ContractCall { 17 | external_contracts, 18 | ..self 19 | } 20 | } 21 | } 22 | 23 | impl ContractDependencyConfigurator for ScriptCall { 24 | fn append_external_contract(&mut self, contract_id: ContractId) { 25 | self.external_contracts.push(contract_id) 26 | } 27 | 28 | fn with_external_contracts(self, external_contracts: Vec) -> Self { 29 | ScriptCall { 30 | external_contracts, 31 | ..self 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/calls/traits/response_parser.rs: -------------------------------------------------------------------------------- 1 | use fuel_tx::Receipt; 2 | use fuels_core::{ 3 | codec::DecoderConfig, 4 | types::{Token, errors::Result, param_types::ParamType}, 5 | }; 6 | 7 | use crate::calls::{ContractCall, ScriptCall, receipt_parser::ReceiptParser, utils::sealed}; 8 | 9 | pub trait ResponseParser: sealed::Sealed { 10 | fn parse_call( 11 | &self, 12 | receipts: &[Receipt], 13 | decoder_config: DecoderConfig, 14 | param_type: &ParamType, 15 | ) -> Result; 16 | } 17 | 18 | impl ResponseParser for ContractCall { 19 | fn parse_call( 20 | &self, 21 | receipts: &[Receipt], 22 | decoder_config: DecoderConfig, 23 | param_type: &ParamType, 24 | ) -> Result { 25 | ReceiptParser::new(receipts, decoder_config).parse_call(self.contract_id, param_type) 26 | } 27 | } 28 | 29 | impl ResponseParser for ScriptCall { 30 | fn parse_call( 31 | &self, 32 | receipts: &[Receipt], 33 | decoder_config: DecoderConfig, 34 | param_type: &ParamType, 35 | ) -> Result { 36 | ReceiptParser::new(receipts, decoder_config).parse_script(param_type) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "std")] 2 | pub mod calls; 3 | #[cfg(feature = "std")] 4 | pub mod contract; 5 | #[cfg(feature = "std")] 6 | pub mod executable; 7 | #[cfg(feature = "std")] 8 | pub mod responses; 9 | 10 | pub const DEFAULT_MAX_FEE_ESTIMATION_TOLERANCE: f32 = 0.50; 11 | 12 | pub mod debug; 13 | 14 | pub(crate) mod assembly; 15 | pub(crate) mod utils; 16 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/responses.rs: -------------------------------------------------------------------------------- 1 | mod call; 2 | mod submit; 3 | 4 | pub use call::*; 5 | pub use submit::*; 6 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/responses/call.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Debug; 2 | 3 | use fuel_tx::TxId; 4 | use fuels_core::{ 5 | codec::{LogDecoder, LogResult}, 6 | traits::{Parameterize, Tokenizable}, 7 | types::{errors::Result, tx_status::Success}, 8 | }; 9 | 10 | /// [`CallResponse`] is a struct that is returned by a call to the contract or script. Its value 11 | /// field holds the decoded typed value returned by the contract's method. The other field holds all 12 | /// the receipts returned by the call. 13 | #[derive(Clone, Debug)] 14 | // ANCHOR: call_response 15 | pub struct CallResponse { 16 | pub value: D, 17 | pub tx_status: Success, 18 | pub tx_id: Option, 19 | pub log_decoder: LogDecoder, 20 | } 21 | // ANCHOR_END: call_response 22 | 23 | impl CallResponse { 24 | pub fn decode_logs(&self) -> LogResult { 25 | self.log_decoder.decode_logs(&self.tx_status.receipts) 26 | } 27 | 28 | pub fn decode_logs_with_type(&self) -> Result> { 29 | self.log_decoder 30 | .decode_logs_with_type::(&self.tx_status.receipts) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/fuels-programs/src/utils.rs: -------------------------------------------------------------------------------- 1 | use fuels_core::types::errors::{Error, error}; 2 | 3 | pub fn prepend_msg<'a>(msg: impl AsRef + 'a) -> impl Fn(Error) -> Error + 'a { 4 | move |err| match err { 5 | Error::IO(orig_msg) => { 6 | error!(IO, "{}: {}", msg.as_ref(), orig_msg) 7 | } 8 | Error::Codec(orig_msg) => { 9 | error!(Codec, "{}: {}", msg.as_ref(), orig_msg) 10 | } 11 | Error::Transaction(reason) => Error::Transaction(reason), 12 | Error::Provider(orig_msg) => { 13 | error!(Provider, "{}: {}", msg.as_ref(), orig_msg) 14 | } 15 | Error::Other(orig_msg) => { 16 | error!(Other, "{}: {}", msg.as_ref(), orig_msg) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /packages/fuels-test-helpers/src/utils.rs: -------------------------------------------------------------------------------- 1 | use fuel_core_chain_config::{CoinConfig, MessageConfig}; 2 | use fuels_core::types::{coin::Coin, message::Message}; 3 | 4 | pub(crate) fn into_coin_configs(coins: Vec) -> Vec { 5 | coins 6 | .into_iter() 7 | .map(Into::into) 8 | .collect::>() 9 | } 10 | 11 | pub(crate) fn into_message_configs(messages: Vec) -> Vec { 12 | messages 13 | .into_iter() 14 | .map(Into::into) 15 | .collect::>() 16 | } 17 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | fn_params_layout = "Tall" 2 | hard_tabs = false 3 | match_arm_leading_pipes = "Never" 4 | max_width = 100 5 | merge_derives = true 6 | remove_nested_parens = true 7 | reorder_imports = true 8 | reorder_modules = true 9 | tab_spaces = 4 10 | use_field_init_shorthand = false 11 | use_small_heuristics = "Default" 12 | use_try_shorthand = false 13 | -------------------------------------------------------------------------------- /scripts/change-log/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "change-log" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | rust-version = { workspace = true } 11 | 12 | [dependencies] 13 | dialoguer = { version = "0.11", features = ["fuzzy-select"] } 14 | dotenv = { workspace = true } 15 | octocrab = { workspace = true, features = ["default"] } 16 | regex = { workspace = true } 17 | serde_json = { workspace = true } 18 | tokio = { workspace = true, features = ["rt-multi-thread", "macros"] } 19 | -------------------------------------------------------------------------------- /scripts/change-log/src/adapters.rs: -------------------------------------------------------------------------------- 1 | pub mod octocrab; 2 | -------------------------------------------------------------------------------- /scripts/change-log/src/domain.rs: -------------------------------------------------------------------------------- 1 | pub mod changelog; 2 | pub mod models; 3 | -------------------------------------------------------------------------------- /scripts/change-log/src/domain/models.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug, Clone)] 2 | pub struct ChangelogInfo { 3 | pub is_breaking: bool, 4 | pub pr_type: String, 5 | pub bullet_point: String, 6 | pub migration_note: String, 7 | pub release_notes: String, 8 | } 9 | -------------------------------------------------------------------------------- /scripts/change-log/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod adapters; 2 | pub mod domain; 3 | pub mod ports; 4 | -------------------------------------------------------------------------------- /scripts/change-log/src/ports.rs: -------------------------------------------------------------------------------- 1 | pub mod github; 2 | -------------------------------------------------------------------------------- /scripts/change-log/src/ports/github.rs: -------------------------------------------------------------------------------- 1 | use crate::domain::models::ChangelogInfo; 2 | 3 | #[allow(async_fn_in_trait)] 4 | pub trait GitHubPort { 5 | /// Retrieve a collection of changelog infos based on the commit comparison between `base` and `head`. 6 | async fn get_changelog_infos( 7 | &self, 8 | owner: &str, 9 | repo: &str, 10 | base: &str, 11 | head: &str, 12 | ) -> Result, Box>; 13 | 14 | /// Retrieve the latest release tag for the given repository. 15 | async fn get_latest_release_tag( 16 | &self, 17 | owner: &str, 18 | repo: &str, 19 | ) -> Result>; 20 | } 21 | -------------------------------------------------------------------------------- /scripts/check-docs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "check-docs" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | rust-version = { workspace = true } 11 | 12 | [dependencies] 13 | anyhow = "1.0.75" 14 | itertools = { workspace = true } 15 | regex = { workspace = true } 16 | -------------------------------------------------------------------------------- /scripts/check-docs/tests/test_data/docs/src/SUMMARY.md: -------------------------------------------------------------------------------- 1 | - [Test](./test.md) 2 | -------------------------------------------------------------------------------- /scripts/check-docs/tests/test_data/docs/src/test-not-there.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/fuels-rs/e510eab463c190600bd8b5f004bd5544b3ffc8cd/scripts/check-docs/tests/test_data/docs/src/test-not-there.md -------------------------------------------------------------------------------- /scripts/check-docs/tests/test_data/docs/src/test.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FuelLabs/fuels-rs/e510eab463c190600bd8b5f004bd5544b3ffc8cd/scripts/check-docs/tests/test_data/docs/src/test.md -------------------------------------------------------------------------------- /scripts/check-docs/tests/test_data/test_anchor_data.rs: -------------------------------------------------------------------------------- 1 | // ANCHOR: test_anchor_line_comment 2 | ///// ANCHOR_END: test_anchor_line_comment 3 | 4 | /* ANCHOR: test_anchor_block_comment */ 5 | /* ANCHOR_END: test_anchor_block_comment */ 6 | 7 | // ANCHOR: test_with_more_forward_slashes 8 | ///// ANCHOR_END: test_with_more_forward_slashes 9 | 10 | // ANCHOR_END: test_no_anchor_beginning 11 | 12 | // ANCHOR: test_no_anchor_end 13 | 14 | // ANCHOR_END: test_end_before_beginning 15 | // ANCHOR: test_end_before_beginning 16 | 17 | // ANCHOR: test_same_name_multiple_time 18 | // ANCHOR_END: test_same_name_multiple_time 19 | 20 | // ANCHOR: test_same_name_multiple_time 21 | // ANCHOR_END: test_same_name_multiple_time 22 | -------------------------------------------------------------------------------- /scripts/check-docs/tests/test_data/test_include_data.md: -------------------------------------------------------------------------------- 1 | 2 | ```rust,ignore 3 | {{#include ./test_anchor_data.rs:test_anchor_line_comment}} 4 | ``` 5 | 6 | ```rust,ignore 7 | {{#include ./test_anchor_data.rs:test_anchor_block_comment}} 8 | ``` 9 | 10 | ```rust,ignore 11 | {{#include ./test_anchor_data.rs:test_with_more_forward_slashes}} 12 | ``` 13 | 14 | ```rust,ignore 15 | {{#include ./test_anchor_data.rs:no_existing_anchor}} 16 | ``` 17 | 18 | Include file with correct path 19 | 20 | ```rust,ignore 21 | {{#include ./test_anchor_data.rs}} 22 | ``` 23 | 24 | Include file with wrong path 25 | 26 | ```rust,ignore 27 | {{#include ./test_anchor_data2.rs}} 28 | ``` 29 | 30 | Another include file with wrong path 31 | 32 | ```rust,ignore 33 | {{#include ./test_anchor_data3.rs}} 34 | ``` 35 | -------------------------------------------------------------------------------- /scripts/fuel-core-version/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fuel-core-version" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | rust-version = { workspace = true } 11 | 12 | [dependencies] 13 | clap = { version = "4.5.3", features = ["derive"] } 14 | color-eyre = "0.6.2" 15 | fuels-accounts = { workspace = true, features = ["std"] } 16 | semver = { workspace = true } 17 | toml = { workspace = true, features = ["parse"] } 18 | -------------------------------------------------------------------------------- /scripts/versions-replacer/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "versions-replacer" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | rust-version = { workspace = true } 11 | 12 | [dependencies] 13 | argh = "0.1.12" 14 | cargo_metadata = "0.18.1" 15 | color-eyre = "0.6.2" 16 | once_cell = "1.18.0" 17 | regex = { workspace = true } 18 | serde = { workspace = true, features = ["derive"] } 19 | walkdir = "2.4.0" 20 | -------------------------------------------------------------------------------- /scripts/versions-replacer/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod metadata; 2 | pub mod replace; 3 | -------------------------------------------------------------------------------- /scripts/versions-replacer/src/metadata.rs: -------------------------------------------------------------------------------- 1 | use std::{collections::HashMap, path::Path}; 2 | 3 | use cargo_metadata::MetadataCommand; 4 | use color_eyre::{Result, eyre::Context}; 5 | use serde::Deserialize; 6 | 7 | #[derive(Deserialize)] 8 | #[serde(rename_all = "kebab-case")] 9 | pub struct WorkspaceMetadata { 10 | pub versions_replacer: VersionsReplacerMetadata, 11 | } 12 | 13 | #[derive(Deserialize)] 14 | #[serde(rename_all = "kebab-case")] 15 | pub struct VersionsReplacerMetadata { 16 | pub external_versions: HashMap, 17 | } 18 | 19 | pub fn collect_versions_from_cargo_toml( 20 | manifest_path: impl AsRef, 21 | ) -> Result> { 22 | let metadata = MetadataCommand::new() 23 | .manifest_path(manifest_path.as_ref()) 24 | .exec() 25 | .wrap_err("failed to execute 'cargo metadata'")?; 26 | let version_map = metadata 27 | .packages 28 | .iter() 29 | .map(|package| (package.name.clone(), package.version.to_string())) 30 | .collect::>(); 31 | Ok(version_map) 32 | } 33 | -------------------------------------------------------------------------------- /wasm-tests/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "wasm32-unknown-unknown" 3 | 4 | [target.wasm32-unknown-unknown] 5 | runner = "wasm-bindgen-test-runner" -------------------------------------------------------------------------------- /wasm-tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasm-tests" 3 | version = { workspace = true } 4 | authors = { workspace = true } 5 | edition = { workspace = true } 6 | homepage = { workspace = true } 7 | license = { workspace = true } 8 | publish = false 9 | repository = { workspace = true } 10 | rust-version = { workspace = true } 11 | 12 | [lib] 13 | crate-type = ['cdylib'] 14 | 15 | [dev-dependencies] 16 | fuels = { workspace = true } 17 | fuels-core = { workspace = true } 18 | getrandom = { version = "0.2.11", features = ["js"] } 19 | hex = { workspace = true } 20 | wasm-bindgen-test = "0.3.39" 21 | --------------------------------------------------------------------------------