Skip to content

Commit

Permalink
Implement log for unhandled errors in asset-router
Browse files Browse the repository at this point in the history
  • Loading branch information
sea212 committed Jan 17, 2024
1 parent 0f13743 commit eeb43e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions zrml/asset-router/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[dependencies]
frame-support = { workspace = true }
frame-system = { workspace = true }
log = { workspace = true }
orml-traits = { workspace = true }
pallet-assets = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive", "max-encoded-len"] }
Expand Down
32 changes: 28 additions & 4 deletions zrml/asset-router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ pub mod pallet {
if let Ok(currency) = T::CurrencyType::try_from($currency_id) {
<T::Currencies as $currency_trait<T::AccountId>>::$currency_method(currency, $($args),+)
} else {
Self::log_unsupported($currency_id, stringify!($currency_method));
$error
}
};
Expand All @@ -232,28 +233,45 @@ pub mod pallet {
} else if let Ok(asset) = T::CustomAssetType::try_from($asset_id) {
T::CustomAssets::$asset_method(asset, $($args),*)
} else {
Self::log_unsupported($asset_id, stringify!($asset_method));
$error
}
};
}

impl<T: Config> Pallet<T> {
#[inline]
fn log_unsupported(asset: T::AssetType, function: &str) {
log::warn!("[AssetRouter] Asset {:?} not supported in function {:?}", asset, function);

This comment has been minimized.

Copy link
@Chralt98

Chralt98 Jan 17, 2024

Member

Would be good to have a log target instead of [AssetRouter].

This comment has been minimized.

Copy link
@sea212

sea212 Jan 17, 2024

Author Member

Thanks for pointing that out, totally forgot about that option.

e7c982a

}
}

impl<T: Config> MultiCurrency<T::AccountId> for Pallet<T> {
type CurrencyId = T::AssetType;
type Balance = T::Balance;

fn minimum_balance(currency_id: Self::CurrencyId) -> Self::Balance {
let min_balance = route_call!(currency_id, minimum_balance, minimum_balance,);
min_balance.unwrap_or(0u8.into())
min_balance.unwrap_or_else(|_b| {
Self::log_unsupported(currency_id, "minimum_balance");
Self::Balance::zero()
})
}

fn total_issuance(currency_id: Self::CurrencyId) -> Self::Balance {
let total_issuance = route_call!(currency_id, total_issuance, total_issuance,);
total_issuance.unwrap_or(0u8.into())
total_issuance.unwrap_or_else(|_b| {
Self::log_unsupported(currency_id, "total_issuance");
Self::Balance::zero()
})
}

fn total_balance(currency_id: Self::CurrencyId, who: &T::AccountId) -> Self::Balance {
let total_balance = route_call!(currency_id, total_balance, balance, who);
total_balance.unwrap_or(0u8.into())
total_balance.unwrap_or_else(|_b| {
Self::log_unsupported(currency_id, "total_balance");
Self::Balance::zero()
})
}

fn free_balance(currency_id: Self::CurrencyId, who: &T::AccountId) -> Self::Balance {
Expand All @@ -266,7 +284,8 @@ pub mod pallet {
} else if let Ok(asset) = T::CustomAssetType::try_from(currency_id) {
T::CustomAssets::reducible_balance(asset, who, false)
} else {
0u8.into()
Self::log_unsupported(currency_id, "free_balance");
Self::Balance::zero()
}
}

Expand Down Expand Up @@ -355,6 +374,7 @@ pub mod pallet {
} else if let Ok(asset) = T::CustomAssetType::try_from(currency_id) {
T::CustomAssets::reducible_balance(asset, who, false) >= value
} else {
Self::log_unsupported(currency_id, "can_slash");
false
}
}
Expand All @@ -379,6 +399,7 @@ pub mod pallet {
.map(|b| amount.saturating_sub(b))
.unwrap_or_else(|_| amount)
} else {
Self::log_unsupported(currency_id, "slash");
amount
}
}
Expand Down Expand Up @@ -553,6 +574,7 @@ pub mod pallet {
);
}

Self::log_unsupported(currency_id, "reserved_balance_named");
Zero::zero()
}

Expand Down Expand Up @@ -583,6 +605,7 @@ pub mod pallet {
);
}

Self::log_unsupported(currency_id, "unreserve_named");
value
}

Expand All @@ -598,6 +621,7 @@ pub mod pallet {
);
}

Self::log_unsupported(currency_id, "slash_reserved_named");
value
}

Expand Down

0 comments on commit eeb43e3

Please sign in to comment.