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

Initial version of helper.ts for CW721-base #131

Merged
merged 14 commits into from
Dec 2, 2020

Conversation

volkrass
Copy link

This is my initial version of helper.ts for CW721-base contract.

npx @cosmjs/cli@^0.23 --init contracts/cosmons/helpers.ts

Following methods are implemented and will be part of helper.ts - comments below will be part of next version. Here for review:

Setup Contract

const client = await useOptions(defaultOptions).setup(<YOUR PASSWORD>);
const partner = await useOptions(defaultOptions).setup(<YOUR PASSWORD>, ".wallet2.key");
const cw721 = CW721(client);
const codeId = <your CodeID>;
const initMsg = { name: "Cosmons", symbol: "mons",  minter: address };
const contract = await client.instantiate(codeId, initMsg, "Virtual Cosmons 1");
const mine = cw721.use(contract.contractAddress);

Transfer Token to Partner

mine.transferNft(partnerAddr, "monster112a9lf95atqvyejqe22xnna8x4mfqd75tkq2kvwcjyysarcsb");

Approve Contract

// Don't call transferNft before, otherwise it fails
mine.approve(address, "monster112a9lf95atqvyejqe22xnna8x4mfqd75tkq2kvwcjyysarcsb");

Queries

mine.nftInfo("monster112a9lf95atqvyejqe22xnna8x4mfqd75tkq2kvwcjyysarcsb")
mine.ownerOf("monster112a9lf95atqvyejqe22xnna8x4mfqd75tkq2kvwcjyysarcsb")
mine.numTokens()
mine.tokens(address, "", 10)
mine.allNftInfo("monster112a9lf95atqvyejqe22xnna8x4mfqd75tkq2kvwcjyysarcsb")
mine.allTokens("", 10)

@CLAassistant
Copy link

CLAassistant commented Oct 21, 2020

CLA assistant check
All committers have signed the CLA.

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.

Nice work here.

Added a lot of very minor comments on it, just some tips to polish it up to a very high quality interface.

Hope this is working well for you in your UI.

},
}

const hackatomOptions: Options = {
Copy link
Member

Choose a reason for hiding this comment

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

These two are pointing to the same network with different faucet, right? Why not unify them?

contracts/cw721-base/helpers.ts Show resolved Hide resolved
// tokenInfo: () => Promise<any>
minter: () => Promise<any>
numTokens: () => Promise<any>
tokens: (owner:string, start_after: string, limit: number ) => Promise<TokensResponse>
Copy link
Member

Choose a reason for hiding this comment

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

start_after and limit are optional here as well

Copy link
Member

Choose a reason for hiding this comment

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

Actually, probably nicest to use startAfter for the interface and convert in the json sent over the wire.

allAllowances: (owner: string, startAfter?: string, limit?: number) => Promise<AllAllowancesResponse>
allAccounts: (startAfter?: string, limit?: number) => Promise<readonly string[]>
contractInfo: () => Promise<any>
ownerOf: (owner: string) => Promise<any>
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 tokenId: string not owner: string

allTokens: (start_after?: string, limit?: number ) => Promise<TokensResponse>

// actions
mint: (token_id: string, owner:string, name:string, description?: 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.

Also takes image?: string I believe

Copy link
Member

Choose a reason for hiding this comment

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

I think defining type TokenId = string somewhere above and using it some places would make the return values clearer - no runtime or type-check difference, just more readable. Actually, what is the string returned here... I guess not the TokenId.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, and for public API, nice to use tokenId rather than token_id

};

const allAllowances = async (owner: string, startAfter?: string, limit?: number): Promise<AllAllowancesResponse> => {
return client.queryContractSmart(contractAddress, {all_allowances: { owner, start_after: startAfter, limit }});
Copy link
Member

Choose a reason for hiding this comment

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

👍

};
*/
// mints tokens, returns ?
const mint = async (token_id: string, owner: string, name:string, description: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.

this is defined as description?: string in the interface above. good to be consistent. (and nice to add image url here as well)

contracts/cw721-base/helpers.ts Outdated Show resolved Hide resolved
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.

Nice cleanup!

@BlockscapeLab
Copy link

@ethanfrey, from my point of view helper.ts is ready to merge. Let me know if there is something what I should improve.

@ethanfrey
Copy link
Member

Sorry for the delay reviewing this. I have been on holiday.

I will check this now. But only one of the 2 github committers has signed the CLA. Could you fix this?

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 quite good. Some small changes requested.

Mainly just replacing any with concrete types.

return wallet;
};

const buildFeeTable = (feeToken: string, gasPrice: number): CosmWasmFeeTable => {
Copy link
Member

Choose a reason for hiding this comment

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

You can remove buildFeeTable now, it is unneeded and handles inside the CosmWasmSigningClient

return accounts.accounts;
};

const minter = async (): Promise<any> => {
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to clarify the return types here. (And all the any until ownerOf).

You can either just return the response verbatum, like allowance, or pull out the important field like allAccounts

}

// total number of tokens issued
const numTokens = async (): Promise<any> => {
Copy link
Member

Choose a reason for hiding this comment

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

again, is this a number? a stringified number? (from Uint128)? please define type

Copy link
Member

Choose a reason for hiding this comment

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

Also, I would put all queries together and all messages/transactions together, just for readability

@volkrass
Copy link
Author

volkrass commented Dec 2, 2020

@ethanfrey , I guess we can close this ticket. My collegues has been fixed the issues, so that this pull request is outdated. What do you think?

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.

Sorry for the delay I missed the notification that this was fixed and it slipped.

Merging now,

@ethanfrey ethanfrey merged commit 4904145 into CosmWasm:master Dec 2, 2020
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.

6 participants