@@ -152,44 +152,23 @@ public function getAllowance(string $ownerAddress, string $spenderAddress): stri
152
152
}
153
153
154
154
/**
155
+ * @param string $method
155
156
* @param array $params
156
157
* @return string
157
158
* @throws CoderException
158
159
*/
159
- public function getCodeTransferFrom (array $ params ): string
160
- {
161
- $ function = $ this ->contract ->functions ['transferFrom ' ];
162
- if (count ($ params ) !== count ($ function ['inputs ' ]))
163
- {
164
- throw new CoderException ('Incorrect number parameters for method transferFrom. ' );
165
- }
166
-
167
- $ data = $ this ->ethAbi ->encodeParameters ($ function , $ params );
168
-
169
- $ functionSignature = $ this ->encodeFunctionSignature ('transferFrom ' );
170
-
171
-
172
- $ code = $ functionSignature . Utils::stripZero ($ data );
173
-
174
- return $ code ;
175
- }
176
-
177
- /**
178
- * @param array $params
179
- * @return string
180
- * @throws CoderException
181
- */
182
- public function getCodeTransfer (array $ params ): string
160
+ public function encodeMethod (string $ method , array $ params ): string
183
161
{
184
- $ function = $ this ->contract ->functions ['transfer ' ];
162
+ $ methodName = strtolower ($ method );
163
+ $ function = $ this ->contract ->functions [$ methodName ];
185
164
if (count ($ params ) !== count ($ function ['inputs ' ]))
186
165
{
187
166
throw new CoderException ('Incorrect number parameters for method transferFrom. ' );
188
167
}
189
168
190
169
$ data = $ this ->ethAbi ->encodeParameters ($ function , $ params );
191
170
192
- $ functionSignature = $ this ->encodeFunctionSignature (' transfer ' );
171
+ $ functionSignature = $ this ->encodeFunctionSignature ($ methodName );
193
172
194
173
195
174
$ code = $ functionSignature . Utils::stripZero ($ data );
@@ -216,26 +195,4 @@ private function encodeFunctionSignature(string $method)
216
195
217
196
return substr (Utils::sha3 ($ rawSignature ), 0 , 10 );
218
197
}
219
-
220
- /**
221
- * @param array $params
222
- * @return string
223
- * @throws CoderException
224
- */
225
- public function getCodeApprove (array $ params ): string
226
- {
227
- $ function = $ this ->contract ->functions ['approve ' ];
228
- if (count ($ params ) !== count ($ function ['inputs ' ]))
229
- {
230
- throw new CoderException ('Incorrect number parameters for method approve. ' );
231
- }
232
- $ data = $ this ->ethAbi ->encodeParameters ($ function , $ params );
233
-
234
- $ functionSignature = $ this ->encodeFunctionSignature ('approve ' );
235
-
236
-
237
- $ code = $ functionSignature . Utils::stripZero ($ data );
238
-
239
- return $ code ;
240
- }
241
198
}
0 commit comments