-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
Output::Change
in output_asset_to()
and `output_asset_id(…
…)` (#6562) ## Description Support to get the `to` and `asset_id` fields of an `Output::Change` were added in FuelLabs/fuel-vm#675. The std-lib now enables this. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
7 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/src/sdk-harness/test_artifacts/tx_output_change_contract/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "tx_output_change_contract" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../sway-lib-std" } |
13 changes: 13 additions & 0 deletions
13
test/src/sdk-harness/test_artifacts/tx_output_change_contract/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
contract; | ||
|
||
use std::asset::transfer; | ||
|
||
abi TxOutputChangeContract { | ||
fn send_assets(to: Address, asset: AssetId, amount: u64); | ||
} | ||
|
||
impl TxOutputChangeContract for Contract { | ||
fn send_assets(to: Address, asset: AssetId, amount: u64) { | ||
transfer(Identity::Address(to), asset, amount); | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
test/src/sdk-harness/test_artifacts/tx_output_predicate/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
predicate; | ||
|
||
use std::outputs::{output_asset_id, output_asset_to}; | ||
use std::outputs::{output_asset_id, output_asset_to, output_type, Output}; | ||
|
||
fn main(index: u64, asset_id: b256, to: b256) -> bool { | ||
fn main(index: u64, asset_id: b256, to: b256, expected_type: Output) -> bool { | ||
let tx_asset_id = output_asset_id(index); | ||
let tx_to = output_asset_to(index); | ||
let tx_output_type = output_type(index); | ||
|
||
assert(tx_asset_id.is_some() && tx_asset_id.unwrap().bits() == asset_id); | ||
assert(tx_to.is_some() && tx_to.unwrap().bits() == to); | ||
assert(tx_output_type.is_some() && tx_output_type.unwrap() == expected_type); | ||
|
||
true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters