Commit bd210511 authored by shajiaiming's avatar shajiaiming

调整请求时间

parent 176cbc54
This diff is collapsed.
...@@ -20,7 +20,7 @@ class Chain33Service ...@@ -20,7 +20,7 @@ class Chain33Service
public function __construct($parameter = []) public function __construct($parameter = [])
{ {
if(empty($parameter)){ if (empty($parameter)) {
$this->node_params = Yii::$app->params['chain33']; $this->node_params = Yii::$app->params['chain33'];
} else { } else {
$this->node_params = $parameter; $this->node_params = $parameter;
...@@ -31,8 +31,8 @@ class Chain33Service ...@@ -31,8 +31,8 @@ class Chain33Service
{ {
$config = $this->node_params; $config = $this->node_params;
$scheme = $config['scheme'] ?? 'http'; $scheme = $config['scheme'] ?? 'http';
$host = $config['host'] ?? '127.0.0.1'; $host = $config['host'] ?? '127.0.0.1';
$port = (string)$config['port'] ?? ''; $port = (string)$config['port'] ?? '';
if ($port) { if ($port) {
return $scheme . '://' . $host . ':' . $port; return $scheme . '://' . $host . ':' . $port;
} else { } else {
...@@ -44,9 +44,9 @@ class Chain33Service ...@@ -44,9 +44,9 @@ class Chain33Service
{ {
$data = [ $data = [
'jsonrpc' => '2.0', 'jsonrpc' => '2.0',
'id' => 0, 'id' => 0,
'method' => $method, 'method' => $method,
'params' => [], 'params' => [],
]; ];
if (!empty($params)) { if (!empty($params)) {
$data['params'][] = $params; $data['params'][] = $params;
...@@ -56,7 +56,11 @@ class Chain33Service ...@@ -56,7 +56,11 @@ class Chain33Service
public function send($params = [], $method = 'Chain33.Query') public function send($params = [], $method = 'Chain33.Query')
{ {
$ch = new Curl(); $timeout = [
'connect_timeout' => 50000,
'timeout_ms' => 40000
];
$ch = new Curl($timeout);
$jsonrpc = self::jsonRpcBuild($params, $method); $jsonrpc = self::jsonRpcBuild($params, $method);
$ch->setHeader('Content-Type', 'application/json'); $ch->setHeader('Content-Type', 'application/json');
$ch->setRawPostData($jsonrpc); $ch->setRawPostData($jsonrpc);
...@@ -124,7 +128,7 @@ class Chain33Service ...@@ -124,7 +128,7 @@ class Chain33Service
* 获取地址下的所有token资产 * 获取地址下的所有token资产
* *
* @param string|array $address * @param string|array $address
* @param string $symbol * @param string $symbol
* @return array * @return array
*/ */
public function getAccountTokenAssets($address, $symbol) public function getAccountTokenAssets($address, $symbol)
...@@ -133,8 +137,8 @@ class Chain33Service ...@@ -133,8 +137,8 @@ class Chain33Service
$address = [$address]; $address = [$address];
} }
$params = [ $params = [
"addresses" => $address, "addresses" => $address,
"execer" => "user.p.guodun.token", "execer" => "user.p.guodun.token",
"tokenSymbol" => $symbol "tokenSymbol" => $symbol
]; ];
return $this->send($params, 'token.GetTokenBalance'); return $this->send($params, 'token.GetTokenBalance');
...@@ -147,18 +151,18 @@ class Chain33Service ...@@ -147,18 +151,18 @@ class Chain33Service
* @param $to * @param $to
* @param $amount * @param $amount
* @param string $note * @param string $note
* @param bool $isToken * @param bool $isToken
* @param string $tokenSymbol * @param string $tokenSymbol
* @return array * @return array
*/ */
public function extractToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '') public function extractToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '')
{ {
$params = [ $params = [
"from" => $to, "from" => $to,
"to" => $from, "to" => $from,
"amount" => -$amount, "amount" => -$amount,
"note" => $note, "note" => $note,
"isToken" => $isToken ? true : false, "isToken" => $isToken ? true : false,
"tokenSymbol" => strtoupper($tokenSymbol) "tokenSymbol" => strtoupper($tokenSymbol)
]; ];
return $this->send($params, 'Chain33.SendToAddress'); return $this->send($params, 'Chain33.SendToAddress');
...@@ -171,18 +175,18 @@ class Chain33Service ...@@ -171,18 +175,18 @@ class Chain33Service
* @param $to * @param $to
* @param $amount * @param $amount
* @param string $note * @param string $note
* @param bool $isToken * @param bool $isToken
* @param string $tokenSymbol * @param string $tokenSymbol
* @return array * @return array
*/ */
public function transToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '') public function transToken($from, $to, $amount, $note = '', $isToken = true, $tokenSymbol = '')
{ {
$params = [ $params = [
"from" => $from, "from" => $from,
"to" => $to, "to" => $to,
"amount" => $amount, "amount" => $amount,
"note" => $note, "note" => $note,
"isToken" => $isToken ? true : false, "isToken" => $isToken ? true : false,
"tokenSymbol" => strtoupper($tokenSymbol) "tokenSymbol" => strtoupper($tokenSymbol)
]; ];
return $this->send($params, 'Chain33.SendToAddress'); return $this->send($params, 'Chain33.SendToAddress');
...@@ -191,25 +195,25 @@ class Chain33Service ...@@ -191,25 +195,25 @@ class Chain33Service
public function createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer) public function createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer)
{ {
$params = [ $params = [
"to" => $to, "to" => $to,
"amount" => $amount, "amount" => $amount,
"isToken" => $isToken, "isToken" => $isToken,
"tokenSymbol" => $tokenSymbol, "tokenSymbol" => $tokenSymbol,
"fee" => $fee, "fee" => $fee,
"note" => $note, "note" => $note,
"execer" => $execer, "execer" => $execer,
]; ];
return $this->send($params, 'Chain33.CreateRawTransaction'); return $this->send($params, 'Chain33.CreateRawTransaction');
} }
public function createRawTransaction($to, $amount, $fee, $note,$execer) public function createRawTransaction($to, $amount, $fee, $note, $execer)
{ {
$params = [ $params = [
"to" => $to, "to" => $to,
"amount" => $amount, "amount" => $amount,
"fee" => $fee, "fee" => $fee,
"note" => $note, "note" => $note,
"execer" => $execer, "execer" => $execer,
]; ];
...@@ -274,11 +278,11 @@ class Chain33Service ...@@ -274,11 +278,11 @@ class Chain33Service
public function structureTrade($amount, $execName, $fee, $isToken = True, $to, $tokenSymbol = '') public function structureTrade($amount, $execName, $fee, $isToken = True, $to, $tokenSymbol = '')
{ {
$params = [ $params = [
"amount" => $amount, "amount" => $amount,
"execName" => $execName, "execName" => $execName,
"fee" => $fee, "fee" => $fee,
"isToken" => $isToken ? true : false, "isToken" => $isToken ? true : false,
"to" => $to, "to" => $to,
"tokenSymbol" => strtoupper($tokenSymbol) "tokenSymbol" => strtoupper($tokenSymbol)
]; ];
return $this->send($params, 'Chain33.CreateRawTransaction'); return $this->send($params, 'Chain33.CreateRawTransaction');
...@@ -287,9 +291,9 @@ class Chain33Service ...@@ -287,9 +291,9 @@ class Chain33Service
public function signTrade($addr, $expire = '2h', $txHex) public function signTrade($addr, $expire = '2h', $txHex)
{ {
$params = [ $params = [
"addr" => $addr, "addr" => $addr,
"expire" => $expire, "expire" => $expire,
"txHex" => $txHex "txHex" => $txHex
]; ];
return $this->send($params, 'Chain33.SignRawTx'); return $this->send($params, 'Chain33.SignRawTx');
} }
...@@ -297,7 +301,7 @@ class Chain33Service ...@@ -297,7 +301,7 @@ class Chain33Service
public function sendTrade($data) public function sendTrade($data)
{ {
$params = [ $params = [
"data" => $data, "data" => $data,
]; ];
return $this->send($params, 'Chain33.SendTransaction'); return $this->send($params, 'Chain33.SendTransaction');
} }
...@@ -329,12 +333,12 @@ class Chain33Service ...@@ -329,12 +333,12 @@ class Chain33Service
public function getTxByAddr($addr, $flag, $count, $direction, $height, $index) public function getTxByAddr($addr, $flag, $count, $direction, $height, $index)
{ {
$params = [ $params = [
'addr' => $addr, 'addr' => $addr,
'flag' => $flag, 'flag' => $flag,
'count' => $count, 'count' => $count,
'direction' => $direction, 'direction' => $direction,
'height' => $height, 'height' => $height,
'index' => $index 'index' => $index
]; ];
return $this->send($params, 'Chain33.GetTxByAddr'); return $this->send($params, 'Chain33.GetTxByAddr');
} }
...@@ -359,9 +363,9 @@ class Chain33Service ...@@ -359,9 +363,9 @@ class Chain33Service
public function unLockWallet($password) public function unLockWallet($password)
{ {
$params = [ $params = [
'passwd' => $password, 'passwd' => $password,
'walletorticket' => false, 'walletorticket' => false,
'timeout' => 30 'timeout' => 30
]; ];
return $this->send($params, 'Chain33.UnLock'); return $this->send($params, 'Chain33.UnLock');
} }
......
...@@ -51,7 +51,6 @@ class CrossChainController extends Controller ...@@ -51,7 +51,6 @@ class CrossChainController extends Controller
'scheme' => $transfer_url[0], 'scheme' => $transfer_url[0],
'host' => str_replace('//', '', $transfer_url[1]), 'host' => str_replace('//', '', $transfer_url[1]),
'port' => isset($transfer_url[2]) ? $transfer_url[2] : '', 'port' => isset($transfer_url[2]) ? $transfer_url[2] : '',
'timeout' => 100
]; ];
$service = new Chain33Service($node_params); $service = new Chain33Service($node_params);
......
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