Skip to content

Commit

Permalink
🐛 Attribute already exists: Error validating metadata: invalid reques…
Browse files Browse the repository at this point in the history
…t on update attribute
  • Loading branch information
dDeedev committed Aug 31, 2023
1 parent 1dfe30f commit 7a56129
Showing 17 changed files with 525 additions and 2,525 deletions.
78 changes: 0 additions & 78 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
@@ -59004,75 +59004,6 @@ definitions:
properties:
code:
type: string
thesixnetwork.sixnft.nftmngr.MsgCreateSchemaAttributeResponse:
type: object
properties:
nftSchemaCode:
type: string
name:
type: string
new_attribute:
type: object
properties:
nftSchemaCode:
type: string
name:
type: string
data_type:
type: string
required:
type: boolean
display_value_field:
type: string
display_option:
type: object
properties:
bool_true_value:
type: string
bool_false_value:
type: string
opensea:
type: object
properties:
display_type:
type: string
trait_type:
type: string
max_value:
type: string
format: uint64
current_value:
type: object
properties:
number_attribute_value:
type: object
properties:
value:
type: string
format: uint64
string_attribute_value:
type: object
properties:
value:
type: string
boolean_attribute_value:
type: object
properties:
value:
type: boolean
float_attribute_value:
type: object
properties:
value:
type: number
format: double
hidden_overide:
type: boolean
title: flag that allows action to override hidden
hidden_to_marketplace:
type: boolean
creator:
type: string
thesixnetwork.sixnft.nftmngr.MsgDeleteActionExecutorResponse:
type: object
properties:
@@ -59140,15 +59071,6 @@ definitions:
properties:
nftSchemaCode:
type: string
thesixnetwork.sixnft.nftmngr.MsgSetNFTAttributeResponse:
type: object
properties:
nft_schema_code:
type: string
attribute_name:
type: string
nft_attribute_value:
type: string
thesixnetwork.sixnft.nftmngr.MsgSetOriginChainResponse:
type: object
properties:
29 changes: 2 additions & 27 deletions proto/nftmngr/tx.proto
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ service Msg {
rpc PerformActionByAdmin(MsgPerformActionByAdmin) returns (MsgPerformActionByAdminResponse);
rpc AddAttribute(MsgAddAttribute) returns (MsgAddAttributeResponse);
rpc AddAction(MsgAddAction) returns (MsgAddActionResponse);
rpc SetNFTAttribute(MsgSetNFTAttribute) returns (MsgSetNFTAttributeResponse);
rpc SetBaseUri(MsgSetBaseUri) returns (MsgSetBaseUriResponse);
rpc ToggleAction(MsgToggleAction) returns (MsgToggleActionResponse);
rpc ChangeSchemaOwner(MsgChangeSchemaOwner) returns (MsgChangeSchemaOwnerResponse);
@@ -37,7 +36,6 @@ service Msg {
rpc CreateActionExecutor(MsgCreateActionExecutor) returns (MsgCreateActionExecutorResponse);
rpc UpdateActionExecutor(MsgUpdateActionExecutor) returns (MsgUpdateActionExecutorResponse);
rpc DeleteActionExecutor(MsgDeleteActionExecutor) returns (MsgDeleteActionExecutorResponse);
rpc CreateSchemaAttribute(MsgCreateSchemaAttribute) returns (MsgCreateSchemaAttributeResponse);
rpc UpdateSchemaAttribute(MsgUpdateSchemaAttribute) returns (MsgUpdateSchemaAttributeResponse);
rpc DeleteSchemaAttribute(MsgDeleteSchemaAttribute) returns (MsgDeleteSchemaAttributeResponse);
rpc UpdateAction(MsgUpdateAction) returns (MsgUpdateActionResponse);
@@ -213,17 +211,6 @@ message MsgAddActionResponse {
OnChainData onchainData = 3;
}

message MsgSetNFTAttribute {
string creator = 1;
string nft_schema_code = 2;
string base64_nft_attribute_value = 3;
}

message MsgSetNFTAttributeResponse {
string nft_schema_code = 1;
string attribute_name = 2;
string nft_attribute_value = 3;
}

message MsgSetBaseUri {
string creator = 1;
@@ -401,24 +388,12 @@ message MsgDeleteActionExecutorResponse {
string executorAddress = 2;
}

message MsgCreateSchemaAttribute {
string creator = 1;
string nftSchemaCode = 2;
string name = 3;
string Base64NewAttriuteDefenition = 4;
}
message MsgCreateSchemaAttributeResponse {
string nftSchemaCode = 1;
string name = 2;
SchemaAttribute new_attribute = 3;
}

message MsgUpdateSchemaAttribute {
string creator = 1;
string nftSchemaCode = 2;
string name = 3;
string Base64NewAttriuteDefenition = 4;
string Base64UpdateAttriuteDefenition = 3;
}

message MsgUpdateSchemaAttributeResponse {
string nftSchemaCode = 1;
string name = 2;
2 changes: 0 additions & 2 deletions x/nftmngr/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdPerformActionByAdmin())
cmd.AddCommand(CmdAddAttribute())
cmd.AddCommand(CmdAddAction())
cmd.AddCommand(CmdSetNFTAttribute())
cmd.AddCommand(CmdSetBaseUri())
cmd.AddCommand(CmdToggleAction())
cmd.AddCommand(CmdChangeSchemaOwner())
@@ -54,7 +53,6 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdCreateActionExecutor())
cmd.AddCommand(CmdUpdateActionExecutor())
cmd.AddCommand(CmdDeleteActionExecutor())
cmd.AddCommand(CmdCreateSchemaAttribute())
cmd.AddCommand(CmdUpdateSchemaAttribute())
cmd.AddCommand(CmdDeleteSchemaAttribute())
cmd.AddCommand(CmdUpdateAction())
43 changes: 3 additions & 40 deletions x/nftmngr/client/cli/tx_schema_attribute.go
Original file line number Diff line number Diff line change
@@ -8,51 +8,15 @@ import (
"github.com/thesixnetwork/sixnft/x/nftmngr/types"
)

func CmdCreateSchemaAttribute() *cobra.Command {
cmd := &cobra.Command{
Use: "create-schema-attribute [nft-schema-code] [name] [base64NewAttriuteDefenition]",
Short: "Create a new schema_attribute",
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
// Get indexes
indexNftSchemaCode := args[0]
indexName := args[1]
// Get value arguments
argBase64NewAttriuteDefenition := args[2]

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

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

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func CmdUpdateSchemaAttribute() *cobra.Command {
cmd := &cobra.Command{
Use: "update-schema-attribute [nft-schema-code] [name] [base66UpdateAttriuteDefenition]",
Use: "update-schema-attribute [nft-schema-code] [base64UpdateAttriuteDefenition]",
Short: "Update a schema_attribute",
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
indexNftSchemaCode := args[0]
indexName := args[1]
// Get value arguments
argBase64NewAttriuteDefenition := args[2]
argBase64NewAttriuteDefenition := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
@@ -62,7 +26,6 @@ func CmdUpdateSchemaAttribute() *cobra.Command {
msg := types.NewMsgUpdateSchemaAttribute(
clientCtx.GetFromAddress().String(),
indexNftSchemaCode,
indexName,
argBase64NewAttriuteDefenition,
)
if err := msg.ValidateBasic(); err != nil {
54 changes: 3 additions & 51 deletions x/nftmngr/client/cli/tx_schema_attribute_test.go
Original file line number Diff line number Diff line change
@@ -18,54 +18,6 @@ import (
// Prevent strconv unused error
var _ = strconv.IntSize

func TestCreateSchemaAttribute(t *testing.T) {
net := network.New(t)
val := net.Validators[0]
ctx := val.ClientCtx

fields := []string{"xyz", "false", "xyz", "xyz", "xyz", "false", "false", "111"}
for _, tc := range []struct {
desc string
idNftSchemaCode string
idName string

args []string
err error
code uint32
}{
{
idNftSchemaCode: strconv.Itoa(0),
idName: strconv.Itoa(0),

desc: "valid",
args: []string{
fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()),
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdk.NewInt(10))).String()),
},
},
} {
t.Run(tc.desc, func(t *testing.T) {
args := []string{
tc.idNftSchemaCode,
tc.idName,
}
args = append(args, fields...)
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateSchemaAttribute(), args)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
var resp sdk.TxResponse
require.NoError(t, ctx.Codec.UnmarshalJSON(out.Bytes(), &resp))
require.Equal(t, tc.code, resp.Code)
}
})
}
}

func TestUpdateSchemaAttribute(t *testing.T) {
net := network.New(t)
val := net.Validators[0]
@@ -84,7 +36,7 @@ func TestUpdateSchemaAttribute(t *testing.T) {
}
args = append(args, fields...)
args = append(args, common...)
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateSchemaAttribute(), args)
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdAddAttribute(), args)
require.NoError(t, err)

for _, tc := range []struct {
@@ -119,7 +71,7 @@ func TestUpdateSchemaAttribute(t *testing.T) {
}
args = append(args, fields...)
args = append(args, tc.args...)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdUpdateSchemaAttribute(), args)
out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdAddAttribute(), args)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
@@ -151,7 +103,7 @@ func TestDeleteSchemaAttribute(t *testing.T) {
}
args = append(args, fields...)
args = append(args, common...)
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdCreateSchemaAttribute(), args)
_, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdAddAttribute(), args)
require.NoError(t, err)

