Skip to content

Commit 84e6988

Browse files
committed
Get ETH operations.
1 parent afb9873 commit 84e6988

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

api/controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ protected function _getHistory($addressHistoryMode = FALSE){
551551
'operations' => array()
552552
);
553553
$address = $this->getParam(0, FALSE);
554+
$showEth = !!$this->getRequest('showEth', FALSE);
554555
if($address){
555556
$address = strtolower($address);
556557
}
@@ -579,7 +580,7 @@ protected function _getHistory($addressHistoryMode = FALSE){
579580
}
580581
$options['history'] = TRUE;
581582
}
582-
$operations = $this->db->getLastTransfers($options);
583+
$operations = $this->db->getLastTransfers($options, $showEth);
583584
if(is_array($operations) && count($operations)){
584585
for($i = 0; $i < count($operations); $i++){
585586
$operation = $operations[$i];

service/lib/ethplorer.php

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,13 @@ public function getTransaction($tx){
657657
* @param string $tx Transaction hash
658658
* @return array
659659
*/
660-
public function getOperations($tx, $type = FALSE){
660+
public function getOperations($tx, $type = FALSE, $showEth = FALSE){
661661
evxProfiler::checkpoint('getOperations', 'START', 'hash=' . $tx);
662662
$search = array("transactionHash" => $tx);
663663
if($type){
664664
$search['type'] = $type;
665665
}
666-
$search['contract'] = array('$ne' => 'ETH');
666+
if(!$showEth) $search['contract'] = array('$ne' => 'ETH');
667667
$cursor = $this->oMongo->find('operations', $search, array('priority' => 1));
668668
$result = array();
669669
foreach($cursor as $res){
@@ -948,9 +948,9 @@ public function getContract($address, $calculateTransactions = TRUE){
948948
* @param string $address Contract address
949949
* @return int
950950
*/
951-
public function countOperations($address, $useFilter = TRUE){
951+
public function countOperations($address, $useFilter = TRUE, $showEth = FALSE){
952952
evxProfiler::checkpoint('countOperations', 'START', 'address=' . $address . ', useFilter = ' . ($useFilter ? 'ON' : 'OFF'));
953-
$cache = 'countOperations-' . $address;
953+
$cache = 'countOperations-' . $address . ($showEth ? '-eth' : '');
954954
$result = $this->oCache->get($cache, false, true, 30);
955955
if(FALSE === $result){
956956
$result = 0;
@@ -968,7 +968,7 @@ public function countOperations($address, $useFilter = TRUE){
968968
$aSearchFields = array('from', 'to', 'address');
969969
foreach($aSearchFields as $searchField){
970970
$search = array($searchField => $address);
971-
$search['contract'] = array('$ne' => 'ETH');
971+
if(!$showEth) $search['contract'] = array('$ne' => 'ETH');
972972
if($useFilter && $this->filter){
973973
$search = array(
974974
'$and' => array(
@@ -1128,7 +1128,7 @@ public function getAddressBalances($address, $withZero = true){
11281128
* @param int $limit Maximum number of records
11291129
* @return array
11301130
*/
1131-
public function getLastTransfers(array $options = array()){
1131+
public function getLastTransfers(array $options = array(), $showEth = FALSE){
11321132
$search = array();
11331133
if(!isset($options['type'])){
11341134
$search['type'] = 'transfer';
@@ -1153,7 +1153,7 @@ public function getLastTransfers(array $options = array()){
11531153
if(isset($options['timestamp']) && ($options['timestamp'] > 0)){
11541154
$search['timestamp'] = array('$gt' => $options['timestamp']);
11551155
}
1156-
$search['contract'] = array('$ne' => 'ETH');
1156+
if(!$showEth) $search['contract'] = array('$ne' => 'ETH');
11571157
$limit = isset($options['limit']) ? (int)$options['limit'] : false;
11581158
$cursor = $this->oMongo->find('operations', $search, $sort, $limit);
11591159

@@ -1173,12 +1173,12 @@ public function getLastTransfers(array $options = array()){
11731173
* @param int $limit Maximum number of records
11741174
* @return array
11751175
*/
1176-
public function getAddressOperations($address, $limit = 10, $offset = false, array $aTypes = NULL){
1176+
public function getAddressOperations($address, $limit = 10, $offset = FALSE, array $aTypes = NULL, $showEth = FALSE){
11771177
evxProfiler::checkpoint('getAddressOperations', 'START', 'address=' . $address . ', limit=' . $limit . ', offset=' . (int)$offset);
11781178

11791179
$result = array();
11801180
$search = array('addresses' => $address);
1181-
$search['contract'] = array('$ne' => 'ETH');
1181+
if(!$showEth) $search['contract'] = array('$ne' => 'ETH');
11821182

11831183
// @todo: remove $or, use special field with from-to-address-txHash concatination maybe
11841184
if($this->filter){
@@ -1292,15 +1292,17 @@ public function getAddressOperationsCSV($address, $type = 'transfer'){
12921292
* @param bool $updateCache Force unexpired cache update
12931293
* @return array
12941294
*/
1295-
public function getTopTokens($limit = 10, $period = 30, $updateCache = false){
1296-
$cache = 'top_tokens-' . $period . '-' . $limit;
1295+
public function getTopTokens($limit = 10, $period = 30, $updateCache = FALSE, $showEth = FALSE){
1296+
$cache = 'top_tokens-' . $period . '-' . $limit . ($showEth ? '-eth' : '');
12971297
$result = $this->oCache->get($cache, false, true, 24 * 3600);
12981298
if($updateCache || (FALSE === $result)){
12991299
$result = array();
1300+
$aMatch = array("timestamp" => array('$gt' => time() - $period * 2 * 24 * 3600, '$lte' => time() - $period * 24 * 3600));
1301+
if(!$showEth) $aMatch['contract'] = array('$ne' => 'ETH');
13001302
$prevData = $this->oMongo->aggregate(
13011303
'operations',
13021304
array(
1303-
array('$match' => array("contract" => array('$ne' => 'ETH'), "timestamp" => array('$gt' => time() - $period * 2 * 24 * 3600, '$lte' => time() - $period * 24 * 3600))),
1305+
array('$match' => $aMatch),
13041306
array(
13051307
'$group' => array(
13061308
"_id" => '$contract',
@@ -1311,10 +1313,11 @@ public function getTopTokens($limit = 10, $period = 30, $updateCache = false){
13111313
array('$limit' => $limit)
13121314
)
13131315
);
1316+
$aMatch['timestamp'] = array('$gt' => time() - $period * 24 * 3600);
13141317
$dbData = $this->oMongo->aggregate(
13151318
'operations',
13161319
array(
1317-
array('$match' => array("contract" => array('$ne' => 'ETH'), "timestamp" => array('$gt' => time() - $period * 24 * 3600))),
1320+
array('$match' => $aMatch),
13181321
array(
13191322
'$group' => array(
13201323
"_id" => '$contract',
@@ -1681,8 +1684,8 @@ protected function _sortByTxCount($a, $b){
16811684
* @param string $address Address
16821685
* @return array
16831686
*/
1684-
public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = 'daily', $cacheLifetime = 1800){
1685-
$cache = 'token_history_grouped-' . ($address ? ($address . '-') : '') . $period . (($type == 'hourly') ? '-hourly' : '');
1687+
public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = 'daily', $cacheLifetime = 1800, $showEth = FALSE){
1688+
$cache = 'token_history_grouped-' . ($address ? ($address . '-') : '') . $period . (($type == 'hourly') ? '-hourly' : '') . ($showEth ? '-eth' : '');
16861689
$result = $this->oCache->get($cache, false, true, $cacheLifetime);
16871690
if(FALSE === $result){
16881691
// Chainy
@@ -1693,7 +1696,7 @@ public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = '
16931696
$tsStart = gmmktime(0, 0, 0, date('n'), date('j') - $period, date('Y'));
16941697
$aMatch = array("timestamp" => array('$gt' => $tsStart));
16951698
if($address) $aMatch["contract"] = $address;
1696-
else $aMatch["contract"] = array('$ne' => 'ETH');
1699+
else if(!$showEth) $aMatch["contract"] = array('$ne' => 'ETH');
16971700
$result = array();
16981701
$_id = array(
16991702
"year" => array('$year' => array('$add' => array($this->oMongo->toDate(0), array('$multiply' => array('$timestamp', 1000))))),
@@ -1731,7 +1734,7 @@ public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = '
17311734
*
17321735
* @return array
17331736
*/
1734-
public function getTokenFullHistoryGrouped(){
1737+
public function getTokenFullHistoryGrouped($showEth = FALSE){
17351738
$tsNow = time();
17361739
$tsStart = 1451606400; // 01.01.2016
17371740
$tsEnd = 1459468800;
@@ -1749,7 +1752,8 @@ public function getTokenFullHistoryGrouped(){
17491752
if(FALSE === $result){
17501753
$result = array();
17511754

1752-
$aMatch = array("contract" => array('$ne' => 'ETH'), "timestamp" => array('$gte' => $tsStart + 1, '$lte' => $tsEnd));
1755+
$aMatch = array("timestamp" => array('$gte' => $tsStart + 1, '$lte' => $tsEnd));
1756+
if(!$showEth) $aMatch["contract"] = array('$ne' => 'ETH');
17531757
$_id = array(
17541758
"year" => array('$year' => array('$add' => array($this->oMongo->toDate(0), array('$multiply' => array('$timestamp', 1000))))),
17551759
"month" => array('$month' => array('$add' => array($this->oMongo->toDate(0), array('$multiply' => array('$timestamp', 1000))))),
@@ -1790,12 +1794,13 @@ public function getTokenFullHistoryGrouped(){
17901794
* @param int $limit Number of tokens
17911795
* @return array
17921796
*/
1793-
public function getTokensCountForLastDay($limit = 30){
1794-
$cache = 'tokens_count-' . $limit;
1797+
public function getTokensCountForLastDay($limit = 30, $showEth = FALSE){
1798+
$cache = 'tokens_count-' . $limit . ($showEth ? '-eth' : '');
17951799
$result = $this->oCache->get($cache, false, true, 3600);
17961800
if(FALSE === $result){
17971801
$tsStart = gmmktime((int)date('G'), 0, 0, date('n'), date('j') - 1, date('Y'));
1798-
$aMatch = array("contract" => array('$ne' => 'ETH'), "timestamp" => array('$gte' => $tsStart));
1802+
$aMatch = array("timestamp" => array('$gte' => $tsStart));
1803+
if(!$showEth) $aMatch["contract"] = array('$ne' => 'ETH');
17991804
$result = array();
18001805
$dbData = $this->oMongo->aggregate(
18011806
'operations',
@@ -2260,10 +2265,10 @@ public function getTokenPriceHistoryGrouped($address, $period = 365, $type = 'da
22602265
return $aResult;
22612266
}
22622267

2263-
public function getAddressPriceHistoryGrouped($address, $updateCache = FALSE){
2268+
public function getAddressPriceHistoryGrouped($address, $updateCache = FALSE, $showEth = FALSE){
22642269
evxProfiler::checkpoint('getAddressPriceHistoryGrouped', 'START', 'address=' . $address);
22652270

2266-
$cache = 'address_operations_history-' . $address;
2271+
$cache = 'address_operations_history-' . $address . ($showEth ? '-eth' : '');
22672272
$result = $this->oCache->get($cache, false, true);
22682273
$updateCache = false;
22692274
if($result && isset($result['timestamp'])){
@@ -2289,7 +2294,7 @@ public function getAddressPriceHistoryGrouped($address, $updateCache = FALSE){
22892294

22902295
foreach($aSearch as $cond){
22912296
$search = array($cond => $address);
2292-
$search['contract'] = array('$ne' => 'ETH');
2297+
if(!$showEth) $search['contract'] = array('$ne' => 'ETH');
22932298
if($updateCache){
22942299
$search = array('$and' => array($search, array('timestamp' => array('$gt' => $result['timestamp']))));
22952300
}

0 commit comments

Comments
 (0)