Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

transfer_all() function in Balances Pallet #8696

Closed
CurlyBracketEffect opened this issue Apr 29, 2021 · 6 comments · Fixed by #9018
Closed

transfer_all() function in Balances Pallet #8696

CurlyBracketEffect opened this issue Apr 29, 2021 · 6 comments · Fixed by #9018
Labels
J0-enhancement An additional feature request. Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.

Comments

@CurlyBracketEffect
Copy link

It would be helpful to have a function that takes into account the transaction fee required to send the entire balance of an account without leaving any dust behind to be reaped.

amountToTransfer + partialFee + tip? = Total balance

@github-actions github-actions bot added the J2-unconfirmed Issue might be valid, but it’s not yet known. label Apr 29, 2021
@kianenigma kianenigma added J0-enhancement An additional feature request. Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be. and removed J2-unconfirmed Issue might be valid, but it’s not yet known. labels Apr 29, 2021
@shawntabrizi
Copy link
Member

I think by the time it gets to the extrinsic, all fees and tips are already deducted from the account, so it should be simple enough to query the free balance of the user account, and then use that amount for a transfer call.

@xlc
Copy link
Contributor

xlc commented Apr 30, 2021

but block weight fee multiplier changes every block so you can never guarantee the transfer success

@shawntabrizi
Copy link
Member

@xlc I think you are reading my comment wrong.

I think a new extrinsic like this solves this:

fn transfer_all_free(origin, to: T::AccountId) {
    let who = ensure_signed(origin)?;
    let total_free = Self::free_balance(who);
    Self::transfer(who, to, total_free, AllowDeath)?;
}

This logic is built into the runtime and happens after all the fee stuff is deducted. So I think it will always succeed when the full transfer is possible.

@kianenigma
Copy link
Contributor

but block weight fee multiplier changes every block so you can never guarantee the transfer success

Yes but not during the block, so for the duration of a single block, it is constant. I think shawn's proposal works.

@mutobui
Copy link
Contributor

mutobui commented Mar 24, 2022

@xlc I think you are reading my comment wrong.

I think a new extrinsic like this solves this:

fn transfer_all_free(origin, to: T::AccountId) {
    let who = ensure_signed(origin)?;
    let total_free = Self::free_balance(who);
    Self::transfer(who, to, total_free, AllowDeath)?;
}

This logic is built into the runtime and happens after all the fee stuff is deducted. So I think it will always succeed when the full transfer is possible.

I try to implement transfer_all_free in runtime with KeepAlive then got the error

ModuleError {
            index: 1,
            error: 4,
            message: Some(
                "KeepAlive",
            ),
        },

@ggwpez
Copy link
Member

ggwpez commented Mar 24, 2022

I try to implement transfer_all_free in runtime with KeepAlive then got the error

Why are you implementing it again? The function already exists now Balances::transfer_all @mutobui

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
J0-enhancement An additional feature request. Z6-mentor An easy task where a mentor is available. Please indicate in the issue who the mentor could be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants