Skip to content

Commit

Permalink
Mint gas to new accounts on ibc operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mikluke committed Mar 3, 2024
1 parent 50e2815 commit f24a3d3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import (
scorumclient "github.com/scorum/cosmos-network/x/scorum/client"
scorumkeeper "github.com/scorum/cosmos-network/x/scorum/keeper"
scorumtypes "github.com/scorum/cosmos-network/x/scorum/types"
scorumwrapper "github.com/scorum/cosmos-network/x/scorum/wrapper"

"github.com/scorum/cosmos-network/x/aviatrix"
aviatrixkeeper "github.com/scorum/cosmos-network/x/aviatrix/keeper"
Expand Down Expand Up @@ -446,7 +447,7 @@ func New(
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scorumwrapper.NewAccountKeeper(app.AccountKeeper, app.BankKeeper, app.ScorumKeeper),
app.BankKeeper,
scopedTransferKeeper,
)
Expand All @@ -459,7 +460,7 @@ func New(
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
scorumwrapper.NewAccountKeeper(app.AccountKeeper, app.BankKeeper, app.ScorumKeeper),
scopedICAHostKeeper,
app.MsgServiceRouter(),
)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ require (
)

replace (
// github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.27
)
40 changes: 40 additions & 0 deletions x/scorum/wrapper/account_keeper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package wrap

import (
"fmt"

"github.com/cosmos/cosmos-sdk/x/auth/types"

sdk "github.com/cosmos/cosmos-sdk/types"
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
scorumkeeper "github.com/scorum/cosmos-network/x/scorum/keeper"
scorumtypes "github.com/scorum/cosmos-network/x/scorum/types"
)

// AccountKeeper is a wrapper of cosmos-sdk/x/auth/keeper.AccountKeeperI that mints gas on setting new account.
// It's used to allow free-gas transactions without registration.
type AccountKeeper struct {
accountkeeper.AccountKeeper
bk bankkeeper.Keeper
sk scorumkeeper.Keeper
}

func NewAccountKeeper(ak accountkeeper.AccountKeeper, bk bankkeeper.Keeper, sk scorumkeeper.Keeper) AccountKeeper {
return AccountKeeper{
AccountKeeper: ak,
bk: bk,
sk: sk,
}
}

func (k AccountKeeper) SetAccount(ctx sdk.Context, acc types.AccountI) {
hasAccount := k.AccountKeeper.HasAccount(ctx, acc.GetAddress())
// must be set before minting to avoid recursion (BankKeeper calls SetAccount if it's not created yet)
k.AccountKeeper.SetAccount(ctx, acc)
if !hasAccount {
if err := k.sk.Mint(ctx, acc.GetAddress(), sdk.NewCoin(scorumtypes.GasDenom, k.sk.GetParams(ctx).GasLimit.Int)); err != nil {
panic(fmt.Sprintf("failed to mint gas to new account: %s", err.Error()))
}
}
}

0 comments on commit f24a3d3

Please sign in to comment.