@@ -657,13 +657,13 @@ public function getTransaction($tx){
657
657
* @param string $tx Transaction hash
658
658
* @return array
659
659
*/
660
- public function getOperations ($ tx , $ type = FALSE ){
660
+ public function getOperations ($ tx , $ type = FALSE , $ showEth = FALSE ){
661
661
evxProfiler::checkpoint ('getOperations ' , 'START ' , 'hash= ' . $ tx );
662
662
$ search = array ("transactionHash " => $ tx );
663
663
if ($ type ){
664
664
$ search ['type ' ] = $ type ;
665
665
}
666
- $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
666
+ if (! $ showEth ) $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
667
667
$ cursor = $ this ->oMongo ->find ('operations ' , $ search , array ('priority ' => 1 ));
668
668
$ result = array ();
669
669
foreach ($ cursor as $ res ){
@@ -948,9 +948,9 @@ public function getContract($address, $calculateTransactions = TRUE){
948
948
* @param string $address Contract address
949
949
* @return int
950
950
*/
951
- public function countOperations ($ address , $ useFilter = TRUE ){
951
+ public function countOperations ($ address , $ useFilter = TRUE , $ showEth = FALSE ){
952
952
evxProfiler::checkpoint ('countOperations ' , 'START ' , 'address= ' . $ address . ', useFilter = ' . ($ useFilter ? 'ON ' : 'OFF ' ));
953
- $ cache = 'countOperations- ' . $ address ;
953
+ $ cache = 'countOperations- ' . $ address . ( $ showEth ? ' -eth ' : '' ) ;
954
954
$ result = $ this ->oCache ->get ($ cache , false , true , 30 );
955
955
if (FALSE === $ result ){
956
956
$ result = 0 ;
@@ -968,7 +968,7 @@ public function countOperations($address, $useFilter = TRUE){
968
968
$ aSearchFields = array ('from ' , 'to ' , 'address ' );
969
969
foreach ($ aSearchFields as $ searchField ){
970
970
$ search = array ($ searchField => $ address );
971
- $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
971
+ if (! $ showEth ) $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
972
972
if ($ useFilter && $ this ->filter ){
973
973
$ search = array (
974
974
'$and ' => array (
@@ -1128,7 +1128,7 @@ public function getAddressBalances($address, $withZero = true){
1128
1128
* @param int $limit Maximum number of records
1129
1129
* @return array
1130
1130
*/
1131
- public function getLastTransfers (array $ options = array ()){
1131
+ public function getLastTransfers (array $ options = array (), $ showEth = FALSE ){
1132
1132
$ search = array ();
1133
1133
if (!isset ($ options ['type ' ])){
1134
1134
$ search ['type ' ] = 'transfer ' ;
@@ -1153,7 +1153,7 @@ public function getLastTransfers(array $options = array()){
1153
1153
if (isset ($ options ['timestamp ' ]) && ($ options ['timestamp ' ] > 0 )){
1154
1154
$ search ['timestamp ' ] = array ('$gt ' => $ options ['timestamp ' ]);
1155
1155
}
1156
- $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
1156
+ if (! $ showEth ) $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
1157
1157
$ limit = isset ($ options ['limit ' ]) ? (int )$ options ['limit ' ] : false ;
1158
1158
$ cursor = $ this ->oMongo ->find ('operations ' , $ search , $ sort , $ limit );
1159
1159
@@ -1173,12 +1173,12 @@ public function getLastTransfers(array $options = array()){
1173
1173
* @param int $limit Maximum number of records
1174
1174
* @return array
1175
1175
*/
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 ){
1177
1177
evxProfiler::checkpoint ('getAddressOperations ' , 'START ' , 'address= ' . $ address . ', limit= ' . $ limit . ', offset= ' . (int )$ offset );
1178
1178
1179
1179
$ result = array ();
1180
1180
$ search = array ('addresses ' => $ address );
1181
- $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
1181
+ if (! $ showEth ) $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
1182
1182
1183
1183
// @todo: remove $or, use special field with from-to-address-txHash concatination maybe
1184
1184
if ($ this ->filter ){
@@ -1292,15 +1292,17 @@ public function getAddressOperationsCSV($address, $type = 'transfer'){
1292
1292
* @param bool $updateCache Force unexpired cache update
1293
1293
* @return array
1294
1294
*/
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 ' : '' ) ;
1297
1297
$ result = $ this ->oCache ->get ($ cache , false , true , 24 * 3600 );
1298
1298
if ($ updateCache || (FALSE === $ result )){
1299
1299
$ 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 ' );
1300
1302
$ prevData = $ this ->oMongo ->aggregate (
1301
1303
'operations ' ,
1302
1304
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 ),
1304
1306
array (
1305
1307
'$group ' => array (
1306
1308
"_id " => '$contract ' ,
@@ -1311,10 +1313,11 @@ public function getTopTokens($limit = 10, $period = 30, $updateCache = false){
1311
1313
array ('$limit ' => $ limit )
1312
1314
)
1313
1315
);
1316
+ $ aMatch ['timestamp ' ] = array ('$gt ' => time () - $ period * 24 * 3600 );
1314
1317
$ dbData = $ this ->oMongo ->aggregate (
1315
1318
'operations ' ,
1316
1319
array (
1317
- array ('$match ' => array ( " contract " => array ( ' $ne ' => ' ETH ' ), " timestamp " => array ( ' $gt ' => time () - $ period * 24 * 3600 )) ),
1320
+ array ('$match ' => $ aMatch ),
1318
1321
array (
1319
1322
'$group ' => array (
1320
1323
"_id " => '$contract ' ,
@@ -1681,8 +1684,8 @@ protected function _sortByTxCount($a, $b){
1681
1684
* @param string $address Address
1682
1685
* @return array
1683
1686
*/
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 ' : '' ) ;
1686
1689
$ result = $ this ->oCache ->get ($ cache , false , true , $ cacheLifetime );
1687
1690
if (FALSE === $ result ){
1688
1691
// Chainy
@@ -1693,7 +1696,7 @@ public function getTokenHistoryGrouped($period = 30, $address = FALSE, $type = '
1693
1696
$ tsStart = gmmktime (0 , 0 , 0 , date ('n ' ), date ('j ' ) - $ period , date ('Y ' ));
1694
1697
$ aMatch = array ("timestamp " => array ('$gt ' => $ tsStart ));
1695
1698
if ($ address ) $ aMatch ["contract " ] = $ address ;
1696
- else $ aMatch ["contract " ] = array ('$ne ' => 'ETH ' );
1699
+ else if (! $ showEth ) $ aMatch ["contract " ] = array ('$ne ' => 'ETH ' );
1697
1700
$ result = array ();
1698
1701
$ _id = array (
1699
1702
"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 = '
1731
1734
*
1732
1735
* @return array
1733
1736
*/
1734
- public function getTokenFullHistoryGrouped (){
1737
+ public function getTokenFullHistoryGrouped ($ showEth = FALSE ){
1735
1738
$ tsNow = time ();
1736
1739
$ tsStart = 1451606400 ; // 01.01.2016
1737
1740
$ tsEnd = 1459468800 ;
@@ -1749,7 +1752,8 @@ public function getTokenFullHistoryGrouped(){
1749
1752
if (FALSE === $ result ){
1750
1753
$ result = array ();
1751
1754
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 ' );
1753
1757
$ _id = array (
1754
1758
"year " => array ('$year ' => array ('$add ' => array ($ this ->oMongo ->toDate (0 ), array ('$multiply ' => array ('$timestamp ' , 1000 ))))),
1755
1759
"month " => array ('$month ' => array ('$add ' => array ($ this ->oMongo ->toDate (0 ), array ('$multiply ' => array ('$timestamp ' , 1000 ))))),
@@ -1790,12 +1794,13 @@ public function getTokenFullHistoryGrouped(){
1790
1794
* @param int $limit Number of tokens
1791
1795
* @return array
1792
1796
*/
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 ' : '' ) ;
1795
1799
$ result = $ this ->oCache ->get ($ cache , false , true , 3600 );
1796
1800
if (FALSE === $ result ){
1797
1801
$ 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 ' );
1799
1804
$ result = array ();
1800
1805
$ dbData = $ this ->oMongo ->aggregate (
1801
1806
'operations ' ,
@@ -2260,10 +2265,10 @@ public function getTokenPriceHistoryGrouped($address, $period = 365, $type = 'da
2260
2265
return $ aResult ;
2261
2266
}
2262
2267
2263
- public function getAddressPriceHistoryGrouped ($ address , $ updateCache = FALSE ){
2268
+ public function getAddressPriceHistoryGrouped ($ address , $ updateCache = FALSE , $ showEth = FALSE ){
2264
2269
evxProfiler::checkpoint ('getAddressPriceHistoryGrouped ' , 'START ' , 'address= ' . $ address );
2265
2270
2266
- $ cache = 'address_operations_history- ' . $ address ;
2271
+ $ cache = 'address_operations_history- ' . $ address . ( $ showEth ? ' -eth ' : '' ) ;
2267
2272
$ result = $ this ->oCache ->get ($ cache , false , true );
2268
2273
$ updateCache = false ;
2269
2274
if ($ result && isset ($ result ['timestamp ' ])){
@@ -2289,7 +2294,7 @@ public function getAddressPriceHistoryGrouped($address, $updateCache = FALSE){
2289
2294
2290
2295
foreach ($ aSearch as $ cond ){
2291
2296
$ search = array ($ cond => $ address );
2292
- $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
2297
+ if (! $ showEth ) $ search ['contract ' ] = array ('$ne ' => 'ETH ' );
2293
2298
if ($ updateCache ){
2294
2299
$ search = array ('$and ' => array ($ search , array ('timestamp ' => array ('$gt ' => $ result ['timestamp ' ]))));
2295
2300
}
0 commit comments