Skip to main content

whole_token_request

Function whole_token_request 

Source
pub fn whole_token_request(
    requested: u64,
    total: u64,
    units_per_token: u64,
) -> u64
Expand description

The micro-token request a whole-token consume hands to plan_consume.

requested is in whole tokens and total is the capped balance in storage units, units_per_token to a token. The result is the request in storage units, cut down to the whole tokens total holds, so the grant plan_consume makes from it is a whole number of tokens and a part token stays in the bucket.

Production passes MICROS_PER_TOKEN. The stateright model in tests/bucket_model.rs drives this same function with a small units_per_token, which keeps its search small.

§Panics

Panics if units_per_token is zero. Convert a whole-token request to storage units, limited by the whole tokens the balance holds.

Saturating the multiplication cannot grant a fractional token or reduce the largest representable whole-token grant.

§Panics

Panics if units_per_token is zero.