@@ -118,15 +118,51 @@ func addAccountContractWithArgs(
118118 AddAuthorizer (signer .Address )
119119
120120 for _ , arg := range args {
121- arg .Type ().ID ()
122121 tx .AddRawArgument (jsoncdc .MustEncode (arg ))
123122 }
124123
124+ // Determine the argument types for the contract init function
125+ program , err := parser .ParseProgram (nil , []byte (contract .Source ), parser.Config {})
126+ if err != nil {
127+ return nil , err
128+ }
129+
130+ // get contract init function
131+ contractAst := program .SoleContractDeclaration ()
132+ if contractAst == nil {
133+ return nil , fmt .Errorf ("failed to find contract declaration" )
134+ }
135+
136+ // get contract init function
137+ specialFunctions := contractAst .Members .SpecialFunctions ()
138+ var initFunction * ast.SpecialFunctionDeclaration
139+ for _ , specialFunction := range specialFunctions {
140+ if specialFunction .FunctionDeclaration .Identifier .Identifier == "init" {
141+ initFunction = specialFunction
142+ break
143+ }
144+ }
145+
146+ // if init function is not found, return error
147+ contractInitArgs := make ([]* ast.Parameter , 0 )
148+ if initFunction != nil {
149+ contractInitArgs = initFunction .FunctionDeclaration .ParameterList .Parameters
150+ }
151+
152+ // get contract init function arguments
153+ if len (contractInitArgs ) != len (args ) {
154+ return nil , fmt .Errorf (
155+ "provided arguments length mismatch, required arguments %d, but provided %d" ,
156+ len (contractInitArgs ),
157+ len (args ),
158+ )
159+ }
160+
125161 // here we itterate over all arguments and possibly extend the transaction input argument
126162 // in the above template to include them
127163 txArgs , addArgs := "" , ""
128- for i , arg := range args {
129- txArgs += fmt .Sprintf (",arg%d:%s" , i , arg .Type (). ID ())
164+ for i , arg := range contractInitArgs {
165+ txArgs += fmt .Sprintf (",arg%d:%s" , i , arg .TypeAnnotation . Type . String ())
130166 addArgs += fmt .Sprintf (",arg%d" , i )
131167 }
132168
@@ -135,7 +171,7 @@ func addAccountContractWithArgs(
135171 tx .SetComputeLimit (flow .DefaultTransactionGasLimit )
136172
137173 t := & Transaction {tx : tx }
138- err : = t .SetSigner (signer )
174+ err = t .SetSigner (signer )
139175 if err != nil {
140176 return nil , err
141177 }
0 commit comments