Skip to content
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

Issue generating types for ics721 #30

Closed
jhernandezb opened this issue Apr 19, 2024 · 5 comments
Closed

Issue generating types for ics721 #30

jhernandezb opened this issue Apr 19, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@jhernandezb
Copy link

Similar to the other issue looks like it can parse array
https://github.com/public-awesome/cw-ics721/blob/main/packages/ics721/schema/ics721.json

9:22AM INF Generating code to cosmwasm/types/ics721/types.go
panic: unsupported type array for definition CallbackMsg_RedeemOutgoingChannelEntries
  {
            "description": "Redeem all entries in outgoing channel.",
            "type": "object",
            "required": ["redeem_outgoing_channel_entries"],
            "properties": {
              "redeem_outgoing_channel_entries": {
                "type": "array",
                "items": {
                  "type": "array",
                  "items": [
                    {
                      "$ref": "#/definitions/ClassId"
                    },
                    {
                      "$ref": "#/definitions/TokenId"
                    }
                  ],
                  "maxItems": 2,
                  "minItems": 2
                }
              }
            },
            "additionalProperties": false
          },

Would it be possible to pass a prefix when generating types? Ideally I'd like to have a single package and do something like

 go-codegen generate  cosmwasm/schemas/ics721.json --prefix ICS721 --output cosmwasm/types/ics721.go --package-name  types

 go-codegen generate  cosmwasm/schemas/cw721-base.json --prefix CW271 --output cosmwasm/types/cw721.go --package-name  types
@srdtrk
Copy link
Owner

srdtrk commented Apr 19, 2024

This issue is harder to fix since this is actually a type of wrapping I haven't considered before, see this. I'll try to address it this weekend.

I don't think you should be needing a prefix, there is another solution for this in go, which is to use separate package names. Here is an example of using separate packages, where each directory contains the types for another contract. And it looks like this in usage. Does this work for you?

@srdtrk srdtrk added the bug Something isn't working label Apr 19, 2024
@srdtrk
Copy link
Owner

srdtrk commented Apr 22, 2024

@jhernandezb I've pushed a fix for the issue. I'm still not 100% sure that the custom Tuple types I've added will serialize/deserialize correctly. I've added some tests and json serde seems good. Feel free to create another issue if you run into json serde issues.

I'll close this issue once you acknowledge the fix or enough time passes :)

@srdtrk
Copy link
Owner

srdtrk commented Apr 26, 2024

Thank you for this issue. Closing this now :)

@srdtrk srdtrk closed this as completed Apr 26, 2024
@jhernandezb
Copy link
Author

jhernandezb commented Apr 29, 2024

Worked perfectly thanks! I think it would be nice to generate an http client helper would you be open to add something like that?, I can see if I can do a PR but essentially we use it a lot with the grpc-web generated endpoints for cosmwasm

func (c *Client) GetClassID(...) {
	type queryResponse struct {
		Response ics721.ClassId `json:"data"`
	}
	resp := &queryResponse{}
	query := ics721.QueryMsg{
		ClassId: &ics721.QueryMsg_ClassId{
			Contract: collection,
		},
	}
       err := c.SmartQuery(ctx, stargazeBridge, query, resp)
	if err != nil {
		return nil, err
	}
   ...
}
func (c *Client) SmartQuery(ctx context.Context, contract string, query any, v any) error {
	bz, err := json.Marshal(query)
	if err != nil {
		return err
	}
	q := base64.StdEncoding.EncodeToString(bz)
	queryUrl := fmt.Sprintf("%s/cosmwasm/wasm/v1/contract/%s/smart/%s", c.baseURL, contract, q)
	return c.DoRequest(ctx, queryUrl, v)
}

@srdtrk
Copy link
Owner

srdtrk commented Apr 30, 2024

replied in #14 (comment) @jhernandezb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants