Commit 11f9ce15 authored by shajiaiming's avatar shajiaiming

发币

parent 8e5e1f52
......@@ -2,12 +2,12 @@
namespace api\controllers;
use common\models\psources\CoinIssueRecord;
use common\models\psources\CoinPlatform;
use Yii;
use yii\data\Pagination;
use api\base\BaseController;
use common\models\psources\CoinPlatform;
use common\models\psources\CoinIssueCoin;
use common\models\psources\CoinIssueChainRecord;
class IssueCoinController extends BaseController
{
......@@ -49,6 +49,14 @@ class IssueCoinController extends BaseController
$code = -1;
goto doEnd;
}
$pre_create_tx = isset($result['pre_create_tx']) ? $result['pre_create_tx'] : '';
if (false == $pre_create_tx) {
$msg = '预签名错误';
$code = -1;
goto doEnd;
}
$result = [
'name' => isset($result['name']) ? $result['name'] : '',
'symbol' => isset($result['symbol']) ? strtoupper($result['symbol']) : '',
......@@ -60,8 +68,6 @@ class IssueCoinController extends BaseController
'chain_id' => $chain_id,
'charge_unit_id' => isset($result['charge_unit_id']) ? $result['charge_unit_id'] : '',
'charge' => $coin_platform->issue_charge,
'step_one_tx' => isset($result['step_one_tx']) ? $result['step_one_tx'] : '',
'step_one_result' => 0
];
$model->load($result, '');
if (!$model->save()) {
......@@ -73,6 +79,16 @@ class IssueCoinController extends BaseController
$code = 0;
$data = $model->getPrimaryKey();
$params = [
'pre_create_tx' => $pre_create_tx,
'finish_tx' => '0',
'issue_coin_id' => $data,
];
$transfer_model = new CoinIssueChainRecord();
$transfer_model->setScenario(CoinIssueChainRecord::SCENARIOS_PRE_CREATE);
$transfer_model->load($params,'');
$transfer_model->save();
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
......
<?php
namespace common\models\psources;
use Yii;
class CoinIssueChainRecord extends CommonActiveRecord
{
//定义场景
const SCENARIOS_PRE_CREATE = 'create';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_issue_chain_record}}';
}
public function rules()
{
return [
[['pre_create_tx', 'pre_send_transaction', 'pre_query_transaction', 'finish_tx', 'finish_send_transaction', 'finish_query_transaction', 'issue_coin_id'], 'required'],
[['issue_coin_id'], 'integer'],
[['finish_tx'], 'safe']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_PRE_CREATE => ['pre_create_tx', 'issue_coin_id', 'finish_tx'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ class CoinIssueCoin extends CommonActiveRecord
public function rules()
{
return [
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id', 'charge_unit_id', 'charge', 'step_one_tx'], 'required'],
[['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'], 'required'],
[['total', 'category', 'platform_id', 'chain_id', 'charge_unit_id'], 'integer'],
['introduction', 'string', 'length' => [1, 20]],
['symbol', 'string', 'length' => [1, 6]],
......@@ -89,7 +89,7 @@ class CoinIssueCoin extends CommonActiveRecord
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id', 'charge_unit_id', 'charge', 'step_one_tx', 'step_one_result'],
self:: SCENARIOS_CREATE => ['name', 'symbol', 'total', 'owner', 'introduction', 'category', 'platform_id', 'chain_id', 'charge_unit_id', 'charge'],
self:: SCENARIOS_UPDATE => ['status', 'msg'],
self:: SCENARIOS_CANCEL => ['status'],
];
......@@ -109,7 +109,6 @@ class CoinIssueCoin extends CommonActiveRecord
'msg' => '失败原因',
'status' => '状态',
'charge_unit_id' => '手续费',
'step_one_tx' => '签名',
];
}
......@@ -144,4 +143,9 @@ class CoinIssueCoin extends CommonActiveRecord
{
return $this->hasOne(CoinSupportedCoin::className(), ['id' => 'charge_unit_id']);
}
public function getTransfer()
{
return $this->hasOne(CoinIssueChainTransfer::className(), ['issue_coin_id' => 'id']);
}
}
\ No newline at end of file
<?php
namespace console\controllers;
use common\models\psources\CoinIssueChainRecord;
use common\service\chain33\Chain33Service;
use Yii;
use yii\console\Controller;
class IssueChainTransferController extends Controller
{
public function actionSendTransaction($step)
{
if (1 == $step) {
$columns = ['id', 'pre_create_tx', 'issue_coin_id'];
$condition = [
'pre_send_transaction' => '0',
'pre_query_transaction' => '0'
];
}
if (2 == $step) {
$columns = ['id', 'finish_tx', 'issue_coin_id'];
$condition = [
'pre_query_transaction' => 'success',
'finish_send_transaction' => '0',
'finish_query_transaction' => '0'
];
}
$model = CoinIssueChainRecord::find()->select($columns)->where($condition)->all();
if (false == $model) {
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '暂无交易计划' . PHP_EOL;
return 0;
}
$node = Yii::$app->params['chain_nodes']['STO'];
$chain_service = new Chain33Service($node);
foreach ($model as $val) {
$result = $chain_service->sendTransaction($val->pre_create_tx);
if (0 != $result['code']) {
$params = [
'pre_query_transaction' => $result['msg']
];
goto doEnd;
}
$params = [
'pre_send_transaction' => $result['result']
];
doEnd :
$current_record = CoinIssueChainRecord::findOne($val->id);
$current_record->load($params, '');
$current_record->update();
echo json_encode($current_record->errors);exit;
}
}
public function actionQueryTransaction($step)
{
if (1 == $step) {
$model = CoinIssueChainRecord::find()->where(['<>' , 'pre_send_transaction', '0'])->all();
}
if (2 == $step) {
$model = CoinIssueChainRecord::find()->where(['<>' , 'pre_send_transaction', '0'])->andWhere(['<>', 'finish_send_transaction', '0'])->all();
}
if (false == $model) {
echo date('Y-m-d H:i:s') . ' STEP: ' . $step . '暂无完成的发送交易' . PHP_EOL;
return 0;
}
foreach ($model as $val) {
}
}
}
\ No newline at end of file
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