Skip to main content

delegate

Attribute Macro delegate 

Source
#[delegate]
Expand description

Generate the necessary code for the WASM runtime to interact with your delegate ergonomically and safely.

§Declaring a manifest

A delegate that wants lifecycle events or node-enforced capabilities declares them, and the macro embeds a manifest in the WASM (see freenet_stdlib::prelude::DelegateManifest):

ⓘ
#[delegate(manifest(lifecycle = [Installed, NodeStarted], capabilities = [Background]))]
impl DelegateInterface for MyDelegate { /* ... */ }

Without manifest(...) nothing is embedded and the delegate behaves as delegates always have. Adding one changes the WASM, and so the delegate key.

Periodic wake-ups are declared the same way, as tag = interval in seconds (60 s to 7 days, at most 4); the node then delivers InboundDelegateMsg::WakeupFired { tag } on that schedule with no app open:

ⓘ
#[delegate(manifest(
    lifecycle = [NodeStarted],
    capabilities = [Background],
    wakeups = [heartbeat = 300],
))]
impl DelegateInterface for MyDelegate { /* ... */ }

A node that predates wake-ups ignores the wakeups entry and still honours the rest, so one build works on both. Such a node asks the user for Background only when a lifecycle kind is listed, so list one (as above) if the delegate should be granted there too.

Listing any lifecycle kind or wake-up requires capabilities = [Background]. Only one manifest per crate: the section is per WASM module. Custom sections must survive any post-processing of the module (wasm-opt --strip-*, wasm-strip remove them); a missing section means “no manifest”, silently.