Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access to {asset_id,to,amount} fields for Variable and Change outputs #675

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [#672](https://github.com/FuelLabs/fuel-vm/pull/672): Remove `GasPrice` policy
- [#672](https://github.com/FuelLabs/fuel-vm/pull/672): Add `gas_price` field to transaction execution
- [#684](https://github.com/FuelLabs/fuel-vm/pull/684): Remove `maturity` field from `Input` coin types. Also remove related `GTF` getter.
- [#675](https://github.com/FuelLabs/fuel-vm/pull/675): Add `GTF` access for `asset_id` and `to` fields for `Change` outputs.

## [Version 0.46.0]

Expand Down
4 changes: 4 additions & 0 deletions fuel-tx/src/transaction/types/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ impl Output {
matches!(self, Self::Coin { .. })
}

pub const fn is_change(&self) -> bool {
matches!(self, Self::Change { .. })
}

pub const fn is_variable(&self) -> bool {
matches!(self, Self::Variable { .. })
}
Expand Down
4 changes: 2 additions & 2 deletions fuel-vm/src/interpreter/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<Tx> GTFInput<'_, Tx> {
(ofs + tx
.outputs()
.get(b)
.filter(|o| o.is_coin())
.filter(|o| o.is_coin() || o.is_change())
.map(Output::repr)
.and_then(|r| r.to_offset())
.and_then(|ofs| tx.outputs_offset_at(b).map(|o| o + ofs))
Expand All @@ -458,7 +458,7 @@ impl<Tx> GTFInput<'_, Tx> {
(ofs + tx
.outputs()
.get(b)
.filter(|o| o.is_coin())
.filter(|o| o.is_coin() || o.is_change())
.map(Output::repr)
.and_then(|r| r.asset_id_offset())
.and_then(|ofs| tx.outputs_offset_at(b).map(|o| o + ofs))
Expand Down
19 changes: 18 additions & 1 deletion fuel-vm/src/tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ fn get_transaction_fields() {
rng.gen(),
)
.add_output(Output::coin(rng.gen(), asset_amt, asset))
.add_output(Output::change(rng.gen(), rng.gen_range(10..1000), asset))
.finalize_checked(height, zero_gas_price);

let inputs = tx.as_ref().inputs();
Expand Down Expand Up @@ -443,6 +444,8 @@ fn get_transaction_fields() {
outputs[1].balance_root().unwrap().to_vec(), // 21 - OutputContractBalanceRoot
outputs[1].state_root().unwrap().to_vec(), // 22 - OutputContractStateRoot
witnesses[1].as_ref().to_vec(), // 23 - WitnessData
outputs[3].asset_id().unwrap().to_vec(), // 24 - OutputCoinAssetId
outputs[3].to().unwrap().to_vec(), // 25 - OutputCoinTo
];

// hardcoded metadata of script len so it can be checked at runtime
Expand Down Expand Up @@ -782,7 +785,7 @@ fn get_transaction_fields() {
op::eq(0x10, 0x10, 0x11),
op::and(0x20, 0x20, 0x10),

// Sjip over always-zero OutputContract fields
// Skip over always-zero OutputContract fields
op::addi(0x30, 0x30, cases[21].len().try_into().unwrap()),
op::addi(0x30, 0x30, cases[22].len().try_into().unwrap()),

Expand All @@ -799,6 +802,20 @@ fn get_transaction_fields() {
op::add(0x30, 0x30, 0x11),
op::and(0x20, 0x20, 0x10),

op::movi(0x19, 0x03),
op::gtf_args(0x10, 0x19, GTFArgs::OutputCoinAssetId),
op::movi(0x11, cases[24].len() as Immediate18),
op::meq(0x10, 0x10, 0x30, 0x11),
op::add(0x30, 0x30, 0x11),
op::and(0x20, 0x20, 0x10),

op::movi(0x19, 0x03),
op::gtf_args(0x10, 0x19, GTFArgs::OutputCoinTo),
op::movi(0x11, cases[25].len() as Immediate18),
op::meq(0x10, 0x10, 0x30, 0x11),
op::add(0x30, 0x30, 0x11),
op::and(0x20, 0x20, 0x10),

op::log(0x20, 0x00, 0x00, 0x00),
op::ret(0x00)
].into_iter().collect();
Expand Down
Loading