From fe6de86e1adf319dcf2c8a384505921c65be0265 Mon Sep 17 00:00:00 2001 From: bitzoic Date: Wed, 11 Dec 2024 12:57:07 +0000 Subject: [PATCH] Make magic numbers constants --- sway-lib-std/src/outputs.sw | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sway-lib-std/src/outputs.sw b/sway-lib-std/src/outputs.sw index 681fd8a0354..527a94de2fc 100644 --- a/sway-lib-std/src/outputs.sw +++ b/sway-lib-std/src/outputs.sw @@ -28,6 +28,9 @@ pub const GTF_OUTPUT_COIN_ASSET_ID = 0x303; // pub const GTF_OUTPUT_CONTRACT_CREATED_CONTRACT_ID = 0x307; // pub const GTF_OUTPUT_CONTRACT_CREATED_STATE_ROOT = 0x308; +const OUTPUT_VARIABLE_ASSET_ID_OFFSET = 48; +const OUTPUT_VARIABLE_TO_OFFSET = 8; + /// The output type for a transaction. pub enum Output { /// A coin output. @@ -230,7 +233,7 @@ pub fn output_asset_id(index: u64) -> Option { Some(Output::Change) => Some(AssetId::from(__gtf::(index, GTF_OUTPUT_COIN_ASSET_ID))), Some(Output::Variable) => { let ptr = output_pointer(index).unwrap(); - Some(AssetId::from(ptr.add_uint_offset(48).read::())) + Some(AssetId::from(ptr.add_uint_offset(OUTPUT_VARIABLE_ASSET_ID_OFFSET).read::())) }, _ => None, } @@ -266,7 +269,7 @@ pub fn output_asset_to(index: u64) -> Option
{ Some(Output::Change) => Some(__gtf::
(index, GTF_OUTPUT_COIN_TO)), Some(Output::Variable) => { let ptr = output_pointer(index).unwrap(); - Some(Address::from(ptr.add_uint_offset(8).read::())) + Some(Address::from(ptr.add_uint_offset(OUTPUT_VARIABLE_TO_OFFSET).read::())) }, _ => None, }