CosmWasm / ts-codegen

Convert your CosmWasm smart contracts into dev-friendly TypeScript classes so you can focus on shipping code.
https://cosmology.zone/products/ts-codegen
Apache License 2.0
115 stars 27 forks source link

Error: contact maintainers [unknown type]: array #36

Closed dusterbloom closed 2 years ago

dusterbloom commented 2 years ago

Dear team,

I am trying to generate the typescript files from a working cosmwasm contract which has been deployed locally as well as on Malaga. The contract messages need to pass more than one argument and we use arrays a lot for that reason.

Error: contact maintainers [unknown type]: array
    at getType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:76:13)
    at getArrayTypeFromType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:59:24)
    at getPropertyType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:132:16)
    at /home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:236:7
    at Array.map (<anonymous>)
    at createTypedObjectParams (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:186:26)
    at createPropertyFunctionWithObjectParamsForExec (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:137:49)
    at /home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:114:12
    at Array.map (<anonymous>)
    at Object.createExecuteInterface (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:111:59)
{
  type: 'object',
  required: [ 'graph', 'graph_id' ],
  properties: {
    graph: { type: 'array', items: [Object], minItems: 0 },
    graph_id: { type: 'integer', format: 'int32' }
  },
  additionalProperties: true
} graph
/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:76
      throw new Error('contact maintainers [unknown type]: ' + type);
            ^

Error: contact maintainers [unknown type]: array
    at getType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:76:13)
    at getArrayTypeFromType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:59:24)
    at getPropertyType (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:132:16)
    at /home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:242:28
    at Array.map (<anonymous>)
    at createTypedObjectParams (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/utils/types.js:186:26)
    at createPropertyFunctionWithObjectParamsForExec (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:137:49)
    at /home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:114:12
    at Array.map (<anonymous>)
    at Object.createExecuteInterface (/home/peppi/.nvm/versions/node/v18.7.0/lib/node_modules/@cosmwasm/ts-codegen/node_modules/wasm-ast-types/main/wasm.js:111:59)

Node.js v18.7.0

`

dusterbloom commented 2 years ago

Here below an example with a simple schema to help you with debugging


  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ExecuteMsg",
  "description": "...",
  "oneOf": [
    {
      "type": "object",
      "required": [
        "update_edges"
      ],
      "properties": {
        "update_edges": {
          "type": "object",
          "required": [
            "edges"
          ],
          "properties": {
            "edges": {
              "type": "array",
              "items": {
                "type": "array",
                "items": [
                  {
                    "type": "integer",
                    "format": "int32"
                  },
                  {
                    "type": "integer",
                    "format": "int32"
                  }
                ],
                "maxItems": 2,
                "minItems": 2
              }
            }
          }
        }
      },
      "additionalProperties": false
    }
  ]
}```
pyramation commented 2 years ago

so if I understand this correctly

interface {
   edges number[][]; 
}
{
  "update_edges": {
    "edges": [
      [
        3,
        3
      ],
      [
        4,
        4
      ]
    ]
  }
}
pyramation commented 2 years ago

also to save some time — can you send me all the json schema for your project? This way if I fix this one but there are others, I can try to get them all at once. Ideally I can make a fixture this way to ensure compatability.

Maybe a gist or PR with JSON in the __fixtures__ dir would be great.

pyramation commented 2 years ago

https://github.com/CosmWasm/ts-codegen/pull/38 should ideally fix any issues @dusterbloom let me know if this works!

dusterbloom commented 2 years ago

@pyramation I updated via npm install -g @cosmwasm/ts-codegen run it again and it worked the first time like a charm. Reaction time very much appreaciate! Thanks

dusterbloom commented 2 years ago

It is working on v. 0.5.2 not on v.0.9.2

