--- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -452,6 +452,10 @@ token: TokenId, amount: u128, ) -> DispatchResult { + if >::get((collection.id, token, owner)) == 0 { + return Err(>::MustBeTokenOwner.into()); + } + let total_supply = >::get((collection.id, token)) .checked_sub(amount) .ok_or(>::TokenValueTooLow)?; @@ -739,12 +743,17 @@ >::ensure_correct_receiver(to)?; let initial_balance_from = >::get((collection.id, token, from)); + + if initial_balance_from == 0 { + return Err(>::MustBeTokenOwner.into()); + } + let updated_balance_from = initial_balance_from .checked_sub(amount) .ok_or(>::TokenValueTooLow)?; let mut create_target = false; let from_to_differ = from != to; - let updated_balance_to = if from != to { + let updated_balance_to = if from != to && amount != 0 { let old_balance = >::get((collection.id, token, to)); if old_balance == 0 { create_target = true; @@ -786,16 +795,17 @@ // ========= - >::nest_if_sent_to_token( - from.clone(), - to, - collection.id, - token, - nesting_budget, - )?; + if let Some(updated_balance_to) = updated_balance_to { + // from != to && amount != 0 + + >::nest_if_sent_to_token( + from.clone(), + to, + collection.id, + token, + nesting_budget, + )?; - if let Some(updated_balance_to) = updated_balance_to { - // from != to if updated_balance_from == 0 { >::remove((collection.id, token, from)); >::unnest_if_nested(from, collection.id, token);