-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move x/auth, x/authz, x/slashing and x/mint Init/Export gen…
…esis to keeper (#11871)
- Loading branch information
1 parent
710b57c
commit 6e18f58
Showing
10 changed files
with
73 additions
and
71 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,53 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
) | ||
|
||
// InitGenesis new authz genesis | ||
func (k Keeper) InitGenesis(ctx sdk.Context, data *authz.GenesisState) { | ||
now := ctx.BlockTime() | ||
for _, entry := range data.Authorization { | ||
// ignore expired authorizations | ||
if entry.Expiration != nil && entry.Expiration.Before(now) { | ||
continue | ||
} | ||
|
||
grantee, err := sdk.AccAddressFromBech32(entry.Grantee) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
granter, err := sdk.AccAddressFromBech32(entry.Granter) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
a, ok := entry.Authorization.GetCachedValue().(authz.Authorization) | ||
if !ok { | ||
panic("expected authorization") | ||
} | ||
|
||
err = k.SaveGrant(ctx, grantee, granter, a, entry.Expiration) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
// ExportGenesis returns a GenesisState for a given context. | ||
func (k Keeper) ExportGenesis(ctx sdk.Context) *authz.GenesisState { | ||
var entries []authz.GrantAuthorization | ||
k.IterateGrants(ctx, func(granter, grantee sdk.AccAddress, grant authz.Grant) bool { | ||
entries = append(entries, authz.GrantAuthorization{ | ||
Granter: granter.String(), | ||
Grantee: grantee.String(), | ||
Expiration: grant.Expiration, | ||
Authorization: grant.Authorization, | ||
}) | ||
return false | ||
}) | ||
|
||
return authz.NewGenesisState(entries) | ||
} |
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
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
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