Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SendRestriction in SendCoins and InputOutputCoins #586

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,37 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, inputs []types.Inp
return err
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

for _, in := range inputs {
inAddress, err := k.ak.AddressCodec().StringToBytes(in.Address)
if err != nil {
return err
}

inAddress = k.ak.GetMergedAccountAddressIfExists(ctx, inAddress)
for _, out := range outputs {
outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address)
if err != nil {
return err
}

outAddress = k.ak.GetMergedAccountAddressIfExists(ctx, outAddress)
_, err = k.sendRestriction.apply(ctx, inAddress, outAddress, out.Coins)
if err != nil {
return err
}
}
}

sdkCtx := sdk.UnwrapSDKContext(ctx)

for _, in := range inputs {
inAddress, err := k.ak.AddressCodec().StringToBytes(in.Address)
RavenXce marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

inAddress = k.ak.GetMergedAccountAddressIfExists(ctx, inAddress)

err = k.subUnlockedCoins(ctx, inAddress, in.Coins)
if err != nil {
return err
Expand All @@ -200,10 +218,6 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, inputs []types.Inp
}

outAddress = k.ak.GetMergedAccountAddressIfExists(ctx, outAddress)
// outAddress, err = k.sendRestriction.apply(ctx, inAddress, outAddress, out.Coins)
// if err != nil {
// return err
// }

if err := k.addCoins(ctx, outAddress, out.Coins); err != nil {
return err
Expand Down Expand Up @@ -246,12 +260,14 @@ func (k BaseSendKeeper) SendCoins(ctx context.Context, fromAddr, toAddr sdk.AccA
return err
}

err = k.subUnlockedCoins(ctx, fromAddr, amt)
// Unreleased improvement in v0.51
// https://github.com/cosmos/cosmos-sdk/pull/20517
toAddr, err = k.sendRestriction.apply(ctx, fromAddr, toAddr, amt)
if err != nil {
return err
}

toAddr, err = k.sendRestriction.apply(ctx, fromAddr, toAddr, amt)
err = k.subUnlockedCoins(ctx, fromAddr, amt)
if err != nil {
return err
}
Expand Down