Skip to content

Commit

Permalink
Make x/rollup helper funcs private
Browse files Browse the repository at this point in the history
  • Loading branch information
natebeauregard committed Aug 21, 2024
1 parent 9a33f62 commit a3a07be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions x/rollup/keeper/deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ func (k *Keeper) setL1BlockHistory(ctx context.Context, info *derive.L1BlockInfo
return nil
}

// ProcessL1SystemDepositTx processes the L1 Attributes deposit tx and returns the L1 block info.
func (k *Keeper) ProcessL1SystemDepositTx(ctx sdk.Context, txBytes []byte) (*derive.L1BlockInfo, error) { //nolint:gocritic // hugeParam
// processL1AttributesTx processes the L1 Attributes deposit tx and returns the L1 block info.
func (k *Keeper) processL1AttributesTx(ctx sdk.Context, txBytes []byte) (*derive.L1BlockInfo, error) { //nolint:gocritic // hugeParam
var tx ethtypes.Transaction
if err := tx.UnmarshalBinary(txBytes); err != nil {
ctx.Logger().Error("Failed to unmarshal system deposit transaction", "index", 0, "err", err, "txBytes", txBytes)
return nil, types.WrapError(types.ErrInvalidL1Txs, "failed to unmarshal system deposit transaction: %v", err)
ctx.Logger().Error("Failed to unmarshal L1 attributes transaction", "index", 0, "err", err, "txBytes", txBytes)
return nil, types.WrapError(types.ErrInvalidL1Txs, "failed to unmarshal L1 attributes transaction: %v", err)
}
if !tx.IsDepositTx() {
ctx.Logger().Error("First L1 tx must be a system deposit tx", "type", tx.Type())
return nil, types.WrapError(types.ErrInvalidL1Txs, "first L1 tx must be a system deposit tx, but got type %d", tx.Type())
ctx.Logger().Error("First L1 tx must be a L1 attributes tx", "type", tx.Type())
return nil, types.WrapError(types.ErrInvalidL1Txs, "first L1 tx must be a L1 attributes tx, but got type %d", tx.Type())
}
l1blockInfo, err := derive.L1BlockInfoFromBytes(k.rollupCfg, 0, tx.Data())
if err != nil {
Expand All @@ -62,8 +62,8 @@ func (k *Keeper) ProcessL1SystemDepositTx(ctx sdk.Context, txBytes []byte) (*der
return l1blockInfo, nil
}

// ProcessL1UserDepositTxs processes the L1 user deposit txs and mints ETH to the user's cosmos address.
func (k *Keeper) ProcessL1UserDepositTxs(ctx sdk.Context, txs [][]byte) error { //nolint:gocritic // hugeParam
// processL1UserDepositTxs processes the L1 user deposit txs and mints ETH to the user's cosmos address.
func (k *Keeper) processL1UserDepositTxs(ctx sdk.Context, txs [][]byte) error { //nolint:gocritic // hugeParam
for i := 1; i < len(txs); i++ {
txBytes := txs[i]
var tx ethtypes.Transaction
Expand All @@ -89,7 +89,7 @@ func (k *Keeper) ProcessL1UserDepositTxs(ctx sdk.Context, txs [][]byte) error {
}
cosmAddr := evmToCosmos(*to)
mintAmount := sdkmath.NewIntFromBigInt(tx.Value())
err := k.MintETH(ctx, cosmAddr, mintAmount)
err := k.mintETH(ctx, cosmAddr, mintAmount)
if err != nil {
ctx.Logger().Error("Failed to mint ETH", "evmAddress", to, "cosmosAddress", cosmAddr, "err", err)
return types.WrapError(types.ErrMintETH, "failed to mint ETH for cosmosAddress: %v; err: %v", cosmAddr, err)
Expand All @@ -98,8 +98,8 @@ func (k *Keeper) ProcessL1UserDepositTxs(ctx sdk.Context, txs [][]byte) error {
return nil
}

// MintETH mints ETH to an account where the amount is in wei.
func (k *Keeper) MintETH(ctx sdk.Context, addr sdk.AccAddress, amount sdkmath.Int) error { //nolint:gocritic // hugeParam
// mintETH mints ETH to an account where the amount is in wei.
func (k *Keeper) mintETH(ctx sdk.Context, addr sdk.AccAddress, amount sdkmath.Int) error { //nolint:gocritic // hugeParam
coin := sdk.NewCoin(types.ETH, amount)
if err := k.bankkeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(coin)); err != nil {
return fmt.Errorf("failed to mint deposit coins to the rollup module: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions x/rollup/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (k *Keeper) ApplyL1Txs(goCtx context.Context, msg *types.MsgApplyL1Txs) (*t
ctx.Logger().Debug("Processing L1 txs", "txCount", len(msg.TxBytes))

// process L1 system deposit tx and get L1 block info
l1blockInfo, err := k.ProcessL1SystemDepositTx(ctx, msg.TxBytes[0])
l1blockInfo, err := k.processL1AttributesTx(ctx, msg.TxBytes[0])
if err != nil {
ctx.Logger().Error("Failed to process L1 system deposit tx", "err", err)
return nil, types.WrapError(types.ErrProcessL1SystemDepositTx, "err: %v", err)
Expand All @@ -52,7 +52,7 @@ func (k *Keeper) ApplyL1Txs(goCtx context.Context, msg *types.MsgApplyL1Txs) (*t
ctx.Logger().Info("Save L1 block history info", "l1blockHistoryInfo", string(lo.Must(json.Marshal(l1blockInfo))))

// process L1 user deposit txs
if err = k.ProcessL1UserDepositTxs(ctx, msg.TxBytes); err != nil {
if err = k.processL1UserDepositTxs(ctx, msg.TxBytes); err != nil {
ctx.Logger().Error("Failed to process L1 user deposit txs", "err", err)
return nil, types.WrapError(types.ErrProcessL1UserDepositTxs, "err: %v", err)
}
Expand All @@ -73,7 +73,7 @@ func (k *Keeper) InitiateWithdrawal(
return nil, types.WrapError(types.ErrInvalidSender, "failed to create cosmos address for sender: %v; error: %v", msg.Sender, err)
}

if err = k.BurnETH(ctx, cosmAddr, msg.Value); err != nil {
if err = k.burnETH(ctx, cosmAddr, msg.Value); err != nil {
ctx.Logger().Error("Failed to burn ETH", "cosmosAddress", cosmAddr, "evmAddress", msg.Target, "err", err)
return nil, types.WrapError(types.ErrBurnETH, "failed to burn ETH for cosmosAddress: %v; err: %v", cosmAddr, err)
}
Expand Down
4 changes: 2 additions & 2 deletions x/rollup/keeper/withdrawals.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/polymerdao/monomer/x/rollup/types"
)

// BurnETH burns ETH from an account where the amount is in wei.
func (k *Keeper) BurnETH(ctx sdk.Context, addr sdk.AccAddress, amount sdkmath.Int) error { //nolint:gocritic // hugeParam
// burnETH burns ETH from an account where the amount is in wei.
func (k *Keeper) burnETH(ctx sdk.Context, addr sdk.AccAddress, amount sdkmath.Int) error { //nolint:gocritic // hugeParam
coins := sdk.NewCoins(sdk.NewCoin(types.ETH, amount))

// Transfer the coins to withdraw from the user account to the rollup module
Expand Down

0 comments on commit a3a07be

Please sign in to comment.