extend ensure_account_can_withdraw and fix transfer check#1978
extend ensure_account_can_withdraw and fix transfer check#1978
Conversation
| who: &T::AccountId, | ||
| _amount: T::Balance, | ||
| reason: WithdrawReason, | ||
| reasons: impl Into<WithdrawReasons>, |
There was a problem hiding this comment.
I never encounter this syntax before. Can I know where I can read more about this syntax?
There was a problem hiding this comment.
in parameter as far as I know it is same as if I have a generic in function T: Into<WithdrawReasons> and then reasons: T I don't have that much material maybe try to google impl trait
There was a problem hiding this comment.
Incorrect - there should be just one WithdrawReason for any single withdraw,
There was a problem hiding this comment.
Let's say I want to create a runtime module that allow user to reserve and transfer in a single runtime call. How can do it? Call ensure_account_can_withdraw twice with different reasons before all the withdraws will not give the correct result.
There was a problem hiding this comment.
actually calling
ensure_account_can_withdraw(who, Reserve | Transfer, new_free_balance)is equivalent to
ensure_account_can_withdraw(who, Transfer, new_free_balance)
ensure_account_can_withdraw(who, Reserve, new_free_balance)| Self::ensure_account_can_withdraw(transactor, value, WithdrawReason::Transfer, new_from_balance)?; | ||
| Self::ensure_account_can_withdraw( | ||
| transactor, | ||
| WithdrawReason::Transfer | WithdrawReason::TransactionPayment, |
There was a problem hiding this comment.
This is not a transaction payment. Transaction payments happen specifically for inclusion of a transaction in the chain.
|
Removal of |
|
Seems like me and @thiolliere have some misunderstanding of the meaning of transaction payment. @gavofyork can you provide some definitions of it? To my understanding, transaction payment, is the transaction fee user have to pay to have the transaction included in the chain.
If my understanding is wrong, that only (1) is counted as transaction payment, then what is the (2) part? It is a fee charged to user. It is not value transferred to another account. Should there be another |
|
Yes that was thought indeed, then maybe (2) is actually just a Transfer reason (I've been to fast into impl, this should have been discussed in the issue) |
|
So It doesn't relate to the balance of the total withdrawal that lands in the transfer destination's account. |
related to #1962
as pointed by @xlc here we don't check if account can withdraw the amount for the TransactionPayment reason.
so it fix it, improve ensure_account_can_withdraw syntax and remove _amount unused parameter from it.
I am not very sure of this, I may be wrong if TransactionPayment reason is considered a subset of Transfer reason.