Commit aa04ceeb authored by shajiaiming's avatar shajiaiming

实现跨链自动交易

parent b71d7bf7
......@@ -47,6 +47,7 @@ class CrossChainController extends BaseController
} else if (3 == $val['step']) {
$seq = 'thrid';
} else {
$seq = 'first';
}
$data['txhex_' . $seq] = $val['tx'];
......
......@@ -21,50 +21,53 @@ class CrossChainController extends Controller
echo date('Y-m-d H:i:s') . '暂无跨链交易计划' . PHP_EOL;
return 0;
}
foreach ($model as $key => $val) {
go(function () use ($val) {
\Co::sleep(0.5);
if (1 == $val['step']) {
$seq = 'first';
} else if (2 == $val['step']) {
$seq = 'second';
} else if (3 == $val['step']) {
$seq = 'thrid';
} else {
}
foreach ($model as $val) {
// go(function () use ($val) {
// \Co::sleep(0.5);
if (1 == $val['current_step']) {
$seq = 'first';
$step = 1;
} else if (2 == $val['current_step']) {
$seq = 'second';
$step = 2;
} else if (3 == $val['current_step']) {
$seq = 'thrid';
$step = 3;
} else {
$seq = 'first';
$step = 1;
}
$node_params = $val['transfer_url_' . $seq];
$node_params = $val['transfer_url_' . $seq];
$node_params = explode(':', $node_params);
$node_params = [
'scheme' => $node_params[0],
'host' => str_replace('//', '', $node_params[1]),
'port' => $node_params[2]
];
$service = new Chain33Service($node_params);
$sign_str = $val['txhex_' . $seq];
$result = $service->sendTransaction($sign_str);
$node_params = Yii::$app->params['chain_parallel']['wasm'][$val['coin_name'] . '_wallet'];
$service = new Chain33Service($node_params);
if (0 != $result['code']) {
$txhash = '0';
$msg = $result['msg'];
goto doEnd;
}
$txhash = $result['result'];
$msg = 'success';
$step = ($step + 1 > 3) ? 3 : ($step + 1);
$txHex = $val['txhex_' . $seq];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21';
$expire = '1m';
doEnd :
$current_step = $step;
$currentModel = CoinCrossChain::findOne($val['id']);
$currentModel->current_step = $current_step;
$currentModel->txhash = $txhash;
$currentModel->msg = $msg;
$currentModel->save();
$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);
if (0 != $result['code']) {
$txhash = '0';
$msg = $result['msg'];
goto doEnd;
}
$txhash = $result['result'];
$msg = 'success';
doEnd :
$currentModel = CoinAirDropTransfer::findOne($id);
$currentModel->txhash = $txhash;
$currentModel->msg = $msg;
$currentModel->save();
});
// });
}
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