-
Notifications
You must be signed in to change notification settings - Fork 5
feat: application transaction #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,330 @@ | ||||||||||||||||||||||||||||||
| import {AlgorandEncoder} from "./algorand.encoder.js" | ||||||||||||||||||||||||||||||
| import {ITransactionHeaderBuilder, TransactionHeader} from "./algorand.transaction.header"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Represents the schema of the state used within an application. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @category Common | ||||||||||||||||||||||||||||||
| * @since v1.0.0 | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| export type StateSchema = { | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Maximum number of integer values that may be stored in | ||||||||||||||||||||||||||||||
| * the [global || local] application key/value store. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Immutable. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| nui: number | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Maximum number of byte slices values that may be stored in | ||||||||||||||||||||||||||||||
| * the [global || local] application key/value store. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Immutable. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| nbs: number | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Includes all fields in {@link TransactionHeader} and "type" is "appl". | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @category Transactions | ||||||||||||||||||||||||||||||
| * @see {@link AlgorandTransactionCrafter} | ||||||||||||||||||||||||||||||
| * @see {@link ApplicationCallTxBuilder} | ||||||||||||||||||||||||||||||
| * @since v1.0.0 | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| export class ApplicationCallTransaction extends TransactionHeader { | ||||||||||||||||||||||||||||||
| declare type: "appl" | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Application ID | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * ID of the application being configured or empty if creating. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apid: bigint // Application id (required) | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * OnComplete | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Defines what additional actions occur with the transaction. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * An application transaction must indicate the action to be taken following the execution of its approvalProgram or clearStateProgram. | ||||||||||||||||||||||||||||||
| * The constants below describe the available actions. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * | Value | Name | Description | | ||||||||||||||||||||||||||||||
| * |-------|------|-------------| | ||||||||||||||||||||||||||||||
| * | 0 | NoOp | Only execute the ApprovalProgram associated with this application ID, with no additional effects. | | ||||||||||||||||||||||||||||||
| * | 1 | OptIn | Before executing the ApprovalProgram, allocate the local state for this application into the sender's account data. | | ||||||||||||||||||||||||||||||
| * | 2 | CloseOut | After executing the ApprovalProgram, clear any local state for this application out of the sender's account data. | | ||||||||||||||||||||||||||||||
| * | 3 | ClearState | Don't execute the ApprovalProgram, and instead execute the ClearStateProgram (which may not reject this transaction). Additionally, clear any local state for this application out of the sender's account data as in CloseOutOC. | | ||||||||||||||||||||||||||||||
| * | 4 | UpdateApplication | After executing the ApprovalProgram, replace the ApprovalProgram and ClearStateProgram associated with this application ID with the programs specified in this transaction. | | ||||||||||||||||||||||||||||||
| * | 5 | DeleteApplication | After executing the ApprovalProgram, delete the application parameters from the account data of the application's creator. | | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apan: number // #onComplete (required) | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Accounts | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * List of accounts in addition to the sender that may be accessed from the | ||||||||||||||||||||||||||||||
| * application's approval-program and clear-state-program. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apat?: Uint8Array[] // Accounts | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Approval Program | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Logic executed for every application transaction, except when on-completion is set to "clear". | ||||||||||||||||||||||||||||||
| * It can read and write global state for the application, as well as account-specific local state. | ||||||||||||||||||||||||||||||
| * Approval programs may reject the transaction. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apap?: Uint8Array // Approval program | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * App Arguments | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Transaction-specific arguments accessed from the application's approval-program and clear-state-program. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apaa?: Uint8Array[] // Application arguments | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Clear State Program | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Logic executed for application transactions with on-completion set to "clear". | ||||||||||||||||||||||||||||||
| * It can read and write global state for the application, as well as account-specific local state. | ||||||||||||||||||||||||||||||
| * Clear state programs cannot reject the transaction. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apsu?: Uint8Array // Clear state program | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Foreign Apps | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Lists the applications in addition to the application-id whose global states may | ||||||||||||||||||||||||||||||
| * be accessed by this application's approval-program and clear-state-program. | ||||||||||||||||||||||||||||||
| * The access is read-only. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apfa?: bigint[] // Foreign apps (check) | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Foreign Assets | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Lists the assets whose AssetParams may be accessed by this application's approval-program and clear-state-program. The access is read-only. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apas?: bigint[] // Foreign assets (check) | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Global {@link StateSchema} | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Holds the maximum number of global state values defined within a {@link StateSchema} object. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apgs?: StateSchema; // Global schema | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Local {@link StateSchema} | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Holds the maximum number of local state values defined within a {@link StateSchema} object. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apls?: StateSchema; // Local schema | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Extra Program Pages | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Number of additional pages allocated to the application's approval and clear state programs. | ||||||||||||||||||||||||||||||
| * Each ExtraProgramPages is 2048 bytes. | ||||||||||||||||||||||||||||||
| * The sum of ApprovalProgram and ClearStateProgram may not exceed 2048*(1+ExtraProgramPages) bytes. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apep?: number // Extra program | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Boxes | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * The boxes that should be made available for the runtime of the program. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| apbx?: { | ||||||||||||||||||||||||||||||
| i: number | ||||||||||||||||||||||||||||||
| n: string | ||||||||||||||||||||||||||||||
| }[] // Boxes | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Encodes the current transaction object into a Uint8Array using the Algorand transaction encoding format. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @return {Uint8Array} The encoded transaction as a Uint8Array. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| encode(): Uint8Array { | ||||||||||||||||||||||||||||||
| return new AlgorandEncoder().encodeTransaction(this) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Interface representing a builder for creating Application Call transactions. | ||||||||||||||||||||||||||||||
| * This builder provides methods to configure various attributes of an Application Call transaction. | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * @category Builders | ||||||||||||||||||||||||||||||
| * @protected | ||||||||||||||||||||||||||||||
| * @since v1.0.0 | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| export interface IApplicationCallTxBuilder extends ITransactionHeaderBuilder<IApplicationCallTxBuilder> { | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apid} | ||||||||||||||||||||||||||||||
| * @param {bigint} apid - The unique identifier of the application to be called. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addApplicationId(apid: bigint): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apan} | ||||||||||||||||||||||||||||||
| * @param {number} apan - which action to take | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addOnComplete(apan: number): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apat} | ||||||||||||||||||||||||||||||
| * @param {string[]} apat - An array of account addresses to be added. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addAccounts(apat: string[]): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apap} | ||||||||||||||||||||||||||||||
| * @param {Uint8Array} apap - The approval program bytes to be added to the transaction. | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addApprovalProgram(apap: Uint8Array): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apaa} | ||||||||||||||||||||||||||||||
| * @param {Uint8Array[]} apaa - Application arguments in bytes | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addApplicationArgs(apaa: Uint8Array[]): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apsu} | ||||||||||||||||||||||||||||||
| * @param {Uint8Array} apsu - The clear state program bytes to be added | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addClearStateProgram(apsu: Uint8Array): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apfa} | ||||||||||||||||||||||||||||||
| * @param {bigint[]} apfa - List of foreign application ids | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addForeignApps(apfa: bigint[]): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apas} | ||||||||||||||||||||||||||||||
| * @param {bigint[]} apas - List of foreign assets ids | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addForeignAssets(apas: bigint[]): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apgs} | ||||||||||||||||||||||||||||||
| * @param {StateSchema} apgs - Global state schema | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addGlobalSchema(apgs: StateSchema): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apls} | ||||||||||||||||||||||||||||||
| * @param {StateSchema} apls - Global state schema | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| addLocalSchema(apls: StateSchema): IApplicationCallTxBuilder; | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * {@inheritDoc ApplicationCallTransaction#apep} | ||||||||||||||||||||||||||||||
| * @param {StateSchema} apep - Number of pages to add | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| * @param {StateSchema} apep - Number of pages to add | |
| * @param {number} apep - Number of pages to add |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method 'addForeignApps' incorrectly assigns to 'this.tx.apas' (Foreign Assets) instead of 'this.tx.apfa' (Foreign Apps). This causes foreign apps to be set as foreign assets.
| this.tx.apas = apps; | |
| return this; | |
| } | |
| addForeignAssets(apfa: bigint[]): IApplicationCallTxBuilder { | |
| this.tx.apfa = apfa; | |
| this.tx.apfa = apps; | |
| return this; | |
| } | |
| addForeignAssets(apfa: bigint[]): IApplicationCallTxBuilder { | |
| this.tx.apas = apfa; |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method 'addForeignAssets' incorrectly assigns to 'this.tx.apfa' (Foreign Apps) instead of 'this.tx.apas' (Foreign Assets). This causes foreign assets to be set as foreign apps. The parameter name should also be changed from 'apfa' to 'apas' for consistency.
| addForeignAssets(apfa: bigint[]): IApplicationCallTxBuilder { | |
| this.tx.apfa = apfa; | |
| addForeignAssets(apas: bigint[]): IApplicationCallTxBuilder { | |
| this.tx.apas = apas; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter description incorrectly states 'Global state schema' when it should be 'Local state schema' to match the method name 'addLocalSchema'.