@@ -47,6 +47,8 @@ class MainController extends Controller{
4747
4848 const bittrexMarketUrl = 'https://api.bittrex.com/v3/markets/LBC-BTC/ticker ' ;
4949
50+ const coingeckoURL = 'https://api.coingecko.com/api/v3/simple/price?ids=lbry-credits&vs_currencies=btc ' ;
51+
5052 const blockchainTickerUrl = 'https://blockchain.info/ticker ' ;
5153
5254 const tagReceiptAddress = 'bLockNgmfvnnnZw7bM6SPz6hk5BVzhevEp ' ;
@@ -94,11 +96,13 @@ protected function _getLatestPrice(): string{
9496 }
9597
9698 if ($ shouldRefreshPrice ) {
97- $ btrxjson = json_decode (self ::curl_get (self ::bittrexMarketUrl));
99+ $ coingeckoJSON = Cache::remember ('coingecko ' ,60 ,static function (){
100+ return json_decode (self ::curl_get (self ::coingeckoURL));
101+ });
98102 $ blckjson = json_decode (self ::curl_get (self ::blockchainTickerUrl));
99103
100- if ($ btrxjson ) {
101- $ onelbc = $ btrxjson -> bidRate ;
104+ if ($ coingeckoJSON ) {
105+ $ onelbc = $ coingeckoJSON ->{ ' lbry-credits ' }-> btc ;
102106 $ lbcPrice = 0 ;
103107 if (isset ($ blckjson ->USD )) {
104108 $ lbcPrice = $ onelbc * $ blckjson ->USD ->buy ;
@@ -162,7 +166,7 @@ public function claims($id = null): JsonResponse|Response|RedirectResponse|View{
162166// $count = $stmt->fetch(\PDO::FETCH_OBJ);
163167 $ numClaims = 20000000 ;
164168
165- $ stmt = $ conn ->getPdo ()->query ('SELECT MAX(id ) AS MaxId FROM claim ' );
169+ $ stmt = $ conn ->getPdo ()->query ('SELECT MAX(Id ) AS MaxId FROM Claims ' );
166170 $ res = $ stmt ->fetch (PDO ::FETCH_OBJ );
167171 $ maxClaimId = $ res ->MaxId ;
168172
@@ -181,7 +185,7 @@ public function claims($id = null): JsonResponse|Response|RedirectResponse|View{
181185 }
182186
183187 $ blockedList = json_decode ($ this ->_getBlockedList ());
184- $ claims = Claim::query ()->addSelect (['publisher ' => 'C.name ' , 'publisher_transaction_hash_id ' => 'C.transaction_hash_id ' , 'publisher_vout ' => 'C.vout ' ])->leftJoin ('Claims ' ,'claim_id ' ,'= ' ,'Claims.publisher_id ' )->where ('Claims.id ' ,'> ' ,$ startLimitId )->where ( 'Claims.id ' ,'<= ' ,$ endLimitId )->orderByDesc ('Claims.id ' )->get ();
188+ $ claims = []; // Claim::query()->selectRaw('Name AS Publisher')-> addSelect(['publisher' => 'C.name', 'publisher_transaction_hash_id' => 'C.transaction_hash_id', 'publisher_vout' => 'C.vout'])->leftJoin('Claims','claim_id','=','Claims.publisher_id')->where('Claims.id','>',$startLimitId)->where( 'Claims.Id ','<=',$endLimitId)->orderByDesc('Id ')->get();
185189
186190 for ($ i = 0 ; $ i < count ($ claims ); $ i ++) {
187191 if ($ canConvert && $ claims [$ i ]->fee > 0 && $ claims [$ i ]->fee_currency == 'USD ' ) {
@@ -344,7 +348,7 @@ public function blocks($height = null): JsonResponse|Response|RedirectResponse|V
344348 $ page = intval (request ()->query ('page ' ));
345349
346350 $ conn = DB ::connection ();
347- $ stmt = $ conn ->getPdo ()->query ('SELECT height AS Total FROM block order by id desc limit 1 ' );
351+ $ stmt = $ conn ->getPdo ()->query ('SELECT Height AS Total FROM Blocks order by Id desc limit 1 ' );
348352 $ count = $ stmt ->fetch (PDO ::FETCH_OBJ );
349353 $ numBlocks = $ count ->Total ;
350354
@@ -357,8 +361,8 @@ public function blocks($height = null): JsonResponse|Response|RedirectResponse|V
357361 }
358362
359363 $ offset = ($ page - 1 ) * $ pageLimit ;
360- $ currentBlock = Block::query ()->select (['height ' ])->orderByDesc ('height ' )->first ();
361- $ blocks = Block::query ()->select (['height ' , 'difficulty ' , 'block_size ' , 'nonce ' , 'block_time ' , ' tx_count ' ])->offset ($ offset )->limit ($ pageLimit )->orderByDesc ('height ' )->get ();
364+ $ currentBlock = Block::query ()->select (['Height ' ])->orderByDesc ('Height ' )->first ();
365+ $ blocks = Block::query ()->select (['Height ' , 'Difficulty ' , 'BlockSize ' , 'Nonce ' , 'BlockTime ' ])->offset ($ offset )->limit ($ pageLimit )->orderByDesc ('Height ' )->get ();//'tx_count'
362366
363367 return self ::generateResponse ('main.blocks ' ,[
364368 'currentBlock ' => $ currentBlock ,
@@ -632,8 +636,9 @@ public function apiblocksize($timePeriod = '24h'): array|JsonResponse{
632636
633637 $ conn = DB ::connection ();
634638 // get avg block sizes for the time period
635- $ stmt = $ conn ->getPdo ()->query ("SELECT AVG(block_size) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(block_time), ' $ sqlDateFormat') AS TimePeriod " .
636- "FROM block WHERE DATE_FORMAT(FROM_UNIXTIME(block_time), ' $ sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC " , [$ start ->format ($ dateFormat )]);
639+ $ stmt = $ conn ->getPdo ()->prepare ("SELECT AVG(BlockSize) AS AvgBlockSize, DATE_FORMAT(FROM_UNIXTIME(BlockTime), ' $ sqlDateFormat') AS TimePeriod " .
640+ "FROM Blocks WHERE DATE_FORMAT(FROM_UNIXTIME(BlockTime), ' $ sqlDateFormat') >= ? GROUP BY TimePeriod ORDER BY TimePeriod ASC " );
641+ $ stmt ->execute ([$ start ->format ($ dateFormat )]);
637642 $ avgBlockSizes = $ stmt ->fetchAll (PDO ::FETCH_OBJ );
638643 foreach ($ avgBlockSizes as $ size ) {
639644 if (!isset ($ resultSet [$ size ->TimePeriod ])) {
0 commit comments