Skip to content

Commit 482e0eb

Browse files
committed
implement gitxn op code and add tests for it and itxn
1 parent 5438a1b commit 482e0eb

File tree

11 files changed

+710
-324
lines changed

11 files changed

+710
-324
lines changed

src/impl/gtxn.ts

Lines changed: 70 additions & 130 deletions
Large diffs are not rendered by default.

src/impl/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ export { Global } from './global'
77
export { GTxn } from './gtxn'
88
export * from './pure'
99
export { Txn, gaid } from './txn'
10-
export { ITxn, ITxnCreate } from './itxn'
10+
export { GITxn, ITxn, ITxnCreate } from './itxn'

src/impl/inner-transactions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ const mapCommonFields = <T extends InnerTxnFields>(
1818
fields: T,
1919
): Omit<T, 'sender' | 'note' | 'rekeyTo'> & { sender?: Account; note?: bytes; rekeyTo?: Account } => {
2020
const { sender, note, rekeyTo, ...rest } = fields
21+
2122
return {
22-
sender: sender instanceof Account ? sender : typeof sender === 'string' ? Account(asBytes(sender)) : undefined,
23+
sender:
24+
sender instanceof Account ? sender : typeof sender === 'string' ? Account(asBytes(sender)) : lazyContext.activeApplication.address,
2325
note: note !== undefined ? asBytes(note) : undefined,
2426
rekeyTo: rekeyTo instanceof Account ? rekeyTo : typeof rekeyTo === 'string' ? Account(asBytes(rekeyTo)) : undefined,
2527
...rest,

src/impl/itxn.ts

Lines changed: 275 additions & 83 deletions
Large diffs are not rendered by default.

src/impl/transactions.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { MAX_ITEMS_IN_LOG } from '../constants'
1515
import { lazyContext } from '../context-helpers/internal-context'
1616
import { Mutable, ObjectKeys } from '../typescript-helpers'
17-
import { asBytes, asNumber, getRandomBytes } from '../util'
17+
import { asBytes, asNumber, asUint64Cls, combineIntoMaxBytePages, getRandomBytes } from '../util'
1818

1919
const baseDefaultFields = () => ({
2020
sender: lazyContext.defaultSender,
@@ -24,7 +24,6 @@ const baseDefaultFields = () => ({
2424
lastValid: Uint64(0),
2525
note: Bytes(),
2626
lease: Bytes(),
27-
typeBytes: Bytes(),
2827
groupIndex: Uint64(0),
2928
txnId: getRandomBytes(32).asAlgoTs(),
3029
rekeyTo: Account(),
@@ -42,7 +41,6 @@ abstract class TransactionBase {
4241
this.lastValid = fields.lastValid ?? baseDefaults.lastValid
4342
this.note = fields.note ?? baseDefaults.note
4443
this.lease = fields.lease ?? baseDefaults.lease
45-
this.typeBytes = fields.typeBytes ?? baseDefaults.typeBytes
4644
this.groupIndex = fields.groupIndex ?? baseDefaults.groupIndex
4745
this.txnId = fields.txnId ?? baseDefaults.txnId
4846
this.rekeyTo = fields.rekeyTo ?? baseDefaults.rekeyTo
@@ -55,7 +53,6 @@ abstract class TransactionBase {
5553
readonly lastValid: uint64
5654
readonly note: bytes
5755
readonly lease: bytes
58-
readonly typeBytes: bytes
5956
readonly groupIndex: uint64
6057
readonly txnId: bytes
6158
readonly rekeyTo: Account
@@ -78,6 +75,7 @@ export class PaymentTransaction extends TransactionBase implements gtxn.PaymentT
7875
readonly amount: uint64
7976
readonly closeRemainderTo: Account
8077
readonly type: TransactionType.Payment = TransactionType.Payment
78+
readonly typeBytes: bytes = asUint64Cls(TransactionType.Payment).toBytes().asAlgoTs()
8179
}
8280

8381
export class KeyRegistrationTransaction extends TransactionBase implements gtxn.KeyRegistrationTxn {
@@ -105,6 +103,7 @@ export class KeyRegistrationTransaction extends TransactionBase implements gtxn.
105103
readonly nonparticipation: boolean
106104
readonly stateProofKey: bytes
107105
readonly type: TransactionType.KeyRegistration = TransactionType.KeyRegistration
106+
readonly typeBytes: bytes = asUint64Cls(TransactionType.KeyRegistration).toBytes().asAlgoTs()
108107
}
109108

110109
export class AssetConfigTransaction extends TransactionBase implements gtxn.AssetConfigTxn {
@@ -144,6 +143,7 @@ export class AssetConfigTransaction extends TransactionBase implements gtxn.Asse
144143
readonly clawback: Account
145144
readonly createdAsset: Asset
146145
readonly type: TransactionType.AssetConfig = TransactionType.AssetConfig
146+
readonly typeBytes: bytes = asUint64Cls(TransactionType.AssetConfig).toBytes().asAlgoTs()
147147
}
148148

149149
export class AssetTransferTransaction extends TransactionBase implements gtxn.AssetTransferTxn {
@@ -168,6 +168,7 @@ export class AssetTransferTransaction extends TransactionBase implements gtxn.As
168168
readonly assetCloseTo: Account
169169

170170
readonly type: TransactionType.AssetTransfer = TransactionType.AssetTransfer
171+
readonly typeBytes: bytes = asUint64Cls(TransactionType.AssetTransfer).toBytes().asAlgoTs()
171172
}
172173

173174
export class AssetFreezeTransaction extends TransactionBase implements gtxn.AssetFreezeTxn {
@@ -188,6 +189,7 @@ export class AssetFreezeTransaction extends TransactionBase implements gtxn.Asse
188189
readonly frozen: boolean
189190

190191
readonly type: TransactionType.AssetFreeze = TransactionType.AssetFreeze
192+
readonly typeBytes: bytes = asUint64Cls(TransactionType.AssetFreeze).toBytes().asAlgoTs()
191193
}
192194

193195
export type ApplicationTransactionFields = TxnFields<gtxn.ApplicationTxn> &
@@ -260,10 +262,10 @@ export class ApplicationTransaction extends TransactionBase implements gtxn.Appl
260262
return Uint64(this.#apps.length)
261263
}
262264
get numApprovalProgramPages() {
263-
return Uint64(this.#approvalProgramPages.length)
265+
return Uint64(this.approvalProgramPages.length)
264266
}
265267
get numClearStateProgramPages() {
266-
return Uint64(this.#clearStateProgramPages.length)
268+
return Uint64(this.clearStateProgramPages.length)
267269
}
268270
get numLogs() {
269271
return Uint64(this.#appLogs.length || lazyContext.getApplicationData(this.appId.id).appLogs.length)
@@ -284,16 +286,17 @@ export class ApplicationTransaction extends TransactionBase implements gtxn.Appl
284286
return this.#apps[asNumber(index)]
285287
}
286288
approvalProgramPages(index: internal.primitives.StubUint64Compat): bytes {
287-
return this.#approvalProgramPages[asNumber(index)]
289+
return combineIntoMaxBytePages(this.#approvalProgramPages)[asNumber(index)]
288290
}
289291
clearStateProgramPages(index: internal.primitives.StubUint64Compat): bytes {
290-
return this.#clearStateProgramPages[asNumber(index)]
292+
return combineIntoMaxBytePages(this.#clearStateProgramPages)[asNumber(index)]
291293
}
292294
logs(index: internal.primitives.StubUint64Compat): bytes {
293295
const i = asNumber(index)
294296
return this.#appLogs[i] ?? lazyContext.getApplicationData(this.appId.id).appLogs ?? Bytes()
295297
}
296298
readonly type: TransactionType.ApplicationCall = TransactionType.ApplicationCall
299+
readonly typeBytes: bytes = asUint64Cls(TransactionType.ApplicationCall).toBytes().asAlgoTs()
297300

298301
/* @internal */
299302
get appLogs() {

0 commit comments

Comments
 (0)