@@ -118,15 +118,51 @@ func addAccountContractWithArgs(
118
118
AddAuthorizer (signer .Address )
119
119
120
120
for _ , arg := range args {
121
- arg .Type ().ID ()
122
121
tx .AddRawArgument (jsoncdc .MustEncode (arg ))
123
122
}
124
123
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
+
125
161
// here we itterate over all arguments and possibly extend the transaction input argument
126
162
// in the above template to include them
127
163
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 ())
130
166
addArgs += fmt .Sprintf (",arg%d" , i )
131
167
}
132
168
@@ -135,7 +171,7 @@ func addAccountContractWithArgs(
135
171
tx .SetComputeLimit (flow .DefaultTransactionGasLimit )
136
172
137
173
t := & Transaction {tx : tx }
138
- err : = t .SetSigner (signer )
174
+ err = t .SetSigner (signer )
139
175
if err != nil {
140
176
return nil , err
141
177
}
0 commit comments