Commit bd210511 authored by shajiaiming's avatar shajiaiming

调整请求时间

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