|
1 | | -import { Contract, TypedApplicationCallFields } from './arc4' |
| 1 | +import { AbiCallOptions, Contract, TypedApplicationCallFields } from './arc4' |
2 | 2 | import { NoImplementation } from './internal/errors' |
3 | 3 | import { DeliberateAny, InstanceMethod } from './internal/typescript-helpers' |
4 | 4 | import { itxn } from './itxn' |
@@ -42,27 +42,138 @@ export type ComposeItxnParams = |
42 | 42 | | itxn.ApplicationCallItxnParams |
43 | 43 |
|
44 | 44 | export type ItxnCompose = { |
| 45 | + /** |
| 46 | + * Begin a transaction group with a payment transaction |
| 47 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 48 | + */ |
45 | 49 | begin(fields: PaymentComposeFields): void |
| 50 | + /** |
| 51 | + * Begin a transaction group with a key registration transaction |
| 52 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 53 | + */ |
46 | 54 | begin(fields: KeyRegistrationComposeFields): void |
| 55 | + /** |
| 56 | + * Begin a transaction group with an asset config transaction |
| 57 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 58 | + */ |
47 | 59 | begin(fields: AssetConfigComposeFields): void |
| 60 | + /** |
| 61 | + * Begin a transaction group with an asset transfer transaction |
| 62 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 63 | + */ |
48 | 64 | begin(fields: AssetTransferComposeFields): void |
| 65 | + /** |
| 66 | + * Begin a transaction group with an asset freeze transaction |
| 67 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 68 | + */ |
49 | 69 | begin(fields: AssetFreezeComposeFields): void |
| 70 | + /** |
| 71 | + * Begin a transaction group with an application call transaction |
| 72 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 73 | + */ |
50 | 74 | begin(fields: ApplicationCallComposeFields): void |
| 75 | + /** |
| 76 | + * Begin a transaction group with a new transaction with the specified fields |
| 77 | + * @param fields Specifies the type, and any transaction fields which should differ from their defaults |
| 78 | + */ |
51 | 79 | begin(fields: AnyTransactionComposeFields): void |
| 80 | + /** |
| 81 | + * Begin a transaction group with a new transaction from the specified itxn params object |
| 82 | + * @param fields |
| 83 | + */ |
52 | 84 | begin(fields: ComposeItxnParams): void |
| 85 | + /** |
| 86 | + * Begin a transaction group with a typed application call transaction. |
| 87 | + * @param method The ABI method to call |
| 88 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 89 | + * |
| 90 | + * @deprecated This overload has been deprecated in favour of the single arg overload where method is specified as a property of the fields |
| 91 | + * object, or via an explicit generic param. (`itxnCompose.begin({ method: MyContract.prototype.myMethod, ... })` or |
| 92 | + * `itxnCompose.begin<typeof MyContract.prototype.myMethod>({ ... })`) |
| 93 | + */ |
53 | 94 | begin<TArgs extends DeliberateAny[]>(method: InstanceMethod<Contract, TArgs>, fields: TypedApplicationCallFields<TArgs>): void |
| 95 | + /** |
| 96 | + * Begin a transaction group with a typed application call transaction. The method can be specified by options.method, or |
| 97 | + * by explicitly defining the type of the generic parameter TMethod. |
| 98 | + * @param options Specifies any transaction fields which should differ from their defaults |
| 99 | + * @typeParam TMethod The type of an ARC4 method signature (eg. `typeof MyContract.prototype.myMethod`) |
| 100 | + */ |
| 101 | + begin<TMethod>(options: AbiCallOptions<TMethod>): void |
54 | 102 |
|
| 103 | + /** |
| 104 | + * Continue a transaction group with a payment transaction |
| 105 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 106 | + */ |
55 | 107 | next(fields: PaymentComposeFields): void |
| 108 | + /** |
| 109 | + * Continue a transaction group with a key registration transaction |
| 110 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 111 | + */ |
56 | 112 | next(fields: KeyRegistrationComposeFields): void |
| 113 | + /** |
| 114 | + * Continue a transaction group with an asset config transaction |
| 115 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 116 | + */ |
57 | 117 | next(fields: AssetConfigComposeFields): void |
| 118 | + /** |
| 119 | + * Continue a transaction group with an asset transfer transaction |
| 120 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 121 | + */ |
58 | 122 | next(fields: AssetTransferComposeFields): void |
| 123 | + /** |
| 124 | + * Continue a transaction group with an asset freeze transaction |
| 125 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 126 | + */ |
59 | 127 | next(fields: AssetFreezeComposeFields): void |
| 128 | + /** |
| 129 | + * Continue a transaction group with an application call transaction |
| 130 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 131 | + */ |
60 | 132 | next(fields: ApplicationCallComposeFields): void |
| 133 | + /** |
| 134 | + * Continue a transaction group with a new transaction with the specified fields |
| 135 | + * @param fields Specifies the type, and any transaction fields which should differ from their defaults |
| 136 | + */ |
61 | 137 | next(fields: AnyTransactionComposeFields): void |
| 138 | + /** |
| 139 | + * Continue a transaction group with a new transaction from the specified itxn params object |
| 140 | + * @param fields |
| 141 | + */ |
62 | 142 | next(fields: ComposeItxnParams): void |
| 143 | + /** |
| 144 | + * Continue a transaction group with a typed application call transaction. |
| 145 | + * @param method The ABI method to call |
| 146 | + * @param fields Specifies any transaction fields which should differ from their defaults |
| 147 | + * |
| 148 | + * @deprecated This overload has been deprecated in favour of the single arg overload where method is specified as a property of the fields |
| 149 | + * object, or via an explicit generic param. (`itxnCompose.next({ method: MyContract.prototype.myMethod, ... })` or |
| 150 | + * `itxnCompose.next<typeof MyContract.prototype.myMethod>({ ... })`) |
| 151 | + */ |
63 | 152 | next<TArgs extends DeliberateAny[]>(method: InstanceMethod<Contract, TArgs>, fields: TypedApplicationCallFields<TArgs>): void |
| 153 | + /** |
| 154 | + * Continue a transaction group with a typed application call transaction. The method can be specified by options.method, or |
| 155 | + * by explicitly defining the type of the generic parameter TMethod. |
| 156 | + * @param options Specifies any transaction fields which should differ from their defaults |
| 157 | + * @typeParam TMethod The type of an ARC4 method signature (eg. `typeof MyContract.prototype.myMethod`) |
| 158 | + */ |
| 159 | + next<TMethod>(options: AbiCallOptions<TMethod>): void |
64 | 160 |
|
| 161 | + /** |
| 162 | + * Submit all transactions in the group |
| 163 | + * |
| 164 | + * @remarks `op.GITxn.lastLog(n)` (and other methods on the GITxn object) can be used to read fields from the most recently submitted |
| 165 | + * transaction group where `n` is a compile time constant representing the index of the transaction in the group. |
| 166 | + */ |
65 | 167 | submit(): void |
66 | 168 | } |
67 | 169 |
|
| 170 | +/** |
| 171 | + * The itxnCompose helper can be used to build dynamically sized itxn groups which aren't supported by the stronger typed itxn paradigm. The |
| 172 | + * first transaction in a group must be 'staged' with `itxnCompose.begin` whilst all other transactions in the group should use `itxnCompose.next`. |
| 173 | + * When the group is complete it can be submitted using `itxnCompose.submit`. |
| 174 | + * |
| 175 | + * @remarks The itxn API offered by teal opcodes has some rough edges which are not fully abstracted over by this compose API, but it hoped that use |
| 176 | + * cases for it are limited and that most transaction groups can be composed with a static size relying on the atomic nature of the outer transaction |
| 177 | + * to ensure multiple smaller itxn groups are committed atomically. |
| 178 | + */ |
68 | 179 | export const itxnCompose: ItxnCompose = NoImplementation.value() |
0 commit comments