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
17e24d61
Commit
17e24d61
authored
Nov 11, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
撤消发行
parent
668b57b5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
175 additions
and
48 deletions
+175
-48
IssueCoinController.php
api/controllers/IssueCoinController.php
+86
-22
CoinIssueCoin.php
common/models/psources/CoinIssueCoin.php
+6
-0
CoinIssueRevokeRecord.php
common/models/psources/CoinIssueRevokeRecord.php
+43
-0
IssueChainTransferController.php
console/controllers/IssueChainTransferController.php
+40
-26
No files found.
api/controllers/IssueCoinController.php
View file @
17e24d61
...
...
@@ -2,6 +2,7 @@
namespace
api\controllers
;
use
common\models\psources\CoinIssueRevokeRecord
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
yii\data\Pagination
;
...
...
@@ -257,6 +258,10 @@ class IssueCoinController extends BaseController
$msg
=
'发行失败。失败原因:'
.
$data
->
transfer
->
finish_query_transaction
;
}
}
if
(
CoinIssueCoin
::
STATUS_CANCEL_FAILED
==
$data
->
status
)
{
$code
=
-
1
;
$msg
=
'撤消失败。失败原因:'
.
$data
->
revoke
->
revoke_query_transaction
;
}
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
...
...
@@ -325,9 +330,8 @@ class IssueCoinController extends BaseController
}
/**
*
申请撤消/确认
*
确认申请
* @param integer id
* @param integer status
* @return array
*/
public
function
actionVerify
()
...
...
@@ -344,19 +348,12 @@ class IssueCoinController extends BaseController
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
$status
=
isset
(
$params
[
'status'
])
?
(
int
)
$params
[
'status'
]
:
0
;
if
(
false
==
$id
||
false
==
$status
)
{
if
(
false
==
$id
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
!
in_array
(
$status
,
[
CoinIssueCoin
::
STATUS_CANCEL
,
CoinIssueCoin
::
STATUS_CONFIRM
]))
{
$msg
=
'错误的状态值'
;
$code
=
-
1
;
goto
doEnd
;
}
$model
=
CoinIssueCoin
::
findOne
(
$id
);
if
(
false
==
$model
)
{
$msg
=
'不存在的记录'
;
...
...
@@ -364,21 +361,11 @@ class IssueCoinController extends BaseController
goto
doEnd
;
}
if
(
CoinIssueCoin
::
STATUS_CONFIRM
==
$status
)
{
if
(
CoinIssueCoin
::
STATUS_PEDDING
!=
$model
->
status
)
{
$msg
=
'该状态下禁止发行'
;
$code
=
-
1
;
goto
doEnd
;
}
}
if
(
CoinIssueCoin
::
STATUS_CANCEL
==
$status
)
{
if
(
'success'
!=
$model
->
transfer
->
pre_query_transaction
)
{
$msg
=
'该状态下禁止撤消'
;
$code
=
-
1
;
goto
doEnd
;
}
}
$record_model
=
CoinIssueChainRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
one
();
if
(
false
==
$record_model
)
{
...
...
@@ -388,7 +375,7 @@ class IssueCoinController extends BaseController
}
$data
=
[
'status'
=>
$status
,
'status'
=>
CoinIssueCoin
::
STATUS_CONFIRM
,
];
$model
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CANCEL
);
$model
->
load
(
$data
,
''
);
...
...
@@ -398,11 +385,88 @@ class IssueCoinController extends BaseController
goto
doEnd
;
}
if
(
$status
==
CoinIssueCoin
::
STATUS_CONFIRM
)
{
$record_model
->
pre_query_transaction
=
'success'
;
$record_model
->
update
();
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
/**
* 申请撤消
* @param integer id
* @param string revoke_tx
* @param string revoke_send_transaction
* @return array
*/
public
function
actionRevoke
()
{
$data
=
null
;
$header
=
Yii
::
$app
->
request
->
headers
;
$platform_id
=
$header
[
'FZM-PLATFORM-ID'
]
??
null
;
if
(
empty
(
$platform_id
))
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
post
();
$id
=
isset
(
$params
[
'id'
])
?
(
int
)
$params
[
'id'
]
:
0
;
$revoke_tx
=
isset
(
$params
[
'revoke_tx'
])
?
$params
[
'revoke_tx'
]
:
''
;
$revoke_send_transaction
=
isset
(
$params
[
'revoke_send_transaction'
])
?
$params
[
'revoke_send_transaction'
]
:
''
;
if
(
false
==
$revoke_tx
||
false
==
$revoke_send_transaction
||
false
==
$id
)
{
$msg
=
'缺少必要的参数'
;
$code
=
-
1
;
goto
doEnd
;
}
$issue_coin
=
CoinIssueCoin
::
findOne
(
$id
);
if
(
false
==
$issue_coin
)
{
$msg
=
'不存在的记录'
;
$code
=
-
1
;
goto
doEnd
;
}
if
(
$issue_coin
->
status
>
CoinIssueCoin
::
STATUS_PEDDING
)
{
$msg
=
'该状态下禁止发行'
;
$code
=
-
1
;
goto
doEnd
;
}
$isExist
=
CoinIssueRevokeRecord
::
find
()
->
where
([
'issue_coin_id'
=>
$id
])
->
count
();
if
(
0
!=
$isExist
)
{
$msg
=
'撤消记录已存在'
;
$code
=
-
1
;
goto
doEnd
;
}
$issue_coin_data
=
[
'status'
=>
CoinIssueCoin
::
STATUS_CANCEL
,
];
$issue_coin
->
setScenario
(
CoinIssueCoin
::
SCENARIOS_CANCEL
);
$issue_coin
->
load
(
$issue_coin_data
,
''
);
if
(
!
$issue_coin
->
save
())
{
$msg
=
current
(
$issue_coin
->
firstErrors
);
$code
=
-
1
;
goto
doEnd
;
}
$issue_revoke_record
=
new
CoinIssueRevokeRecord
();
$issue_revoke_data
=
[
'issue_coin_id'
=>
$id
,
'revoke_tx'
=>
$revoke_tx
,
'revoke_send_transaction'
=>
$revoke_send_transaction
,
'revoke_query_transaction'
=>
'standby'
,
];
$issue_revoke_record
->
setScenario
(
CoinIssueRevokeRecord
::
SCENARIOS_CREATE
);
$issue_revoke_record
->
load
(
$issue_revoke_data
,
''
);
$issue_revoke_record
->
save
();
$code
=
0
;
$msg
=
'success'
;
...
...
common/models/psources/CoinIssueCoin.php
View file @
17e24d61
...
...
@@ -26,6 +26,7 @@ class CoinIssueCoin extends CommonActiveRecord
const
TYPE_YES
=
1
;
//是增发
const
ISSUE_TOKEN
=
'issue_token'
;
const
REVOKE_TOKEN
=
'revoke_token'
;
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
...
...
@@ -164,4 +165,8 @@ class CoinIssueCoin extends CommonActiveRecord
{
return
$this
->
hasOne
(
CoinIssueChainRecord
::
className
(),
[
'issue_coin_id'
=>
'id'
]);
}
public
function
getRevoke
()
{
return
$this
->
hasOne
(
CoinIssueRevokeRecord
::
className
(),
[
'issue_coin_id'
=>
'id'
]);
}
}
\ No newline at end of file
common/models/psources/CoinIssueRevokeRecord.php
0 → 100644
View file @
17e24d61
<?php
namespace
common\models\psources
;
use
Yii
;
class
CoinIssueRevokeRecord
extends
CommonActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coins_issue_revoke_record}}'
;
}
public
function
rules
()
{
return
[
[[
'revoke_tx'
,
'revoke_send_transaction'
,
'issue_coin_id'
],
'required'
],
[[
'issue_coin_id'
],
'integer'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'revoke_tx'
,
'revoke_send_transaction'
,
'issue_coin_id'
,
'revoke_query_transaction'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
getCoin
()
{
return
$this
->
hasOne
(
CoinIssueCoin
::
className
(),
[
'id'
=>
'issue_coin_id'
]);
}
}
\ No newline at end of file
console/controllers/IssueChainTransferController.php
View file @
17e24d61
...
...
@@ -2,6 +2,7 @@
namespace
console\controllers
;
use
common\models\psources\CoinIssueRevokeRecord
;
use
Yii
;
use
yii\console\Controller
;
use
yii\helpers\ArrayHelper
;
...
...
@@ -274,55 +275,68 @@ class IssueChainTransferController extends Controller
public
function
actionCancel
()
{
$redis
=
Yii
::
$app
->
redis
;
$issue_coin_model
=
CoinIssueCoin
::
find
()
->
where
([
'status'
=>
CoinIssueCoin
::
STATUS_CANCEL
])
->
all
();
if
(
false
==
$issue_coin_model
)
{
echo
date
(
'Y-m-d H:i:s'
)
.
'暂无需要撤消的发行'
.
PHP_EOL
;
return
0
;
}
$node
=
Yii
::
$app
->
params
[
'chain_nodes'
][
'STO'
];
$chain_service
=
new
Chain33Service
(
$node
);
$service
=
new
Chain33Service
(
$node
);
$current_time
=
time
();
foreach
(
$issue_coin_model
as
$val
)
{
$data
=
[];
//执行1.3构造
$result
=
$chain_service
->
CreateRawTokenRevokeTx
(
$val
->
symbol
,
$val
->
owner
);
if
(
null
!=
$result
[
'error'
])
{
$status
=
CoinIssueCoin
::
STATUS_CANCEL_FAILED
;
$result
=
$service
->
QueryTransaction
(
$val
->
revoke
->
revoke_send_transaction
);
if
(
isset
(
$result
[
'result'
][
'actionName'
])
&&
'unknown'
==
$result
[
'result'
][
'actionName'
])
{
$data
=
[
'
pre_query_transaction'
=>
'fail
'
'
revoke_query_transaction'
=>
'success
'
];
$status
=
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
;
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
$txHex
=
$result
[
'result'
];
$privkey
=
'8ac19c0b8858ccd6ed34e2bce0f11be2fc696e658d0b98fb1d3ef85ec5a3992c'
;
$expire
=
'1m'
;
//执行1.3签名
$signRawTx
=
$chain_service
->
signRawTx
(
$privkey
,
$txHex
,
$expire
);
if
(
0
!=
$signRawTx
[
'code'
])
{
$status
=
CoinIssueCoin
::
STATUS_CANCEL_FAILED
;
}
else
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'ty'
])
&&
2
==
$result
[
'result'
][
'receipt'
][
'ty'
])
{
$data
=
[
'
pre_query_transaction'
=>
'fail
'
'
revoke_query_transaction'
=>
'success
'
];
$status
=
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
;
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
//执行1.3交易
$result
=
$chain_service
->
sendTransaction
(
$signRawTx
[
'result'
]);
if
(
0
!=
$result
[
'code'
])
{
}
else
{
$status
=
CoinIssueCoin
::
STATUS_CANCEL_FAILED
;
if
(
isset
(
$result
[
'result'
][
'receipt'
][
'logs'
]))
{
foreach
(
$result
[
'result'
][
'receipt'
][
'logs'
]
as
$log
)
{
if
(
isset
(
$log
[
'tyName'
])
&&
'LogErr'
==
$log
[
'tyName'
])
{
$data
=
[
'pre_query_transaction'
=>
'fail'
'revoke_query_transaction'
=>
$log
[
'log'
]
];
goto
doEnd
;
break
;
}
$status
=
CoinIssueCoin
::
STATUS_CANCEL_SUCCESS
;
}
}
else
{
$data
=
[
'pre_query_transaction'
=>
$result
[
'result
'
]
'revoke_query_transaction'
=>
$result
[
'msg
'
]
];
}
$cache_error_time
=
$redis
->
hget
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
if
(
false
==
$cache_error_time
)
{
$redis
->
hmset
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
,
$current_time
);
continue
;
}
if
((
$current_time
-
$cache_error_time
)
<
30
)
{
continue
;
}
$redis
->
hdel
(
CoinIssueCoin
::
REVOKE_TOKEN
,
$val
->
id
);
goto
doEnd
;
}
doEnd
:
CoinIssueCoin
::
updateAll
([
'status'
=>
$status
],
[
'id'
=>
$val
->
id
,
]);
CoinIssue
Chain
Record
::
updateAll
(
$data
,
[
CoinIssue
Revoke
Record
::
updateAll
(
$data
,
[
'issue_coin_id'
=>
$val
->
id
,
]);
}
...
...
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