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
f507a8ca
Commit
f507a8ca
authored
Feb 10, 2020
by
shajiaming
Browse files
Options
Browse Files
Download
Plain Diff
列表加入时间
parents
dfd28bfe
f79117ee
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
295 additions
and
26 deletions
+295
-26
MarketController.php
api/controllers/MarketController.php
+19
-11
WalletChainController.php
api/controllers/WalletChainController.php
+169
-0
WalletChain.php
common/models/psources/WalletChain.php
+70
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+20
-5
Bilaxy.php
common/service/exchange/Bilaxy.php
+17
-10
No files found.
api/controllers/MarketController.php
View file @
f507a8ca
...
...
@@ -45,25 +45,32 @@ class MarketController extends BaseController
goto
doEnd
;
}
if
(
!
in_array
(
$exchange
,
Yii
::
$app
->
params
[
'exchange'
]))
{
$this
->
msg
=
'invalid exchange'
;
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$currency_ticker
=
$exchange
->
getTicker
(
$currency
,
'USDT'
);
$base_currency_ticker
=
$exchange
->
getTicker
(
$base_currency
,
'USDT'
);
if
(
empty
(
$currency_ticker
)
||
empty
(
$base_currency_ticker
))
{
$this
->
code
=
-
1
;
$this
->
msg
=
'此交易所暂不支持所选币种!'
;
goto
doEnd
;
}
$currency_quotation
=
[
'low'
=>
(
float
)
sprintf
(
"%0.4f"
,
$currency_ticker
[
'low'
]),
'high'
=>
(
float
)
sprintf
(
"%0.4f"
,
$currency_ticker
[
'high'
]),
'last'
=>
(
float
)
sprintf
(
"%0.4f"
,
$currency_ticker
[
'last'
]),
'rmb'
=>
(
float
)
sprintf
(
"%0.2f"
,
$currency_ticker
[
'last'
]),
];
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$quotation
=
$exchange
->
getTicker
(
$currency
,
'USDT'
);
$quotation
=
[
'low'
=>
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'low'
]
/
100
),
'high'
=>
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'high'
]
/
100
),
'last'
=>
(
float
)
sprintf
(
"%0.4f"
,
$quotation
[
'last'
]
/
100
),
'rmb'
=>
(
float
)
sprintf
(
"%0.2f"
,
$quotation
[
'last'
]
/
100
),
$base_currency_quotation
=
[
'low'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_currency_ticker
[
'low'
]),
'high'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_currency_ticker
[
'high'
]),
'last'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_currency_ticker
[
'last'
]),
'rmb'
=>
(
float
)
sprintf
(
"%0.2f"
,
$base_currency_ticker
[
'last'
]),
];
echo
json_encode
(
$quotation
);
exit
;
$this
->
data
=
(
float
)
sprintf
(
"%0.4f"
,
$currency_quotation
[
'last'
]
/
$base_currency_quotation
[
'last'
]);
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'
tick'
=>
$this
->
data
];
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'
data'
=>
$this
->
data
];
}
}
\ No newline at end of file
api/controllers/WalletChainController.php
0 → 100644
View file @
f507a8ca
<?php
namespace
api\controllers
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
api\base\BaseController
;
use
common\models\psources\WalletChain
;
use
yii\data\Pagination
;
class
WalletChainController
extends
BaseController
{
/**
* h5发行链列表
* @param string wallet_address
* @return array
*/
public
function
actionChains
()
{
if
(
!
Yii
::
$app
->
request
->
isGet
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'请求方式错误!'
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
get
();
$wallet_address
=
isset
(
$params
[
'wallet_address'
])
?
$params
[
'wallet_address'
]
:
''
;
if
(
false
==
$wallet_address
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
10
);
$query
=
WalletChain
::
find
()
->
select
(
'id, token, platform, create_time, status'
)
->
where
([
'wallet_address'
=>
$wallet_address
])
->
orderBy
(
'id'
);
$model
=
$query
->
offset
((
$page
-
1
)
*
$size
)
->
orderBy
(
'create_time desc'
)
->
limit
(
$size
)
->
asArray
()
->
all
();
$countQuery
=
clone
$query
;
$pages
=
new
Pagination
([
'totalCount'
=>
$countQuery
->
count
(),
'pageSize'
=>
$size
]);
$this
->
data
=
[
'list'
=>
$model
,
'page'
=>
[
'pageCount'
=>
$pages
->
pageCount
,
'pageSize'
=>
$size
,
'currentPage'
=>
$page
,
]
];
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
/**
* h5发行链
* @param string platform
* @param string address
* @param string private_key
* @param string fee
* @param string token
* @param string host
* @param string port
* @param string wallet_address
* @param string hash
* @return array
*/
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'
];
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
();
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
/**
* h5发行链
* @param string wallet_address
* @return array
*/
public
function
actionDetail
()
{
if
(
!
Yii
::
$app
->
request
->
isGet
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'请求方式错误!'
;
goto
doEnd
;
}
$params
=
Yii
::
$app
->
request
->
get
();
$id
=
isset
(
$params
[
'id'
])
?
$params
[
'id'
]
:
''
;
if
(
false
==
$id
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$model
=
WalletChain
::
find
()
->
select
(
'platform, token, address, private_key, fee, host, port, hash, status'
)
->
where
([
'id'
=>
(
int
)
$id
])
->
asArray
()
->
one
();
if
(
empty
(
$model
))
{
goto
doEnd
;
}
$model
[
'fee'
]
=
$model
[
'fee'
]
.
$model
[
'token'
];
$model
[
'charge'
]
=
'10BTY'
;
$this
->
data
=
$model
;
goto
doEnd
;
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
}
\ No newline at end of file
common/models/psources/WalletChain.php
0 → 100644
View file @
f507a8ca
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
WalletChain
extends
BaseActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
STATUS_NO
=
0
;
//创建失败
const
STATUS_YES
=
1
;
//创建成功
const
ORIGIN_MANAGE
=
1
;
//管理员创建
const
ORIGIN_USER
=
2
;
//h5用户创建
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{wallet_chain}}'
;
}
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'
,
'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'
],
[[
'platform'
],
'string'
,
'length'
=>
[
1
,
30
]],
[[
'token'
],
'string'
,
'length'
=>
[
1
,
10
]],
[[
'port'
,
'status'
,
'origin'
],
'integer'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'status'
,
'origin'
,
'hash'
],
self
::
SCENARIOS_UPDATE
=>
[
'status'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
\ No newline at end of file
common/service/chain33/Chain33Service.php
View file @
f507a8ca
...
...
@@ -54,12 +54,8 @@ class Chain33Service
return
json_encode
(
$data
);
}
public
function
send
(
$params
=
[],
$method
=
'Chain33.Query'
)
public
function
send
(
$params
=
[],
$method
=
'Chain33.Query'
,
$timeout
=
[]
)
{
$timeout
=
[
'connect_timeout'
=>
50000
,
'timeout_ms'
=>
40000
];
$ch
=
new
Curl
(
$timeout
);
$jsonrpc
=
self
::
jsonRpcBuild
(
$params
,
$method
);
$ch
->
setHeader
(
'Content-Type'
,
'application/json'
);
...
...
@@ -449,4 +445,23 @@ class Chain33Service
];
return
$this
->
send
(
$params
,
'Chain33.UnLock'
);
}
/**
* @param ParaName
* @param ParaSerAddr
* @return array|mixed
* 解锁钱包
*/
public
function
addPara
(
$paraName
,
$paraSerAddr
)
{
$params
=
[
'ParaName'
=>
$paraName
,
'ParaSerAddr'
=>
$paraSerAddr
,
];
$timeout
=
[
'connect_timeout'
=>
50000
,
'timeout_ms'
=>
50000
];
return
$this
->
send
(
$params
,
'CoinsControl.AddParaCoinsInfo'
,
$timeout
);
}
}
common/service/exchange/Bilaxy.php
View file @
f507a8ca
...
...
@@ -8,7 +8,7 @@ class Bilaxy extends Exchange implements ExchangeInterface
{
protected
$supported_symbol
=
'supported_symbol_bilaxy'
;
protected
$quotation_prefix
=
'quotation_bilaxy_'
;
protected
$base_url
=
'https://
api.bilaxy.com/v1/tickers
'
;
protected
$base_url
=
'https://
newapi.bilaxy.com/
'
;
public
function
symbolExists
(
$tag
=
'BVA'
,
$aim
=
"USDT"
)
...
...
@@ -38,7 +38,15 @@ class Bilaxy extends Exchange implements ExchangeInterface
*/
public
function
setSupportedSymbol
()
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'BVA_USDT'
);
$curl
=
new
Curl
();
$api
=
$this
->
base_url
.
'/v1/ticker/24hr'
;
$content
=
$curl
->
get
(
$api
,
false
);
//json
if
(
is_array
(
$content
))
{
foreach
(
$content
as
$key
=>
$item
)
{
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
strtoupper
(
$key
));
}
}
}
/**
...
...
@@ -49,14 +57,13 @@ class Bilaxy extends Exchange implements ExchangeInterface
public
function
setQuotation
()
{
$curl
=
new
Curl
();
$content
=
$curl
->
get
(
$this
->
base_url
,
false
);
if
(
is_array
(
$content
)
&&
isset
(
$content
[
'data'
]))
{
$data
=
$content
[
'data'
];
$key
=
$this
->
quotation_prefix
.
'BVA_USDT'
;
foreach
(
$data
as
$item
)
{
if
(
260
==
$item
[
'symbol'
])
{
$this
->
redis
->
hmset
(
$key
,
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'high'
],
'last'
,
$item
[
'last'
]);
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
'KPC8_USDT'
);
$api
=
$this
->
base_url
.
'/v1/ticker/24hr'
;
$content
=
$curl
->
get
(
$api
,
false
);
if
(
is_array
(
$content
))
{
foreach
(
$content
as
$key
=>
$item
)
{
$this
->
redis
->
hmset
(
$this
->
quotation_prefix
.
strtoupper
(
$key
),
'low'
,
$item
[
'low'
],
'high'
,
$item
[
'height'
],
'last'
,
$item
[
'close'
]);
if
(
!
$this
->
redis
->
sismember
(
$this
->
supported_symbol
,
strtoupper
(
$key
))){
$this
->
redis
->
sadd
(
$this
->
supported_symbol
,
strtoupper
(
$key
));
}
}
}
...
...
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