Skip to content

Commit 178fb34

Browse files
committed
Refactor UnlockTokens method to trim 'uamf' suffix from msg.Amount before parsing to uint64, enhancing input validation and preventing parsing errors.
1 parent 67fefc2 commit 178fb34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

x/evmbridge/keeper/msg_server_unlock_tokens.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"strconv"
7+
"strings"
78
"time"
89

910
"github.com/airchains-network/junction/x/evmbridge/types"
@@ -44,7 +45,8 @@ func (k msgServer) UnlockTokens(goCtx context.Context, msg *types.MsgUnlockToken
4445
}
4546

4647
// we need to check if the passed amount is a valid number or not
47-
_, err = strconv.ParseUint(msg.Amount, 10, 64)
48+
trimmedAmount := strings.TrimSuffix(msg.Amount, "uamf")
49+
_, err = strconv.ParseUint(trimmedAmount, 10, 64)
4850
if err != nil {
4951
return nil, types.ErrInvalidAmount.Wrapf("invalid amount: %s", err)
5052
}
@@ -58,7 +60,7 @@ func (k msgServer) UnlockTokens(goCtx context.Context, msg *types.MsgUnlockToken
5860
if err != nil {
5961
return nil, types.ErrInvalidAmount.Wrap(err.Error())
6062
}
61-
amountUint64, err := strconv.ParseUint(msg.Amount, 10, 64)
63+
amountUint64, err := strconv.ParseUint(trimmedAmount, 10, 64)
6264
if err != nil {
6365
return nil, types.ErrInvalidAmount.Wrapf("invalid amount: %s", err)
6466
}

0 commit comments

Comments
 (0)