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

Implement cw4-group typescript helper #476

Merged
merged 9 commits into from
Oct 15, 2021
Merged

Implement cw4-group typescript helper #476

merged 9 commits into from
Oct 15, 2021

Conversation

orkunkl
Copy link
Contributor

@orkunkl orkunkl commented Oct 7, 2021

This PR implements ts helper for cw4-group contract.

Copy link
Member

@webmaster128 webmaster128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd just update the repo name CosmWasm/cosmwasm-plus -> CosmWasm/cw-plus

@orkunkl orkunkl requested a review from webmaster128 October 7, 2021 16:38
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good.
I see two flaws in the API mapping. Could can fix them and merge.

TL;DR we need a new ts-helpers repo somewhere for all this code, and it should be published to npm to make life easy for app developers, not just @cosmjs/cli.

It brings up a number of larger questions for me however:

  • Where should this ts code really live (maybe a different repo that is just TS)?
  • How to best reuse code? - there is common network config/setup code in all of these.
  • How to import this into an app (not just the cli)?
  • How to test?

I would strongly propose splitting these code into 2 orthogonal pieces - network setup (useOptions and the eg. pebblenet options) and the contract helpers.

They should be published to npm and easily importable from frontend apps.

For the cli, one could use two setup methods, eg..:

Usage: npx @cosmjs/cli@^0.26 --init https://raw.githubusercontent.com/CosmWasm/cw-cli/master/pebblenet.ts --init https://raw.githubusercontent.com/CosmWasm/cw-plus/master/contracts/cw4-group/helpers.ts

Then the rest of the functions would work as in the docs, just pulling the Network code from a different place than the group code.

}
}

const pebblenetGasPrice = GasPrice.fromString("0.01upebble");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pebble net config is repeated in each helper, right?

Copy link
Contributor Author

@orkunkl orkunkl Oct 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR we need a new ts-helpers repo somewhere for all this code, and it should be published to npm to make life easy for app developers, not just @cosmjs/cli.

Great we had some plans to move to. https://github.com/InterWasm/DAO/issues/26 @findolor

recoverMnemonic: (password: string, filename?: string) => Promise<string>
}

const useOptions = (options: Options): Network => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as is this "useOptions" code

}

interface MemberListResponse {
readonly members: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be something like:

interface MemberListResponse {
  readonly members: []Member;
}

interface Members {
  readonly addr: string;
  readonly weight: number;
}

See:

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct Member {
    pub addr: String,
    pub weight: u64,
}

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
pub struct MemberListResponse {
    pub members: Vec<Member>,
}


// actions
updateAdmin: (txSigner: string, admin?: string) => Promise<string>
updateMembers: (txSigner: string, remove: string[], add: string[] ) => Promise<string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See:

    UpdateMembers {
        remove: Vec<String>,
        add: Vec<Member>,
    },

The add argument is a []Member like above in the query... it must have both the address and the weight

// actions
updateAdmin: (txSigner: string, admin?: string) => Promise<string>
updateMembers: (txSigner: string, remove: string[], add: string[] ) => Promise<string>
addHook: (txSigner: string, addr: string) => Promise<string>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I highly doubt these will be called by any client code. I would remove them to avoid confusing devs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added _ prefix

  // will not used by end user for testing purposes
  _addHook: (txSigner: string, addr: string) => Promise<string>
  _removeHook: (txSigner: string, addr: string) => Promise<string>

};
}

const downloadWasm = async (url: string): Promise<Uint8Array> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper may belong in a standard library or something.

@orkunkl orkunkl requested a review from ethanfrey October 9, 2021 10:07
Copy link
Member

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ethanfrey ethanfrey merged commit f4f91f0 into main Oct 15, 2021
@ethanfrey ethanfrey deleted the cw4-helper branch October 15, 2021 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants