123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace App\Servers;
- use App\Models\BlockInfo;
- use App\Models\BlockItems;
- use App\Models\CoinType;
- use App\Models\Config;
- use App\Models\Member;
- use App\Models\MemberCoins;
- use App\Servers\Icon\TronRPC;
- use App\Servers\Icon\Utils;
- use Illuminate\Support\Facades\DB;
- /**
- * Tron区块分析模块
- */
- class TronAnalyzeServer
- {
- public static function tronAnalyze()
- {
- $block_info = BlockInfo::where('id', 1)->first();
- if($block_info->{'num'}>=$block_info->{'analyze'} - 5 || true){
- $tron_block = TronRPC::CreationTron()->getBlockByNum();
- }else{
- $tron_block=$block_info->{'num'};
- }
- if ($block_info->{'analyze'} + 6 < $tron_block) {
- $analyze = $block_info->{'analyze'} + 1;
- $block_deal = TronRPC::CreationTron()->getBlockById($analyze);
- if (empty($block_deal)) return false;
- DB::beginTransaction();
- if (!empty($block_deal['transactions'])) {
- //USDT 合约地址 0xdac17f958d2ee523a2206206994597c13d831ec7
- $hy_address = '41a614f803b6fd780986a42c78ec9c7f77e6ded13c';
- foreach ($block_deal['transactions'] as $t_key=>$deal_info) {
- if(empty($deal_info['ret'][0]['contractRet']) || $deal_info['ret'][0]['contractRet']!='SUCCESS'){
- continue;
- }
- $block_item = [];
- $pay_data=$deal_info['raw_data']['contract'][0]['parameter']['value'];
- $my_hy_address=empty($pay_data['contract_address']) ?'':$pay_data['contract_address'];
- if ( $my_hy_address == $hy_address) {
- if(empty($pay_data['data']))continue;
- $input = $pay_data['data'];
- $to = '41'.substr($input, 32, 40);
- $value = substr($input, 72);
- $money = Utils::int2fund(Utils::hex2dec('0x' . $value), 6);
- $to = TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($to));
- $block_item = [
- 'm_id' => 0,
- 'coin_id' => 4,
- 'coin_name' => 'USDT',
- 'block_num' => $block_info->{'analyze'} + 1,
- 'money' => $money,
- 'from_a' => TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($pay_data['owner_address'])),
- 'hash' => $deal_info['txID'],
- 'to_a' => $to,
- 'pay_at' => date('Y-m-d H:i:s'),
- 'fee_limit' =>empty($deal_info['raw_data']['fee_limit'])?0:$deal_info['raw_data']['fee_limit'],
- ];
- }
- if (!empty($block_item)) {
- $member_coin = Member::whereIn('address', [$block_item['to_a'],$block_item['from_a']])->select(['id','address'])->first();
- if (!empty($member_coin)) {
- $block_item['m_id'] = $member_coin->{'id'};
- $block_item['to_type'] = $block_item['to_a']==$member_coin->{'address'}?1:2;
- $item_num = BlockItems::where('m_id', $block_item['m_id'])->where('hash', $block_item['hash'])->where('coin_id', $block_item['coin_id'])->count();
- if($item_num<=0){
- BlockItems::create($block_item);
- }
- }
- }
- }
- }
- BlockInfo::where('id', 1)->update(['analyze' => $block_info->{'analyze'} + 1, 'num' => $tron_block]);
- DB::commit();
- return true;
- }
- return false;
- }
- }
|