Skip to content

Commit

Permalink
feat(itc): add title format options for nft minting campaigns (#168)
Browse files Browse the repository at this point in the history
* update itc nft mint details

* feat: add title format options for nft minting campaigns

* fix mispell
  • Loading branch information
harish551 authored Apr 15, 2024
1 parent cc2ca72 commit 6dd2b27
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 235 deletions.
2 changes: 2 additions & 0 deletions proto/OmniFlix/itc/v1/itc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ message NFTDetails {
bool nsfw = 9;
string data = 10;
string uri_hash = 11;
uint64 start_index = 12;
string name_delimeter = 13;
}

message Claim {
Expand Down
6 changes: 6 additions & 0 deletions x/itc/client/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func validate(nft *types.NFTDetails) error {
if nft.MediaUri == "" {
return fmt.Errorf("nft media uri is required")
}
if nft.StartIndex <= 0 {
return fmt.Errorf("start index is required and should be greater than 0")
}
if nft.NameDelimeter != "" && len(nft.NameDelimeter) > 1 {
return fmt.Errorf("name delemeter should be a single character string")
}
return nil
}

Expand Down
23 changes: 11 additions & 12 deletions x/itc/keeper/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (k Keeper) CreateCampaign(
ctx sdk.Context,
creator sdk.AccAddress,
campaign types.Campaign,
creationFee sdk.Coin,
) error {
_, err := k.nftKeeper.GetDenomInfo(ctx, campaign.NftDenomId)
if err != nil {
Expand Down Expand Up @@ -51,14 +50,6 @@ func (k Keeper) CreateCampaign(
)
}
}
// cut creation fee amount and fund the community pool
if err := k.distributionKeeper.FundCommunityPool(
ctx,
sdk.NewCoins(creationFee),
creator,
); err != nil {
return err
}

k.SetCampaign(ctx, campaign)
k.SetNextCampaignNumber(ctx, campaign.Id+1)
Expand Down Expand Up @@ -193,12 +184,18 @@ func (k Keeper) Claim(ctx sdk.Context, campaign types.Campaign, claimer sdk.AccA
}

if campaign.ClaimType == types.CLAIM_TYPE_NFT || campaign.ClaimType == types.CLAIM_TYPE_FT_AND_NFT {
campaign.MintCount += 1
nftIndex := campaign.NftMintDetails.StartIndex + campaign.MintCount
nftTitle := fmt.Sprintf(
"%s %s%d",
campaign.NftMintDetails.Name,
campaign.NftMintDetails.NameDelimeter,
nftIndex,
)
if err := k.nftKeeper.MintONFT(
ctx,
campaign.NftMintDetails.DenomId,
generateClaimNftId(ctx, campaign.Id, campaign.MintCount),
campaign.NftMintDetails.Name+fmt.Sprintf("%d", campaign.MintCount),
generateClaimNftId(ctx, campaign.Id, nftIndex),
nftTitle,
campaign.NftMintDetails.Description,
campaign.NftMintDetails.MediaUri,
campaign.NftMintDetails.UriHash,
Expand All @@ -214,6 +211,8 @@ func (k Keeper) Claim(ctx sdk.Context, campaign types.Campaign, claimer sdk.AccA
return errorsmod.Wrapf(types.ErrClaimingNFT,
"unable to mint nft denomId %s", campaign.NftMintDetails.DenomId)
}
// set campaign mint count
campaign.MintCount += 1
}
// set claim
k.SetClaim(ctx, claim)
Expand Down
12 changes: 11 additions & 1 deletion x/itc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (m msgServer) CreateCampaign(goCtx context.Context,
"given fee (%s) not matched with campaign creation fee. %s required to create itc campaign",
msg.CreationFee.String(), campaignCreationFee.String())
}

if (msg.ClaimType == types.CLAIM_TYPE_FT || msg.ClaimType == types.CLAIM_TYPE_FT_AND_NFT) && msg.Distribution == nil {
return nil, errorsmod.Wrapf(
types.ErrInvalidNFTMintDetails,
Expand All @@ -77,6 +78,15 @@ func (m msgServer) CreateCampaign(goCtx context.Context,
)
}

// cut creation fee amount and fund the community pool
if err := m.distributionKeeper.FundCommunityPool(
ctx,
sdk.NewCoins(msg.CreationFee),
creator,
); err != nil {
return nil, err
}

availableTokens := msg.Deposit
campaignNumber := m.Keeper.GetNextCampaignNumber(ctx)
campaign := types.NewCampaign(campaignNumber,
Expand All @@ -95,7 +105,7 @@ func (m msgServer) CreateCampaign(goCtx context.Context,
msg.NftMintDetails,
msg.Distribution,
)
err = m.Keeper.CreateCampaign(ctx, creator, campaign, msg.CreationFee)
err = m.Keeper.CreateCampaign(ctx, creator, campaign)
if err != nil {
return nil, err
}
Expand Down
40 changes: 20 additions & 20 deletions x/itc/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6dd2b27

Please sign in to comment.