dusterbloom commented 2 years ago
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "ExecuteMsg",
  "description": "The execute message comes as a Enum (list) at the moment there are two functions. The first function (CreateEdge) makes it possible for a debtor to post a debt on-chain. The second function (UpdateEdges) makes it possible for the network owner to update a list of edges (obligation) and reduce the amount saved through cycles finding.",
  "oneOf": [
    {
      "type": "object",
      "required": [
        "create_edge"
      ],
      "properties": {
        "create_edge": {
          "type": "object",
          "required": [
            "amount",
            "creditor"
          ],
          "properties": {
            "amount": {
              "type": "integer",
              "format": "int32"
            },
            "creditor": {
              "$ref": "#/definitions/Addr"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "edit_edge"
      ],
      "properties": {
        "edit_edge": {
          "type": "object",
          "required": [
            "amount",
            "creditor",
            "edge_id"
          ],
          "properties": {
            "amount": {
              "type": "integer",
              "format": "int32"
            },
            "creditor": {
              "$ref": "#/definitions/Addr"
            },
            "edge_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "remove_edge"
      ],
      "properties": {
        "remove_edge": {
          "type": "object",
          "required": [
            "edge_id"
          ],
          "properties": {
            "edge_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "create_graph"
      ],
      "properties": {
        "create_graph": {
          "type": "object",
          "required": [
            "graph"
          ],
          "properties": {
            "graph": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Edge"
              }
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "create_graph_simplified"
      ],
      "properties": {
        "create_graph_simplified": {
          "type": "object",
          "required": [
            "graph",
            "graph_id"
          ],
          "properties": {
            "graph": {
              "type": "array",
              "items": {
                "type": "array",
                "items": [
                  {
                    "$ref": "#/definitions/Addr"
                  },
                  {
                    "$ref": "#/definitions/Addr"
                  },
                  {
                    "type": "integer",
                    "format": "int32"
                  }
                ],
                "maxItems": 3,
                "minItems": 3
              }
            },
            "graph_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "edit_graph_simplified"
      ],
      "properties": {
        "edit_graph_simplified": {
          "type": "object",
          "required": [
            "graph",
            "graph_id"
          ],
          "properties": {
            "graph": {
              "type": "array",
              "items": {
                "type": "array",
                "items": [
                  {
                    "$ref": "#/definitions/Addr"
                  },
                  {
                    "$ref": "#/definitions/Addr"
                  },
                  {
                    "type": "integer",
                    "format": "int32"
                  }
                ],
                "maxItems": 3,
                "minItems": 3
              }
            },
            "graph_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "remove_graph"
      ],
      "properties": {
        "remove_graph": {
          "type": "object",
          "required": [
            "graph_id"
          ],
          "properties": {
            "graph_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "update_edges"
      ],
      "properties": {
        "update_edges": {
          "type": "object",
          "required": [
            "edges"
          ],
          "properties": {
            "edges": {
              "type": "array",
              "items": {
                "type": "array",
                "items": [
                  {
                    "type": "integer",
                    "format": "int32"
                  },
                  {
                    "type": "integer",
                    "format": "int32"
                  }
                ],
                "maxItems": 2,
                "minItems": 2
              }
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "find_savings"
      ],
      "properties": {
        "find_savings": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "find_savings_in_a_graph"
      ],
      "properties": {
        "find_savings_in_a_graph": {
          "type": "object",
          "required": [
            "graph_id"
          ],
          "properties": {
            "graph_id": {
              "type": "integer",
              "format": "int32"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "reset"
      ],
      "properties": {
        "reset": {
          "type": "object"
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "save_network_to_file"
      ],
      "properties": {
        "save_network_to_file": {
          "type": "object",
          "required": [
            "filepath"
          ],
          "properties": {
            "filepath": {
              "type": "string"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "create_graph_from_file"
      ],
      "properties": {
        "create_graph_from_file": {
          "type": "object",
          "required": [
            "filepath"
          ],
          "properties": {
            "filepath": {
              "type": "string"
            }
          }
        }
      },
      "additionalProperties": false
    },
    {
      "type": "object",
      "required": [
        "apply_set_off_from_file"
      ],
      "properties": {
        "apply_set_off_from_file": {
          "type": "object",
          "required": [
            "filepath"
          ],
          "properties": {
            "filepath": {
              "type": "string"
            }
          }
        }
      },
      "additionalProperties": false
    }
  ],
  "definitions": {
    "Addr": {
      "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
      "type": "string"
    },
    "Edge": {
      "description": "An Edge is an ascertained obligation between two parties both identified by their Address. Each edge is denominated implicitly in the Network Denomination of reference and has an amount and an identifier both expressed as i32.",
      "type": "object",
      "required": [
        "amount",
        "creditor",
        "debtor",
        "edge_id"
      ],
      "properties": {
        "amount": {
          "type": "integer",
          "format": "int32"
        },
        "creditor": {
          "$ref": "#/definitions/Addr"
        },
        "debtor": {
          "$ref": "#/definitions/Addr"
        },
        "edge_id": {
          "type": "integer",
          "format": "int32"
        },
        "graph_id": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int32"
        }
      }
    }
  }
}
pyramation commented 2 years ago

ok I think this should do it!

https://github.com/CosmWasm/ts-codegen/pull/53