@algorandfoundation/algokit-utils 9.0.1 → 9.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/asset.mjs +1 -1
- package/package.json +1 -1
- package/transaction/legacy-bridge.js.map +1 -1
- package/transaction/legacy-bridge.mjs +1 -1
- package/transaction/legacy-bridge.mjs.map +1 -1
- package/transaction/transaction.js.map +1 -1
- package/transaction/transaction.mjs.map +1 -1
- package/transfer/transfer-algos.mjs +1 -1
- package/types/account-manager.js.map +1 -1
- package/types/account-manager.mjs.map +1 -1
- package/types/algorand-client-transaction-creator.js.map +1 -1
- package/types/algorand-client-transaction-creator.mjs.map +1 -1
- package/types/algorand-client-transaction-sender.js.map +1 -1
- package/types/algorand-client-transaction-sender.mjs.map +1 -1
- package/types/algorand-client.d.ts +13 -2
- package/types/algorand-client.js +17 -1
- package/types/algorand-client.js.map +1 -1
- package/types/algorand-client.mjs +17 -1
- package/types/algorand-client.mjs.map +1 -1
- package/types/app-client.js +32 -32
- package/types/app-client.js.map +1 -1
- package/types/app-client.mjs +33 -33
- package/types/app-client.mjs.map +1 -1
- package/types/app-deployer.js.map +1 -1
- package/types/app-deployer.mjs.map +1 -1
- package/types/async-event-emitter.js.map +1 -1
- package/types/async-event-emitter.mjs.map +1 -1
- package/types/composer.d.ts +21 -1
- package/types/composer.js +58 -15
- package/types/composer.js.map +1 -1
- package/types/composer.mjs +58 -15
- package/types/composer.mjs.map +1 -1
- package/types/instance-of.d.ts +6 -0
- package/types/instance-of.js +3 -0
- package/types/instance-of.js.map +1 -0
- package/types/instance-of.mjs +2 -0
- package/types/instance-of.mjs.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-deployer.js","sources":["../../src/types/app-deployer.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport * as indexer from '../indexer-lookup'\nimport { calculateExtraProgramPages } from '../util'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport {\n APP_DEPLOY_NOTE_DAPP,\n OnSchemaBreak,\n OnUpdate,\n type ABIReturn,\n type AppDeployMetadata,\n type SendAppCreateTransactionResult,\n type SendAppUpdateTransactionResult,\n type TealTemplateParams,\n} from './app'\nimport { AppManager } from './app-manager'\nimport {\n AppCreateMethodCall,\n AppCreateParams,\n AppDeleteMethodCall,\n AppDeleteParams,\n AppUpdateMethodCall,\n AppUpdateParams,\n TransactionComposer,\n} from './composer'\nimport { Expand } from './expand'\nimport { ConfirmedTransactionResult, SendParams } from './transaction'\n\n/** Params to specify an update transaction for an app deployment */\nexport type DeployAppUpdateParams = Expand<Omit<AppUpdateParams, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify an update method call for an app deployment */\nexport type DeployAppUpdateMethodCall = Expand<Omit<AppUpdateMethodCall, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify a transaction for an app deployment */\nexport type DeployAppDeleteParams = Expand<Omit<AppDeleteParams, 'appId'>>\n/** Params to specify a delete method call for an app deployment */\nexport type DeployAppDeleteMethodCall = Expand<Omit<AppDeleteMethodCall, 'appId'>>\n\n/** The parameters to idempotently deploy an app */\nexport type AppDeployParams = Expand<\n SendParams & {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code before compiling it (used if teal code is passed in as a string) */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break (storage schema or extra pages change) is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL code update is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `update` - Update the app with the new TEAL code\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams: AppCreateParams | AppCreateMethodCall\n /** Update transaction parameters to use if an update needs to be issued as part of deployment */\n updateParams: DeployAppUpdateParams | DeployAppUpdateMethodCall\n /** Delete transaction parameters to use if a delete needs to be issued as part of deployment */\n deleteParams: DeployAppDeleteParams | DeployAppDeleteMethodCall\n /** Optional cached value of the existing apps for the given creator; use this to avoid an indexer lookup */\n existingDeployments?: AppLookup\n /** Whether or not to ignore the app metadata cache and force a lookup, default: use the cache **/\n ignoreCache?: boolean\n }\n>\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppDeployMetadata {\n /** The id of the app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: Address\n /** The round the app was created */\n createdRound: bigint\n /** The last round that the app was updated */\n updatedRound: bigint\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n /** The address of the creator associated with this lookup */\n creator: Readonly<Address>\n /** A hash map of app name to app metadata */\n apps: {\n [name: string]: AppMetadata\n }\n}\n\nexport type AppDeployResult =\n | Expand<{ operationPerformed: 'create' } & Omit<AppMetadata, 'appId' | 'appAddress'> & SendAppCreateTransactionResult>\n | Expand<{ operationPerformed: 'update' } & AppMetadata & SendAppUpdateTransactionResult>\n | Expand<\n { operationPerformed: 'replace' } & Omit<AppMetadata, 'appId' | 'appAddress'> &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n >\n | Expand<{ operationPerformed: 'nothing' } & AppMetadata>\n\n/** Allows management of deployment and deployment metadata of applications. */\nexport class AppDeployer {\n private _appManager: AppManager\n private _transactionSender: AlgorandClientTransactionSender\n private _indexer?: algosdk.Indexer\n private _appLookups = new Map<string, AppLookup>()\n\n /**\n * Creates an `AppManager`\n * @param appManager An `AppManager` instance\n * @param transactionSender An `AlgorandClientTransactionSender` instance\n * @param indexer An optional indexer instance; supply if you want to indexer to look up app metadata\n * @example\n * ```ts\n * const deployer = new AppDeployer(appManager, transactionSender, indexer)\n * ```\n */\n constructor(appManager: AppManager, transactionSender: AlgorandClientTransactionSender, indexer?: algosdk.Indexer) {\n this._appManager = appManager\n this._transactionSender = transactionSender\n this._indexer = indexer\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param deployment The arguments to control the app deployment\n * @returns The result of the deployment\n * @example\n * ```ts\n * const deployResult = await deployer.deploy({\n * createParams: {\n * sender: 'SENDER_ADDRESS',\n * approvalProgram: 'APPROVAL PROGRAM',\n * clearStateProgram: 'CLEAR PROGRAM',\n * schema: {\n * globalByteSlices: 0,\n * globalInts: 0,\n * localByteSlices: 0,\n * localInts: 0\n * }\n * },\n * updateParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * deleteParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },\n * onSchemaBreak: 'append',\n * onUpdate: 'append'\n * })\n * ```\n */\n async deploy(deployment: AppDeployParams): Promise<AppDeployResult> {\n const {\n metadata,\n deployTimeParams,\n onSchemaBreak,\n onUpdate,\n createParams,\n updateParams,\n deleteParams,\n existingDeployments,\n ignoreCache,\n ...sendParams\n } = deployment\n\n // Set creation note\n\n createParams.note = updateParams.note = TransactionComposer.arc2Note({\n dAppName: APP_DEPLOY_NOTE_DAPP,\n data: metadata,\n format: 'j',\n })\n\n // Check for required fields\n\n if (existingDeployments && existingDeployments.creator.toString() !== createParams.sender.toString()) {\n throw new Error(\n `Received invalid existingDeployments value for creator ${existingDeployments.creator} when attempting to deploy for creator ${createParams.sender}`,\n )\n }\n if (!existingDeployments && !this._indexer) {\n throw new Error(\n `Didn't receive an indexer client when this AppManager was created, but also didn't receive an existingDeployments cache - one of them must be provided`,\n )\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Idempotently deploying app \"${metadata.name}\" from creator ${createParams.sender} using ${createParams.approvalProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'} and ${createParams.clearStateProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'}`,\n )\n\n // Compile code if required\n\n const compiledApproval =\n typeof createParams.approvalProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.approvalProgram, deployTimeParams, metadata)\n : undefined\n const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : createParams.approvalProgram\n\n const compiledClear =\n typeof createParams.clearStateProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.clearStateProgram, deployTimeParams)\n : undefined\n const clearStateProgram = compiledClear ? compiledClear.compiledBase64ToBytes : createParams.clearStateProgram\n\n // Define routines for create, update, and replace\n\n const createApp = async () => {\n const result = await ('method' in createParams\n ? this._transactionSender.appCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram, ...sendParams })\n : this._transactionSender.appCreate({ ...createParams, approvalProgram, clearStateProgram, ...sendParams }))\n const appMetadata: AppMetadata = {\n appId: result.appId,\n appAddress: result.appAddress,\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(result.confirmation.confirmedRound!),\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'create',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppCreateTransactionResult & AppMetadata & { operationPerformed: 'create' }\n }\n const updateApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Updating existing ${metadata.name} app for ${createParams.sender} to version ${metadata.version}.`,\n )\n const result = await ('method' in updateParams\n ? this._transactionSender.appUpdateMethodCall({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n })\n : this._transactionSender.appUpdate({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n }))\n const appMetadata: AppMetadata = {\n appId: existingApp.appId,\n appAddress: existingApp.appAddress,\n createdMetadata: existingApp.createdMetadata,\n createdRound: existingApp.createdRound,\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n ...metadata,\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'update',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppUpdateTransactionResult & AppMetadata & { operationPerformed: 'update' }\n }\n const replaceApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Deploying a new ${metadata.name} app for ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Deleting existing ${metadata.name} app with id ${existingApp.appId} from ${deleteParams.sender} account.`,\n )\n\n const composer = this._transactionSender.newGroup()\n if ('method' in createParams) {\n composer.addAppCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram })\n } else {\n composer.addAppCreate({ ...createParams, approvalProgram, clearStateProgram })\n }\n const createIndex = await composer.count()\n if ('method' in deleteParams) {\n composer.addAppDeleteMethodCall({ appId: existingApp.appId, ...deleteParams })\n } else {\n composer.addAppDelete({ appId: existingApp.appId, ...deleteParams })\n }\n const result = await composer.send({ ...sendParams })\n const confirmation = result.confirmations.at(createIndex - 1)!\n const transaction = result.transactions.at(createIndex - 1)!\n const deleteTransaction = result.transactions.at(-1)!\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Sent transactions ${transaction.txID()} to create app with id ${confirmation.applicationIndex} and ${deleteTransaction.txID()} to delete app with id ${\n existingApp.appId\n } from ${createParams.sender} account.`,\n )\n\n const appMetadata: AppMetadata = {\n appId: BigInt(confirmation.applicationIndex!),\n appAddress: algosdk.getApplicationAddress(confirmation.applicationIndex!),\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(confirmation.confirmedRound!),\n updatedRound: BigInt(confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n\n return {\n operationPerformed: 'replace',\n ...result,\n compiledApproval,\n compiledClear,\n transaction,\n confirmation,\n return: 'method' in createParams ? result.returns?.[0] : undefined,\n deleteReturn: 'method' in deleteParams ? result.returns?.at(-1) : undefined,\n ...appMetadata,\n deleteResult: { transaction: deleteTransaction, confirmation: result.confirmations.at(-1)! },\n } satisfies { operationPerformed: 'replace' } & AppMetadata &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n }\n\n // Lookup existing app metadata\n\n const apps = existingDeployments ?? (await this.getCreatorAppsByName(createParams.sender, ignoreCache))\n\n const existingApp = apps.apps[metadata.name]\n if (!existingApp || existingApp.deleted) {\n Config.getLogger(sendParams?.suppressLog).info(\n `App ${metadata.name} not found in apps created by ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n return await createApp()\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Existing app ${metadata.name} found by creator ${createParams.sender}, with app id ${existingApp.appId} and version ${existingApp.version}.`,\n )\n\n const existingAppRecord = await this._appManager.getById(existingApp.appId)\n const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')\n const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')\n const existingExtraPages = calculateExtraProgramPages(existingAppRecord.approvalProgram, existingAppRecord.clearStateProgram)\n\n const newApprovalBytes = Buffer.from(approvalProgram)\n const newClearBytes = Buffer.from(clearStateProgram)\n const newApproval = newApprovalBytes.toString('base64')\n const newClear = newClearBytes.toString('base64')\n const newExtraPages = calculateExtraProgramPages(newApprovalBytes, newClearBytes)\n\n // Check for changes\n\n const isUpdate = newApproval !== existingApproval || newClear !== existingClear\n const isSchemaBreak =\n existingAppRecord.localInts < (createParams.schema?.localInts ?? 0) ||\n existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||\n existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||\n existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||\n existingExtraPages < newExtraPages\n\n if (isSchemaBreak) {\n Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {\n from: {\n globalInts: existingAppRecord.globalInts,\n globalByteSlices: existingAppRecord.globalByteSlices,\n localInts: existingAppRecord.localInts,\n localByteSlices: existingAppRecord.localByteSlices,\n extraProgramPages: existingExtraPages,\n },\n to: { ...createParams.schema, extraProgramPages: newExtraPages },\n })\n\n if (onSchemaBreak === undefined || onSchemaBreak === 'fail' || onSchemaBreak === OnSchemaBreak.Fail) {\n throw new Error(\n 'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +\n 'If you want to try deleting and recreating the app then ' +\n 're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',\n )\n }\n\n if (onSchemaBreak === 'append' || onSchemaBreak === OnSchemaBreak.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onSchemaBreak=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n\n if (isUpdate) {\n Config.getLogger(sendParams?.suppressLog).info(\n `Detected a TEAL update in app ${existingApp.appId} for creator ${createParams.sender}`,\n )\n\n if (onUpdate === undefined || onUpdate === 'fail' || onUpdate === OnUpdate.Fail) {\n throw new Error('Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.')\n }\n\n if (onUpdate === 'append' || onUpdate === OnUpdate.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onUpdate=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (onUpdate === 'update' || onUpdate === OnUpdate.UpdateApp) {\n if (existingApp.updatable) {\n Config.getLogger(sendParams?.suppressLog).info(`App is updatable and onUpdate=UpdateApp, updating app...`)\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n `App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail`,\n )\n }\n\n return await updateApp(existingApp)\n }\n\n if (onUpdate === 'replace' || onUpdate === OnUpdate.ReplaceApp) {\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n }\n\n Config.getLogger(sendParams?.suppressLog).debug('No detected changes in app, nothing to do.')\n\n return { ...existingApp, operationPerformed: 'nothing' }\n }\n\n private updateAppLookup(sender: string | Address, appMetadata: AppMetadata) {\n const s = typeof sender === 'string' ? sender : sender.toString()\n const lookup = this._appLookups.get(s)\n if (!lookup) {\n this._appLookups.set(s, { creator: Address.fromString(s), apps: { [appMetadata.name]: appMetadata } })\n } else {\n lookup.apps[appMetadata.name] = appMetadata\n }\n }\n\n /**\n * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have\n * an [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) `AppDeployNote` as the transaction\n * note of the app creation transaction.\n *\n * This function caches the result for the given creator account so that subsequent calls will not require an indexer lookup.\n *\n * If the `AppManager` instance wasn't created with an indexer client, this function will throw an error.\n *\n * @param creatorAddress The address of the account that is the creator of the apps you want to search for\n * @param ignoreCache Whether or not to ignore the cache and force a lookup, default: use the cache\n * @returns A name-based lookup of the app metadata\n * @example\n * ```ts\n * const result = await deployer.getCreatorAppsByName(creator)\n */\n async getCreatorAppsByName(creatorAddress: string | Address, ignoreCache?: boolean): Promise<AppLookup> {\n const appLookup: Record<string, AppMetadata> = {}\n\n const address = typeof creatorAddress === 'string' ? creatorAddress : creatorAddress.toString()\n if (!ignoreCache && this._appLookups.has(address)) {\n return this._appLookups.get(address)!\n }\n\n if (!this._indexer) {\n throw new Error(`Didn't receive an indexer client when this AppManager was created, but received a call to getCreatorApps`)\n }\n\n // Extract all apps that account created\n const createdApps = (await indexer.lookupAccountCreatedApplicationByAddress(this._indexer, creatorAddress))\n .map((a) => {\n return { id: a.id, createdAtRound: a.createdAtRound!, deleted: a.deleted }\n })\n .sort((a, b) => Number(a.createdAtRound - b.createdAtRound))\n\n // For each app that account created (in parallel)...\n const apps = await Promise.all(\n createdApps.map(async (createdApp) => {\n // Find any app transactions for that app in the round it was created (should always just be a single creation transaction)\n const appTransactions = await indexer.searchTransactions(this._indexer!, (s) =>\n s\n .minRound(createdApp.createdAtRound)\n .txType(algosdk.TransactionType.appl)\n .applicationID(Number(createdApp.id))\n .address(creatorAddress)\n .addressRole('sender')\n .notePrefix(Buffer.from(APP_DEPLOY_NOTE_DAPP).toString('base64')),\n )\n\n // Triple check the transaction is intact by filtering for the one we want:\n // * application-id is 0 when the app is first created\n // * also verify the sender to prevent a potential security risk\n const appCreationTransaction = appTransactions.transactions.filter(\n (t) => t.applicationTransaction?.applicationId === 0n && t.sender.toString() === creatorAddress.toString(),\n )[0]\n\n const latestAppUpdateTransaction = appTransactions.transactions\n .filter((t) => t.sender.toString() === creatorAddress.toString())\n .sort((a, b) =>\n a.confirmedRound === b.confirmedRound\n ? (b.intraRoundOffset! - a.intraRoundOffset!) / 10\n : Number(b.confirmedRound! - a.confirmedRound!),\n )[0]\n\n if (!appCreationTransaction?.note)\n // No note; ignoring\n return null\n\n return { createdApp, appCreationTransaction, latestAppUpdateTransaction }\n }),\n )\n\n apps\n .filter((a) => a !== null)\n .forEach((a) => {\n const { createdApp, appCreationTransaction, latestAppUpdateTransaction } = a!\n\n const parseNote = (note?: string) => {\n if (!note) {\n // No note; ignoring...\n return\n }\n\n if (!note.startsWith(`${APP_DEPLOY_NOTE_DAPP}:j{`))\n // Clearly not APP_DEPLOY JSON; ignoring...\n return\n\n return JSON.parse(note.substring(APP_DEPLOY_NOTE_DAPP.length + 2)) as AppDeployMetadata\n }\n\n try {\n const creationNote = parseNote(\n appCreationTransaction.note ? Buffer.from(appCreationTransaction.note).toString('utf-8') : undefined,\n )\n const updateNote = parseNote(\n latestAppUpdateTransaction.note ? Buffer.from(latestAppUpdateTransaction.note).toString('utf-8') : undefined,\n )\n if (creationNote?.name) {\n appLookup[creationNote.name] = {\n appId: createdApp.id,\n appAddress: algosdk.getApplicationAddress(createdApp.id),\n createdMetadata: creationNote,\n createdRound: appCreationTransaction.confirmedRound ?? 0n,\n ...(updateNote ?? creationNote),\n updatedRound: latestAppUpdateTransaction?.confirmedRound ?? 0n,\n deleted: createdApp.deleted ?? false,\n }\n }\n } catch (e) {\n Config.logger.warn(\n `Received error trying to retrieve app with ${createdApp.id} for creator ${creatorAddress}; failing silently`,\n e,\n )\n return\n }\n })\n\n const lookup = {\n creator: typeof creatorAddress === 'string' ? Address.fromString(creatorAddress) : creatorAddress,\n apps: appLookup,\n }\n\n this._appLookups.set(creatorAddress.toString(), lookup)\n\n return lookup\n }\n}\n"],"names":["TransactionComposer","APP_DEPLOY_NOTE_DAPP","Config","calculateExtraProgramPages","OnSchemaBreak","OnUpdate","Address","indexer.lookupAccountCreatedApplication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AQ,EAAE,EAAE,MAAM,CAAC;AAEvD,QAAA,OAAO,MAAM;;AAEhB;;;;"}
|
|
1
|
+
{"version":3,"file":"app-deployer.js","sources":["../../src/types/app-deployer.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport * as indexer from '../indexer-lookup'\nimport { calculateExtraProgramPages } from '../util'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport {\n APP_DEPLOY_NOTE_DAPP,\n OnSchemaBreak,\n OnUpdate,\n type ABIReturn,\n type AppDeployMetadata,\n type SendAppCreateTransactionResult,\n type SendAppUpdateTransactionResult,\n type TealTemplateParams,\n} from './app'\nimport { AppManager } from './app-manager'\nimport {\n AppCreateMethodCall,\n AppCreateParams,\n AppDeleteMethodCall,\n AppDeleteParams,\n AppUpdateMethodCall,\n AppUpdateParams,\n TransactionComposer,\n} from './composer'\nimport { Expand } from './expand'\nimport { ConfirmedTransactionResult, SendParams } from './transaction'\n\n/** Params to specify an update transaction for an app deployment */\nexport type DeployAppUpdateParams = Expand<Omit<AppUpdateParams, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify an update method call for an app deployment */\nexport type DeployAppUpdateMethodCall = Expand<Omit<AppUpdateMethodCall, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify a transaction for an app deployment */\nexport type DeployAppDeleteParams = Expand<Omit<AppDeleteParams, 'appId'>>\n/** Params to specify a delete method call for an app deployment */\nexport type DeployAppDeleteMethodCall = Expand<Omit<AppDeleteMethodCall, 'appId'>>\n\n/** The parameters to idempotently deploy an app */\nexport type AppDeployParams = Expand<\n SendParams & {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code before compiling it (used if teal code is passed in as a string) */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break (storage schema or extra pages change) is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL code update is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `update` - Update the app with the new TEAL code\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams: AppCreateParams | AppCreateMethodCall\n /** Update transaction parameters to use if an update needs to be issued as part of deployment */\n updateParams: DeployAppUpdateParams | DeployAppUpdateMethodCall\n /** Delete transaction parameters to use if a delete needs to be issued as part of deployment */\n deleteParams: DeployAppDeleteParams | DeployAppDeleteMethodCall\n /** Optional cached value of the existing apps for the given creator; use this to avoid an indexer lookup */\n existingDeployments?: AppLookup\n /** Whether or not to ignore the app metadata cache and force a lookup, default: use the cache **/\n ignoreCache?: boolean\n }\n>\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppDeployMetadata {\n /** The id of the app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: Address\n /** The round the app was created */\n createdRound: bigint\n /** The last round that the app was updated */\n updatedRound: bigint\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n /** The address of the creator associated with this lookup */\n creator: Readonly<Address>\n /** A hash map of app name to app metadata */\n apps: {\n [name: string]: AppMetadata\n }\n}\n\nexport type AppDeployResult =\n | Expand<{ operationPerformed: 'create' } & Omit<AppMetadata, 'appId' | 'appAddress'> & SendAppCreateTransactionResult>\n | Expand<{ operationPerformed: 'update' } & AppMetadata & SendAppUpdateTransactionResult>\n | Expand<\n { operationPerformed: 'replace' } & Omit<AppMetadata, 'appId' | 'appAddress'> &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n >\n | Expand<{ operationPerformed: 'nothing' } & AppMetadata>\n\n/** Allows management of deployment and deployment metadata of applications. */\nexport class AppDeployer {\n private _appManager: AppManager\n private _transactionSender: AlgorandClientTransactionSender\n private _indexer?: algosdk.Indexer\n private _appLookups = new Map<string, AppLookup>()\n\n /**\n * Creates an `AppManager`\n * @param appManager An `AppManager` instance\n * @param transactionSender An `AlgorandClientTransactionSender` instance\n * @param indexer An optional indexer instance; supply if you want to indexer to look up app metadata\n * @example\n * ```ts\n * const deployer = new AppDeployer(appManager, transactionSender, indexer)\n * ```\n */\n constructor(appManager: AppManager, transactionSender: AlgorandClientTransactionSender, indexer?: algosdk.Indexer) {\n this._appManager = appManager\n this._transactionSender = transactionSender\n this._indexer = indexer\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param deployment The arguments to control the app deployment\n * @returns The result of the deployment\n * @example\n * ```ts\n * const deployResult = await deployer.deploy({\n * createParams: {\n * sender: 'SENDER_ADDRESS',\n * approvalProgram: 'APPROVAL PROGRAM',\n * clearStateProgram: 'CLEAR PROGRAM',\n * schema: {\n * globalByteSlices: 0,\n * globalInts: 0,\n * localByteSlices: 0,\n * localInts: 0\n * }\n * },\n * updateParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * deleteParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },\n * onSchemaBreak: 'append',\n * onUpdate: 'append'\n * })\n * ```\n */\n async deploy(deployment: AppDeployParams): Promise<AppDeployResult> {\n const {\n metadata,\n deployTimeParams,\n onSchemaBreak,\n onUpdate,\n createParams,\n updateParams,\n deleteParams,\n existingDeployments,\n ignoreCache,\n ...sendParams\n } = deployment\n\n // Set creation note\n\n createParams.note = updateParams.note = TransactionComposer.arc2Note({\n dAppName: APP_DEPLOY_NOTE_DAPP,\n data: metadata,\n format: 'j',\n })\n\n // Check for required fields\n\n if (existingDeployments && existingDeployments.creator.toString() !== createParams.sender.toString()) {\n throw new Error(\n `Received invalid existingDeployments value for creator ${existingDeployments.creator} when attempting to deploy for creator ${createParams.sender}`,\n )\n }\n if (!existingDeployments && !this._indexer) {\n throw new Error(\n `Didn't receive an indexer client when this AppManager was created, but also didn't receive an existingDeployments cache - one of them must be provided`,\n )\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Idempotently deploying app \"${metadata.name}\" from creator ${createParams.sender} using ${createParams.approvalProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'} and ${createParams.clearStateProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'}`,\n )\n\n // Compile code if required\n\n const compiledApproval =\n typeof createParams.approvalProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.approvalProgram, deployTimeParams, metadata)\n : undefined\n const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : createParams.approvalProgram\n\n const compiledClear =\n typeof createParams.clearStateProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.clearStateProgram, deployTimeParams)\n : undefined\n const clearStateProgram = compiledClear ? compiledClear.compiledBase64ToBytes : createParams.clearStateProgram\n\n // Define routines for create, update, and replace\n\n const createApp = async () => {\n const result = await ('method' in createParams\n ? this._transactionSender.appCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram, ...sendParams })\n : this._transactionSender.appCreate({ ...createParams, approvalProgram, clearStateProgram, ...sendParams }))\n const appMetadata: AppMetadata = {\n appId: result.appId,\n appAddress: result.appAddress,\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(result.confirmation.confirmedRound!),\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'create',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppCreateTransactionResult & AppMetadata & { operationPerformed: 'create' }\n }\n const updateApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Updating existing ${metadata.name} app for ${createParams.sender} to version ${metadata.version}.`,\n )\n const result = await ('method' in updateParams\n ? this._transactionSender.appUpdateMethodCall({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n })\n : this._transactionSender.appUpdate({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n }))\n const appMetadata: AppMetadata = {\n appId: existingApp.appId,\n appAddress: existingApp.appAddress,\n createdMetadata: existingApp.createdMetadata,\n createdRound: existingApp.createdRound,\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n ...metadata,\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'update',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppUpdateTransactionResult & AppMetadata & { operationPerformed: 'update' }\n }\n const replaceApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Deploying a new ${metadata.name} app for ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Deleting existing ${metadata.name} app with id ${existingApp.appId} from ${deleteParams.sender} account.`,\n )\n\n const composer = this._transactionSender.newGroup()\n if ('method' in createParams) {\n composer.addAppCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram })\n } else {\n composer.addAppCreate({ ...createParams, approvalProgram, clearStateProgram })\n }\n const createIndex = await composer.count()\n if ('method' in deleteParams) {\n composer.addAppDeleteMethodCall({ appId: existingApp.appId, ...deleteParams })\n } else {\n composer.addAppDelete({ appId: existingApp.appId, ...deleteParams })\n }\n const result = await composer.send({ ...sendParams })\n const confirmation = result.confirmations.at(createIndex - 1)!\n const transaction = result.transactions.at(createIndex - 1)!\n const deleteTransaction = result.transactions.at(-1)!\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Sent transactions ${transaction.txID()} to create app with id ${confirmation.applicationIndex} and ${deleteTransaction.txID()} to delete app with id ${\n existingApp.appId\n } from ${createParams.sender} account.`,\n )\n\n const appMetadata: AppMetadata = {\n appId: BigInt(confirmation.applicationIndex!),\n appAddress: algosdk.getApplicationAddress(confirmation.applicationIndex!),\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(confirmation.confirmedRound!),\n updatedRound: BigInt(confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n\n return {\n operationPerformed: 'replace',\n ...result,\n compiledApproval,\n compiledClear,\n transaction,\n confirmation,\n return: 'method' in createParams ? result.returns?.[0] : undefined,\n deleteReturn: 'method' in deleteParams ? result.returns?.at(-1) : undefined,\n ...appMetadata,\n deleteResult: { transaction: deleteTransaction, confirmation: result.confirmations.at(-1)! },\n } satisfies { operationPerformed: 'replace' } & AppMetadata &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n }\n\n // Lookup existing app metadata\n\n const apps = existingDeployments ?? (await this.getCreatorAppsByName(createParams.sender, ignoreCache))\n\n const existingApp = apps.apps[metadata.name]\n if (!existingApp || existingApp.deleted) {\n Config.getLogger(sendParams?.suppressLog).info(\n `App ${metadata.name} not found in apps created by ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n return await createApp()\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Existing app ${metadata.name} found by creator ${createParams.sender}, with app id ${existingApp.appId} and version ${existingApp.version}.`,\n )\n\n const existingAppRecord = await this._appManager.getById(existingApp.appId)\n const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')\n const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')\n const existingExtraPages = calculateExtraProgramPages(existingAppRecord.approvalProgram, existingAppRecord.clearStateProgram)\n\n const newApprovalBytes = Buffer.from(approvalProgram)\n const newClearBytes = Buffer.from(clearStateProgram)\n const newApproval = newApprovalBytes.toString('base64')\n const newClear = newClearBytes.toString('base64')\n const newExtraPages = calculateExtraProgramPages(newApprovalBytes, newClearBytes)\n\n // Check for changes\n\n const isUpdate = newApproval !== existingApproval || newClear !== existingClear\n const isSchemaBreak =\n existingAppRecord.localInts < (createParams.schema?.localInts ?? 0) ||\n existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||\n existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||\n existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||\n existingExtraPages < newExtraPages\n\n if (isSchemaBreak) {\n Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {\n from: {\n globalInts: existingAppRecord.globalInts,\n globalByteSlices: existingAppRecord.globalByteSlices,\n localInts: existingAppRecord.localInts,\n localByteSlices: existingAppRecord.localByteSlices,\n extraProgramPages: existingExtraPages,\n },\n to: { ...createParams.schema, extraProgramPages: newExtraPages },\n })\n\n if (onSchemaBreak === undefined || onSchemaBreak === 'fail' || onSchemaBreak === OnSchemaBreak.Fail) {\n throw new Error(\n 'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +\n 'If you want to try deleting and recreating the app then ' +\n 're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',\n )\n }\n\n if (onSchemaBreak === 'append' || onSchemaBreak === OnSchemaBreak.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onSchemaBreak=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n\n if (isUpdate) {\n Config.getLogger(sendParams?.suppressLog).info(\n `Detected a TEAL update in app ${existingApp.appId} for creator ${createParams.sender}`,\n )\n\n if (onUpdate === undefined || onUpdate === 'fail' || onUpdate === OnUpdate.Fail) {\n throw new Error('Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.')\n }\n\n if (onUpdate === 'append' || onUpdate === OnUpdate.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onUpdate=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (onUpdate === 'update' || onUpdate === OnUpdate.UpdateApp) {\n if (existingApp.updatable) {\n Config.getLogger(sendParams?.suppressLog).info(`App is updatable and onUpdate=UpdateApp, updating app...`)\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n `App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail`,\n )\n }\n\n return await updateApp(existingApp)\n }\n\n if (onUpdate === 'replace' || onUpdate === OnUpdate.ReplaceApp) {\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n }\n\n Config.getLogger(sendParams?.suppressLog).debug('No detected changes in app, nothing to do.')\n\n return { ...existingApp, operationPerformed: 'nothing' }\n }\n\n private updateAppLookup(sender: string | Address, appMetadata: AppMetadata) {\n const s = typeof sender === 'string' ? sender : sender.toString()\n const lookup = this._appLookups.get(s)\n if (!lookup) {\n this._appLookups.set(s, { creator: Address.fromString(s), apps: { [appMetadata.name]: appMetadata } })\n } else {\n lookup.apps[appMetadata.name] = appMetadata\n }\n }\n\n /**\n * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have\n * an [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) `AppDeployNote` as the transaction\n * note of the app creation transaction.\n *\n * This function caches the result for the given creator account so that subsequent calls will not require an indexer lookup.\n *\n * If the `AppManager` instance wasn't created with an indexer client, this function will throw an error.\n *\n * @param creatorAddress The address of the account that is the creator of the apps you want to search for\n * @param ignoreCache Whether or not to ignore the cache and force a lookup, default: use the cache\n * @returns A name-based lookup of the app metadata\n * @example\n * ```ts\n * const result = await deployer.getCreatorAppsByName(creator)\n */\n async getCreatorAppsByName(creatorAddress: string | Address, ignoreCache?: boolean): Promise<AppLookup> {\n const appLookup: Record<string, AppMetadata> = {}\n\n const address = typeof creatorAddress === 'string' ? creatorAddress : creatorAddress.toString()\n if (!ignoreCache && this._appLookups.has(address)) {\n return this._appLookups.get(address)!\n }\n\n if (!this._indexer) {\n throw new Error(`Didn't receive an indexer client when this AppManager was created, but received a call to getCreatorApps`)\n }\n\n // Extract all apps that account created\n const createdApps = (await indexer.lookupAccountCreatedApplicationByAddress(this._indexer, creatorAddress))\n .map((a) => {\n return { id: a.id, createdAtRound: a.createdAtRound!, deleted: a.deleted }\n })\n .sort((a, b) => Number(a.createdAtRound - b.createdAtRound))\n\n // For each app that account created (in parallel)...\n const apps = await Promise.all(\n createdApps.map(async (createdApp) => {\n // Find any app transactions for that app in the round it was created (should always just be a single creation transaction)\n const appTransactions = await indexer.searchTransactions(this._indexer!, (s) =>\n s\n .minRound(createdApp.createdAtRound)\n .txType(algosdk.TransactionType.appl)\n .applicationID(Number(createdApp.id))\n .address(creatorAddress)\n .addressRole('sender')\n .notePrefix(Buffer.from(APP_DEPLOY_NOTE_DAPP).toString('base64')),\n )\n\n // Triple check the transaction is intact by filtering for the one we want:\n // * application-id is 0 when the app is first created\n // * also verify the sender to prevent a potential security risk\n const appCreationTransaction = appTransactions.transactions.filter(\n (t) => t.applicationTransaction?.applicationId === 0n && t.sender.toString() === creatorAddress.toString(),\n )[0]\n\n const latestAppUpdateTransaction = appTransactions.transactions\n .filter((t) => t.sender.toString() === creatorAddress.toString())\n .sort((a, b) =>\n a.confirmedRound === b.confirmedRound\n ? (b.intraRoundOffset! - a.intraRoundOffset!) / 10\n : Number(b.confirmedRound! - a.confirmedRound!),\n )[0]\n\n if (!appCreationTransaction?.note)\n // No note; ignoring\n return null\n\n return { createdApp, appCreationTransaction, latestAppUpdateTransaction }\n }),\n )\n\n apps\n .filter((a) => a !== null)\n .forEach((a) => {\n const { createdApp, appCreationTransaction, latestAppUpdateTransaction } = a!\n\n const parseNote = (note?: string) => {\n if (!note) {\n // No note; ignoring...\n return\n }\n\n if (!note.startsWith(`${APP_DEPLOY_NOTE_DAPP}:j{`))\n // Clearly not APP_DEPLOY JSON; ignoring...\n return\n\n return JSON.parse(note.substring(APP_DEPLOY_NOTE_DAPP.length + 2)) as AppDeployMetadata\n }\n\n try {\n const creationNote = parseNote(\n appCreationTransaction.note ? Buffer.from(appCreationTransaction.note).toString('utf-8') : undefined,\n )\n const updateNote = parseNote(\n latestAppUpdateTransaction.note ? Buffer.from(latestAppUpdateTransaction.note).toString('utf-8') : undefined,\n )\n if (creationNote?.name) {\n appLookup[creationNote.name] = {\n appId: createdApp.id,\n appAddress: algosdk.getApplicationAddress(createdApp.id),\n createdMetadata: creationNote,\n createdRound: appCreationTransaction.confirmedRound ?? 0n,\n ...(updateNote ?? creationNote),\n updatedRound: latestAppUpdateTransaction?.confirmedRound ?? 0n,\n deleted: createdApp.deleted ?? false,\n }\n }\n } catch (e) {\n Config.logger.warn(\n `Received error trying to retrieve app with ${createdApp.id} for creator ${creatorAddress}; failing silently`,\n e,\n )\n return\n }\n })\n\n const lookup = {\n creator: typeof creatorAddress === 'string' ? Address.fromString(creatorAddress) : creatorAddress,\n apps: appLookup,\n }\n\n this._appLookups.set(creatorAddress.toString(), lookup)\n\n return lookup\n }\n}\n"],"names":["TransactionComposer","APP_DEPLOY_NOTE_DAPP","Config","calculateExtraProgramPages","OnSchemaBreak","OnUpdate","Address","indexer.lookupAccountCreatedApplicationByAddress","indexer.searchTransactions"],"mappings":";;;;;;;;;AA8GA;MACa,WAAW,CAAA;AAMtB;;;;;;;;;AASG;AACH,IAAA,WAAA,CAAY,UAAsB,EAAE,iBAAkD,EAAE,OAAyB,EAAA;AAZzG,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAqB;AAahD,QAAA,IAAI,CAAC,WAAW,GAAG,UAAU;AAC7B,QAAA,IAAI,CAAC,kBAAkB,GAAG,iBAAiB;AAC3C,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;;AAGzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;IACH,MAAM,MAAM,CAAC,UAA2B,EAAA;QACtC,MAAM,EACJ,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,GAAG,UAAU,EACd,GAAG,UAAU;;QAId,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,GAAGA,kCAAmB,CAAC,QAAQ,CAAC;AACnE,YAAA,QAAQ,EAAEC,8BAAoB;AAC9B,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,MAAM,EAAE,GAAG;AACZ,SAAA,CAAC;;AAIF,QAAA,IAAI,mBAAmB,IAAI,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE;AACpG,YAAA,MAAM,IAAI,KAAK,CACb,CAAA,uDAAA,EAA0D,mBAAmB,CAAC,OAAO,CAA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AAA,MAAM,MAAM,GAAG;AACb,YAAA,OAAO,EAAE,OAAO,cAAc,KAAK,QAAQ,GAAGI,eAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,cAAc;AACjG,YAAA,IAAI,EAAE,SAAS;SAChB;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC;AAEvD,QAAA,OAAO,MAAM;;AAEhB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-deployer.mjs","sources":["../../src/types/app-deployer.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport * as indexer from '../indexer-lookup'\nimport { calculateExtraProgramPages } from '../util'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport {\n APP_DEPLOY_NOTE_DAPP,\n OnSchemaBreak,\n OnUpdate,\n type ABIReturn,\n type AppDeployMetadata,\n type SendAppCreateTransactionResult,\n type SendAppUpdateTransactionResult,\n type TealTemplateParams,\n} from './app'\nimport { AppManager } from './app-manager'\nimport {\n AppCreateMethodCall,\n AppCreateParams,\n AppDeleteMethodCall,\n AppDeleteParams,\n AppUpdateMethodCall,\n AppUpdateParams,\n TransactionComposer,\n} from './composer'\nimport { Expand } from './expand'\nimport { ConfirmedTransactionResult, SendParams } from './transaction'\n\n/** Params to specify an update transaction for an app deployment */\nexport type DeployAppUpdateParams = Expand<Omit<AppUpdateParams, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify an update method call for an app deployment */\nexport type DeployAppUpdateMethodCall = Expand<Omit<AppUpdateMethodCall, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify a transaction for an app deployment */\nexport type DeployAppDeleteParams = Expand<Omit<AppDeleteParams, 'appId'>>\n/** Params to specify a delete method call for an app deployment */\nexport type DeployAppDeleteMethodCall = Expand<Omit<AppDeleteMethodCall, 'appId'>>\n\n/** The parameters to idempotently deploy an app */\nexport type AppDeployParams = Expand<\n SendParams & {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code before compiling it (used if teal code is passed in as a string) */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break (storage schema or extra pages change) is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL code update is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `update` - Update the app with the new TEAL code\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams: AppCreateParams | AppCreateMethodCall\n /** Update transaction parameters to use if an update needs to be issued as part of deployment */\n updateParams: DeployAppUpdateParams | DeployAppUpdateMethodCall\n /** Delete transaction parameters to use if a delete needs to be issued as part of deployment */\n deleteParams: DeployAppDeleteParams | DeployAppDeleteMethodCall\n /** Optional cached value of the existing apps for the given creator; use this to avoid an indexer lookup */\n existingDeployments?: AppLookup\n /** Whether or not to ignore the app metadata cache and force a lookup, default: use the cache **/\n ignoreCache?: boolean\n }\n>\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppDeployMetadata {\n /** The id of the app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: Address\n /** The round the app was created */\n createdRound: bigint\n /** The last round that the app was updated */\n updatedRound: bigint\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n /** The address of the creator associated with this lookup */\n creator: Readonly<Address>\n /** A hash map of app name to app metadata */\n apps: {\n [name: string]: AppMetadata\n }\n}\n\nexport type AppDeployResult =\n | Expand<{ operationPerformed: 'create' } & Omit<AppMetadata, 'appId' | 'appAddress'> & SendAppCreateTransactionResult>\n | Expand<{ operationPerformed: 'update' } & AppMetadata & SendAppUpdateTransactionResult>\n | Expand<\n { operationPerformed: 'replace' } & Omit<AppMetadata, 'appId' | 'appAddress'> &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n >\n | Expand<{ operationPerformed: 'nothing' } & AppMetadata>\n\n/** Allows management of deployment and deployment metadata of applications. */\nexport class AppDeployer {\n private _appManager: AppManager\n private _transactionSender: AlgorandClientTransactionSender\n private _indexer?: algosdk.Indexer\n private _appLookups = new Map<string, AppLookup>()\n\n /**\n * Creates an `AppManager`\n * @param appManager An `AppManager` instance\n * @param transactionSender An `AlgorandClientTransactionSender` instance\n * @param indexer An optional indexer instance; supply if you want to indexer to look up app metadata\n * @example\n * ```ts\n * const deployer = new AppDeployer(appManager, transactionSender, indexer)\n * ```\n */\n constructor(appManager: AppManager, transactionSender: AlgorandClientTransactionSender, indexer?: algosdk.Indexer) {\n this._appManager = appManager\n this._transactionSender = transactionSender\n this._indexer = indexer\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param deployment The arguments to control the app deployment\n * @returns The result of the deployment\n * @example\n * ```ts\n * const deployResult = await deployer.deploy({\n * createParams: {\n * sender: 'SENDER_ADDRESS',\n * approvalProgram: 'APPROVAL PROGRAM',\n * clearStateProgram: 'CLEAR PROGRAM',\n * schema: {\n * globalByteSlices: 0,\n * globalInts: 0,\n * localByteSlices: 0,\n * localInts: 0\n * }\n * },\n * updateParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * deleteParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },\n * onSchemaBreak: 'append',\n * onUpdate: 'append'\n * })\n * ```\n */\n async deploy(deployment: AppDeployParams): Promise<AppDeployResult> {\n const {\n metadata,\n deployTimeParams,\n onSchemaBreak,\n onUpdate,\n createParams,\n updateParams,\n deleteParams,\n existingDeployments,\n ignoreCache,\n ...sendParams\n } = deployment\n\n // Set creation note\n\n createParams.note = updateParams.note = TransactionComposer.arc2Note({\n dAppName: APP_DEPLOY_NOTE_DAPP,\n data: metadata,\n format: 'j',\n })\n\n // Check for required fields\n\n if (existingDeployments && existingDeployments.creator.toString() !== createParams.sender.toString()) {\n throw new Error(\n `Received invalid existingDeployments value for creator ${existingDeployments.creator} when attempting to deploy for creator ${createParams.sender}`,\n )\n }\n if (!existingDeployments && !this._indexer) {\n throw new Error(\n `Didn't receive an indexer client when this AppManager was created, but also didn't receive an existingDeployments cache - one of them must be provided`,\n )\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Idempotently deploying app \"${metadata.name}\" from creator ${createParams.sender} using ${createParams.approvalProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'} and ${createParams.clearStateProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'}`,\n )\n\n // Compile code if required\n\n const compiledApproval =\n typeof createParams.approvalProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.approvalProgram, deployTimeParams, metadata)\n : undefined\n const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : createParams.approvalProgram\n\n const compiledClear =\n typeof createParams.clearStateProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.clearStateProgram, deployTimeParams)\n : undefined\n const clearStateProgram = compiledClear ? compiledClear.compiledBase64ToBytes : createParams.clearStateProgram\n\n // Define routines for create, update, and replace\n\n const createApp = async () => {\n const result = await ('method' in createParams\n ? this._transactionSender.appCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram, ...sendParams })\n : this._transactionSender.appCreate({ ...createParams, approvalProgram, clearStateProgram, ...sendParams }))\n const appMetadata: AppMetadata = {\n appId: result.appId,\n appAddress: result.appAddress,\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(result.confirmation.confirmedRound!),\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'create',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppCreateTransactionResult & AppMetadata & { operationPerformed: 'create' }\n }\n const updateApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Updating existing ${metadata.name} app for ${createParams.sender} to version ${metadata.version}.`,\n )\n const result = await ('method' in updateParams\n ? this._transactionSender.appUpdateMethodCall({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n })\n : this._transactionSender.appUpdate({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n }))\n const appMetadata: AppMetadata = {\n appId: existingApp.appId,\n appAddress: existingApp.appAddress,\n createdMetadata: existingApp.createdMetadata,\n createdRound: existingApp.createdRound,\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n ...metadata,\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'update',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppUpdateTransactionResult & AppMetadata & { operationPerformed: 'update' }\n }\n const replaceApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Deploying a new ${metadata.name} app for ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Deleting existing ${metadata.name} app with id ${existingApp.appId} from ${deleteParams.sender} account.`,\n )\n\n const composer = this._transactionSender.newGroup()\n if ('method' in createParams) {\n composer.addAppCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram })\n } else {\n composer.addAppCreate({ ...createParams, approvalProgram, clearStateProgram })\n }\n const createIndex = await composer.count()\n if ('method' in deleteParams) {\n composer.addAppDeleteMethodCall({ appId: existingApp.appId, ...deleteParams })\n } else {\n composer.addAppDelete({ appId: existingApp.appId, ...deleteParams })\n }\n const result = await composer.send({ ...sendParams })\n const confirmation = result.confirmations.at(createIndex - 1)!\n const transaction = result.transactions.at(createIndex - 1)!\n const deleteTransaction = result.transactions.at(-1)!\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Sent transactions ${transaction.txID()} to create app with id ${confirmation.applicationIndex} and ${deleteTransaction.txID()} to delete app with id ${\n existingApp.appId\n } from ${createParams.sender} account.`,\n )\n\n const appMetadata: AppMetadata = {\n appId: BigInt(confirmation.applicationIndex!),\n appAddress: algosdk.getApplicationAddress(confirmation.applicationIndex!),\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(confirmation.confirmedRound!),\n updatedRound: BigInt(confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n\n return {\n operationPerformed: 'replace',\n ...result,\n compiledApproval,\n compiledClear,\n transaction,\n confirmation,\n return: 'method' in createParams ? result.returns?.[0] : undefined,\n deleteReturn: 'method' in deleteParams ? result.returns?.at(-1) : undefined,\n ...appMetadata,\n deleteResult: { transaction: deleteTransaction, confirmation: result.confirmations.at(-1)! },\n } satisfies { operationPerformed: 'replace' } & AppMetadata &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n }\n\n // Lookup existing app metadata\n\n const apps = existingDeployments ?? (await this.getCreatorAppsByName(createParams.sender, ignoreCache))\n\n const existingApp = apps.apps[metadata.name]\n if (!existingApp || existingApp.deleted) {\n Config.getLogger(sendParams?.suppressLog).info(\n `App ${metadata.name} not found in apps created by ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n return await createApp()\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Existing app ${metadata.name} found by creator ${createParams.sender}, with app id ${existingApp.appId} and version ${existingApp.version}.`,\n )\n\n const existingAppRecord = await this._appManager.getById(existingApp.appId)\n const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')\n const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')\n const existingExtraPages = calculateExtraProgramPages(existingAppRecord.approvalProgram, existingAppRecord.clearStateProgram)\n\n const newApprovalBytes = Buffer.from(approvalProgram)\n const newClearBytes = Buffer.from(clearStateProgram)\n const newApproval = newApprovalBytes.toString('base64')\n const newClear = newClearBytes.toString('base64')\n const newExtraPages = calculateExtraProgramPages(newApprovalBytes, newClearBytes)\n\n // Check for changes\n\n const isUpdate = newApproval !== existingApproval || newClear !== existingClear\n const isSchemaBreak =\n existingAppRecord.localInts < (createParams.schema?.localInts ?? 0) ||\n existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||\n existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||\n existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||\n existingExtraPages < newExtraPages\n\n if (isSchemaBreak) {\n Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {\n from: {\n globalInts: existingAppRecord.globalInts,\n globalByteSlices: existingAppRecord.globalByteSlices,\n localInts: existingAppRecord.localInts,\n localByteSlices: existingAppRecord.localByteSlices,\n extraProgramPages: existingExtraPages,\n },\n to: { ...createParams.schema, extraProgramPages: newExtraPages },\n })\n\n if (onSchemaBreak === undefined || onSchemaBreak === 'fail' || onSchemaBreak === OnSchemaBreak.Fail) {\n throw new Error(\n 'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +\n 'If you want to try deleting and recreating the app then ' +\n 're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',\n )\n }\n\n if (onSchemaBreak === 'append' || onSchemaBreak === OnSchemaBreak.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onSchemaBreak=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n\n if (isUpdate) {\n Config.getLogger(sendParams?.suppressLog).info(\n `Detected a TEAL update in app ${existingApp.appId} for creator ${createParams.sender}`,\n )\n\n if (onUpdate === undefined || onUpdate === 'fail' || onUpdate === OnUpdate.Fail) {\n throw new Error('Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.')\n }\n\n if (onUpdate === 'append' || onUpdate === OnUpdate.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onUpdate=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (onUpdate === 'update' || onUpdate === OnUpdate.UpdateApp) {\n if (existingApp.updatable) {\n Config.getLogger(sendParams?.suppressLog).info(`App is updatable and onUpdate=UpdateApp, updating app...`)\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n `App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail`,\n )\n }\n\n return await updateApp(existingApp)\n }\n\n if (onUpdate === 'replace' || onUpdate === OnUpdate.ReplaceApp) {\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n }\n\n Config.getLogger(sendParams?.suppressLog).debug('No detected changes in app, nothing to do.')\n\n return { ...existingApp, operationPerformed: 'nothing' }\n }\n\n private updateAppLookup(sender: string | Address, appMetadata: AppMetadata) {\n const s = typeof sender === 'string' ? sender : sender.toString()\n const lookup = this._appLookups.get(s)\n if (!lookup) {\n this._appLookups.set(s, { creator: Address.fromString(s), apps: { [appMetadata.name]: appMetadata } })\n } else {\n lookup.apps[appMetadata.name] = appMetadata\n }\n }\n\n /**\n * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have\n * an [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) `AppDeployNote` as the transaction\n * note of the app creation transaction.\n *\n * This function caches the result for the given creator account so that subsequent calls will not require an indexer lookup.\n *\n * If the `AppManager` instance wasn't created with an indexer client, this function will throw an error.\n *\n * @param creatorAddress The address of the account that is the creator of the apps you want to search for\n * @param ignoreCache Whether or not to ignore the cache and force a lookup, default: use the cache\n * @returns A name-based lookup of the app metadata\n * @example\n * ```ts\n * const result = await deployer.getCreatorAppsByName(creator)\n */\n async getCreatorAppsByName(creatorAddress: string | Address, ignoreCache?: boolean): Promise<AppLookup> {\n const appLookup: Record<string, AppMetadata> = {}\n\n const address = typeof creatorAddress === 'string' ? creatorAddress : creatorAddress.toString()\n if (!ignoreCache && this._appLookups.has(address)) {\n return this._appLookups.get(address)!\n }\n\n if (!this._indexer) {\n throw new Error(`Didn't receive an indexer client when this AppManager was created, but received a call to getCreatorApps`)\n }\n\n // Extract all apps that account created\n const createdApps = (await indexer.lookupAccountCreatedApplicationByAddress(this._indexer, creatorAddress))\n .map((a) => {\n return { id: a.id, createdAtRound: a.createdAtRound!, deleted: a.deleted }\n })\n .sort((a, b) => Number(a.createdAtRound - b.createdAtRound))\n\n // For each app that account created (in parallel)...\n const apps = await Promise.all(\n createdApps.map(async (createdApp) => {\n // Find any app transactions for that app in the round it was created (should always just be a single creation transaction)\n const appTransactions = await indexer.searchTransactions(this._indexer!, (s) =>\n s\n .minRound(createdApp.createdAtRound)\n .txType(algosdk.TransactionType.appl)\n .applicationID(Number(createdApp.id))\n .address(creatorAddress)\n .addressRole('sender')\n .notePrefix(Buffer.from(APP_DEPLOY_NOTE_DAPP).toString('base64')),\n )\n\n // Triple check the transaction is intact by filtering for the one we want:\n // * application-id is 0 when the app is first created\n // * also verify the sender to prevent a potential security risk\n const appCreationTransaction = appTransactions.transactions.filter(\n (t) => t.applicationTransaction?.applicationId === 0n && t.sender.toString() === creatorAddress.toString(),\n )[0]\n\n const latestAppUpdateTransaction = appTransactions.transactions\n .filter((t) => t.sender.toString() === creatorAddress.toString())\n .sort((a, b) =>\n a.confirmedRound === b.confirmedRound\n ? (b.intraRoundOffset! - a.intraRoundOffset!) / 10\n : Number(b.confirmedRound! - a.confirmedRound!),\n )[0]\n\n if (!appCreationTransaction?.note)\n // No note; ignoring\n return null\n\n return { createdApp, appCreationTransaction, latestAppUpdateTransaction }\n }),\n )\n\n apps\n .filter((a) => a !== null)\n .forEach((a) => {\n const { createdApp, appCreationTransaction, latestAppUpdateTransaction } = a!\n\n const parseNote = (note?: string) => {\n if (!note) {\n // No note; ignoring...\n return\n }\n\n if (!note.startsWith(`${APP_DEPLOY_NOTE_DAPP}:j{`))\n // Clearly not APP_DEPLOY JSON; ignoring...\n return\n\n return JSON.parse(note.substring(APP_DEPLOY_NOTE_DAPP.length + 2)) as AppDeployMetadata\n }\n\n try {\n const creationNote = parseNote(\n appCreationTransaction.note ? Buffer.from(appCreationTransaction.note).toString('utf-8') : undefined,\n )\n const updateNote = parseNote(\n latestAppUpdateTransaction.note ? Buffer.from(latestAppUpdateTransaction.note).toString('utf-8') : undefined,\n )\n if (creationNote?.name) {\n appLookup[creationNote.name] = {\n appId: createdApp.id,\n appAddress: algosdk.getApplicationAddress(createdApp.id),\n createdMetadata: creationNote,\n createdRound: appCreationTransaction.confirmedRound ?? 0n,\n ...(updateNote ?? creationNote),\n updatedRound: latestAppUpdateTransaction?.confirmedRound ?? 0n,\n deleted: createdApp.deleted ?? false,\n }\n }\n } catch (e) {\n Config.logger.warn(\n `Received error trying to retrieve app with ${createdApp.id} for creator ${creatorAddress}; failing silently`,\n e,\n )\n return\n }\n })\n\n const lookup = {\n creator: typeof creatorAddress === 'string' ? Address.fromString(creatorAddress) : creatorAddress,\n apps: appLookup,\n }\n\n this._appLookups.set(creatorAddress.toString(), lookup)\n\n return lookup\n }\n}\n"],"names":["indexer.lookupAccountCreatedApplicationByAddress","indexer.searchTransactions"],"mappings":";;;;;;;AA8GA;MACa,WAAW,CAAA;AAMtB;;;;;;;;;AASG;AACH,IAAA,WAAA,CAAY,UAAsB,EAAE,iBAAkD,EAAE,OAAyB,EAAA;AAZzG,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAqB;AAahD,QAAA,IAAI,CAAC,WAAW,GAAG,UAAU;AAC7B,QAAA,IAAI,CAAC,kBAAkB,GAAG,iBAAiB;AAC3C,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;;AAGzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;IACH,MAAM,MAAM,CAAC,UAA2B,EAAA;QACtC,MAAM,EACJ,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,GAAG,UAAU,EACd,GAAG,UAAU;;QAId,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,GAAG,mBAAmB,CAAC,QAAQ,CAAC;AACnE,YAAA,QAAQ,EAAE,oBAAoB;AAC9B,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,MAAM,EAAE,GAAG;AACZ,SAAA,CAAC;;AAIF,QAAA,IAAI,mBAAmB,IAAI,m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AAC,IAAI,CAChB,CAA8C,2CAAA,EAAA,UAAU,CAAC,EAAE,gBAAgB,cAAc,CAAA,kBAAA,CAAoB,EAC7G,CAAC,CACF;gBACD;;AAEJ,SAAC,CAAC;AAEJ,QAAA,MAAM,MAAM,GAAG;AACb,YAAA,OAAO,EAAE,OAAO,cAAc,KAAK,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,cAAc;AACjG,YAAA,IAAI,EAAE,SAAS;SAChB;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC;AAEvD,QAAA,OAAO,MAAM;;AAEhB;;;;"}
|
|
1
|
+
{"version":3,"file":"app-deployer.mjs","sources":["../../src/types/app-deployer.ts"],"sourcesContent":["import algosdk, { Address } from 'algosdk'\nimport { Config } from '../config'\nimport * as indexer from '../indexer-lookup'\nimport { calculateExtraProgramPages } from '../util'\nimport { AlgorandClientTransactionSender } from './algorand-client-transaction-sender'\nimport {\n APP_DEPLOY_NOTE_DAPP,\n OnSchemaBreak,\n OnUpdate,\n type ABIReturn,\n type AppDeployMetadata,\n type SendAppCreateTransactionResult,\n type SendAppUpdateTransactionResult,\n type TealTemplateParams,\n} from './app'\nimport { AppManager } from './app-manager'\nimport {\n AppCreateMethodCall,\n AppCreateParams,\n AppDeleteMethodCall,\n AppDeleteParams,\n AppUpdateMethodCall,\n AppUpdateParams,\n TransactionComposer,\n} from './composer'\nimport { Expand } from './expand'\nimport { ConfirmedTransactionResult, SendParams } from './transaction'\n\n/** Params to specify an update transaction for an app deployment */\nexport type DeployAppUpdateParams = Expand<Omit<AppUpdateParams, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify an update method call for an app deployment */\nexport type DeployAppUpdateMethodCall = Expand<Omit<AppUpdateMethodCall, 'appId' | 'approvalProgram' | 'clearStateProgram'>>\n/** Params to specify a transaction for an app deployment */\nexport type DeployAppDeleteParams = Expand<Omit<AppDeleteParams, 'appId'>>\n/** Params to specify a delete method call for an app deployment */\nexport type DeployAppDeleteMethodCall = Expand<Omit<AppDeleteMethodCall, 'appId'>>\n\n/** The parameters to idempotently deploy an app */\nexport type AppDeployParams = Expand<\n SendParams & {\n /** The deployment metadata */\n metadata: AppDeployMetadata\n /** Any deploy-time parameters to replace in the TEAL code before compiling it (used if teal code is passed in as a string) */\n deployTimeParams?: TealTemplateParams\n /** What action to perform if a schema break (storage schema or extra pages change) is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onSchemaBreak?: 'replace' | 'fail' | 'append' | OnSchemaBreak\n /** What action to perform if a TEAL code update is detected:\n *\n * * `fail` - Fail the deployment (throw an error, **default**)\n * * `update` - Update the app with the new TEAL code\n * * `replace` - Delete the old app and create a new one\n * * `append` - Deploy a new app and leave the old one as is\n */\n onUpdate?: 'update' | 'replace' | 'fail' | 'append' | OnUpdate\n /** Create transaction parameters to use if a create needs to be issued as part of deployment */\n createParams: AppCreateParams | AppCreateMethodCall\n /** Update transaction parameters to use if an update needs to be issued as part of deployment */\n updateParams: DeployAppUpdateParams | DeployAppUpdateMethodCall\n /** Delete transaction parameters to use if a delete needs to be issued as part of deployment */\n deleteParams: DeployAppDeleteParams | DeployAppDeleteMethodCall\n /** Optional cached value of the existing apps for the given creator; use this to avoid an indexer lookup */\n existingDeployments?: AppLookup\n /** Whether or not to ignore the app metadata cache and force a lookup, default: use the cache **/\n ignoreCache?: boolean\n }\n>\n\n/** The metadata that can be collected about a deployed app */\nexport interface AppMetadata extends AppDeployMetadata {\n /** The id of the app */\n appId: bigint\n /** The Algorand address of the account associated with the app */\n appAddress: Address\n /** The round the app was created */\n createdRound: bigint\n /** The last round that the app was updated */\n updatedRound: bigint\n /** The metadata when the app was created */\n createdMetadata: AppDeployMetadata\n /** Whether or not the app is deleted */\n deleted: boolean\n}\n\n/** A lookup of name -> Algorand app for a creator */\nexport interface AppLookup {\n /** The address of the creator associated with this lookup */\n creator: Readonly<Address>\n /** A hash map of app name to app metadata */\n apps: {\n [name: string]: AppMetadata\n }\n}\n\nexport type AppDeployResult =\n | Expand<{ operationPerformed: 'create' } & Omit<AppMetadata, 'appId' | 'appAddress'> & SendAppCreateTransactionResult>\n | Expand<{ operationPerformed: 'update' } & AppMetadata & SendAppUpdateTransactionResult>\n | Expand<\n { operationPerformed: 'replace' } & Omit<AppMetadata, 'appId' | 'appAddress'> &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n >\n | Expand<{ operationPerformed: 'nothing' } & AppMetadata>\n\n/** Allows management of deployment and deployment metadata of applications. */\nexport class AppDeployer {\n private _appManager: AppManager\n private _transactionSender: AlgorandClientTransactionSender\n private _indexer?: algosdk.Indexer\n private _appLookups = new Map<string, AppLookup>()\n\n /**\n * Creates an `AppManager`\n * @param appManager An `AppManager` instance\n * @param transactionSender An `AlgorandClientTransactionSender` instance\n * @param indexer An optional indexer instance; supply if you want to indexer to look up app metadata\n * @example\n * ```ts\n * const deployer = new AppDeployer(appManager, transactionSender, indexer)\n * ```\n */\n constructor(appManager: AppManager, transactionSender: AlgorandClientTransactionSender, indexer?: algosdk.Indexer) {\n this._appManager = appManager\n this._transactionSender = transactionSender\n this._indexer = indexer\n }\n\n /**\n * Idempotently deploy (create if not exists, update if changed) an app against the given name for the given creator account, including deploy-time TEAL template placeholder substitutions (if specified).\n *\n * To understand the architecture decisions behind this functionality please see https://github.com/algorandfoundation/algokit-cli/blob/main/docs/architecture-decisions/2023-01-12_smart-contract-deployment.md\n *\n * **Note:** When using the return from this function be sure to check `operationPerformed` to get access to various return properties like `transaction`, `confirmation` and `deleteResult`.\n *\n * **Note:** if there is a breaking state schema change to an existing app (and `onSchemaBreak` is set to `'replace'`) the existing app will be deleted and re-created.\n *\n * **Note:** if there is an update (different TEAL code) to an existing app (and `onUpdate` is set to `'replace'`) the existing app will be deleted and re-created.\n * @param deployment The arguments to control the app deployment\n * @returns The result of the deployment\n * @example\n * ```ts\n * const deployResult = await deployer.deploy({\n * createParams: {\n * sender: 'SENDER_ADDRESS',\n * approvalProgram: 'APPROVAL PROGRAM',\n * clearStateProgram: 'CLEAR PROGRAM',\n * schema: {\n * globalByteSlices: 0,\n * globalInts: 0,\n * localByteSlices: 0,\n * localInts: 0\n * }\n * },\n * updateParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * deleteParams: {\n * sender: 'SENDER_ADDRESS'\n * },\n * metadata: { name: 'my_app', version: '2.0', updatable: false, deletable: false },\n * onSchemaBreak: 'append',\n * onUpdate: 'append'\n * })\n * ```\n */\n async deploy(deployment: AppDeployParams): Promise<AppDeployResult> {\n const {\n metadata,\n deployTimeParams,\n onSchemaBreak,\n onUpdate,\n createParams,\n updateParams,\n deleteParams,\n existingDeployments,\n ignoreCache,\n ...sendParams\n } = deployment\n\n // Set creation note\n\n createParams.note = updateParams.note = TransactionComposer.arc2Note({\n dAppName: APP_DEPLOY_NOTE_DAPP,\n data: metadata,\n format: 'j',\n })\n\n // Check for required fields\n\n if (existingDeployments && existingDeployments.creator.toString() !== createParams.sender.toString()) {\n throw new Error(\n `Received invalid existingDeployments value for creator ${existingDeployments.creator} when attempting to deploy for creator ${createParams.sender}`,\n )\n }\n if (!existingDeployments && !this._indexer) {\n throw new Error(\n `Didn't receive an indexer client when this AppManager was created, but also didn't receive an existingDeployments cache - one of them must be provided`,\n )\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Idempotently deploying app \"${metadata.name}\" from creator ${createParams.sender} using ${createParams.approvalProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'} and ${createParams.clearStateProgram.length} bytes of ${typeof createParams.approvalProgram === 'string' ? 'teal code' : 'AVM bytecode'}`,\n )\n\n // Compile code if required\n\n const compiledApproval =\n typeof createParams.approvalProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.approvalProgram, deployTimeParams, metadata)\n : undefined\n const approvalProgram = compiledApproval ? compiledApproval.compiledBase64ToBytes : createParams.approvalProgram\n\n const compiledClear =\n typeof createParams.clearStateProgram === 'string'\n ? await this._appManager.compileTealTemplate(createParams.clearStateProgram, deployTimeParams)\n : undefined\n const clearStateProgram = compiledClear ? compiledClear.compiledBase64ToBytes : createParams.clearStateProgram\n\n // Define routines for create, update, and replace\n\n const createApp = async () => {\n const result = await ('method' in createParams\n ? this._transactionSender.appCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram, ...sendParams })\n : this._transactionSender.appCreate({ ...createParams, approvalProgram, clearStateProgram, ...sendParams }))\n const appMetadata: AppMetadata = {\n appId: result.appId,\n appAddress: result.appAddress,\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(result.confirmation.confirmedRound!),\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'create',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppCreateTransactionResult & AppMetadata & { operationPerformed: 'create' }\n }\n const updateApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Updating existing ${metadata.name} app for ${createParams.sender} to version ${metadata.version}.`,\n )\n const result = await ('method' in updateParams\n ? this._transactionSender.appUpdateMethodCall({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n })\n : this._transactionSender.appUpdate({\n appId: existingApp.appId,\n approvalProgram,\n clearStateProgram,\n ...updateParams,\n ...sendParams,\n }))\n const appMetadata: AppMetadata = {\n appId: existingApp.appId,\n appAddress: existingApp.appAddress,\n createdMetadata: existingApp.createdMetadata,\n createdRound: existingApp.createdRound,\n updatedRound: BigInt(result.confirmation.confirmedRound!),\n ...metadata,\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n return {\n operationPerformed: 'update',\n compiledApproval,\n compiledClear,\n ...result,\n ...appMetadata,\n } satisfies SendAppUpdateTransactionResult & AppMetadata & { operationPerformed: 'update' }\n }\n const replaceApp = async (existingApp: AppMetadata) => {\n Config.getLogger(sendParams?.suppressLog).info(\n `Deploying a new ${metadata.name} app for ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Deleting existing ${metadata.name} app with id ${existingApp.appId} from ${deleteParams.sender} account.`,\n )\n\n const composer = this._transactionSender.newGroup()\n if ('method' in createParams) {\n composer.addAppCreateMethodCall({ ...createParams, approvalProgram, clearStateProgram })\n } else {\n composer.addAppCreate({ ...createParams, approvalProgram, clearStateProgram })\n }\n const createIndex = await composer.count()\n if ('method' in deleteParams) {\n composer.addAppDeleteMethodCall({ appId: existingApp.appId, ...deleteParams })\n } else {\n composer.addAppDelete({ appId: existingApp.appId, ...deleteParams })\n }\n const result = await composer.send({ ...sendParams })\n const confirmation = result.confirmations.at(createIndex - 1)!\n const transaction = result.transactions.at(createIndex - 1)!\n const deleteTransaction = result.transactions.at(-1)!\n\n Config.getLogger(sendParams?.suppressLog).warn(\n `Sent transactions ${transaction.txID()} to create app with id ${confirmation.applicationIndex} and ${deleteTransaction.txID()} to delete app with id ${\n existingApp.appId\n } from ${createParams.sender} account.`,\n )\n\n const appMetadata: AppMetadata = {\n appId: BigInt(confirmation.applicationIndex!),\n appAddress: algosdk.getApplicationAddress(confirmation.applicationIndex!),\n ...metadata,\n createdMetadata: metadata,\n createdRound: BigInt(confirmation.confirmedRound!),\n updatedRound: BigInt(confirmation.confirmedRound!),\n deleted: false,\n }\n this.updateAppLookup(createParams.sender, appMetadata)\n\n return {\n operationPerformed: 'replace',\n ...result,\n compiledApproval,\n compiledClear,\n transaction,\n confirmation,\n return: 'method' in createParams ? result.returns?.[0] : undefined,\n deleteReturn: 'method' in deleteParams ? result.returns?.at(-1) : undefined,\n ...appMetadata,\n deleteResult: { transaction: deleteTransaction, confirmation: result.confirmations.at(-1)! },\n } satisfies { operationPerformed: 'replace' } & AppMetadata &\n SendAppCreateTransactionResult & {\n deleteReturn?: ABIReturn\n deleteResult: ConfirmedTransactionResult\n }\n }\n\n // Lookup existing app metadata\n\n const apps = existingDeployments ?? (await this.getCreatorAppsByName(createParams.sender, ignoreCache))\n\n const existingApp = apps.apps[metadata.name]\n if (!existingApp || existingApp.deleted) {\n Config.getLogger(sendParams?.suppressLog).info(\n `App ${metadata.name} not found in apps created by ${createParams.sender}; deploying app with version ${metadata.version}.`,\n )\n\n return await createApp()\n }\n\n Config.getLogger(sendParams?.suppressLog).info(\n `Existing app ${metadata.name} found by creator ${createParams.sender}, with app id ${existingApp.appId} and version ${existingApp.version}.`,\n )\n\n const existingAppRecord = await this._appManager.getById(existingApp.appId)\n const existingApproval = Buffer.from(existingAppRecord.approvalProgram).toString('base64')\n const existingClear = Buffer.from(existingAppRecord.clearStateProgram).toString('base64')\n const existingExtraPages = calculateExtraProgramPages(existingAppRecord.approvalProgram, existingAppRecord.clearStateProgram)\n\n const newApprovalBytes = Buffer.from(approvalProgram)\n const newClearBytes = Buffer.from(clearStateProgram)\n const newApproval = newApprovalBytes.toString('base64')\n const newClear = newClearBytes.toString('base64')\n const newExtraPages = calculateExtraProgramPages(newApprovalBytes, newClearBytes)\n\n // Check for changes\n\n const isUpdate = newApproval !== existingApproval || newClear !== existingClear\n const isSchemaBreak =\n existingAppRecord.localInts < (createParams.schema?.localInts ?? 0) ||\n existingAppRecord.globalInts < (createParams.schema?.globalInts ?? 0) ||\n existingAppRecord.localByteSlices < (createParams.schema?.localByteSlices ?? 0) ||\n existingAppRecord.globalByteSlices < (createParams.schema?.globalByteSlices ?? 0) ||\n existingExtraPages < newExtraPages\n\n if (isSchemaBreak) {\n Config.getLogger(sendParams?.suppressLog).warn(`Detected a breaking app schema change in app ${existingApp.appId}:`, {\n from: {\n globalInts: existingAppRecord.globalInts,\n globalByteSlices: existingAppRecord.globalByteSlices,\n localInts: existingAppRecord.localInts,\n localByteSlices: existingAppRecord.localByteSlices,\n extraProgramPages: existingExtraPages,\n },\n to: { ...createParams.schema, extraProgramPages: newExtraPages },\n })\n\n if (onSchemaBreak === undefined || onSchemaBreak === 'fail' || onSchemaBreak === OnSchemaBreak.Fail) {\n throw new Error(\n 'Schema break detected and onSchemaBreak=OnSchemaBreak.Fail, stopping deployment. ' +\n 'If you want to try deleting and recreating the app then ' +\n 're-run with onSchemaBreak=OnSchemaBreak.ReplaceApp',\n )\n }\n\n if (onSchemaBreak === 'append' || onSchemaBreak === OnSchemaBreak.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onSchemaBreak=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is deletable and onSchemaBreak=ReplaceApp, will attempt to create new app and delete old app',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).info(\n 'App is not deletable but onSchemaBreak=ReplaceApp, will attempt to delete app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n\n if (isUpdate) {\n Config.getLogger(sendParams?.suppressLog).info(\n `Detected a TEAL update in app ${existingApp.appId} for creator ${createParams.sender}`,\n )\n\n if (onUpdate === undefined || onUpdate === 'fail' || onUpdate === OnUpdate.Fail) {\n throw new Error('Update detected and onUpdate=Fail, stopping deployment. Try a different onUpdate value to not fail.')\n }\n\n if (onUpdate === 'append' || onUpdate === OnUpdate.AppendApp) {\n Config.getLogger(sendParams?.suppressLog).info('onUpdate=AppendApp, will attempt to create a new app')\n return await createApp()\n }\n\n if (onUpdate === 'update' || onUpdate === OnUpdate.UpdateApp) {\n if (existingApp.updatable) {\n Config.getLogger(sendParams?.suppressLog).info(`App is updatable and onUpdate=UpdateApp, updating app...`)\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n `App is not updatable but onUpdate=UpdateApp, will attempt to update app, update will most likely fail`,\n )\n }\n\n return await updateApp(existingApp)\n }\n\n if (onUpdate === 'replace' || onUpdate === OnUpdate.ReplaceApp) {\n if (existingApp.deletable) {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is deletable and onUpdate=ReplaceApp, creating new app and deleting old app...',\n )\n } else {\n Config.getLogger(sendParams?.suppressLog).warn(\n 'App is not deletable and onUpdate=ReplaceApp, will attempt to create new app and delete old app, delete will most likely fail',\n )\n }\n\n return await replaceApp(existingApp)\n }\n }\n\n Config.getLogger(sendParams?.suppressLog).debug('No detected changes in app, nothing to do.')\n\n return { ...existingApp, operationPerformed: 'nothing' }\n }\n\n private updateAppLookup(sender: string | Address, appMetadata: AppMetadata) {\n const s = typeof sender === 'string' ? sender : sender.toString()\n const lookup = this._appLookups.get(s)\n if (!lookup) {\n this._appLookups.set(s, { creator: Address.fromString(s), apps: { [appMetadata.name]: appMetadata } })\n } else {\n lookup.apps[appMetadata.name] = appMetadata\n }\n }\n\n /**\n * Returns a lookup of name => app metadata (id, address, ...metadata) for all apps created by the given account that have\n * an [ARC-2](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0002.md) `AppDeployNote` as the transaction\n * note of the app creation transaction.\n *\n * This function caches the result for the given creator account so that subsequent calls will not require an indexer lookup.\n *\n * If the `AppManager` instance wasn't created with an indexer client, this function will throw an error.\n *\n * @param creatorAddress The address of the account that is the creator of the apps you want to search for\n * @param ignoreCache Whether or not to ignore the cache and force a lookup, default: use the cache\n * @returns A name-based lookup of the app metadata\n * @example\n * ```ts\n * const result = await deployer.getCreatorAppsByName(creator)\n */\n async getCreatorAppsByName(creatorAddress: string | Address, ignoreCache?: boolean): Promise<AppLookup> {\n const appLookup: Record<string, AppMetadata> = {}\n\n const address = typeof creatorAddress === 'string' ? creatorAddress : creatorAddress.toString()\n if (!ignoreCache && this._appLookups.has(address)) {\n return this._appLookups.get(address)!\n }\n\n if (!this._indexer) {\n throw new Error(`Didn't receive an indexer client when this AppManager was created, but received a call to getCreatorApps`)\n }\n\n // Extract all apps that account created\n const createdApps = (await indexer.lookupAccountCreatedApplicationByAddress(this._indexer, creatorAddress))\n .map((a) => {\n return { id: a.id, createdAtRound: a.createdAtRound!, deleted: a.deleted }\n })\n .sort((a, b) => Number(a.createdAtRound - b.createdAtRound))\n\n // For each app that account created (in parallel)...\n const apps = await Promise.all(\n createdApps.map(async (createdApp) => {\n // Find any app transactions for that app in the round it was created (should always just be a single creation transaction)\n const appTransactions = await indexer.searchTransactions(this._indexer!, (s) =>\n s\n .minRound(createdApp.createdAtRound)\n .txType(algosdk.TransactionType.appl)\n .applicationID(Number(createdApp.id))\n .address(creatorAddress)\n .addressRole('sender')\n .notePrefix(Buffer.from(APP_DEPLOY_NOTE_DAPP).toString('base64')),\n )\n\n // Triple check the transaction is intact by filtering for the one we want:\n // * application-id is 0 when the app is first created\n // * also verify the sender to prevent a potential security risk\n const appCreationTransaction = appTransactions.transactions.filter(\n (t) => t.applicationTransaction?.applicationId === 0n && t.sender.toString() === creatorAddress.toString(),\n )[0]\n\n const latestAppUpdateTransaction = appTransactions.transactions\n .filter((t) => t.sender.toString() === creatorAddress.toString())\n .sort((a, b) =>\n a.confirmedRound === b.confirmedRound\n ? (b.intraRoundOffset! - a.intraRoundOffset!) / 10\n : Number(b.confirmedRound! - a.confirmedRound!),\n )[0]\n\n if (!appCreationTransaction?.note)\n // No note; ignoring\n return null\n\n return { createdApp, appCreationTransaction, latestAppUpdateTransaction }\n }),\n )\n\n apps\n .filter((a) => a !== null)\n .forEach((a) => {\n const { createdApp, appCreationTransaction, latestAppUpdateTransaction } = a!\n\n const parseNote = (note?: string) => {\n if (!note) {\n // No note; ignoring...\n return\n }\n\n if (!note.startsWith(`${APP_DEPLOY_NOTE_DAPP}:j{`))\n // Clearly not APP_DEPLOY JSON; ignoring...\n return\n\n return JSON.parse(note.substring(APP_DEPLOY_NOTE_DAPP.length + 2)) as AppDeployMetadata\n }\n\n try {\n const creationNote = parseNote(\n appCreationTransaction.note ? Buffer.from(appCreationTransaction.note).toString('utf-8') : undefined,\n )\n const updateNote = parseNote(\n latestAppUpdateTransaction.note ? Buffer.from(latestAppUpdateTransaction.note).toString('utf-8') : undefined,\n )\n if (creationNote?.name) {\n appLookup[creationNote.name] = {\n appId: createdApp.id,\n appAddress: algosdk.getApplicationAddress(createdApp.id),\n createdMetadata: creationNote,\n createdRound: appCreationTransaction.confirmedRound ?? 0n,\n ...(updateNote ?? creationNote),\n updatedRound: latestAppUpdateTransaction?.confirmedRound ?? 0n,\n deleted: createdApp.deleted ?? false,\n }\n }\n } catch (e) {\n Config.logger.warn(\n `Received error trying to retrieve app with ${createdApp.id} for creator ${creatorAddress}; failing silently`,\n e,\n )\n return\n }\n })\n\n const lookup = {\n creator: typeof creatorAddress === 'string' ? Address.fromString(creatorAddress) : creatorAddress,\n apps: appLookup,\n }\n\n this._appLookups.set(creatorAddress.toString(), lookup)\n\n return lookup\n }\n}\n"],"names":["indexer.lookupAccountCreatedApplicationByAddress","indexer.searchTransactions"],"mappings":";;;;;;;AA8GA;MACa,WAAW,CAAA;AAMtB;;;;;;;;;AASG;AACH,IAAA,WAAA,CAAY,UAAsB,EAAE,iBAAkD,EAAE,OAAyB,EAAA;AAZzG,QAAA,IAAA,CAAA,WAAW,GAAG,IAAI,GAAG,EAAqB;AAahD,QAAA,IAAI,CAAC,WAAW,GAAG,UAAU;AAC7B,QAAA,IAAI,CAAC,kBAAkB,GAAG,iBAAiB;AAC3C,QAAA,IAAI,CAAC,QAAQ,GAAG,OAAO;;AAGzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCG;IACH,MAAM,MAAM,CAAC,UAA2B,EAAA;QACtC,MAAM,EACJ,QAAQ,EACR,gBAAgB,EAChB,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACX,GAAG,UAAU,EACd,GAAG,UAAU;;QAId,YAAY,CAAC,IAAI,GAAG,YAAY,CAAC,IAAI,GAAG,mBAAmB,CAAC,QAAQ,CAAC;AACnE,YAAA,QAAQ,EAAE,oB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,EAAE,UAAU,CAAC,OAAO,IAAI,KAAK;qBACrC;;;YAEH,OAAO,CAAC,EAAE;AACV,gBAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAChB,CAA8C,2CAAA,EAAA,UAAU,CAAC,EAAE,gBAAgB,cAAc,CAAA,kBAAA,CAAoB,EAC7G,CAAC,CACF;gBACD;;AAEJ,SAAC,CAAC;AAEJ,QAAA,MAAM,MAAM,GAAG;AACb,YAAA,OAAO,EAAE,OAAO,cAAc,KAAK,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,GAAG,cAAc;AACjG,YAAA,IAAI,EAAE,SAAS;SAChB;AAED,QAAA,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC;AAEvD,QAAA,OAAO,MAAM;;AAEhB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-event-emitter.js","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":";;MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc;;AA5CzB,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;AACxD,QAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;AACxD,YAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;;;IAMpC,EAAE,CAAC,SAA0B,EAAE,QAA4B,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE;QAClE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAA8B,CAAC;AAChE,QAAA,OAAO,IAAI;;IAKb,IAAI,CAAC,SAA0B,EAAE,QAA4B,EAAA;QAC3D,MAAM,eAAe,GAAuB,OAAO,KAAK,EAAE,SAAS,KAAI;AACrE,YAAA,IAAI;AACF,gBAAA,OAAO,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;;oBAC/B;AACR,gBAAA,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,eAAe,CAAC;;AAEnD,SAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC;QACtD,OAAO,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;;IAG5C,cAAc,CAAC,SAA0B,EAAE,QAA4B,EAAA;QACrE,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC7D,IAAI,eAAe,EAAE;AACnB,YAAA,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;AACxC,YAAA,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"async-event-emitter.js","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":";;MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc;;AA5CzB,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;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AAC,eAAe,CAAC,EAAE,CAAC,CAAC;;;aAExF;AACL,YAAA,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE;gBACzD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;;;AAIxF,QAAA,OAAO,IAAI;;AAId;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-event-emitter.mjs","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":"MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc;;AA5CzB,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;AACxD,QAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;AACxD,YAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;;;IAMpC,EAAE,CAAC,SAA0B,EAAE,QAA4B,EAAA;AACzD,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,EAAE;QAClE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAA8B,CAAC;AAChE,QAAA,OAAO,IAAI;;IAKb,IAAI,CAAC,SAA0B,EAAE,QAA4B,EAAA;QAC3D,MAAM,eAAe,GAAuB,OAAO,KAAK,EAAE,SAAS,KAAI;AACrE,YAAA,IAAI;AACF,gBAAA,OAAO,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;;oBAC/B;AACR,gBAAA,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,eAAe,CAAC;;AAEnD,SAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC;QACtD,OAAO,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC;;IAG5C,cAAc,CAAC,SAA0B,EAAE,QAA4B,EAAA;QACrE,MAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC7D,IAAI,eAAe,EAAE;AACnB,YAAA,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC;AACxC,YAAA,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"async-event-emitter.mjs","sources":["../../src/types/async-event-emitter.ts"],"sourcesContent":["import { EventDataMap, EventType } from './lifecycle-events'\n\nexport type AsyncEventListener<T = unknown> = (event: T, eventName: string | symbol) => Promise<void> | void\n\nexport class AsyncEventEmitter {\n private listenerWrapperMap = new WeakMap<AsyncEventListener, AsyncEventListener>()\n private listenerMap: Record<string | symbol, AsyncEventListener[]> = {}\n\n async emitAsync<K extends EventType>(eventName: K, event: EventDataMap[K]): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void>\n async emitAsync(eventName: string | symbol, event: unknown): Promise<void> {\n for (const listener of this.listenerMap[eventName] ?? []) {\n await listener(event, eventName)\n }\n }\n\n on<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n on<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n on(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n if (!this.listenerMap[eventName]) this.listenerMap[eventName] = []\n this.listenerMap[eventName].push(listener as AsyncEventListener)\n return this\n }\n\n once<K extends EventType>(eventName: K, listener: AsyncEventListener<EventDataMap[K]>): AsyncEventEmitter\n once<T = unknown>(eventName: string | symbol, listener: AsyncEventListener<T>): AsyncEventEmitter\n once(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener: AsyncEventListener = async (event, eventName) => {\n try {\n return await listener(event, eventName)\n } finally {\n this.removeListener(eventName, wrappedListener)\n }\n }\n this.listenerWrapperMap.set(listener, wrappedListener)\n return this.on(eventName, wrappedListener)\n }\n\n removeListener(eventName: string | symbol, listener: AsyncEventListener): AsyncEventEmitter {\n const wrappedListener = this.listenerWrapperMap.get(listener)\n if (wrappedListener) {\n this.listenerWrapperMap.delete(listener)\n if (this.listenerMap[eventName]?.indexOf(wrappedListener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(wrappedListener), 1)\n }\n } else {\n if (this.listenerMap[eventName]?.indexOf(listener) !== -1) {\n this.listenerMap[eventName].splice(this.listenerMap[eventName].indexOf(listener), 1)\n }\n }\n\n return this\n }\n\n off = this.removeListener\n}\n"],"names":[],"mappings":"MAIa,iBAAiB,CAAA;AAA9B,IAAA,WAAA,GAAA;AACU,QAAA,IAAA,CAAA,kBAAkB,GAAG,IAAI,OAAO,EAA0C;QAC1E,IAAW,CAAA,WAAA,GAAkD,EAAE;AAgDvE,QAAA,IAAA,CAAA,GAAG,GAAG,IAAI,CAAC,cAAc;;AA5CzB,IAAA,MAAM,SAAS,CAAC,SAA0B,EAAE,KAAc,EAAA;AACxD,QAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE;AACxD,YAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;;;IAMpC,EAAE,CAAC,SAA0B,EAAE,QAA4B,EAAA;AACzD,Q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AAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;;;AAIxF,QAAA,OAAO,IAAI;;AAId;;;;"}
|
package/types/composer.d.ts
CHANGED
|
@@ -416,6 +416,13 @@ export type Txn = (PaymentParams & {
|
|
|
416
416
|
} | ((AppCallMethodCall | AppCreateMethodCall | AppUpdateMethodCall) & {
|
|
417
417
|
type: 'methodCall';
|
|
418
418
|
});
|
|
419
|
+
/**
|
|
420
|
+
* A function that transforms an error into a new error.
|
|
421
|
+
*
|
|
422
|
+
* In most cases, an ErrorTransformer should first check if it can or should transform the error
|
|
423
|
+
* and return the input error if it cannot or should not transform it.
|
|
424
|
+
*/
|
|
425
|
+
export type ErrorTransformer = (error: Error) => Promise<Error>;
|
|
419
426
|
/** Parameters to create an `TransactionComposer`. */
|
|
420
427
|
export type TransactionComposerParams = {
|
|
421
428
|
/** The algod client to use to get suggestedParams and send the transaction group */
|
|
@@ -430,9 +437,14 @@ export type TransactionComposerParams = {
|
|
|
430
437
|
defaultValidityWindow?: bigint;
|
|
431
438
|
/** An existing `AppManager` to use to manage app compilation and cache compilation results.
|
|
432
439
|
*
|
|
433
|
-
* If not specified
|
|
440
|
+
* If not specified then an ephemeral one will be created.
|
|
434
441
|
*/
|
|
435
442
|
appManager?: AppManager;
|
|
443
|
+
/**
|
|
444
|
+
* An array of error transformers to use when an error is caught in simulate or execute
|
|
445
|
+
* callbacks can later be registered with `registerErrorTransformer`
|
|
446
|
+
*/
|
|
447
|
+
errorTransformers?: ErrorTransformer[];
|
|
436
448
|
};
|
|
437
449
|
/** Set of transactions built by `TransactionComposer`. */
|
|
438
450
|
export interface BuiltTransactions {
|
|
@@ -466,12 +478,20 @@ export declare class TransactionComposer {
|
|
|
466
478
|
/** Whether the validity window was explicitly set on construction */
|
|
467
479
|
private defaultValidityWindowIsExplicit;
|
|
468
480
|
private appManager;
|
|
481
|
+
private errorTransformers;
|
|
482
|
+
private transformError;
|
|
469
483
|
/**
|
|
470
484
|
* Create a `TransactionComposer`.
|
|
471
485
|
* @param params The configuration for this composer
|
|
472
486
|
* @returns The `TransactionComposer` instance
|
|
473
487
|
*/
|
|
474
488
|
constructor(params: TransactionComposerParams);
|
|
489
|
+
/**
|
|
490
|
+
* Register a function that will be used to transform an error caught when simulating or executing
|
|
491
|
+
*
|
|
492
|
+
* @returns The composer so you can chain method calls
|
|
493
|
+
*/
|
|
494
|
+
registerErrorTransformer(transformer: ErrorTransformer): this;
|
|
475
495
|
/**
|
|
476
496
|
* Add a pre-built transaction to the transaction group.
|
|
477
497
|
* @param transaction The pre-built transaction
|
package/types/composer.js
CHANGED
|
@@ -15,8 +15,37 @@ const address = (address) => {
|
|
|
15
15
|
return typeof address === 'string' ? algosdk.Address.fromString(address) : address;
|
|
16
16
|
};
|
|
17
17
|
const MAX_TRANSACTION_GROUP_SIZE = 16;
|
|
18
|
+
class InvalidErrorTransformerValue extends Error {
|
|
19
|
+
constructor(originalError, value) {
|
|
20
|
+
super(`An error transformer returned a non-error value: ${value}. The original error before any transformation: ${originalError}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class ErrorTransformerError extends Error {
|
|
24
|
+
constructor(originalError, cause) {
|
|
25
|
+
super(`An error transformer threw an error: ${cause}. The original error before any transformation: ${originalError} `, { cause });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
18
28
|
/** TransactionComposer helps you compose and execute transactions as a transaction group. */
|
|
19
29
|
class TransactionComposer {
|
|
30
|
+
async transformError(originalError) {
|
|
31
|
+
// Transformers only work with Error instances, so immediately return anything else
|
|
32
|
+
if (!(originalError instanceof Error)) {
|
|
33
|
+
return originalError;
|
|
34
|
+
}
|
|
35
|
+
let transformedError = originalError;
|
|
36
|
+
for (const transformer of this.errorTransformers) {
|
|
37
|
+
try {
|
|
38
|
+
transformedError = await transformer(transformedError);
|
|
39
|
+
if (!(transformedError instanceof Error)) {
|
|
40
|
+
return new InvalidErrorTransformerValue(originalError, transformedError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (errorFromTransformer) {
|
|
44
|
+
return new ErrorTransformerError(originalError, errorFromTransformer);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return transformedError;
|
|
48
|
+
}
|
|
20
49
|
/**
|
|
21
50
|
* Create a `TransactionComposer`.
|
|
22
51
|
* @param params The configuration for this composer
|
|
@@ -42,6 +71,16 @@ class TransactionComposer {
|
|
|
42
71
|
this.defaultValidityWindow = params.defaultValidityWindow ?? this.defaultValidityWindow;
|
|
43
72
|
this.defaultValidityWindowIsExplicit = params.defaultValidityWindow !== undefined;
|
|
44
73
|
this.appManager = params.appManager ?? new types_appManager.AppManager(params.algod);
|
|
74
|
+
this.errorTransformers = params.errorTransformers ?? [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Register a function that will be used to transform an error caught when simulating or executing
|
|
78
|
+
*
|
|
79
|
+
* @returns The composer so you can chain method calls
|
|
80
|
+
*/
|
|
81
|
+
registerErrorTransformer(transformer) {
|
|
82
|
+
this.errorTransformers.push(transformer);
|
|
83
|
+
return this;
|
|
45
84
|
}
|
|
46
85
|
/**
|
|
47
86
|
* Add a pre-built transaction to the transaction group.
|
|
@@ -1311,19 +1350,24 @@ class TransactionComposer {
|
|
|
1311
1350
|
const { firstValid: firstRound } = suggestedParams;
|
|
1312
1351
|
waitRounds = Number(BigInt(lastRound) - BigInt(firstRound)) + 1;
|
|
1313
1352
|
}
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1353
|
+
try {
|
|
1354
|
+
return await transaction.sendAtomicTransactionComposer({
|
|
1355
|
+
atc: this.atc,
|
|
1356
|
+
suppressLog: params?.suppressLog,
|
|
1357
|
+
maxRoundsToWaitForConfirmation: waitRounds,
|
|
1358
|
+
populateAppCallResources: params?.populateAppCallResources,
|
|
1359
|
+
coverAppCallInnerTransactionFees: params?.coverAppCallInnerTransactionFees,
|
|
1360
|
+
additionalAtcContext: params?.coverAppCallInnerTransactionFees
|
|
1361
|
+
? {
|
|
1362
|
+
maxFees: this.txnMaxFees,
|
|
1363
|
+
suggestedParams: suggestedParams,
|
|
1364
|
+
}
|
|
1365
|
+
: undefined,
|
|
1366
|
+
}, this.algod);
|
|
1367
|
+
}
|
|
1368
|
+
catch (originalError) {
|
|
1369
|
+
throw await this.transformError(originalError);
|
|
1370
|
+
}
|
|
1327
1371
|
}
|
|
1328
1372
|
/**
|
|
1329
1373
|
* @deprecated Use `send` instead.
|
|
@@ -1379,8 +1423,7 @@ class TransactionComposer {
|
|
|
1379
1423
|
if (config.Config.debug) {
|
|
1380
1424
|
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, { simulateResponse });
|
|
1381
1425
|
}
|
|
1382
|
-
|
|
1383
|
-
throw error;
|
|
1426
|
+
throw await this.transformError(error);
|
|
1384
1427
|
}
|
|
1385
1428
|
if (config.Config.debug && config.Config.traceAll) {
|
|
1386
1429
|
await config.Config.events.emitAsync(types_lifecycleEvents.EventType.TxnGroupSimulated, { simulateResponse });
|