TronAnalyzeServer.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace App\Servers;
  3. use App\Jobs\SetMemberCoin;
  4. use App\Models\BlockInfo;
  5. use App\Models\BlockItems;
  6. use App\Models\BuyJobs;
  7. use App\Models\CoinType;
  8. use App\Models\Config;
  9. use App\Models\MemberCoins;
  10. use App\Models\MemberCoinTwo;
  11. use App\Servers\Icon\TronRPC;
  12. use App\Servers\Eth\Utils;
  13. use Illuminate\Support\Facades\DB;
  14. /**
  15. * Tron区块分析模块
  16. */
  17. class TronAnalyzeServer
  18. {
  19. public static function tronAnalyze()
  20. {
  21. $block_info = BlockInfo::where('id', 2)->first();
  22. if($block_info->{'num'}>=$block_info->{'analyze'} - 5 || true){
  23. $tron_block = TronRPC::CreationTron()->getBlockByNum();
  24. }else{
  25. $tron_block=$block_info->{'num'};
  26. }
  27. if ($block_info->{'analyze'} + 6 < $tron_block) {
  28. $analyze = $block_info->{'analyze'} + 1;
  29. $block_deal = TronRPC::CreationTron()->getBlockById($analyze);
  30. if (empty($block_deal)) return false;
  31. DB::beginTransaction();
  32. if (!empty($block_deal['transactions'])) {
  33. //USDT 合约地址 0xdac17f958d2ee523a2206206994597c13d831ec7
  34. // $hy_address = Config::where('key', 'hy_address')->value('value');
  35. $hy_address = '41a614f803b6fd780986a42c78ec9c7f77e6ded13c';
  36. foreach ($block_deal['transactions'] as $t_key=>$deal_info) {
  37. if(empty($deal_info['ret'][0]['contractRet']) || $deal_info['ret'][0]['contractRet']!='SUCCESS'){
  38. continue;
  39. }
  40. // var_dump('---------OK');
  41. $block_item = [];
  42. $pay_data=$deal_info['raw_data']['contract'][0]['parameter']['value'];
  43. $my_hy_address=empty($pay_data['contract_address']) ?'':$pay_data['contract_address'];
  44. if ( $my_hy_address == $hy_address) {
  45. if(empty($pay_data['data']))continue;
  46. $input = $pay_data['data'];
  47. $to = '41'.substr($input, 32, 40);
  48. $value = substr($input, 72);
  49. $money = Utils::int2fund(Utils::hex2dec('0x' . $value), 6);
  50. $to = TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($to));
  51. $block_item = [
  52. 'm_id' => 0,
  53. 'coin_id' => 4,
  54. 'coin_name' => 'USDT',
  55. 'block_num' => $block_info->{'analyze'} + 1,
  56. 'money' => $money,
  57. 'from_a' => TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($pay_data['owner_address'])),
  58. 'hash' => $deal_info['txID'],
  59. 'to_a' => $to,
  60. 'pay_at' => date('Y-m-d H:i:s'),
  61. 'fee_limit' =>empty($deal_info['raw_data']['fee_limit'])?0:$deal_info['raw_data']['fee_limit'],
  62. ];
  63. }
  64. if (!empty($block_item)) {
  65. $member_coin = MemberCoins::where('coin_id', $block_item['coin_id'])->whereIn('address', [$block_item['to_a'],$block_item['from_a']])->first();
  66. if (!empty($member_coin)) {
  67. $block_item['m_id'] = $member_coin->{'m_id'};
  68. $block_item['to_type'] = $block_item['to_a']==$member_coin->{'address'}?1:2;
  69. $item_num = BlockItems::where('m_id', $block_item['m_id'])->where('hash', $block_item['hash'])->where('coin_id', $block_item['coin_id'])->count();
  70. $receipt_trx='TC35X33LLF3ARY1P1HzYZaFngVCH5GKLjv';
  71. if ($item_num <= 0 && $block_item['to_type']==1) {
  72. //添加广播转账信息
  73. $block_item = BlockItems::create($block_item);
  74. $mix_num = 0.01;
  75. if ($block_item['money'] >= $mix_num) {
  76. BroadcastServer::addBroadcast($block_item['coin_id'], $block_item['money'], $member_coin['address'], $member_coin['private'], $receipt_trx, $member_coin['m_id'], $block_item->{'id'}, 1);
  77. }
  78. }elseif ($item_num <= 0 && $block_item['to_type']==2){
  79. if( $block_item['to_a']==$receipt_trx){
  80. $block_item = BlockItems::create($block_item);
  81. //转出成功后天就余额
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. BlockInfo::where('id', 2)->update(['analyze' => $block_info->{'analyze'} + 1, 'num' => $tron_block]);
  89. DB::commit();
  90. return true;
  91. }
  92. return false;
  93. }
  94. }