Skip to content

Commit

Permalink
Added change alias transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lxgr-linux committed Jan 23, 2024
1 parent 1f4b366 commit c00470a
Show file tree
Hide file tree
Showing 11 changed files with 814 additions and 226 deletions.
2 changes: 2 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68997,6 +68997,8 @@ definitions:
cardId:
type: string
format: uint64
DecentralCardGame.cardchain.cardchain.MsgChangeAliasResponse:
type: object
DecentralCardGame.cardchain.cardchain.MsgChangeArtistResponse:
type: object
DecentralCardGame.cardchain.cardchain.MsgCommitCouncilResponseResponse:
Expand Down
164 changes: 86 additions & 78 deletions proto/cardchain/cardchain/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,49 @@ option go_package = "github.com/DecentralCardGame/Cardchain/x/cardchain/types";

// Msg defines the Msg service.
service Msg {
rpc Createuser (MsgCreateuser ) returns (MsgCreateuserResponse );
rpc BuyCardScheme (MsgBuyCardScheme ) returns (MsgBuyCardSchemeResponse );
rpc VoteCard (MsgVoteCard ) returns (MsgVoteCardResponse );
rpc SaveCardContent (MsgSaveCardContent ) returns (MsgSaveCardContentResponse );
rpc TransferCard (MsgTransferCard ) returns (MsgTransferCardResponse );
rpc DonateToCard (MsgDonateToCard ) returns (MsgDonateToCardResponse );
rpc AddArtwork (MsgAddArtwork ) returns (MsgAddArtworkResponse );
rpc ChangeArtist (MsgChangeArtist ) returns (MsgChangeArtistResponse );
rpc RegisterForCouncil (MsgRegisterForCouncil ) returns (MsgRegisterForCouncilResponse );
rpc ReportMatch (MsgReportMatch ) returns (MsgReportMatchResponse );
rpc ApointMatchReporter (MsgApointMatchReporter ) returns (MsgApointMatchReporterResponse );
rpc CreateSet (MsgCreateSet ) returns (MsgCreateSetResponse );
rpc AddCardToSet (MsgAddCardToSet ) returns (MsgAddCardToSetResponse );
rpc FinalizeSet (MsgFinalizeSet ) returns (MsgFinalizeSetResponse );
rpc BuyBoosterPack (MsgBuyBoosterPack ) returns (MsgBuyBoosterPackResponse );
rpc RemoveCardFromSet (MsgRemoveCardFromSet ) returns (MsgRemoveCardFromSetResponse );
rpc RemoveContributorFromSet (MsgRemoveContributorFromSet) returns (MsgRemoveContributorFromSetResponse);
rpc AddContributorToSet (MsgAddContributorToSet ) returns (MsgAddContributorToSetResponse );
rpc CreateSellOffer (MsgCreateSellOffer ) returns (MsgCreateSellOfferResponse );
rpc BuyCard (MsgBuyCard ) returns (MsgBuyCardResponse );
rpc RemoveSellOffer (MsgRemoveSellOffer ) returns (MsgRemoveSellOfferResponse );
rpc AddArtworkToSet (MsgAddArtworkToSet ) returns (MsgAddArtworkToSetResponse );
rpc AddStoryToSet (MsgAddStoryToSet ) returns (MsgAddStoryToSetResponse );
rpc SetCardRarity (MsgSetCardRarity ) returns (MsgSetCardRarityResponse );
rpc CreateCouncil (MsgCreateCouncil ) returns (MsgCreateCouncilResponse );
rpc CommitCouncilResponse (MsgCommitCouncilResponse ) returns (MsgCommitCouncilResponseResponse );
rpc RevealCouncilResponse (MsgRevealCouncilResponse ) returns (MsgRevealCouncilResponseResponse );
rpc RestartCouncil (MsgRestartCouncil ) returns (MsgRestartCouncilResponse );
rpc RewokeCouncilRegistration (MsgRewokeCouncilRegistration ) returns (MsgRewokeCouncilRegistrationResponse );
rpc ConfirmMatch (MsgConfirmMatch ) returns (MsgConfirmMatchResponse );
rpc SetProfileCard (MsgSetProfileCard ) returns (MsgSetProfileCardResponse );
rpc OpenBoosterPack (MsgOpenBoosterPack ) returns (MsgOpenBoosterPackResponse );
rpc TransferBoosterPack (MsgTransferBoosterPack ) returns (MsgTransferBoosterPackResponse );
rpc SetSetStoryWriter (MsgSetSetStoryWriter ) returns (MsgSetSetStoryWriterResponse );
rpc SetSetArtist (MsgSetSetArtist ) returns (MsgSetSetArtistResponse );
rpc SetUserWebsite (MsgSetUserWebsite ) returns (MsgSetUserWebsiteResponse );
rpc SetUserBiography (MsgSetUserBiography ) returns (MsgSetUserBiographyResponse );
rpc Createuser (MsgCreateuser ) returns (MsgCreateuserResponse );
rpc BuyCardScheme (MsgBuyCardScheme ) returns (MsgBuyCardSchemeResponse );
rpc VoteCard (MsgVoteCard ) returns (MsgVoteCardResponse );
rpc SaveCardContent (MsgSaveCardContent ) returns (MsgSaveCardContentResponse );
rpc TransferCard (MsgTransferCard ) returns (MsgTransferCardResponse );
rpc DonateToCard (MsgDonateToCard ) returns (MsgDonateToCardResponse );
rpc AddArtwork (MsgAddArtwork ) returns (MsgAddArtworkResponse );
rpc ChangeArtist (MsgChangeArtist ) returns (MsgChangeArtistResponse );
rpc RegisterForCouncil (MsgRegisterForCouncil ) returns (MsgRegisterForCouncilResponse );
rpc ReportMatch (MsgReportMatch ) returns (MsgReportMatchResponse );
rpc ApointMatchReporter (MsgApointMatchReporter ) returns (MsgApointMatchReporterResponse );
rpc CreateSet (MsgCreateSet ) returns (MsgCreateSetResponse );
rpc AddCardToSet (MsgAddCardToSet ) returns (MsgAddCardToSetResponse );
rpc FinalizeSet (MsgFinalizeSet ) returns (MsgFinalizeSetResponse );
rpc BuyBoosterPack (MsgBuyBoosterPack ) returns (MsgBuyBoosterPackResponse );
rpc RemoveCardFromSet (MsgRemoveCardFromSet ) returns (MsgRemoveCardFromSetResponse );
rpc RemoveContributorFromSet (MsgRemoveContributorFromSet ) returns (MsgRemoveContributorFromSetResponse );
rpc AddContributorToSet (MsgAddContributorToSet ) returns (MsgAddContributorToSetResponse );
rpc CreateSellOffer (MsgCreateSellOffer ) returns (MsgCreateSellOfferResponse );
rpc BuyCard (MsgBuyCard ) returns (MsgBuyCardResponse );
rpc RemoveSellOffer (MsgRemoveSellOffer ) returns (MsgRemoveSellOfferResponse );
rpc AddArtworkToSet (MsgAddArtworkToSet ) returns (MsgAddArtworkToSetResponse );
rpc AddStoryToSet (MsgAddStoryToSet ) returns (MsgAddStoryToSetResponse );
rpc SetCardRarity (MsgSetCardRarity ) returns (MsgSetCardRarityResponse );
rpc CreateCouncil (MsgCreateCouncil ) returns (MsgCreateCouncilResponse );
rpc CommitCouncilResponse (MsgCommitCouncilResponse ) returns (MsgCommitCouncilResponseResponse );
rpc RevealCouncilResponse (MsgRevealCouncilResponse ) returns (MsgRevealCouncilResponseResponse );
rpc RestartCouncil (MsgRestartCouncil ) returns (MsgRestartCouncilResponse );
rpc RewokeCouncilRegistration (MsgRewokeCouncilRegistration) returns (MsgRewokeCouncilRegistrationResponse);
rpc ConfirmMatch (MsgConfirmMatch ) returns (MsgConfirmMatchResponse );
rpc SetProfileCard (MsgSetProfileCard ) returns (MsgSetProfileCardResponse );
rpc OpenBoosterPack (MsgOpenBoosterPack ) returns (MsgOpenBoosterPackResponse );
rpc TransferBoosterPack (MsgTransferBoosterPack ) returns (MsgTransferBoosterPackResponse );
rpc SetSetStoryWriter (MsgSetSetStoryWriter ) returns (MsgSetSetStoryWriterResponse );
rpc SetSetArtist (MsgSetSetArtist ) returns (MsgSetSetArtistResponse );
rpc SetUserWebsite (MsgSetUserWebsite ) returns (MsgSetUserWebsiteResponse );
rpc SetUserBiography (MsgSetUserBiography ) returns (MsgSetUserBiographyResponse );

// this line is used by starport scaffolding # proto/tx/rpc
rpc MultiVoteCard (MsgMultiVoteCard ) returns (MsgMultiVoteCardResponse );
rpc OpenMatch (MsgOpenMatch ) returns (MsgOpenMatchResponse );
rpc SetSetName (MsgSetSetName) returns (MsgSetSetNameResponse);
rpc MultiVoteCard (MsgMultiVoteCard) returns (MsgMultiVoteCardResponse);
rpc OpenMatch (MsgOpenMatch ) returns (MsgOpenMatchResponse );
rpc SetSetName (MsgSetSetName ) returns (MsgSetSetNameResponse );
rpc ChangeAlias (MsgChangeAlias ) returns (MsgChangeAliasResponse );
}
message MsgCreateuser {
string creator = 1;
Expand All @@ -73,16 +74,16 @@ message MsgBuyCardScheme {
cosmos.base.v1beta1.Coin bid = 2 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin"];

/*
string bid = 2;
string bid = 2;
*/}

message MsgBuyCardSchemeResponse {
uint64 cardId = 1;
}

message MsgVoteCard {
string creator = 1;
uint64 cardId = 2;
string creator = 1;
uint64 cardId = 2;
VoteType voteType = 3;
}

Expand Down Expand Up @@ -175,49 +176,49 @@ message MsgCreateSet {
message MsgCreateSetResponse {}

message MsgAddCardToSet {
string creator = 1;
uint64 setId = 2;
uint64 cardId = 3;
string creator = 1;
uint64 setId = 2;
uint64 cardId = 3;
}

message MsgAddCardToSetResponse {}

message MsgFinalizeSet {
string creator = 1;
uint64 setId = 2;
string creator = 1;
uint64 setId = 2;
}

message MsgFinalizeSetResponse {}

message MsgBuyBoosterPack {
string creator = 1;
uint64 setId = 2;
string creator = 1;
uint64 setId = 2;
}

message MsgBuyBoosterPackResponse {
bool airdropClaimed = 1;
}

message MsgRemoveCardFromSet {
string creator = 1;
uint64 setId = 2;
uint64 cardId = 3;
string creator = 1;
uint64 setId = 2;
uint64 cardId = 3;
}

message MsgRemoveCardFromSetResponse {}

message MsgRemoveContributorFromSet {
string creator = 1;
uint64 setId = 2;
string user = 3;
string creator = 1;
uint64 setId = 2;
string user = 3;
}

message MsgRemoveContributorFromSetResponse {}

message MsgAddContributorToSet {
string creator = 1;
uint64 setId = 2;
string user = 3;
string creator = 1;
uint64 setId = 2;
string user = 3;
}

message MsgAddContributorToSetResponse {}
Expand Down Expand Up @@ -245,26 +246,26 @@ message MsgRemoveSellOffer {
message MsgRemoveSellOfferResponse {}

message MsgAddArtworkToSet {
string creator = 1;
uint64 setId = 2;
bytes image = 3;
string creator = 1;
uint64 setId = 2;
bytes image = 3;
}

message MsgAddArtworkToSetResponse {}

message MsgAddStoryToSet {
string creator = 1;
uint64 setId = 2;
string story = 3;
string creator = 1;
uint64 setId = 2;
string story = 3;
}

message MsgAddStoryToSetResponse {}

message MsgSetCardRarity {
string creator = 1;
uint64 cardId = 2;
uint64 setId = 3;
CardRarity rarity = 4;
string creator = 1;
uint64 cardId = 2;
uint64 setId = 3;
CardRarity rarity = 4;
}

message MsgSetCardRarityResponse {}
Expand Down Expand Up @@ -342,17 +343,17 @@ message MsgTransferBoosterPack {
message MsgTransferBoosterPackResponse {}

message MsgSetSetStoryWriter {
string creator = 1;
uint64 setId = 2;
string storyWriter = 3;
string creator = 1;
uint64 setId = 2;
string storyWriter = 3;
}

message MsgSetSetStoryWriterResponse {}

message MsgSetSetArtist {
string creator = 1;
uint64 setId = 2;
string artist = 3;
string creator = 1;
uint64 setId = 2;
string artist = 3;
}

message MsgSetSetArtistResponse {}
Expand Down Expand Up @@ -392,10 +393,17 @@ message MsgOpenMatchResponse {
}

message MsgSetSetName {
string creator = 1;
uint64 setId = 2;
string name = 3;
string creator = 1;
uint64 setId = 2;
string name = 3;
}

message MsgSetSetNameResponse {}

message MsgChangeAlias {
string creator = 1;
string alias = 2;
}

message MsgChangeAliasResponse {}

1 change: 1 addition & 0 deletions x/cardchain/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdMultiVoteCard())
cmd.AddCommand(CmdMsgOpenMatch())
cmd.AddCommand(CmdSetSetName())
cmd.AddCommand(CmdChangeAlias())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
42 changes: 42 additions & 0 deletions x/cardchain/client/cli/tx_change_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cli

import (
"strconv"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/spf13/cobra"
)

var _ = strconv.Itoa(0)

func CmdChangeAlias() *cobra.Command {
cmd := &cobra.Command{
Use: "change-alias [alias]",
Short: "Broadcast message changeAlias",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
argAlias := args[0]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgChangeAlias(
clientCtx.GetFromAddress().String(),
argAlias,
)
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
23 changes: 23 additions & 0 deletions x/cardchain/keeper/msg_server_change_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package keeper

import (
"context"

"github.com/DecentralCardGame/Cardchain/x/cardchain/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func (k msgServer) ChangeAlias(goCtx context.Context, msg *types.MsgChangeAlias) (*types.MsgChangeAliasResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

user, err := k.GetUserFromString(ctx, msg.Creator)
if err != nil {
return nil, err
}

user.Alias = msg.Alias

k.SetUserFromUser(ctx, user)

return &types.MsgChangeAliasResponse{}, nil
}
15 changes: 15 additions & 0 deletions x/cardchain/module_simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ const (
// TODO: Determine the simulation weight value
defaultWeightMsgSetSetName int = 100

opWeightMsgChangeAlias = "op_weight_msg_change_alias"
// TODO: Determine the simulation weight value
defaultWeightMsgChangeAlias int = 100

// this line is used by starport scaffolding # simapp/module/const
)

Expand Down Expand Up @@ -669,6 +673,17 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp
cardchainsimulation.SimulateMsgSetSetName(am.accountKeeper, am.bankKeeper, am.keeper),
))

var weightMsgChangeAlias int
simState.AppParams.GetOrGenerate(simState.Cdc, opWeightMsgChangeAlias, &weightMsgChangeAlias, nil,
func(_ *rand.Rand) {
weightMsgChangeAlias = defaultWeightMsgChangeAlias
},
)
operations = append(operations, simulation.NewWeightedOperation(
weightMsgChangeAlias,
cardchainsimulation.SimulateMsgChangeAlias(am.accountKeeper, am.bankKeeper, am.keeper),
))

// this line is used by starport scaffolding # simapp/module/operation

return operations
Expand Down
Loading

0 comments on commit c00470a

Please sign in to comment.