pub trait BudgetStore: Send + Sync {
Show 38 methods
// Required methods
fn try_increment(
&self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
) -> Result<bool, BudgetStoreError>;
fn try_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
) -> Result<bool, BudgetStoreError>;
fn try_charge_cost_with_ids_and_authority(
&self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<bool, BudgetStoreError>;
fn reverse_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn reverse_charge_cost_with_ids_and_authority(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError>;
fn reduce_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn reduce_charge_cost_with_ids_and_authority(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError>;
fn settle_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
) -> Result<(), BudgetStoreError>;
fn settle_charge_cost_with_ids_and_authority(
&self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
authority: Option<&BudgetEventAuthority>,
) -> Result<(), BudgetStoreError>;
fn list_usages(
&self,
limit: usize,
capability_id: Option<&str>,
) -> Result<Vec<BudgetUsageRecord>, BudgetStoreError>;
fn get_usage(
&self,
capability_id: &str,
grant_index: usize,
) -> Result<Option<BudgetUsageRecord>, BudgetStoreError>;
// Provided methods
fn try_charge_cost_with_ids(
&self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<bool, BudgetStoreError> { ... }
fn reverse_charge_cost_with_ids(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn reduce_charge_cost_with_ids(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn settle_charge_cost_with_ids(
&self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
hold_id: Option<&str>,
event_id: Option<&str>,
) -> Result<(), BudgetStoreError> { ... }
fn get_invocation_quota_usage(
&self,
_key: &BudgetQuotaKey,
) -> Result<Option<BudgetInvocationQuotaUsage>, BudgetStoreError> { ... }
fn get_cumulative_approval_account_usage(
&self,
_key: &BudgetCumulativeApprovalAccountKey,
) -> Result<Option<BudgetCumulativeApprovalAccountUsage>, BudgetStoreError> { ... }
fn get_cumulative_approval_operation_usage(
&self,
_operation_id: &str,
) -> Result<Option<BudgetCumulativeApprovalUsage>, BudgetStoreError> { ... }
fn list_mutation_events(
&self,
_limit: usize,
_capability_id: Option<&str>,
_grant_index: Option<usize>,
) -> Result<Vec<BudgetMutationRecord>, BudgetStoreError> { ... }
fn budget_guarantee_level(&self) -> BudgetGuaranteeLevel { ... }
fn budget_authority_profile(&self) -> BudgetAuthorityProfile { ... }
fn budget_metering_profile(&self) -> BudgetMeteringProfile { ... }
fn capture_invocation_reservations(
&self,
_request: BudgetCaptureInvocationRequest,
) -> Result<BudgetInvocationCaptureDecision, BudgetStoreError> { ... }
fn authorize_cumulative_approval(
&self,
_request: BudgetAuthorizeCumulativeApprovalRequest,
) -> Result<BudgetCumulativeApprovalAuthorizationDecision, BudgetStoreError> { ... }
fn cancel_captured_before_dispatch(
&self,
_request: BudgetCancelCapturedBeforeDispatchRequest,
) -> Result<BudgetCapturedBeforeDispatchCancellationDecision, BudgetStoreError> { ... }
fn authorize_budget_hold(
&self,
request: BudgetAuthorizeHoldRequest,
) -> Result<BudgetAuthorizeHoldDecision, BudgetStoreError> { ... }
fn reverse_budget_hold(
&self,
_request: BudgetReverseHoldRequest,
) -> Result<BudgetReverseHoldDecision, BudgetStoreError> { ... }
fn release_budget_hold(
&self,
_request: BudgetReleaseHoldRequest,
) -> Result<BudgetReleaseHoldDecision, BudgetStoreError> { ... }
fn reconcile_budget_hold(
&self,
_request: BudgetReconcileHoldRequest,
) -> Result<BudgetReconcileHoldDecision, BudgetStoreError> { ... }
fn capture_budget_hold(
&self,
_request: BudgetCaptureHoldRequest,
) -> Result<BudgetCaptureHoldDecision, BudgetStoreError> { ... }
fn reap_orphaned_holds(
&self,
realized_by_hold: &HashMap<String, u64>,
) -> Result<(usize, usize), BudgetStoreError> { ... }
fn count_open_holds(&self) -> Result<usize, BudgetStoreError> { ... }
fn list_open_delegated_reserved_hold_ids(
&self,
) -> Result<Option<Vec<String>>, BudgetStoreError> { ... }
fn request_id_has_reserved_hold(
&self,
request_id: &str,
) -> Result<Option<bool>, BudgetStoreError> { ... }
fn get_budget_hold(
&self,
hold_id: &str,
) -> Result<Option<BudgetHoldSnapshot>, BudgetStoreError> { ... }
fn mark_hold_reserved(
&self,
_hold_id: &str,
_reserved_until_unix_secs: i64,
_currency: &str,
_payment_reference: Option<&str>,
_envelope: &ReservedHoldEnvelope,
) -> Result<(), BudgetStoreError> { ... }
fn reserve_invocation_hold(
&self,
_hold_id: &str,
_capability_id: &str,
_grant_index: usize,
_reserved_until_unix_secs: i64,
_envelope: &ReservedHoldEnvelope,
) -> Result<(), BudgetStoreError> { ... }
fn reap_expired_reserved_holds(
&self,
now_unix_secs: i64,
) -> Result<usize, BudgetStoreError> { ... }
}Required Methods§
fn try_increment( &self, capability_id: &str, grant_index: usize, max_invocations: Option<u32>, ) -> Result<bool, BudgetStoreError>
Sourcefn try_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
max_invocations: Option<u32>,
cost_units: u64,
max_cost_per_invocation: Option<u64>,
max_total_cost_units: Option<u64>,
) -> Result<bool, BudgetStoreError>
fn try_charge_cost( &self, capability_id: &str, grant_index: usize, max_invocations: Option<u32>, cost_units: u64, max_cost_per_invocation: Option<u64>, max_total_cost_units: Option<u64>, ) -> Result<bool, BudgetStoreError>
Atomically check monetary budget limits and record provisional exposure if within bounds.
Checks:
invocation_count < max_invocations(if set)cost_units <= max_cost_per_invocation(if set)(total_cost_exposed + total_cost_realized_spend + cost_units) <= max_total_cost_units(if set)
On pass: increments invocation_count by 1 and total_cost_exposed by
cost_units, allocates a new replication seq, returns Ok(true).
On any limit exceeded: rolls back, returns Ok(false).
Apply a charge under the caller’s durable hold/event identity and authority fence. Implementations must preserve all three values or return an explicit unsupported error. This method is required so a backend upgrade cannot compile successfully and fail only on live calls.
Sourcefn reverse_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>
fn reverse_charge_cost( &self, capability_id: &str, grant_index: usize, cost_units: u64, ) -> Result<(), BudgetStoreError>
Reverse a previously applied provisional exposure for a pre-execution denial path.
Reverse a charge under the exact durable identity and authority fence.
Sourcefn reduce_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
cost_units: u64,
) -> Result<(), BudgetStoreError>
fn reduce_charge_cost( &self, capability_id: &str, grant_index: usize, cost_units: u64, ) -> Result<(), BudgetStoreError>
Release a previously exposed monetary amount without changing invocation count.
This is used when the kernel needs to release provisional exposure without realizing any spend in the budget store itself.
Release exposure under the exact durable identity and authority fence.
Sourcefn settle_charge_cost(
&self,
capability_id: &str,
grant_index: usize,
exposed_cost_units: u64,
realized_cost_units: u64,
) -> Result<(), BudgetStoreError>
fn settle_charge_cost( &self, capability_id: &str, grant_index: usize, exposed_cost_units: u64, realized_cost_units: u64, ) -> Result<(), BudgetStoreError>
Atomically release provisional exposure and record realized spend.
This removes exposed_cost_units from total_cost_exposed and adds
realized_cost_units to total_cost_realized_spend without changing
invocation count. realized_cost_units must not exceed
exposed_cost_units.
Reconcile exposure and spend under the exact durable identity and authority fence.
fn list_usages( &self, limit: usize, capability_id: Option<&str>, ) -> Result<Vec<BudgetUsageRecord>, BudgetStoreError>
fn get_usage( &self, capability_id: &str, grant_index: usize, ) -> Result<Option<BudgetUsageRecord>, BudgetStoreError>
Provided Methods§
fn try_charge_cost_with_ids( &self, capability_id: &str, grant_index: usize, max_invocations: Option<u32>, cost_units: u64, max_cost_per_invocation: Option<u64>, max_total_cost_units: Option<u64>, hold_id: Option<&str>, event_id: Option<&str>, ) -> Result<bool, BudgetStoreError>
fn reverse_charge_cost_with_ids( &self, capability_id: &str, grant_index: usize, cost_units: u64, hold_id: Option<&str>, event_id: Option<&str>, ) -> Result<(), BudgetStoreError>
fn reduce_charge_cost_with_ids( &self, capability_id: &str, grant_index: usize, cost_units: u64, hold_id: Option<&str>, event_id: Option<&str>, ) -> Result<(), BudgetStoreError>
fn settle_charge_cost_with_ids( &self, capability_id: &str, grant_index: usize, exposed_cost_units: u64, realized_cost_units: u64, hold_id: Option<&str>, event_id: Option<&str>, ) -> Result<(), BudgetStoreError>
fn get_invocation_quota_usage( &self, _key: &BudgetQuotaKey, ) -> Result<Option<BudgetInvocationQuotaUsage>, BudgetStoreError>
fn get_cumulative_approval_account_usage( &self, _key: &BudgetCumulativeApprovalAccountKey, ) -> Result<Option<BudgetCumulativeApprovalAccountUsage>, BudgetStoreError>
fn get_cumulative_approval_operation_usage( &self, _operation_id: &str, ) -> Result<Option<BudgetCumulativeApprovalUsage>, BudgetStoreError>
fn list_mutation_events( &self, _limit: usize, _capability_id: Option<&str>, _grant_index: Option<usize>, ) -> Result<Vec<BudgetMutationRecord>, BudgetStoreError>
fn budget_guarantee_level(&self) -> BudgetGuaranteeLevel
fn budget_metering_profile(&self) -> BudgetMeteringProfile
fn capture_invocation_reservations( &self, _request: BudgetCaptureInvocationRequest, ) -> Result<BudgetInvocationCaptureDecision, BudgetStoreError>
fn cancel_captured_before_dispatch( &self, _request: BudgetCancelCapturedBeforeDispatchRequest, ) -> Result<BudgetCapturedBeforeDispatchCancellationDecision, BudgetStoreError>
fn reverse_budget_hold( &self, _request: BudgetReverseHoldRequest, ) -> Result<BudgetReverseHoldDecision, BudgetStoreError>
fn release_budget_hold( &self, _request: BudgetReleaseHoldRequest, ) -> Result<BudgetReleaseHoldDecision, BudgetStoreError>
fn reconcile_budget_hold( &self, _request: BudgetReconcileHoldRequest, ) -> Result<BudgetReconcileHoldDecision, BudgetStoreError>
fn capture_budget_hold( &self, _request: BudgetCaptureHoldRequest, ) -> Result<BudgetCaptureHoldDecision, BudgetStoreError>
fn reap_orphaned_holds( &self, realized_by_hold: &HashMap<String, u64>, ) -> Result<(usize, usize), BudgetStoreError>
fn count_open_holds(&self) -> Result<usize, BudgetStoreError>
fn list_open_delegated_reserved_hold_ids( &self, ) -> Result<Option<Vec<String>>, BudgetStoreError>
fn request_id_has_reserved_hold( &self, request_id: &str, ) -> Result<Option<bool>, BudgetStoreError>
fn get_budget_hold( &self, hold_id: &str, ) -> Result<Option<BudgetHoldSnapshot>, BudgetStoreError>
fn mark_hold_reserved( &self, _hold_id: &str, _reserved_until_unix_secs: i64, _currency: &str, _payment_reference: Option<&str>, _envelope: &ReservedHoldEnvelope, ) -> Result<(), BudgetStoreError>
fn reserve_invocation_hold( &self, _hold_id: &str, _capability_id: &str, _grant_index: usize, _reserved_until_unix_secs: i64, _envelope: &ReservedHoldEnvelope, ) -> Result<(), BudgetStoreError>
fn reap_expired_reserved_holds( &self, now_unix_secs: i64, ) -> Result<usize, BudgetStoreError>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".