Commit c2310492 authored by shajiaiming's avatar shajiaiming

new version block trade

parent e03eaab6
...@@ -99,6 +99,26 @@ class Chain33Business ...@@ -99,6 +99,26 @@ class Chain33Business
return ['code' => -1, 'msg' => $result['msg']]; return ['code' => -1, 'msg' => $result['msg']];
} }
public static function tradeToken($amount, $execName, $fee, $isToken = True, $to, $tokenSymbol = '')
{
$service = new Chain33Service();
$result = $service->structureTrade($amount, $execName, $fee, $isToken, $to, $tokenSymbol);
if ($result['code'] != 0 ) {
return ['code' => -1, 'msg' => $result['error']];
}
$signBefore = $result['result'];
$result = $service->signTrade($addr = '1AEoZD1fKUGjGtxkXS7j1zieVWSkrA1fLn', $expire = "2h", $signBefore);
if ($result['code'] != 0 ) {
return ['code' => -1, 'msg' => $result['error']];
}
$signAfter = $result['result'];
$result = $service->sendTrade($signAfter);
if ($result['code'] != 0 ) {
return ['code' => -1, 'msg' => $result['error']];
}
return $result['result'];
}
/** /**
* 获取最新的区块 * 获取最新的区块
*/ */
......
...@@ -164,14 +164,22 @@ class CoinReleaseCheck extends BaseActiveRecord ...@@ -164,14 +164,22 @@ class CoinReleaseCheck extends BaseActiveRecord
} }
$walletpasswd = Yii::$app->redis->get('wallet_passwd'); $walletpasswd = Yii::$app->redis->get('wallet_passwd');
Chain33Business::unLockWallet($walletpasswd); Chain33Business::unLockWallet($walletpasswd);
$result = Chain33Business::transToken( $result = Chain33Business::tradeToken(
trim($address),
trim($this->to_address),
(int)$this->amount, (int)$this->amount,
"锁仓释放", '',
1000,
$isToken, $isToken,
trim($this->to_address),
$this->coin $this->coin
); );
// $result = Chain33Business::transToken(
// trim($address),
// trim($this->to_address),
// (int)$this->amount,
// "锁仓释放",
// $isToken,
// $this->coin
// );
if (is_array($result)) { if (is_array($result)) {
$trans->rollBack(); $trans->rollBack();
throw new \Exception(Yii::t('backend', $result['msg']), $result['code']); throw new \Exception(Yii::t('backend', $result['msg']), $result['code']);
......
...@@ -130,6 +130,38 @@ class Chain33Service ...@@ -130,6 +130,38 @@ class Chain33Service
return $this->send($params, 'Chain33.SendToAddress'); return $this->send($params, 'Chain33.SendToAddress');
} }
public function structureTrade($amount, $execName, $fee, $isToken = True, $to, $tokenSymbol = '')
{
$params = [
"amount" => $amount,
"execName" => $execName,
"fee" => $fee,
"isToken" => $isToken ? true : false,
"to" => $to,
"tokenSymbol" => strtoupper($tokenSymbol)
];
return $this->send($params, 'Chain33.CreateRawTransaction');
}
public function signTrade($addr, $expire = '2h', $txHex)
{
$params = [
"addr" => $addr,
"expire" => $expire,
"txHex" => $txHex
];
return $this->send($params, 'Chain33.SignRawTx');
}
public function sendTrade($data)
{
$params = [
"data" => $data,
];
return $this->send($params, 'Chain33.SendTransaction');
}
/** /**
* 获取最新的区块 * 获取最新的区块
*/ */
......
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