11import type { OnCompleteActionStr } from '@algorandfoundation/algorand-typescript'
22import type { CreateOptions } from '@algorandfoundation/algorand-typescript/arc4'
33import js_sha512 from 'js-sha512'
4+ import { ConventionalRouting } from './constants'
45import type { TypeInfo } from './encoders'
56import { Arc4MethodConfigSymbol , Contract } from './impl/contract'
67import { getArc4TypeName as getArc4TypeNameForARC4Encoded } from './impl/encoded-types'
@@ -22,7 +23,12 @@ export const attachAbiMetadata = (contract: { new (): Contract }, methodName: st
2223 metadataStore . set ( contract , { } )
2324 }
2425 const metadatas : Record < string , AbiMetadata > = metadataStore . get ( contract ) as Record < string , AbiMetadata >
25- metadatas [ methodName ] = metadata
26+ const conventionalRoutingConfig = getConventionalRoutingConfig ( methodName )
27+ metadatas [ methodName ] = {
28+ ...metadata ,
29+ allowActions : metadata . allowActions ?? conventionalRoutingConfig ?. allowActions ,
30+ onCreate : metadata . onCreate ?? conventionalRoutingConfig ?. onCreate ,
31+ }
2632}
2733
2834export const getContractAbiMetadata = < T extends Contract > ( contract : T | { new ( ) : T } ) : Record < string , AbiMetadata > => {
@@ -110,3 +116,36 @@ const getArc4TypeName = (t: TypeInfo): string => {
110116 }
111117 return entry
112118}
119+
120+ /**
121+ * Get routing properties inferred by conventional naming
122+ * @param methodName The name of the method
123+ */
124+ const getConventionalRoutingConfig = ( methodName : string ) : Pick < AbiMetadata , 'allowActions' | 'onCreate' > | undefined => {
125+ switch ( methodName ) {
126+ case ConventionalRouting . methodNames . closeOutOfApplication :
127+ return {
128+ allowActions : [ 'CloseOut' ] ,
129+ onCreate : 'disallow' ,
130+ }
131+ case ConventionalRouting . methodNames . createApplication :
132+ return {
133+ onCreate : 'require' ,
134+ }
135+ case ConventionalRouting . methodNames . deleteApplication :
136+ return {
137+ allowActions : [ 'DeleteApplication' ] ,
138+ }
139+ case ConventionalRouting . methodNames . optInToApplication :
140+ return {
141+ allowActions : [ 'OptIn' ] ,
142+ }
143+ case ConventionalRouting . methodNames . updateApplication :
144+ return {
145+ allowActions : [ 'UpdateApplication' ] ,
146+ onCreate : 'disallow' ,
147+ }
148+ default :
149+ return undefined
150+ }
151+ }
0 commit comments