-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mint gas to new accounts on ibc operations
- Loading branch information
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} | ||
} | ||
} |