Skip to content

Commit

Permalink
emit same events with cosmos-sdk interface
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Oct 23, 2024
1 parent aaae3ee commit 96eec93
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,46 @@ func (k MoveSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
return err
}

Check warning on line 119 in x/bank/keeper/send.go

View check run for this annotation

Codecov / codecov/patch

x/bank/keeper/send.go#L118-L119

Added lines #L118 - L119 were not covered by tests

// event emission
sdkCtx := sdk.UnwrapSDKContext(ctx)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(types.AttributeKeySender, input.Address),
),
)

// emit coin spent event
sdkCtx.EventManager().EmitEvent(
types.NewCoinSpentEvent(fromAddr, input.Coins),
)

// emit coin received events and do address caching
addrMap := make(map[string][]byte)
for _, output := range outputs {
addr, err := k.ak.AddressCodec().StringToBytes(output.Address)
if err != nil {
return err
}

Check warning on line 141 in x/bank/keeper/send.go

View check run for this annotation

Codecov / codecov/patch

x/bank/keeper/send.go#L140-L141

Added lines #L140 - L141 were not covered by tests

// cache bytes address
addrMap[output.Address] = addr

// emit coin received event
sdkCtx.EventManager().EmitEvent(
types.NewCoinReceivedEvent(addr, output.Coins),
)

// emit transfer event (for compatibility with cosmos bank)
sdkCtx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeTransfer,
sdk.NewAttribute(types.AttributeKeyRecipient, output.Address),
sdk.NewAttribute(sdk.AttributeKeyAmount, output.Coins.String()),
),
)
}

for _, coin := range input.Coins {
if !coin.Amount.IsPositive() {
continue

Check warning on line 163 in x/bank/keeper/send.go

View check run for this annotation

Codecov / codecov/patch

x/bank/keeper/send.go#L163

Added line #L163 was not covered by tests
Expand All @@ -132,16 +171,6 @@ func (k MoveSendKeeper) InputOutputCoins(ctx context.Context, input types.Input,
continue

Check warning on line 171 in x/bank/keeper/send.go

View check run for this annotation

Codecov / codecov/patch

x/bank/keeper/send.go#L171

Added line #L171 was not covered by tests
}

// cache bytes address
if _, ok := addrMap[output.Address]; !ok {
addr, err := k.ak.AddressCodec().StringToBytes(output.Address)
if err != nil {
return err
}

addrMap[output.Address] = addr
}

recipients = append(recipients, addrMap[output.Address])
amounts = append(amounts, output.Coins.AmountOf(coin.Denom))
}
Expand Down

0 comments on commit 96eec93

Please sign in to comment.