feat(evm): add find_all_grants to Policy trait with shared auto_type queries
This commit is contained in:
@@ -97,6 +97,11 @@ pub trait Policy: Sized {
|
||||
conn: &mut impl AsyncConnection<Backend = Sqlite>,
|
||||
) -> impl Future<Output = QueryResult<Option<Grant<Self::Settings>>>> + Send;
|
||||
|
||||
// Return all non-revoked grants, eagerly loading policy-specific settings
|
||||
fn find_all_grants(
|
||||
conn: &mut impl AsyncConnection<Backend = Sqlite>,
|
||||
) -> impl Future<Output = QueryResult<Vec<Grant<Self::Settings>>>> + Send;
|
||||
|
||||
// Records, updates or deletes rate limits
|
||||
// In other words, records grant-specific things after transaction is executed
|
||||
fn record_transaction(
|
||||
@@ -192,6 +197,19 @@ pub enum SpecificGrant {
|
||||
TokenTransfer(token_transfers::Settings),
|
||||
}
|
||||
|
||||
/// Blanket conversion from a typed `Grant<S>` into `Grant<SpecificGrant>`.
|
||||
/// Lets the engine collect across all policies into one `Vec<Grant<SpecificGrant>>`.
|
||||
impl<S: Into<SpecificGrant>> From<Grant<S>> for Grant<SpecificGrant> {
|
||||
fn from(g: Grant<S>) -> Self {
|
||||
Grant {
|
||||
id: g.id,
|
||||
shared_grant_id: g.shared_grant_id,
|
||||
shared: g.shared,
|
||||
settings: g.settings.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FullGrant<PolicyGrant> {
|
||||
pub basic: SharedGrantSettings,
|
||||
pub specific: PolicyGrant,
|
||||
|
||||
Reference in New Issue
Block a user