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
689ef567
Commit
689ef567
authored
Feb 24, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/issue_coin' into 'master'
Feature/issue coin See merge request
!295
parents
2f1c0fce
ded7b59c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
216 additions
and
47 deletions
+216
-47
WalletChainController.php
api/controllers/WalletChainController.php
+88
-46
CoinPlatformWithHold.php
common/models/psources/CoinPlatformWithHold.php
+65
-0
WalletChain.php
common/models/psources/WalletChain.php
+1
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+1
-1
IssueChainTransferController.php
console/controllers/IssueChainTransferController.php
+61
-0
No files found.
api/controllers/WalletChainController.php
View file @
689ef567
...
...
@@ -2,6 +2,8 @@
namespace
api\controllers
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinPlatformWithHold
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
api\base\BaseController
;
...
...
@@ -35,8 +37,8 @@ class WalletChainController extends BaseController
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
10
);
$query
=
WalletChain
::
find
()
->
select
(
'id, token, platform,
create_time, status
'
)
$query
=
CoinPlatformWithHold
::
find
()
->
select
(
'id, token, platform,
status, create_time
'
)
->
where
([
'wallet_address'
=>
$wallet_address
])
->
orderBy
(
'id'
);
...
...
@@ -75,55 +77,83 @@ class WalletChainController extends BaseController
public
function
actionChain
()
{
$request
=
Yii
::
$app
->
request
;
if
(
!
$request
->
isPost
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'请求方式错误!'
;
goto
doEnd
;
}
$post
=
$request
->
post
();
$model
=
new
WalletChain
();
$model
->
setScenario
(
WalletChain
::
SCENARIOS_CREATE
);
$params
=
[
'platform'
=>
isset
(
$post
[
'platform'
])
?
$post
[
'platform'
]
:
''
,
'address'
=>
isset
(
$post
[
'address'
])
?
$post
[
'address'
]
:
''
,
'private_key'
=>
isset
(
$post
[
'private_key'
])
?
$post
[
'private_key'
]
:
''
,
'token'
=>
isset
(
$post
[
'token'
])
?
strtoupper
(
$post
[
'token'
])
:
''
,
'host'
=>
isset
(
$post
[
'host'
])
?
$post
[
'host'
]
:
''
,
'port'
=>
isset
(
$post
[
'port'
])
?
$post
[
'port'
]
:
''
,
'wallet_address'
=>
isset
(
$post
[
'wallet_address'
])
?
$post
[
'wallet_address'
]
:
''
,
'status'
=>
WalletChain
::
STATUS_NO
,
'origin'
=>
WalletChain
::
ORIGIN_MANAGE
,
'fee'
=>
isset
(
$post
[
'fee'
])
?
$post
[
'fee'
]
:
''
,
'hash'
=>
isset
(
$post
[
'hash'
])
?
$post
[
'hash'
]
:
''
];
if
(
$model
->
load
(
$params
,
''
)
&&
!
$model
->
save
())
{
$this
->
msg
=
$model
->
errors
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$id
=
Yii
::
$app
->
p_sources
->
getLastInsertID
();
// $params = [
// 'platform' => 'BZCHAIN',
// 'host' => '112.74.59.221',
// 'port' => 1235,
// ];
$node_params
=
Yii
::
$app
->
params
[
'para'
];
$service
=
new
Chain33Service
(
$node_params
);
$result
=
$service
->
addPara
(
$params
[
'platform'
],
$params
[
'host'
]
.
':'
.
$params
[
'port'
]);
if
(
0
!=
$result
[
'code'
])
{
$this
->
code
=
$result
[
'code'
];
$this
->
msg
=
$result
[
'msg'
];
if
(
$request
->
isPost
)
{
$model
=
new
CoinPlatformWithHold
();
$model
->
setScenario
(
CoinPlatformWithHold
::
SCENARIOS_CREATE
);
$params
=
[
'platform'
=>
isset
(
$post
[
'platform'
])
?
$post
[
'platform'
]
:
''
,
'address'
=>
isset
(
$post
[
'address'
])
?
$post
[
'address'
]
:
''
,
'private_key'
=>
isset
(
$post
[
'private_key'
])
?
$post
[
'private_key'
]
:
''
,
'token'
=>
isset
(
$post
[
'token'
])
?
strtoupper
(
$post
[
'token'
])
:
''
,
'host'
=>
isset
(
$post
[
'host'
])
?
$post
[
'host'
]
:
''
,
'port'
=>
isset
(
$post
[
'port'
])
?
$post
[
'port'
]
:
''
,
'wallet_address'
=>
isset
(
$post
[
'wallet_address'
])
?
$post
[
'wallet_address'
]
:
''
,
'status'
=>
CoinPlatformWithHold
::
STATUS_UNPAID
,
'origin'
=>
CoinPlatformWithHold
::
ORIGIN_USER
,
'fee'
=>
isset
(
$post
[
'fee'
])
?
$post
[
'fee'
]
:
''
,
'exer'
=>
'user.p.'
.
(
isset
(
$post
[
'platform'
])
?
$post
[
'platform'
]
:
''
)
];
if
(
$model
->
load
(
$params
,
''
)
&&
!
$model
->
validate
())
{
$errors
=
''
;
foreach
(
$model
->
errors
as
$error
)
{
$errors
.=
$error
[
0
];
}
$this
->
msg
=
$errors
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$node_params
=
Yii
::
$app
->
params
[
'para'
];
$service
=
new
Chain33Service
(
$node_params
);
$result
=
$service
->
addPara
(
$params
[
'platform'
],
$params
[
'host'
]
.
':'
.
$params
[
'port'
]);
if
(
0
!=
$result
[
'code'
])
{
$this
->
code
=
$result
[
'code'
];
$this
->
msg
=
$result
[
'msg'
];
goto
doEnd
;
}
$model
->
save
();
$this
->
data
=
(
int
)
Yii
::
$app
->
p_sources
->
getLastInsertID
();
goto
doEnd
;
}
$chain_update
=
WalletChain
::
find
()
->
where
([
'id'
=>
$id
])
->
one
();
$chain_update
->
setScenario
(
WalletChain
::
SCENARIOS_UPDATE
);
$chain_update
->
status
=
WalletChain
::
STATUS_YES
;
$chain_update
->
save
();
if
(
$request
->
isPut
)
{
$id
=
isset
(
$post
[
'id'
])
?
$post
[
'id'
]
:
0
;
$hash
=
isset
(
$post
[
'hash'
])
?
$post
[
'hash'
]
:
0
;
if
(
false
==
$id
||
false
==
$hash
)
{
$this
->
msg
=
'缺少必要的参数'
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$model
=
CoinPlatformWithHold
::
findOne
(
$id
);
if
(
empty
(
$model
))
{
$this
->
msg
=
'数据不存在'
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$model
->
setScenario
(
CoinPlatformWithHold
::
SCENARIOS_UPDATE
);
$params
=
[
'id'
=>
$id
,
'hash'
=>
$hash
,
'status'
=>
CoinPlatformWithHold
::
STATUS_CREATEING
];
if
(
$model
->
load
(
$params
,
''
)
&&
!
$model
->
save
())
{
$errors
=
''
;
foreach
(
$model
->
errors
as
$error
)
{
$errors
.=
$error
[
0
];
}
$this
->
msg
=
$errors
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$this
->
syncCoin
([
'platform'
=>
$model
[
'platform'
],
'token'
=>
$model
[
'token'
]]);
}
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
...
...
@@ -152,7 +182,7 @@ class WalletChainController extends BaseController
}
$model
=
WalletChain
::
find
()
->
select
(
'platform, token, address, private_key, fee, host, port, hash, status
'
)
->
where
([
'id'
=>
(
int
)
$id
])
->
asArray
()
->
one
();
$model
=
CoinPlatformWithHold
::
find
()
->
select
(
'platform, token, address, private_key, fee, host, port, hash, status, create_time
'
)
->
where
([
'id'
=>
(
int
)
$id
])
->
asArray
()
->
one
();
if
(
empty
(
$model
))
{
goto
doEnd
;
}
...
...
@@ -165,4 +195,15 @@ class WalletChainController extends BaseController
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
public
function
syncCoin
(
$params
=
[])
{
$model
=
new
Coin
();
$model
->
nickname
=
[
'ja'
=>
''
,
'en-US'
=>
''
,
'zh-CN'
=>
''
];
$model
->
name
=
$params
[
'token'
];
$model
->
platform
=
$params
[
'platform'
];
$model
->
chain
=
'BTY'
;
$model
->
platform_id
=
1
;
$model
->
save
();
}
}
\ No newline at end of file
common/models/psources/CoinPlatformWithHold.php
View file @
689ef567
...
...
@@ -10,6 +10,71 @@ namespace common\models\psources;
class
CoinPlatformWithHold
extends
BaseActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
SCENARIOS_CONSOLE
=
'console'
;
const
STATUS_NO
=
0
;
//创建失败
const
STATUS_YES
=
1
;
//创建成功
const
STATUS_CREATEING
=
2
;
//生效中
const
STATUS_UNPAID
=
3
;
//尚未支付
const
ORIGIN_MANAGE
=
1
;
//管理员创建
const
ORIGIN_USER
=
2
;
//h5用户创建
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'platform'
=>
'平行链名称'
,
'address'
=>
'代扣地址'
,
'private_key'
=>
'代扣私钥'
,
'execer'
=>
'执行器'
,
'fee'
=>
'手续费'
,
'brower_url'
=>
'浏览器链接'
,
'token'
=>
'手续费(基础代币)'
,
'host'
=>
'钱包服务IP'
,
'port'
=>
'钱包服务端口'
,
'wallet_address'
=>
'钱包地址'
,
'status'
=>
'申请状态'
,
'origin'
=>
'创建人'
,
'hash'
=>
'申请费用hash'
];
}
public
function
rules
()
{
return
[
[[
'platform'
,
'address'
,
'private_key'
,
'exer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'status'
,
'port'
,
'fee'
,
'origin'
],
'required'
],
[[
'platform'
,
'address'
,
'private_key'
,
'exer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
],
'string'
],
[
'address'
,
'unique'
,
'message'
=>
'地址已存在'
],
[
'platform'
,
'unique'
,
'message'
=>
'平行链已存在'
],
[[
'platform'
],
'string'
,
'length'
=>
[
1
,
30
]],
[[
'token'
],
'string'
,
'length'
=>
[
1
,
10
]],
[[
'port'
,
'status'
,
'origin'
],
'integer'
],
[
'host'
,
'verfiyIp'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'status'
,
'origin'
,
'hash'
,
'exer'
],
self
::
SCENARIOS_UPDATE
=>
[
'id'
,
'hash'
,
'status'
],
self
::
SCENARIOS_CONSOLE
=>
[
'status'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
public
function
verfiyIp
(
$attribute
,
$params
)
{
if
(
!
preg_match
(
'/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/'
,
$this
->
host
))
{
$this
->
addError
(
$attribute
,
'错误的Ip地址'
);
return
false
;
}
}
public
static
function
tableName
()
{
return
'coin_platform_withhold'
;
...
...
common/models/psources/WalletChain.php
View file @
689ef567
...
...
@@ -52,6 +52,7 @@ class WalletChain extends BaseActiveRecord
return
[
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'status'
,
'port'
,
'fee'
,
'origin'
,
'hash'
],
'required'
],
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
],
'string'
],
[
'address'
,
'unique'
,
'message'
=>
'地址已存在'
],
[[
'platform'
],
'string'
,
'length'
=>
[
1
,
30
]],
[[
'token'
],
'string'
,
'length'
=>
[
1
,
10
]],
[[
'port'
,
'status'
,
'origin'
],
'integer'
],
...
...
common/service/chain33/Chain33Service.php
View file @
689ef567
...
...
@@ -413,7 +413,7 @@ class Chain33Service
'payload'
=>
[
'status'
=>
1
,
'queryAll'
=>
true
,
'symbolOnly'
=>
true
//
'symbolOnly' => true
]
];
return
$this
->
send
(
$params
,
'Chain33.Query'
);
...
...
console/controllers/IssueChainTransferController.php
View file @
689ef567
...
...
@@ -2,8 +2,10 @@
namespace
console\controllers
;
use
common\components\Tools
;
use
common\models\psources\CoinIssueRevokeRecord
;
use
common\models\psources\CoinPlatformWithHold
;
use
common\models\psources\WalletChain
;
use
Yii
;
use
yii\console\Controller
;
use
yii\helpers\ArrayHelper
;
...
...
@@ -368,6 +370,65 @@ class IssueChainTransferController extends Controller
return
0
;
}
public
function
actionUpdateChain
()
{
$current_time
=
date
(
'Y-m-d H:i:s'
,
strtotime
(
'-10 minute'
));
$chains
=
CoinPlatformWithHold
::
find
()
->
where
([
'status'
=>
CoinPlatformWithHold
::
STATUS_CREATEING
,
'origin'
=>
CoinPlatformWithHold
::
ORIGIN_USER
])
->
andWhere
([
'<'
,
'create_time'
,
$current_time
])
->
all
();
if
(
empty
(
$chains
))
{
echo
date
(
'Y-m-d H:i:s'
)
.
'无需更新的链'
.
PHP_EOL
;
return
0
;
}
foreach
(
$chains
as
$chain
)
{
$chain
->
setScenario
(
CoinPlatformWithHold
::
SCENARIOS_CONSOLE
);
$chain
->
status
=
CoinPlatformWithHold
::
STATUS_YES
;
$chain
->
save
();
}
echo
date
(
'Y-m-d H:i:s'
)
.
'更新成功'
.
PHP_EOL
;
return
0
;
}
public
function
actionAsyncCoin
()
{
$chains
=
CoinPlatformWithHold
::
find
()
->
select
(
'host, platform'
)
->
where
([
'status'
=>
1
,
'origin'
=>
CoinPlatformWithHold
::
ORIGIN_USER
])
->
asArray
()
->
all
();
foreach
(
$chains
as
$chain
){
$node
=
[
'scheme'
=>
'http'
,
'host'
=>
$chain
[
'host'
],
'port'
=>
8901
];
$chain_service
=
new
Chain33Service
(
$node
);
$result
=
$chain_service
->
getTokens
(
'token'
,
'GetTokens'
);
if
(
null
!=
$result
[
'error'
])
continue
;
$tokens
=
isset
(
$result
[
'result'
][
'tokens'
])
?
$result
[
'result'
][
'tokens'
]
:
null
;
if
(
null
==
$tokens
)
continue
;
foreach
(
$tokens
as
$key
=>
$token
)
{
$model_coin
=
Coin
::
find
()
->
where
([
'name'
=>
$token
[
'symbol'
],
'platform'
=>
$chain
[
'platform'
],
'chain'
=>
'BTY'
])
->
one
();
if
(
empty
(
$model_coin
))
{
$model
=
new
Coin
();
$model
->
name
=
$token
[
'symbol'
];
$model
->
sid
=
$token
[
'name'
];
$model
->
nickname
=
[
'ja'
=>
''
,
'en-US'
=>
''
,
'zh-CN'
=>
''
];
$model
->
introduce
=
[
'ja'
=>
''
,
'en-US'
=>
''
,
'zh-CN'
=>
$token
[
'introduction'
]];
$model
->
platform
=
$chain
[
'platform'
];
$model
->
publish_count
=
$token
[
'total'
];
$model
->
chain
=
'BTY'
;
$model
->
platform_id
=
1
;
$model
->
treaty
=
1
;
$model
->
save
();
}
}
}
}
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