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

cw20-base: upgrade helper.ts to cosmjs 0.25 #248

Merged
merged 4 commits into from
Jul 13, 2021
Merged

Conversation

orkunkl
Copy link
Contributor

@orkunkl orkunkl commented Mar 18, 2021

WIP

const keyfile = filename || options.defaultKeyFile;
const wallet = await loadOrCreateWallet(hackatomOptions, keyfile, password);
const client = await connect(wallet, hackatomOptions);
const account = (await wallet.getAccounts())[0].address;
Copy link
Member

Choose a reason for hiding this comment

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

Better call this address


// ensure we have some tokens
if (options.faucetUrl) {
const account = await client.getAccount();
if (!account) {
Copy link
Member

Choose a reason for hiding this comment

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

This is always false now, because account is always a non-empty address. I.e. you never get tokens


// ensure we have some tokens
if (options.faucetUrl) {
const account = await client.getAccount();
Copy link
Member

Choose a reason for hiding this comment

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

This tells you whether or not the account exists on chain. You probably want to keep it

Copy link
Member

Choose a reason for hiding this comment

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

Checking if the account is empty (if they had tokens earlier but spent them all) is a fair enough check.
It's on the client side, so being stricter doesn't add security

const use = (contractAddress: string): CW20Instance => {
const balance = async (account?: string): Promise<string> => {
const address = account || client.senderAddress;
const result = await client.queryContractSmart(contractAddress, {balance: { address }});
const address = account || (await cw20Client.wallet.getAccounts())[0].address;
Copy link
Member

Choose a reason for hiding this comment

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

You stored it here:

Suggested change
const address = account || (await cw20Client.wallet.getAccounts())[0].address;
const address = account || cw20Client.sender;

@orkunkl orkunkl force-pushed the cw20-upgrade-helper branch from a06539f to 8ab10fc Compare July 6, 2021 12:45
@orkunkl
Copy link
Contributor Author

orkunkl commented Jul 6, 2021

An external contributor fixed helper.ts and sent to me. This version works now.

@orkunkl orkunkl marked this pull request as ready for review July 6, 2021 15:20
@orkunkl orkunkl requested review from webmaster128 and ethanfrey July 6, 2021 15:20
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.

Looks good. Thanks

* Usage: npx @cosmjs/cli@^0.23 --init https://raw.githubusercontent.com/CosmWasm/cosmwasm-plus/master/contracts/cw20-base/helpers.ts
*
*
* Usage: npx @cosmjs/cli@^0.25 --init https://raw.githubusercontent.com/CosmWasm/cosmwasm-plus/master/contracts/cw20-base/helpers.ts
Copy link
Member

Choose a reason for hiding this comment

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

👍


// ensure we have some tokens
if (options.faucetUrl) {
const account = await client.getAccount();
Copy link
Member

Choose a reason for hiding this comment

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

Checking if the account is empty (if they had tokens earlier but spent them all) is a fair enough check.
It's on the client side, so being stricter doesn't add security

@ethanfrey ethanfrey merged commit caa64a0 into main Jul 13, 2021
@ethanfrey ethanfrey deleted the cw20-upgrade-helper branch July 13, 2021 22:33
@ethanfrey ethanfrey changed the title cw20-base: upgrade helper.ts to cosmjs 0.24.1 cw20-base: upgrade helper.ts to cosmjs 0.25 Jul 13, 2021
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