Skip to content

Commit

Permalink
Merge pull request #58 from neutron-org/feat/hooks
Browse files Browse the repository at this point in the history
Feat: refactor hooks
  • Loading branch information
pr0n00gler authored Sep 24, 2024
2 parents d567e3c + 4dbd2a2 commit 207f347
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions x/bank/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ var (
priv2 = secp256k1.GenPrivKey()
addr2 = sdk.AccAddress(priv2.PubKey().Address())
addr3 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
addr4 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())
addr5 = sdk.AccAddress(secp256k1.GenPrivKey().PubKey().Address())

coins = sdk.Coins{sdk.NewInt64Coin("foocoin", 10)}
halfCoins = sdk.Coins{sdk.NewInt64Coin("foocoin", 5)}
Expand Down Expand Up @@ -572,4 +574,30 @@ func TestHooks(t *testing.T) {
require.NoError(t, err)
require.Equal(t, countTrackBeforeSend, expNextCount)
expNextCount++

err = s.BankKeeper.InputOutputCoins(ctx, types.Input{Address: addr1.String(), Coins: triggerTrackSendAmount}, []types.Output{{Address: addr2.String(), Coins: triggerTrackSendAmount}})
require.NoError(t, err)
require.Equal(t, countTrackBeforeSend, expNextCount)

multiSendTrackInput := types.Input{
Address: addr1.String(),
Coins: triggerTrackSendAmount.MulInt(sdkmath.NewInt(4)),
}
multiSendTrackOutput := []types.Output{{
Address: addr2.String(),
Coins: triggerTrackSendAmount,
}, {
Address: addr3.String(),
Coins: triggerTrackSendAmount,
}, {
Address: addr4.String(),
Coins: triggerTrackSendAmount,
}, {
Address: addr5.String(),
Coins: triggerTrackSendAmount,
}}
err = s.BankKeeper.InputOutputCoins(ctx, multiSendTrackInput, multiSendTrackOutput)
require.NoError(t, err)
expNextCount += 4
require.Equal(t, countTrackBeforeSend, expNextCount)
}
13 changes: 13 additions & 0 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
return err
}

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

if err := k.BlockBeforeSend(ctx, inAddress, outAddress, out.Coins); err != nil {
return err
}

k.TrackBeforeSend(ctx, inAddress, outAddress, out.Coins)
}

err = k.subUnlockedCoins(ctx, inAddress, input.Coins)
if err != nil {
return err
Expand Down

0 comments on commit 207f347

Please sign in to comment.