xielin 5 years ago
parent
commit
bdd1f5fd03
4 changed files with 48 additions and 43 deletions
  1. 2 2
      .env.example
  2. 42 37
      app/Console/Commands/Trace.php
  3. 3 3
      app/Http/Controllers/IndexController.php
  4. 1 1
      routes/api.php

+ 2 - 2
.env.example

@@ -28,7 +28,7 @@ CLUSTER=default
 APOLLO_NAMESPACES="application,community-manage"
 APOLLO_CONFIG_SERVER=http://127.0.0.1:18080
 
-RPC_NODE_URL=https://127.0.0.1:8888
-RPC_KEOSD_URL=http://127.0.0.1:8900
+RPC_NODE_URL=https://api.cypherglass.com
+RPC_KEOSD_URL=https://api.cypherglass.com
 OSS_URL=https://oss.caihongxingqiu.com/
 TRACE_SERVICE_URL=http://192.168.23.111:9900

+ 42 - 37
app/Console/Commands/Trace.php

@@ -133,44 +133,49 @@ class Trace extends Command
 
     protected function transcation($md5)
     {
-        $api = (new ChainFactory())->api(base_path());
-        $walapi = (new WalletFactory())->api(base_path());
-        $eos = (new EosRpc($api, $walapi));
-        $accountA = "alice";
-        $accountB = "bob";
-        $coinCode = "SYS";
-        $coin = "1.0000";//每次转移多少
+        try{
+            $api = (new ChainFactory())->api(base_path());
+            $walapi = (new WalletFactory())->api(base_path());
+            $eos = (new EosRpc($api, $walapi));
+            $accountA = "chxqsuyuanaa";
+            $accountB = "chxqsuyuanbb";
+            $coinCode = "EOS";
+            $coin = "0.1";//每次转多少
 
-        $walletPassword = "PW5KFL5mQSWauhwnYTMFU3v9ALhkTCuCkfvVJgzJTpRKZysygTJZe";
-        $walletName = "default";
-        $eos->setWalletInfo($walletName, $walletPassword);
-        $aliceBalance = $api->getCurrencyBalance('eosio.token', $accountA, $coinCode);
-        $bobBalance = $api->getCurrencyBalance('eosio.token', $accountB, $coinCode);
-        $balaceA = 0;
-        $balaceB = 0;
-        if (isset($aliceBalance[$accountA])) {
-            $balaceA = $aliceBalance[$accountA][0];
-        }
-        if (isset($bobBalance[$accountB])) {
-            $balaceB = $bobBalance[$accountB][0];
-        }
-        if ($balaceA == 0 && $balaceB == 0) {
-            $this->line("两个账号都没钱了,快充钱");
-            return;
-        }
-        if ($balaceA >= $coin * 2) {
-            $trans = $eos->transfer($accountA, $accountB, $coin . " " . $coinCode, $md5, 'eosio.token', false);
-        }elseif ($balaceB >= $coin * 2) {
-            $trans = $eos->transfer($accountB, $accountA, $coin . " " . $coinCode, $md5, 'eosio.token', false);
-        }else{
-            $this->line('账号余额不足');
-            return;
+            $walletPassword = "PW5KiK4oBMgjvxjhYxJzeRWNYtLot7GbH9wLM8pDmTH17yzUb4GTP";
+            $walletName = "caihongxingqiu";
+            $eos->setWalletInfo($walletName, $walletPassword);
+            $aliceBalance = $api->getCurrencyBalance('eosio.token', $accountA, $coinCode);
+            $bobBalance = $api->getCurrencyBalance('eosio.token', $accountB, $coinCode);
+            $balaceA = 0;
+            $balaceB = 0;
+            if (isset($aliceBalance[$accountA])) {
+                $balaceA = $aliceBalance[$accountA][0];
+            }
+            if (isset($bobBalance[$accountB])) {
+                $balaceB = $bobBalance[$accountB][0];
+            }
+            if ($balaceA == 0 && $balaceB == 0) {
+                $this->line("两个账号都没钱了,快充钱");
+                return false;
+            }
+            if ($balaceA >= $coin * 2) {
+                $trans = $eos->transfer($accountA, $accountB, $coin . " " . $coinCode, $md5, 'eosio.token', false);
+            }elseif ($balaceB >= $coin * 2) {
+                $trans = $eos->transfer($accountB, $accountA, $coin . " " . $coinCode, $md5, 'eosio.token', false);
+            }else{
+                $this->line('账号余额不足');
+                return false;
+            }
+            Log::debug('transinfo:'.\GuzzleHttp\json_encode($trans));
+            return [
+                'transaction_id' => $trans['trans']['transaction_id'] ?? '',
+                'block_num' => $trans['trans']['processed']['block_num'] ?? 0,
+                'block_time' => $trans['trans']['processed']['block_time'] ?? ''
+            ];
+        }catch (\Exception $exception){
+            $this->line('上链失败:'.$exception->getMessage());
+            return false;
         }
-
-        return [
-            'transaction_id' => $trans['trans']['transaction_id'] ?? '',
-            'block_num' => $trans['trans']['processed']['block_num'] ?? 0,
-            'block_time' => $trans['trans']['processed']['block_time'] ?? ''
-        ];
     }
 }

+ 3 - 3
app/Http/Controllers/IndexController.php

@@ -25,15 +25,15 @@ class IndexController extends Controller
         $this->metaRepository = $metaRepository;
     }
 
-    public function index(Request $request)
+    public function index(Request $request,$patch_num)
     {
-        $validator = Validator::make($request->all(), [
+        $validator = Validator::make(['patch_num'=>$patch_num], [
             'patch_num' => 'required'
         ]);
         if ($validator->fails()) {
             return $this->response->error($validator->errors()->first(), 500);
         }
-        $meta = $this->metaRepository->view($request->all());
+        $meta = $this->metaRepository->view(['patch_num'=>$patch_num]);
         if($meta){
             return $this->response->item($meta, new MetaTransformer());
         }

+ 1 - 1
routes/api.php

@@ -22,7 +22,7 @@ $api->version('v1', [
     $api->post('ueupload', 'UeditorController@index');
 
     //前台
-    $api->get('egg', 'IndexController@index');
+    $api->get('egg/{patch_num}', 'IndexController@index');
 
     //后台
     //登录