@@ -19,7 +19,8 @@ class ethplorerController {
19
19
protected $ db ;
20
20
protected $ command ;
21
21
protected $ params = array ();
22
- protected $ apiCommands = array ('getTxInfo ' , 'getTokenHistory ' , 'getAddressInfo ' , 'getTokenInfo ' );
22
+ protected $ apiCommands = array ('getTxInfo ' , 'getTokenHistory ' , 'getAddressInfo ' , 'getTokenInfo ' , 'getAddressHistory ' );
23
+ protected $ defaults ;
23
24
24
25
public function __construct ($ es ){
25
26
if (!($ es instanceof Ethplorer)){
@@ -76,9 +77,11 @@ public function sendError($code, $message){
76
77
public function run (){
77
78
$ command = $ this ->getCommand ();
78
79
if ($ command && in_array ($ command , $ this ->apiCommands ) && method_exists ($ this , $ command )){
79
- if (!$ this ->db ->checkAPIkey ($ this ->getRequest ('apiKey ' , FALSE ))){
80
+ $ key = $ this ->getRequest ('apiKey ' , FALSE );
81
+ if (!$ key || !$ this ->db ->checkAPIkey ($ key )){
80
82
$ this ->sendError (1 , 'Invalid API key ' );
81
83
}
84
+ $ this ->defaults = $ this ->db ->getAPIKeyDefaults ($ key , $ this ->getCommand ());
82
85
$ result = call_user_func (array ($ this , $ this ->getCommand ()));
83
86
$ this ->sendResult ($ result );
84
87
}
@@ -231,10 +234,11 @@ public function getTokenHistory(){
231
234
if ((FALSE !== $ address ) && (!$ this ->db ->isValidAddress ($ address ))){
232
235
$ this ->sendError (104 , 'Invalid address format ' );
233
236
}
237
+ $ maxLimit = is_array ($ this ->defaults ) && isset ($ this ->defaults ['limit ' ]) ? $ this ->defaults ['limit ' ] : 10 ;
234
238
$ options = array (
235
239
'address ' => $ this ->getParam (0 , FALSE ),
236
240
'type ' => $ this ->getRequest ('type ' , FALSE ),
237
- 'limit ' => min (abs ((int )$ this ->getRequest ('limit ' , 10 )), 10 ),
241
+ 'limit ' => min (abs ((int )$ this ->getRequest ('limit ' , 10 )), $ maxLimit ),
238
242
'timestamp ' => (int )$ this ->getRequest ('tsAfter ' , 0 )
239
243
);
240
244
$ operations = $ this ->db ->getLastTransfers ($ options );
@@ -261,6 +265,50 @@ public function getTokenHistory(){
261
265
return $ result ;
262
266
}
263
267
268
+ // @todo: remove copypaste
269
+ public function getAddressHistory (){
270
+ $ result = array (
271
+ 'operations ' => array ()
272
+ );
273
+ $ address = $ this ->getParam (0 , FALSE );
274
+ if ($ address ){
275
+ $ address = strtolower ($ address );
276
+ }
277
+ if ((FALSE !== $ address ) && (!$ this ->db ->isValidAddress ($ address ))){
278
+ $ this ->sendError (104 , 'Invalid address format ' );
279
+ }
280
+ $ maxLimit = is_array ($ this ->defaults ) && isset ($ this ->defaults ['limit ' ]) ? $ this ->defaults ['limit ' ] : 10 ;
281
+ $ options = array (
282
+ 'address ' => $ this ->getParam (0 , FALSE ),
283
+ 'type ' => $ this ->getRequest ('type ' , FALSE ),
284
+ 'limit ' => min (abs ((int )$ this ->getRequest ('limit ' , 10 )), $ maxLimit ),
285
+ 'timestamp ' => (int )$ this ->getRequest ('tsAfter ' , 0 ),
286
+ 'history ' => TRUE
287
+ );
288
+ $ operations = $ this ->db ->getLastTransfers ($ options );
289
+ if (is_array ($ operations ) && count ($ operations )){
290
+ for ($ i = 0 ; $ i < count ($ operations ); $ i ++){
291
+ $ operation = $ operations [$ i ];
292
+ $ res = array (
293
+ 'timestamp ' => $ operation ['timestamp ' ],
294
+ 'transactionHash ' => $ operation ['transactionHash ' ],
295
+ 'tokenInfo ' => $ operation ['token ' ],
296
+ 'type ' => $ operation ['type ' ],
297
+ 'value ' => $ operation ['value ' ],
298
+ );
299
+ if (isset ($ operation ['address ' ])){
300
+ $ res ['address ' ] = $ operation ['address ' ];
301
+ }
302
+ if (isset ($ operation ['from ' ])){
303
+ $ res ['from ' ] = $ operation ['from ' ];
304
+ $ res ['to ' ] = $ operation ['to ' ];
305
+ }
306
+ $ result ['operations ' ][] = $ res ;
307
+ }
308
+ }
309
+ return $ result ;
310
+ }
311
+
264
312
protected function _bn2float ($ aNumber ){
265
313
$ res = 0 ;
266
314
if (isset ($ aNumber ['c ' ]) && !empty ($ aNumber ['c ' ])){
0 commit comments