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

Call ID Insertion and Resolution For #520 #533

Merged
merged 12 commits into from
Dec 9, 2024
Merged

Call ID Insertion and Resolution For #520 #533

merged 12 commits into from
Dec 9, 2024

Conversation

tbraun96
Copy link
Collaborator

@tbraun96 tbraun96 commented Dec 7, 2024

Resolves #520
Resolves #534

  1. Define the context. TangleClientContext now requires a call_id field:
#[derive(Clone, TangleClientContext)]
pub struct MyContext {
    #[config]
    sdk_config: StdGadgetConfiguration,
    #[call_id]
    call_id: Option<u64>,
}
  1. Access the call id at runtime via the context:
#[job(
    id = 0,
    params(x),
    event_listener(
        listener = TangleEventListener<MyContext, JobCalled>,
        pre_processor = services_pre_processor,
        post_processor = services_post_processor,
    ),
)]
/// Returns x^2 saturating to [`u64::MAX`] if overflow occurs.
pub fn xsquare(x: u64, context: MyContext) -> Result<u64, gadget_sdk::Error> {
    assert!(context.call_id.is_some()); // <----- Assertion success; runtime injection occurs
    Ok(x.saturating_pow(2))
}

NOTE: This only propagates the call_id from the pre-processor to the job function. The propagation from the job function to the post-processor is not covered.

@Serial-ATA Serial-ATA force-pushed the call_id_insertion branch 2 times, most recently from 39065c2 to f79195c Compare December 9, 2024 21:29
@tbraun96 tbraun96 merged commit 4471000 into main Dec 9, 2024
12 checks passed
This was referenced Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Completed ✅
Development

Successfully merging this pull request may close these issues.

Runtime Call ID Injection (for the job function) [TASK] Testing fetcher is not automatically generated
3 participants