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

fix: increase discoverability of algokit resolve by id and name methods #108

Merged
merged 5 commits into from
Aug 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 72 additions & 2 deletions src/app-client.ts
aorumbayev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Algodv2 } from 'algosdk'
import { ApplicationClient, AppSpecAppDetails } from './types/app-client'
import { Algodv2, Indexer, SuggestedParams } from 'algosdk'
import { AppLookup, TealTemplateParams } from './types/app'
import { AppSpecAppDetails, ApplicationClient } from './types/app-client'
import { AppSpec } from './types/app-spec'
import { SendTransactionFrom } from './types/transaction'

/**
* Create a new ApplicationClient instance
Expand All @@ -10,3 +13,70 @@ import { ApplicationClient, AppSpecAppDetails } from './types/app-client'
export function getAppClient(appDetails: AppSpecAppDetails, algod: Algodv2) {
return new ApplicationClient(appDetails, algod)
}

/**
* Create a new ApplicationClient instance by id
* @param app The ARC-0032 application spec as either:
* * Parsed JSON `AppSpec`
* * Raw JSON string
* @param id The id of an existing app to call using this client, or 0 if the app hasn't been created yet
* @param algod An algod instance
* @param sender Default sender to use for transactions issued by this application client
* @param params Default suggested params object to use
* @param deployTimeParams Optionally provide any deploy-time parameters to replace in the TEAL code; if specified here will get used in calls to `deploy`, `create` and `update` unless overridden in those calls
* @param name The optional name to use to mark the app when deploying `ApplicationClient.deploy` (default: uses the name in the ABI contract)
*
* @returns The application client
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also add a set of example docstrings for valid simple and copy-pasteable example invocation for getAppClientById, getAppClientByCreatorAndName and for getAppClient as well?

export function getAppClientById(
app: AppSpec | string,
id: number | bigint,
inaie-makerx marked this conversation as resolved.
Show resolved Hide resolved
algod: Algodv2,
sender?: SendTransactionFrom,
params?: SuggestedParams,
deployTimeParams?: TealTemplateParams,
name?: string,
) {
const appDetails: AppSpecAppDetails = { app, sender, params, deployTimeParams, resolveBy: 'id', id, name }
return new ApplicationClient(appDetails, algod)
}

/**
* Create a new ApplicationClient instance by creator and name
* @param app The ARC-0032 application spec as either:
* * Parsed JSON `AppSpec`
* * Raw JSON string
* @param creatorAddress The address of the app creator account to resolve the app by
* @param findExistingUsing The mechanism to find an existing app instance metadata for the given creator and name; either:
* An indexer instance to search the creator account apps; or
* * The cached value of the existing apps for the given creator from `getCreatorAppsByName`
* @param algod An algod instance
* @param sender Default sender to use for transactions issued by this application client
* @param params Default suggested params object to use
* @param deployTimeParams Optionally provide any deploy-time parameters to replace in the TEAL code; if specified here will get used in calls to `deploy`, `create` and `update` unless overridden in those calls
* @param name The optional name override to resolve the app by within the creator account (default: uses the name in the ABI contract)
*
* @returns The application client
*/
export function getAppClientByCreatorAndName(
app: AppSpec | string,
creatorAddress: string,
findExistingUsing: Indexer | AppLookup,
algod: Algodv2,
sender?: SendTransactionFrom,
params?: SuggestedParams,
deployTimeParams?: TealTemplateParams,
name?: string,
) {
const appDetails: AppSpecAppDetails = {
app,
sender,
params,
deployTimeParams,
resolveBy: 'creatorAndName',
creatorAddress,
name,
findExistingUsing,
}
return new ApplicationClient(appDetails, algod)
}
Loading