for _, tc := range []struct {
45 changes: 0 additions & 45 deletions x/nftmngr/client/cli/tx_set_nft_attribute.go

This file was deleted.

6 changes: 0 additions & 6 deletions x/nftmngr/handler.go
Original file line number Diff line number Diff line change
@@ -32,9 +32,6 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgAddAction:
res, err := msgServer.AddAction(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgSetNFTAttribute:
res, err := msgServer.SetNFTAttribute(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgSetBaseUri:
res, err := msgServer.SetBaseUri(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
@@ -89,9 +86,6 @@ func NewHandler(k keeper.Keeper) sdk.Handler {
case *types.MsgDeleteActionExecutor:
res, err := msgServer.DeleteActionExecutor(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgCreateSchemaAttribute:
res, err := msgServer.CreateSchemaAttribute(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgUpdateSchemaAttribute:
res, err := msgServer.UpdateSchemaAttribute(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
7 changes: 7 additions & 0 deletions x/nftmngr/keeper/msg_server_add_action.go
Original file line number Diff line number Diff line change
@@ -48,6 +48,13 @@ func (k msgServer) AddAction(goCtx context.Context, msg *types.MsgAddAction) (*t
// append new action
schema.OnchainData.Actions = append(schema.OnchainData.Actions, &new_action)

// save index of action
k.Keeper.SetActionOfSchema(ctx,types.ActionOfSchema{
Name: new_action.Name,
NftSchemaCode: schema.Code,
Index: uint64(len(schema.OnchainData.Actions) - 1),
})

// save schema
k.Keeper.SetNFTSchema(ctx, schema)

Loading

0 comments on commit 7a56129

Please sign in to comment.