Commit fb4759e4 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into develop

parents 8add2c6c b7c28d00
......@@ -8,6 +8,8 @@
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinTokenTransfer;
use common\service\chain33\Chain33Service;
use Yii;
......@@ -45,4 +47,80 @@ class TradeController extends BaseController
}
public function actionAddressIsExist()
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if(!$coinTokenTransfer){
return ['code' => 0, 'msg' => 'record does not exist'];
}
return ['code' => 1, 'msg' => 'record already exists'];
}
public function actionTokenTransfer()
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if($coinTokenTransfer){
return ['code' => -1, 'msg' => 'record already exists'];
}
$fee = 100000;
$amount = 1 * 1e8;
$note = '2050糖果';
$execer = 'user.p.youngplus.token';
$isToken = true;
$tokenSymbol = 'YPLUS';
$service = new Chain33Service();
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){
$msg = $createRawTransaction['msg'];
$code = -1;
goto doEnd;
}
$txHex = $createRawTransaction['result'];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2';
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
$msg = $signRawTx['msg'];
$code = -1;
goto doEnd;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
$msg = $result['msg'];
$code = -1;
goto doEnd;
}
$code = 1;
$msg = $result['result'];
doEnd :
$coinTokenTransfer = new CoinTokenTransfer();
$coinTokenTransfer->coin_address = $to;
$coinTokenTransfer->msg = $msg;
$coinTokenTransfer->code = $code;
$coinTokenTransfer->save();
return ['code' => $code, 'msg' => $msg];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinTokenTransfer extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_token_transfer}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['coin_address','msg', 'code'], 'required'],
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['coin_address','msg', 'code'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
......@@ -156,6 +156,21 @@ class Chain33Service
return $this->send($params, 'Chain33.SendToAddress');
}
public function createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer)
{
$params = [
"to" => $to,
"amount" => $amount,
"isToken" => $isToken,
"tokenSymbol" => $tokenSymbol,
"fee" => $fee,
"note" => $note,
"execer" => $execer,
];
return $this->send($params, 'Chain33.CreateRawTransaction');
}
public function createRawTransaction($to, $amount, $fee, $note,$execer)
{
$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