@@ -19,7 +19,7 @@ class ethplorerController {
19
19
protected $ db ;
20
20
protected $ command ;
21
21
protected $ params = array ();
22
- protected $ apiCommands = array ('getTxInfo ' , 'getTokenHistory ' , 'getAddressInfo ' , 'getTokenInfo ' , /* 'getAddressHistory'*/ );
22
+ protected $ apiCommands = array ('getTxInfo ' , 'getTokenHistory ' , 'getAddressInfo ' , 'getTokenInfo ' , 'getAddressHistory ' );
23
23
protected $ defaults ;
24
24
25
25
public function __construct ($ es ){
@@ -224,67 +224,42 @@ public function getTxInfo(){
224
224
}
225
225
226
226
public function getTokenHistory (){
227
- $ result = array (
228
- 'operations ' => array ()
229
- );
230
- $ address = $ this ->getParam (0 , FALSE );
231
- if ($ address ){
232
- $ address = strtolower ($ address );
233
- }
234
- if ((FALSE !== $ address ) && (!$ this ->db ->isValidAddress ($ address ))){
235
- $ this ->sendError (104 , 'Invalid address format ' );
236
- }
237
- $ maxLimit = is_array ($ this ->defaults ) && isset ($ this ->defaults ['limit ' ]) ? $ this ->defaults ['limit ' ] : 10 ;
238
- $ options = array (
239
- 'address ' => $ this ->getParam (0 , FALSE ),
240
- 'type ' => $ this ->getRequest ('type ' , FALSE ),
241
- 'limit ' => min (abs ((int )$ this ->getRequest ('limit ' , 10 )), $ maxLimit ),
242
- 'timestamp ' => (int )$ this ->getRequest ('tsAfter ' , 0 )
243
- );
244
- $ operations = $ this ->db ->getLastTransfers ($ options );
245
- if (is_array ($ operations ) && count ($ operations )){
246
- for ($ i = 0 ; $ i < count ($ operations ); $ i ++){
247
- $ operation = $ operations [$ i ];
248
- $ res = array (
249
- 'timestamp ' => $ operation ['timestamp ' ],
250
- 'transactionHash ' => $ operation ['transactionHash ' ],
251
- 'tokenInfo ' => $ operation ['token ' ],
252
- 'type ' => $ operation ['type ' ],
253
- 'value ' => $ operation ['value ' ],
254
- );
255
- if (isset ($ operation ['address ' ])){
256
- $ res ['address ' ] = $ operation ['address ' ];
257
- }
258
- if (isset ($ operation ['from ' ])){
259
- $ res ['from ' ] = $ operation ['from ' ];
260
- $ res ['to ' ] = $ operation ['to ' ];
261
- }
262
- $ result ['operations ' ][] = $ res ;
263
- }
264
- }
265
- return $ result ;
227
+ return $ this ->_getHistory ();
266
228
}
267
229
268
230
// @todo: remove copypaste
269
231
public function getAddressHistory (){
232
+ return $ this ->_getHistory (TRUE );
233
+ }
234
+
235
+ protected function _getHistory ($ addressHistoryMode = FALSE ){
270
236
$ result = array (
271
237
'operations ' => array ()
272
238
);
273
239
$ address = $ this ->getParam (0 , FALSE );
274
240
if ($ address ){
275
241
$ address = strtolower ($ address );
276
242
}
277
- if ((FALSE !== $ address ) && (!$ this ->db ->isValidAddress ($ address ))){
243
+ if ((! $ address && $ addressHistoryMode ) || (( FALSE !== $ address ) && (!$ this ->db ->isValidAddress ($ address) ))){
278
244
$ this ->sendError (104 , 'Invalid address format ' );
279
245
}
280
246
$ maxLimit = is_array ($ this ->defaults ) && isset ($ this ->defaults ['limit ' ]) ? $ this ->defaults ['limit ' ] : 10 ;
281
247
$ options = array (
282
- 'address ' => $ this -> getParam ( 0 , FALSE ) ,
248
+ 'address ' => $ address ,
283
249
'type ' => $ this ->getRequest ('type ' , FALSE ),
284
250
'limit ' => min (abs ((int )$ this ->getRequest ('limit ' , 10 )), $ maxLimit ),
285
- 'timestamp ' => (int )$ this ->getRequest ('tsAfter ' , 0 ),
286
- 'history ' => TRUE
287
251
);
252
+ if ($ addressHistoryMode ){
253
+ $ token = $ this ->getRequest ('token ' , FALSE );
254
+ if (FALSE !== $ token ){
255
+ $ token = strtolower ($ token );
256
+ if (!$ this ->db ->isValidAddress ($ token )){
257
+ $ this ->sendError (104 , 'Invalid token address format ' );
258
+ }
259
+ $ options ['token ' ] = $ token ;
260
+ }
261
+ $ options ['history ' ] = TRUE ;
262
+ }
288
263
$ operations = $ this ->db ->getLastTransfers ($ options );
289
264
if (is_array ($ operations ) && count ($ operations )){
290
265
for ($ i = 0 ; $ i < count ($ operations ); $ i ++){
0 commit comments