@@ -10,7 +10,8 @@ import type {
1010 KeyRegistrationComposeFields ,
1111 PaymentComposeFields ,
1212} from '@algorandfoundation/algorand-typescript'
13- import type { TypedApplicationCallFields } from '@algorandfoundation/algorand-typescript/arc4'
13+ import type { AbiCallOptions , TypedApplicationCallFields } from '@algorandfoundation/algorand-typescript/arc4'
14+ import { getContractMethod } from '../abi-metadata'
1415import { lazyContext } from '../context-helpers/internal-context'
1516import type { DeliberateAny , InstanceMethod } from '../typescript-helpers'
1617import { getApplicationCallInnerTxnContext } from './c2c'
@@ -29,16 +30,9 @@ class ItxnCompose {
2930 fields : TypedApplicationCallFields < TArgs > ,
3031 contract ?: Contract | { new ( ) : Contract } ,
3132 ) : void
32- begin < TArgs extends DeliberateAny [ ] > ( ...args : unknown [ ] ) : void {
33- lazyContext . txn . activeGroup . constructingItxnGroup . push (
34- args . length === 1
35- ? ( args [ 0 ] as AnyTransactionComposeFields )
36- : getApplicationCallInnerTxnContext (
37- args [ 0 ] as InstanceMethod < Contract , TArgs > ,
38- args [ 1 ] as TypedApplicationCallFields < TArgs > ,
39- args [ 2 ] as Contract | { new ( ) : Contract } ,
40- ) ,
41- )
33+ begin < TMethod > ( options : AbiCallOptions < TMethod > , contract : string , method : string ) : void
34+ begin ( ...args : unknown [ ] ) : void {
35+ this . addInnerTransaction ( ...args )
4236 }
4337
4438 next ( fields : PaymentComposeFields ) : void
@@ -49,22 +43,49 @@ class ItxnCompose {
4943 next ( fields : ApplicationCallComposeFields ) : void
5044 next ( fields : AnyTransactionComposeFields ) : void
5145 next ( fields : ComposeItxnParams ) : void
52- next < TArgs extends DeliberateAny [ ] > ( _method : InstanceMethod < Contract , TArgs > , _fields : TypedApplicationCallFields < TArgs > ) : void
53- next < TArgs extends DeliberateAny [ ] > ( ...args : unknown [ ] ) : void {
54- lazyContext . txn . activeGroup . constructingItxnGroup . push (
55- args . length === 1
56- ? ( args [ 0 ] as AnyTransactionComposeFields )
57- : getApplicationCallInnerTxnContext (
58- args [ 0 ] as InstanceMethod < Contract , TArgs > ,
59- args [ 1 ] as TypedApplicationCallFields < TArgs > ,
60- args [ 2 ] as Contract | { new ( ) : Contract } ,
61- ) ,
62- )
46+ next < TArgs extends DeliberateAny [ ] > (
47+ _method : InstanceMethod < Contract , TArgs > ,
48+ _fields : TypedApplicationCallFields < TArgs > ,
49+ contract ?: Contract | { new ( ) : Contract } ,
50+ ) : void
51+ next < TMethod > ( options : AbiCallOptions < TMethod > , contract : string , method : string ) : void
52+ next ( ...args : unknown [ ] ) : void {
53+ this . addInnerTransaction ( ...args )
6354 }
6455
6556 submit ( ) : void {
6657 lazyContext . txn . activeGroup . submitInnerTransactionGroup ( )
6758 }
59+
60+ private addInnerTransaction < TArgs extends DeliberateAny [ ] > ( ...args : unknown [ ] ) : void {
61+ let innerTxnFields
62+
63+ // Single argument: direct transaction fields
64+ if ( args . length === 1 ) {
65+ innerTxnFields = args [ 0 ] as AnyTransactionComposeFields
66+ }
67+ // Three arguments with object fields (deprecated signature):
68+ // e.g. `itxnCompose.begin(Hello.prototype.greet, { appId, args: ['ho'] })`
69+ else if ( args . length === 3 && typeof args [ 1 ] === 'object' ) {
70+ innerTxnFields = getApplicationCallInnerTxnContext (
71+ args [ 0 ] as InstanceMethod < Contract , TArgs > ,
72+ args [ 1 ] as TypedApplicationCallFields < TArgs > ,
73+ args [ 2 ] as Contract | { new ( ) : Contract } ,
74+ )
75+ }
76+ // Three arguments with string contract name:
77+ // e.g. `itxnCompose.next({ method: Hello.prototype.greet, appId, args: ['ho'] })`
78+ // or `itxnCompose.next<typeof Hello.prototype.greet>({ appId, args: ['ho'] })`
79+ else {
80+ const contractFullName = args [ 1 ] as string
81+ const methodName = args [ 2 ] as string
82+ const { method, contract } = getContractMethod ( contractFullName , methodName )
83+
84+ innerTxnFields = getApplicationCallInnerTxnContext ( method , args [ 0 ] as TypedApplicationCallFields < TArgs > , contract )
85+ }
86+
87+ lazyContext . txn . activeGroup . constructingItxnGroup . push ( innerTxnFields )
88+ }
6889}
6990
7091/** @internal */
0 commit comments