@@ -14,7 +14,7 @@ import {
1414import { MAX_ITEMS_IN_LOG } from '../constants'
1515import { lazyContext } from '../context-helpers/internal-context'
1616import { Mutable , ObjectKeys } from '../typescript-helpers'
17- import { asBytes , asNumber , asUint64Cls , combineIntoMaxBytePages , getRandomBytes } from '../util'
17+ import { asBytes , asMaybeBytesCls , asMaybeUint64Cls , asNumber , asUint64Cls , combineIntoMaxBytePages , getRandomBytes } from '../util'
1818
1919const baseDefaultFields = ( ) => ( {
2020 sender : lazyContext . defaultSender ,
@@ -44,6 +44,7 @@ abstract class TransactionBase {
4444 this . groupIndex = fields . groupIndex ?? baseDefaults . groupIndex
4545 this . txnId = fields . txnId ?? baseDefaults . txnId
4646 this . rekeyTo = fields . rekeyTo ?? baseDefaults . rekeyTo
47+ this . scratchSpace = Array ( 256 ) . fill ( Uint64 ( 0 ) )
4748 }
4849
4950 readonly sender : Account
@@ -56,6 +57,28 @@ abstract class TransactionBase {
5657 readonly groupIndex : uint64
5758 readonly txnId : bytes
5859 readonly rekeyTo : Account
60+ readonly scratchSpace : Array < bytes | uint64 >
61+
62+ setScratchSlot (
63+ index : internal . primitives . StubUint64Compat ,
64+ value : internal . primitives . StubBytesCompat | internal . primitives . StubUint64Compat ,
65+ ) : void {
66+ const i = asNumber ( index )
67+ if ( i >= this . scratchSpace . length ) {
68+ throw internal . errors . internalError ( 'invalid scratch slot' )
69+ }
70+ const bytesValue = asMaybeBytesCls ( value )
71+ const uint64Value = asMaybeUint64Cls ( value )
72+ this . scratchSpace [ i ] = bytesValue ?. asAlgoTs ( ) ?? uint64Value ?. asAlgoTs ( ) ?? Uint64 ( 0 )
73+ }
74+
75+ getScratchSlot ( index : internal . primitives . StubUint64Compat ) : bytes | uint64 {
76+ const i = asNumber ( index )
77+ if ( i >= this . scratchSpace . length ) {
78+ throw internal . errors . internalError ( 'invalid scratch slot' )
79+ }
80+ return this . scratchSpace [ i ]
81+ }
5982}
6083
6184export class PaymentTransaction extends TransactionBase implements gtxn . PaymentTxn {
@@ -201,6 +224,7 @@ export type ApplicationTransactionFields = TxnFields<gtxn.ApplicationTxn> &
201224 approvalProgramPages : Array < bytes >
202225 clearStateProgramPages : Array < bytes >
203226 appLogs : Array < bytes >
227+ scratchSpace : Array < bytes | uint64 >
204228 } >
205229
206230export class ApplicationTransaction extends TransactionBase implements gtxn . ApplicationTxn {
@@ -233,6 +257,7 @@ export class ApplicationTransaction extends TransactionBase implements gtxn.Appl
233257 this . #apps = fields . apps ?? [ ]
234258 this . #approvalProgramPages = fields . approvalProgramPages ?? ( fields . approvalProgram ? [ fields . approvalProgram ] : [ ] )
235259 this . #clearStateProgramPages = fields . clearStateProgramPages ?? ( fields . clearStateProgram ? [ fields . clearStateProgram ] : [ ] )
260+ fields . scratchSpace ?. forEach ( ( v , i ) => this . setScratchSlot ( i , v ) )
236261 }
237262
238263 readonly appId : Application
0 commit comments