Skip to content

Conversation

@DarthBenro008
Copy link
Owner

Optional callback

  • not every call is made by contract, the callback reverts if the caller isnt a contract
  • making an optional callback which defaults to True if None is passed
  • Fuel scripts can now call simplevrf without the contract reverting due to callback.

Feature requested by @IGI-111

#[payable]
#[storage(read, write)]
fn request(seed: b256) -> u64;
fn request(seed: b256, callback: Option<bool>) -> u64;
Copy link

@IGI-111 IGI-111 Aug 26, 2025

Choose a reason for hiding this comment

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

I'm not sure I understand the logic behind making it an Option. This will still be incompatible with all previous usages, since the function selector hash includes the arguments.

If you want backwards compatibility, a better way would be to have a fn request_without_callback(seed: b256) -> u64.

If you're willing to break the interface however, I think making it an Option<b256> makes more sense, allowing the callback to be another contract than the caller:

// same behavior as current usage
let rid = request(seed, Some(CONTRACT_ID));
// no callback
let rid = request(seed, None);
// call another contract
let rid = request(seed, Some(other_contract_id));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants