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
116 stars 29 forks source link

some messages are not objects but instead scalar values #21

Open pyramation opened 2 years ago

pyramation commented 2 years ago

Here is the latest export for ExecuteMsg (in Typescript)

export type ExecuteMsg = {
  mint: {
    [k: string]: unknown;
  };
} | {
  set_whitelist: {
    whitelist: string;
    [k: string]: unknown;
  };
} | {
  update_start_time: Timestamp;
} | {
  update_per_address_limit: {
    per_address_limit: number;
    [k: string]: unknown;
  };
} | {
  mint_to: {
    recipient: string;
    [k: string]: unknown;
  };
} | {
  mint_for: {
    recipient: string;
    token_id: number;
    [k: string]: unknown;
  };
} | {
  withdraw: {
    [k: string]: unknown;
  };
};

I noticed that update_start_time is the only one that doesn't take an object. Every other message uses either an empty object or an object with props.

update_start_time: Timestamp

Is there a convention? Or should we account for this in the cosmwasm-typescript-gen

pyramation commented 2 years ago

from @grod220 (after closing #67 in favor of combining issues):

When you have a query type such as:

#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
    #[returns(String)]
    AllPreviousOwners(String),

The generated typescript will be missing the String argument required for this query:

  allPreviousOwners = async (): Promise<String> => {
    return this.client.queryContractSmart(this.contractAddress, {
      all_previous_owners: {}
    });
  };

Reproducible example here: https://github.com/grod220/ts-codegen-example/blob/master/contracts/account-nft/src/msg/query.rs#L32-L33

pyramation commented 2 years ago

example in our code https://github.com/CosmWasm/ts-codegen/commit/acbb8339cd8c8a9cb7311548832e08239516cfa8

pyramation commented 2 years ago
yubrew commented 2 years ago

Is this still an open issue? Timestamps in typescript work as a nanosecond int wrapped as a string. We're explicitly using Timestamp instead of block time (time or height) to avoid potential confusion with block height. https://github.com/public-awesome/stargaze-tools/blob/main/scripts/minter.ts#L277