Commit aa04ceeb authored by shajiaiming's avatar shajiaiming

实现跨链自动交易

parent b71d7bf7
...@@ -47,6 +47,7 @@ class CrossChainController extends BaseController ...@@ -47,6 +47,7 @@ class CrossChainController extends BaseController
} else if (3 == $val['step']) { } else if (3 == $val['step']) {
$seq = 'thrid'; $seq = 'thrid';
} else { } else {
$seq = 'first';
} }
$data['txhex_' . $seq] = $val['tx']; $data['txhex_' . $seq] = $val['tx'];
......
...@@ -21,36 +21,35 @@ class CrossChainController extends Controller ...@@ -21,36 +21,35 @@ class CrossChainController extends Controller
echo date('Y-m-d H:i:s') . '暂无跨链交易计划' . PHP_EOL; echo date('Y-m-d H:i:s') . '暂无跨链交易计划' . PHP_EOL;
return 0; return 0;
} }
foreach ($model as $key => $val) {
go(function () use ($val) { foreach ($model as $val) {
\Co::sleep(0.5); // go(function () use ($val) {
if (1 == $val['step']) { // \Co::sleep(0.5);
if (1 == $val['current_step']) {
$seq = 'first'; $seq = 'first';
} else if (2 == $val['step']) { $step = 1;
} else if (2 == $val['current_step']) {
$seq = 'second'; $seq = 'second';
} else if (3 == $val['step']) { $step = 2;
} else if (3 == $val['current_step']) {
$seq = 'thrid'; $seq = 'thrid';
$step = 3;
} else { } else {
$seq = 'first';
$step = 1;
} }
$node_params = $val['transfer_url_' . $seq]; $node_params = $val['transfer_url_' . $seq];
$node_params = explode(':', $node_params);
$node_params = Yii::$app->params['chain_parallel']['wasm'][$val['coin_name'] . '_wallet']; $node_params = [
'scheme' => $node_params[0],
'host' => str_replace('//', '', $node_params[1]),
'port' => $node_params[2]
];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
$sign_str = $val['txhex_' . $seq];
$txHex = $val['txhex_' . $seq];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21';
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if (0 != $signRawTx['code']) {
$txhash = '0';
$msg = $signRawTx['msg'];
goto doEnd;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str); $result = $service->sendTransaction($sign_str);
if (0 != $result['code']) { if (0 != $result['code']) {
$txhash = '0'; $txhash = '0';
$msg = $result['msg']; $msg = $result['msg'];
...@@ -58,13 +57,17 @@ class CrossChainController extends Controller ...@@ -58,13 +57,17 @@ class CrossChainController extends Controller
} }
$txhash = $result['result']; $txhash = $result['result'];
$msg = 'success'; $msg = 'success';
$step = ($step + 1 > 3) ? 3 : ($step + 1);
doEnd : doEnd :
$currentModel = CoinAirDropTransfer::findOne($id); $current_step = $step;
$currentModel = CoinCrossChain::findOne($val['id']);
$currentModel->current_step = $current_step;
$currentModel->txhash = $txhash; $currentModel->txhash = $txhash;
$currentModel->msg = $msg; $currentModel->msg = $msg;
$currentModel->save(); $currentModel->save();
});
// });
} }
return 0; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment