From 6f809e92c1ebf1a7ee94a994261a285c04edbef6 Mon Sep 17 00:00:00 2001 From: beer-1 Date: Thu, 24 Oct 2024 14:12:48 +0900 Subject: [PATCH] create account if not exists --- x/bank/keeper/send.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index b8f95931..001c99aa 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -166,17 +166,24 @@ func (k MoveSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, recipients := make([]sdk.AccAddress, 0, len(outputs)) amounts := make([]math.Int, 0, len(outputs)) for _, output := range outputs { + // Create account if recipient does not exist. + outAddress := addrMap[output.Address] + accExists := k.ak.HasAccount(ctx, outAddress) + if !accExists { + defer telemetry.IncrCounter(1, "new", "account") + k.ak.SetAccount(ctx, k.ak.NewAccountWithAddress(ctx, outAddress)) + } + amount := output.Coins.AmountOf(coin.Denom) if !amount.IsPositive() { continue } - recipients = append(recipients, addrMap[output.Address]) + recipients = append(recipients, outAddress) amounts = append(amounts, output.Coins.AmountOf(coin.Denom)) } - err = k.mk.MultiSend(ctx, fromAddr, coin.Denom, recipients, amounts) - if err != nil { + if err = k.mk.MultiSend(ctx, fromAddr, coin.Denom, recipients, amounts); err != nil { return err } }