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
fb4759e4
Commit
fb4759e4
authored
Apr 29, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into develop
parents
8add2c6c
b7c28d00
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
133 additions
and
0 deletions
+133
-0
TradeController.php
api/controllers/TradeController.php
+79
-0
CoinTokenTransfer.php
common/models/psources/CoinTokenTransfer.php
+39
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+15
-0
No files found.
api/controllers/TradeController.php
View file @
fb4759e4
...
...
@@ -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
common/models/psources/CoinTokenTransfer.php
0 → 100644
View file @
fb4759e4
<?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
common/service/chain33/Chain33Service.php
View file @
fb4759e4
...
...
@@ -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
=
[
...
...
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