Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
8e5e1f52
Commit
8e5e1f52
authored
Oct 30, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分步交易
parent
5debe802
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
124 additions
and
81 deletions
+124
-81
IssueCoinController.php
api/controllers/IssueCoinController.php
+3
-1
CoinIssueCoin.php
common/models/psources/CoinIssueCoin.php
+3
-2
Chain33Service.php
common/service/chain33/Chain33Service.php
+9
-0
IssueCoinController.php
console/controllers/IssueCoinController.php
+109
-78
No files found.
api/controllers/IssueCoinController.php
View file @
8e5e1f52
...
@@ -59,7 +59,9 @@ class IssueCoinController extends BaseController
...
@@ -59,7 +59,9 @@ class IssueCoinController extends BaseController
'platform_id'
=>
$platform_id
,
'platform_id'
=>
$platform_id
,
'chain_id'
=>
$chain_id
,
'chain_id'
=>
$chain_id
,
'charge_unit_id'
=>
isset
(
$result
[
'charge_unit_id'
])
?
$result
[
'charge_unit_id'
]
:
''
,
'charge_unit_id'
=>
isset
(
$result
[
'charge_unit_id'
])
?
$result
[
'charge_unit_id'
]
:
''
,
'charge'
=>
$coin_platform
->
issue_charge
'charge'
=>
$coin_platform
->
issue_charge
,
'step_one_tx'
=>
isset
(
$result
[
'step_one_tx'
])
?
$result
[
'step_one_tx'
]
:
''
,
'step_one_result'
=>
0
];
];
$model
->
load
(
$result
,
''
);
$model
->
load
(
$result
,
''
);
if
(
!
$model
->
save
())
{
if
(
!
$model
->
save
())
{
...
...
common/models/psources/CoinIssueCoin.php
View file @
8e5e1f52
...
@@ -39,7 +39,7 @@ class CoinIssueCoin extends CommonActiveRecord
...
@@ -39,7 +39,7 @@ class CoinIssueCoin extends CommonActiveRecord
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
'required'
],
[[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
,
'step_one_tx'
],
'required'
],
[[
'total'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
],
'integer'
],
[[
'total'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
],
'integer'
],
[
'introduction'
,
'string'
,
'length'
=>
[
1
,
20
]],
[
'introduction'
,
'string'
,
'length'
=>
[
1
,
20
]],
[
'symbol'
,
'string'
,
'length'
=>
[
1
,
6
]],
[
'symbol'
,
'string'
,
'length'
=>
[
1
,
6
]],
...
@@ -89,7 +89,7 @@ class CoinIssueCoin extends CommonActiveRecord
...
@@ -89,7 +89,7 @@ class CoinIssueCoin extends CommonActiveRecord
public
function
scenarios
()
public
function
scenarios
()
{
{
$scenarios
=
[
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'name'
,
'symbol'
,
'total'
,
'owner'
,
'introduction'
,
'category'
,
'platform_id'
,
'chain_id'
,
'charge_unit_id'
,
'charge'
],
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_UPDATE
=>
[
'status'
,
'msg'
],
self
::
SCENARIOS_UPDATE
=>
[
'status'
,
'msg'
],
self
::
SCENARIOS_CANCEL
=>
[
'status'
],
self
::
SCENARIOS_CANCEL
=>
[
'status'
],
];
];
...
@@ -109,6 +109,7 @@ class CoinIssueCoin extends CommonActiveRecord
...
@@ -109,6 +109,7 @@ class CoinIssueCoin extends CommonActiveRecord
'msg'
=>
'失败原因'
,
'msg'
=>
'失败原因'
,
'status'
=>
'状态'
,
'status'
=>
'状态'
,
'charge_unit_id'
=>
'手续费'
,
'charge_unit_id'
=>
'手续费'
,
'step_one_tx'
=>
'签名'
,
];
];
}
}
...
...
common/service/chain33/Chain33Service.php
View file @
8e5e1f52
...
@@ -303,6 +303,15 @@ class Chain33Service
...
@@ -303,6 +303,15 @@ class Chain33Service
return
$this
->
send
(
$params
,
'token.CreateRawTokenPreCreateTx'
);
return
$this
->
send
(
$params
,
'token.CreateRawTokenPreCreateTx'
);
}
}
public
function
createRawTokenFinishTx
(
$symbol
,
$owner
)
{
$params
=
[
'symbol'
=>
$symbol
,
'owner'
=>
$owner
];
return
$this
->
send
(
$params
,
'token.CreateRawTokenFinishTx'
);
}
public
function
getBlock2MainInfo
(
$start
,
$end
)
public
function
getBlock2MainInfo
(
$start
,
$end
)
{
{
$params
=
[
$params
=
[
...
...
console/controllers/IssueCoinController.php
View file @
8e5e1f52
...
@@ -107,7 +107,7 @@ class IssueCoinController extends Controller
...
@@ -107,7 +107,7 @@ class IssueCoinController extends Controller
$currentModel
=
CoinIssueTransfer
::
findOne
(
$val
[
'id'
]);
$currentModel
=
CoinIssueTransfer
::
findOne
(
$val
[
'id'
]);
$currentModel
->
query_result
=
$query_result
;
$currentModel
->
query_result
=
$query_result
;
if
(
$unissue
>
-
1
){
if
(
$unissue
>
-
1
)
{
$currentModel
->
unissue
=
$unissue
;
$currentModel
->
unissue
=
$unissue
;
}
}
$currentModel
->
msg
=
$msg
;
$currentModel
->
msg
=
$msg
;
...
@@ -121,6 +121,41 @@ class IssueCoinController extends Controller
...
@@ -121,6 +121,41 @@ class IssueCoinController extends Controller
* @param $type 0 未开启人工 1 已开启人工
* @param $type 0 未开启人工 1 已开启人工
* @return
* @return
*/
*/
public
function
actionAutoTransfer
()
{
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
select
(
'id, step_one_tx'
)
->
where
([
'step_one_result'
=>
0
])
->
andWhere
([
'<>'
,
'step_one_tx'
,
''
])
->
asArray
()
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无1.1执行任务'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$service
=
new
Chain33Service
(
$node
);
foreach
(
$issue_coin_model
as
$val
)
{
go
(
function
()
use
(
$val
,
$service
)
{
\Co
::
sleep
(
0.5
);
$result
=
$service
->
sendTransaction
(
$val
[
'step_one_tx'
]);
$send_result
=
$result
[
'result'
];
$currentModel
=
CoinIssueCoin
::
findOne
(
$val
[
'id'
]);
$currentModel
->
step_one_result
=
$send_result
;
$currentModel
->
save
();
});
}
echo
date
(
'Y-m-d H:i:s'
)
.
'1.1 交易完成'
.
PHP_EOL
;
return
0
;
}
/**
* 自动发币
* @param $type 0 未开启人工 1 已开启人工
* @return
*/
public
function
actionAutoIssue
(
$type
)
public
function
actionAutoIssue
(
$type
)
{
{
if
(
0
==
$type
)
{
if
(
0
==
$type
)
{
...
@@ -138,6 +173,7 @@ class IssueCoinController extends Controller
...
@@ -138,6 +173,7 @@ class IssueCoinController extends Controller
$issue_coin_model
=
CoinIssueCoin
::
find
()
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
select
(
'id, name, platform_id, chain_id, symbol, introduction, total, category, owner'
)
->
select
(
'id, name, platform_id, chain_id, symbol, introduction, total, category, owner'
)
->
where
([
'status'
=>
$status
])
->
where
([
'status'
=>
$status
])
->
andWhere
([
'<>'
,
'step_one_result'
,
0
])
->
all
();
->
all
();
if
(
false
==
$issue_coin_model
)
{
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无发行任务'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无发行任务'
.
PHP_EOL
;
...
@@ -146,94 +182,89 @@ class IssueCoinController extends Controller
...
@@ -146,94 +182,89 @@ class IssueCoinController extends Controller
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$chain_service
=
new
Chain33Service
(
$node
);
$chain_service
=
new
Chain33Service
(
$node
);
foreach
(
$issue_coin_model
as
$issue_coin
)
{
foreach
(
$issue_coin_model
as
$issue_coin
)
{
$params
=
[
//执行1.2构造
'name'
=>
$issue_coin
->
name
,
$result
=
$chain_service
->
createRawTokenFinishTx
(
$issue_coin
->
symbol
,
$issue_coin
->
owner
);
'symbol'
=>
$issue_coin
->
symbol
,
if
(
null
!=
$result
[
'error'
])
{
'introduction'
=>
$issue_coin
->
introduction
,
'total'
=>
(
int
)
$issue_coin
->
total
,
'price'
=>
isset
(
$issue_coin
->
platform
->
issue_charge
)
?
(
int
)
$issue_coin
->
platform
->
issue_charge
:
0
,
'category'
=>
(
int
)
$issue_coin
->
category
,
'owner'
=>
$issue_coin
->
owner
];
$result
=
$chain_service
->
createRawTokenPreCreateTx
(
$params
);
if
(
null
==
$result
[
'error'
]
&&
false
==
$result
[
'code'
])
{
$data
=
[
$data
=
[
'msg'
=>
$result
[
'result'
],
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'status'
=>
CoinIssueCoin
::
SUCCESS_ISSUE
,
'msg'
=>
$result
[
'msg'
]
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
];
];
$params
[
'platform_id'
]
=
$issue_coin
->
platform_id
;
goto
doEnd
;
$params
[
'platform'
]
=
$issue_coin
->
chain
->
platform
;
}
#$this->syncTransfer($issue_transfer['id']);
$this
->
syncRecord
(
$params
);
$txHex
=
$result
[
'result'
];
$this
->
syncCoin
(
$params
);
#$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e21';
}
else
{
$privkey
=
$issue_coin
->
chain
->
private_key
;
$expire
=
'1m'
;
//执行1.2签名
$signRawTx
=
$chain_service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$data
=
[
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'msg'
=>
$result
[
'msg'
]
];
];
goto
doEnd
;
}
}
if
(
$data
[
'status'
]
>
CoinIssueCoin
::
REFUSE_ISSUE
)
{
//执行1.2交易
CoinIssueCoin
::
updateAll
(
$data
,
[
$result
=
$chain_service
->
sendTransaction
(
$signRawTx
[
'result'
]);
'id'
=>
$issue_coin
->
id
,
if
(
0
!=
$result
[
'code'
])
{
]);
$data
=
[
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
'msg'
=>
$result
[
'msg'
]
];
goto
doEnd
;
}
}
$data
=
[
'msg'
=>
$result
[
'result'
],
'status'
=>
CoinIssueCoin
::
SUCCESS_ISSUE
,
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
];
$params
[
'platform_id'
]
=
$issue_coin
->
platform_id
;
$params
[
'platform'
]
=
$issue_coin
->
chain
->
platform
;
$this
->
syncRecord
(
$params
);
$this
->
syncCoin
(
$params
);
doEnd
:
CoinIssueCoin
::
updateAll
(
$data
,
[
'id'
=>
$issue_coin
->
id
,
]);
}
}
echo
date
(
'Y-m-d H:i:s'
)
.
'发行成功'
.
PHP_EOL
;
echo
date
(
'Y-m-d H:i:s'
)
.
'发行成功'
.
PHP_EOL
;
return
0
;
return
0
;
// $issue_transfers = CoinIssueTransfer::find()
// ->where(['<>', 'send_result', '0'])
$params
=
[
// ->andWhere(['msg' => 'success'])
'name'
=>
$issue_coin
->
name
,
// ->andWhere(['unissue' => 1])
'symbol'
=>
$issue_coin
->
symbol
,
// ->asArray()
'introduction'
=>
$issue_coin
->
introduction
,
// ->all();
'total'
=>
(
int
)
$issue_coin
->
total
,
// if (false == $issue_transfers) {
'price'
=>
isset
(
$issue_coin
->
platform
->
issue_charge
)
?
(
int
)
$issue_coin
->
platform
->
issue_charge
:
0
,
// echo date('Y-m-d H:i:s') . '暂无发行任务' . PHP_EOL;
'category'
=>
(
int
)
$issue_coin
->
category
,
// return 0;
'owner'
=>
$issue_coin
->
owner
// }
];
//
// $node = Yii::$app->params['chain_nodes']['STO'];
$result
=
$chain_service
->
createRawTokenPreCreateTx
(
$params
);
// $chain_service = new Chain33Service($node);
if
(
null
==
$result
[
'error'
]
&&
false
==
$result
[
'code'
])
{
// foreach ($issue_transfers as $issue_transfer) {
$data
=
[
// $issue_coin_model = CoinIssueCoin::find()
'msg'
=>
$result
[
'result'
],
// ->select('id, name, platform_id, chain_id, symbol, introduction, total, category, owner')
'status'
=>
CoinIssueCoin
::
SUCCESS_ISSUE
,
// ->where(['id' => $issue_transfer['issue_coin_id'], 'status' => $status])
'charge_pay'
=>
CoinIssueCoin
::
ALLOW_PAY
// ->one();
];
//
$params
[
'platform_id'
]
=
$issue_coin
->
platform_id
;
// if (false == $issue_coin_model) continue;
$params
[
'platform'
]
=
$issue_coin
->
chain
->
platform
;
// $params = [
#$this->syncTransfer($issue_transfer['id']);
// 'name' => $issue_coin_model->name,
$this
->
syncRecord
(
$params
);
// 'symbol' => $issue_coin_model->symbol,
$this
->
syncCoin
(
$params
);
// 'introduction' => $issue_coin_model->introduction,
}
else
{
// 'total' => (int)$issue_coin_model->total,
$data
=
[
// 'price' => isset($issue_coin_model->platform->issue_charge) ? (int)$issue_coin_model->platform->issue_charge : 0,
'status'
=>
CoinIssueCoin
::
FAIL_ISSUE
,
// 'category' => (int)$issue_coin_model->category,
];
// 'owner' => $issue_coin_model->owner
}
// ];
if
(
$data
[
'status'
]
>
CoinIssueCoin
::
REFUSE_ISSUE
)
{
//
CoinIssueCoin
::
updateAll
(
$data
,
[
// $result = $chain_service->createRawTokenPreCreateTx($params);
'id'
=>
$issue_coin
->
id
,
// if (null == $result['error'] && false == $result['code']) {
]);
// $status = CoinIssueCoin::SUCCESS_ISSUE;
}
// $params['platform_id'] = $issue_coin_model->platform_id;
// $params['platform'] = $issue_coin_model->chain->platform;
// $this->syncTransfer($issue_transfer['id']);
// $this->syncRecord($params);
// $this->syncCoin($params);
// } else {
// $status = CoinIssueCoin::FAIL_ISSUE;
// }
// if ($status > CoinIssueCoin::REFUSE_ISSUE) {
// CoinIssueCoin::updateAll([
// 'msg' => $result['result'],
// 'status' => $status
// ], [
// 'id' => $issue_coin_model->id,
// ]);
// }
// }
// echo date('Y-m-d H:i:s') . '发行成功' . PHP_EOL;
// return 0;
}
}
public
function
syncCoin
(
$params
=
[])
public
function
syncCoin
(
$params
=
[])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment