|
17 | 17 |
|
18 | 18 | //! Trait for handling imbalances. |
19 | 19 |
|
20 | | -use crate::traits::misc::TryDrop; |
| 20 | +use frame_support::traits::{fungible, fungibles, misc::TryDrop}; |
| 21 | +use sp_core::TypedGet; |
| 22 | +use sp_std::marker::PhantomData; |
21 | 23 |
|
22 | 24 | /// Handler for when some currency "account" decreased in balance for |
23 | 25 | /// some reason. |
@@ -53,3 +55,29 @@ pub trait OnUnbalanced<Imbalance: TryDrop> { |
53 | 55 | } |
54 | 56 |
|
55 | 57 | impl<Imbalance: TryDrop> OnUnbalanced<Imbalance> for () {} |
| 58 | + |
| 59 | +/// Resolves received asset credit to account `A`, implementing [`OnUnbalanced`]. |
| 60 | +/// |
| 61 | +/// Credits that cannot be resolved to account `A` are dropped. This may occur if the account for |
| 62 | +/// address `A` does not exist and the existential deposit requirement is not met. |
| 63 | +pub struct ResolveTo<A, F>(PhantomData<(A, F)>); |
| 64 | +impl<A: TypedGet, F: fungible::Balanced<A::Type>> OnUnbalanced<fungible::Credit<A::Type, F>> |
| 65 | + for ResolveTo<A, F> |
| 66 | +{ |
| 67 | + fn on_nonzero_unbalanced(credit: fungible::Credit<A::Type, F>) { |
| 68 | + let _ = F::resolve(&A::get(), credit).map_err(|c| drop(c)); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/// Resolves received asset credit to account `A`, implementing [`OnUnbalanced`]. |
| 73 | +/// |
| 74 | +/// Credits that cannot be resolved to account `A` are dropped. This may occur if the account for |
| 75 | +/// address `A` does not exist and the existential deposit requirement is not met. |
| 76 | +pub struct ResolveAssetTo<A, F>(PhantomData<(A, F)>); |
| 77 | +impl<A: TypedGet, F: fungibles::Balanced<A::Type>> OnUnbalanced<fungibles::Credit<A::Type, F>> |
| 78 | + for ResolveAssetTo<A, F> |
| 79 | +{ |
| 80 | + fn on_nonzero_unbalanced(credit: fungibles::Credit<A::Type, F>) { |
| 81 | + let _ = F::resolve(&A::get(), credit).map_err(|c| drop(c)); |
| 82 | + } |
| 83 | +} |
0 commit comments