-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable data in geneis state to be exported #310
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
215331d
enable data in geneis state to be exported
396221b
set data in init genesis method
ca972ca
err handle
8e2d97e
add function to use in InitGenesis including validation
taiki1frsh 02ad262
modify proto for genesis state
taiki1frsh 1cd5179
modification of proto
taiki1frsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,19 +1,70 @@ | ||
package nftmint | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
nfttypes "github.com/cosmos/cosmos-sdk/x/nft" | ||
|
||
"github.com/UnUniFi/chain/x/nftmint/keeper" | ||
"github.com/UnUniFi/chain/x/nftmint/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// InitGenesis initializes the store state from a genesis state. | ||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, accountKeeper types.AccountKeeper, gs types.GenesisState) { | ||
func InitGenesis(ctx sdk.Context, k keeper.Keeper, nftKeeper types.NftKeeper, gs types.GenesisState) { | ||
k.SetParamSet(ctx, gs.Params) | ||
|
||
for _, classAttributes := range gs.ClassAttributesList { | ||
if err := InitClassRelatingData(ctx, k, nftKeeper, *classAttributes); err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
// ExportGenesis export genesis state for nftmarket module | ||
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) types.GenesisState { | ||
classAttributesList := k.GetClassAttributesList(ctx) | ||
|
||
return types.GenesisState{ | ||
Params: k.GetParamSet(ctx), | ||
Params: k.GetParamSet(ctx), | ||
ClassAttributesList: classAttributesList, | ||
} | ||
} | ||
|
||
func InitClassRelatingData(ctx sdk.Context, k keeper.Keeper, nftKeeper types.NftKeeper, classAttributes types.ClassAttributes) error { | ||
class, exists := nftKeeper.GetClass(ctx, classAttributes.ClassId) | ||
if !exists { | ||
return sdkerrors.Wrap(nfttypes.ErrClassNotExists, classAttributes.ClassId) | ||
} | ||
|
||
params := k.GetParamSet(ctx) | ||
if err := types.ValidateCreateClass( | ||
params, | ||
class.Name, class.Symbol, classAttributes.BaseTokenUri, class.Description, | ||
classAttributes.MintingPermission, | ||
classAttributes.TokenSupplyCap, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
if err := k.SetClassAttributes(ctx, types.NewClassAttributes( | ||
class.Id, | ||
classAttributes.Owner.AccAddress(), | ||
classAttributes.BaseTokenUri, | ||
classAttributes.MintingPermission, | ||
classAttributes.TokenSupplyCap, | ||
)); err != nil { | ||
return err | ||
} | ||
|
||
owningClassIdList := k.AddClassIDToOwningClassIdList(ctx, classAttributes.Owner.AccAddress(), class.Id) | ||
if err := k.SetOwningClassIdList(ctx, owningClassIdList); err != nil { | ||
return err | ||
} | ||
|
||
classNameIdList := k.AddClassNameIdList(ctx, class.Name, class.Id) | ||
if err := k.SetClassNameIdList(ctx, classNameIdList); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think more validations will need to be added here for ClassNameIdLists and OwningClassIdLists.
As well as usage of usage of class ids on OwningClassIdLists that's not on ClassNameIdLists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know.
was thinking about whether i should add that kind of validation for those.
But, eventually i didn't do that since x/nftmarket doesn't have those type of validation, too, right?
do you even think i should add here now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a mandatory one but would be good to add for completeness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkXultra
what do you think?
should i do this for this PR or do i just put this as an issue and give someone else this task?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taiki1frsh
How long will it take?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkXultra
without test, it doesn't take an hour.
with out, i guess around four or five hour.