Skip to content

Commit

Permalink
send without acc creation
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Nov 28, 2023
1 parent 598a024 commit 5d90758
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type SendKeeper interface {

InputOutputCoins(ctx sdk.Context, inputs []types.Input, outputs []types.Output) error
SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsWithoutAccCreation(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error

GetParams(ctx sdk.Context) types.Params
SetParams(ctx sdk.Context, params types.Params)
Expand Down Expand Up @@ -131,13 +132,7 @@ func (k BaseSendKeeper) InputOutputCoins(ctx sdk.Context, inputs []types.Input,
// SendCoins transfers amt coins from a sending account to a receiving account.
// An error is returned upon failure.
func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
err := k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
}

err = k.addCoins(ctx, toAddr, amt)
if err != nil {
if err := k.SendCoinsWithoutAccCreation(ctx, fromAddr, toAddr, amt); err != nil {
return err
}

Expand All @@ -151,6 +146,20 @@ func (k BaseSendKeeper) SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAd
k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, toAddr))
}

return nil
}

func (k BaseSendKeeper) SendCoinsWithoutAccCreation(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error {
err := k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
}

err = k.addCoins(ctx, toAddr, amt)
if err != nil {
return err
}

ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeTransfer,
Expand Down

0 comments on commit 5d90758

Please sign in to comment.