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
b9594ab6
Commit
b9594ab6
authored
Feb 06, 2020
by
shajiaming
Browse files
Options
Browse Files
Download
Plain Diff
solve conflict
parents
f58a5430
f555604a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
15 deletions
+131
-15
MarketController.php
api/controllers/MarketController.php
+51
-0
WalletChainController.php
api/controllers/WalletChainController.php
+33
-10
WalletChain.php
common/models/psources/WalletChain.php
+27
-0
Chain33Service.php
common/service/chain33/Chain33Service.php
+20
-5
No files found.
api/controllers/MarketController.php
View file @
b9594ab6
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
api\controllers
;
namespace
api\controllers
;
use
common\service\exchange\ExchangeFactory
;
use
Yii
;
use
Yii
;
use
api\base\BaseController
;
use
api\base\BaseController
;
use
common\service\exchange\ExchangeBuilderFactory
;
use
common\service\exchange\ExchangeBuilderFactory
;
...
@@ -32,4 +33,53 @@ class MarketController extends BaseController
...
@@ -32,4 +33,53 @@ class MarketController extends BaseController
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'tick'
=>
$ticker
??
[]];
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'tick'
=>
$ticker
??
[]];
}
}
public
function
actionIndex
()
{
$currency
=
Yii
::
$app
->
request
->
post
(
'currency'
,
''
);
$base_currency
=
Yii
::
$app
->
request
->
post
(
'base_currency'
,
''
);
$exchange
=
Yii
::
$app
->
request
->
post
(
"exchange"
,
'Zhaobi'
);
$base_exchange
=
Yii
::
$app
->
request
->
post
(
"base_exchange"
,
'Zhaobi'
);
if
(
false
==
$currency
||
false
==
$base_currency
)
{
$msg
=
'invalid symbol'
;
$code
=
-
1
;
goto
doEnd
;
}
$exchange
=
ExchangeFactory
::
createExchange
(
$exchange
);
$quotation
=
$exchange
->
getTicker
(
$currency
);
$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
),
];
echo
json_encode
(
$quotation
);
exit
;
$base_exchange
=
ExchangeFactory
::
createExchange
(
$base_exchange
);
$base_quotation
=
$base_exchange
->
getTicker
(
$base_currency
);
$base_quotation
=
[
'low'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_quotation
[
'low'
]
/
100
),
'high'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_quotation
[
'high'
]
/
100
),
'last'
=>
(
float
)
sprintf
(
"%0.4f"
,
$base_quotation
[
'last'
]
/
100
),
'rmb'
=>
(
float
)
sprintf
(
"%0.2f"
,
$base_quotation
[
'last'
]
/
100
),
];
$builder
=
ExchangeBuilderFactory
::
create
(
'Zhaobi'
);
$result
=
$builder
->
getDetail
(
strtoupper
(
$currency
),
strtoupper
(
$base_currency
));
if
(
-
1
==
$result
[
'code'
])
{
$msg
=
'invalid symbol'
;
$code
=
-
1
;
goto
doEnd
;
}
$code
=
0
;
$msg
=
'ok'
;
$ticker
=
$result
[
'ticker'
];
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'tick'
=>
$ticker
??
[]];
}
}
}
\ No newline at end of file
api/controllers/WalletChainController.php
View file @
b9594ab6
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
api\controllers
;
namespace
api\controllers
;
use
common\service\chain33\Chain33Service
;
use
Yii
;
use
Yii
;
use
api\base\BaseController
;
use
api\base\BaseController
;
use
common\models\psources\WalletChain
;
use
common\models\psources\WalletChain
;
...
@@ -35,7 +36,7 @@ class WalletChainController extends BaseController
...
@@ -35,7 +36,7 @@ class WalletChainController extends BaseController
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
10
);
$size
=
Yii
::
$app
->
request
->
get
(
'size'
,
10
);
$query
=
WalletChain
::
find
()
$query
=
WalletChain
::
find
()
->
select
(
'id, token, platform'
)
->
select
(
'id, token, platform
, status
'
)
->
where
([
'wallet_address'
=>
$wallet_address
])
->
where
([
'wallet_address'
=>
$wallet_address
])
->
orderBy
(
'id'
);
->
orderBy
(
'id'
);
...
@@ -90,16 +91,39 @@ class WalletChainController extends BaseController
...
@@ -90,16 +91,39 @@ class WalletChainController extends BaseController
'host'
=>
isset
(
$post
[
'host'
])
?
$post
[
'host'
]
:
''
,
'host'
=>
isset
(
$post
[
'host'
])
?
$post
[
'host'
]
:
''
,
'port'
=>
isset
(
$post
[
'port'
])
?
$post
[
'port'
]
:
''
,
'port'
=>
isset
(
$post
[
'port'
])
?
$post
[
'port'
]
:
''
,
'wallet_address'
=>
isset
(
$post
[
'wallet_address'
])
?
$post
[
'wallet_address'
]
:
''
,
'wallet_address'
=>
isset
(
$post
[
'wallet_address'
])
?
$post
[
'wallet_address'
]
:
''
,
'hash'
=>
isset
(
$post
[
'hash'
])
?
$post
[
'hash'
]
:
''
,
'status'
=>
WalletChain
::
STATUS_NO
,
'fee'
=>
isset
(
$post
[
'fee'
])
?
$post
[
'fee'
]
:
''
'origin'
=>
WalletChain
::
ORIGIN_MANAGE
,
'fee'
=>
isset
(
$post
[
'fee'
])
?
$post
[
'fee'
]
:
''
,
'hash'
=>
isset
(
$post
[
'hash'
])
?
$post
[
'hash'
]
:
''
];
];
if
(
$model
->
load
(
$params
,
''
)
&&
$model
->
save
())
{
if
(
$model
->
load
(
$params
,
''
)
&&
!
$model
->
save
())
{
$this
->
msg
=
$model
->
errors
;
$this
->
code
=
-
1
;
goto
doEnd
;
goto
doEnd
;
}
}
$this
->
msg
=
$model
->
errors
;
$id
=
Yii
::
$app
->
p_sources
->
getLastInsertID
();
$this
->
code
=
-
1
;
// $params = [
goto
doEnd
;
// '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
:
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
...
@@ -128,7 +152,7 @@ class WalletChainController extends BaseController
...
@@ -128,7 +152,7 @@ class WalletChainController extends BaseController
}
}
$model
=
WalletChain
::
find
()
->
select
(
'platform, token, address, private_key, fee, host, port, hash'
)
->
where
([
'id'
=>
(
int
)
$id
])
->
asArray
()
->
one
();
$model
=
WalletChain
::
find
()
->
select
(
'platform, token, address, private_key, fee, host, port, hash
, status
'
)
->
where
([
'id'
=>
(
int
)
$id
])
->
asArray
()
->
one
();
if
(
empty
(
$model
))
{
if
(
empty
(
$model
))
{
goto
doEnd
;
goto
doEnd
;
}
}
...
@@ -141,4 +165,4 @@ class WalletChainController extends BaseController
...
@@ -141,4 +165,4 @@ class WalletChainController extends BaseController
doEnd
:
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
}
}
}
\ No newline at end of file
common/models/psources/WalletChain.php
View file @
b9594ab6
...
@@ -11,6 +11,15 @@ class WalletChain extends BaseActiveRecord
...
@@ -11,6 +11,15 @@ class WalletChain extends BaseActiveRecord
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_CREATE
=
'create'
;
const
SCENARIOS_UPDATE
=
'update'
;
const
SCENARIOS_UPDATE
=
'update'
;
<<<<<<<
HEAD
=======
const
STATUS_NO
=
0
;
//创建失败
const
STATUS_YES
=
1
;
//创建成功
const
ORIGIN_MANAGE
=
1
;
//管理员创建
const
ORIGIN_USER
=
2
;
//h5用户创建
>>>>>>>
feature
/
ticker
public
static
function
getDb
()
public
static
function
getDb
()
{
{
return
Yii
::
$app
->
get
(
'p_sources'
);
return
Yii
::
$app
->
get
(
'p_sources'
);
...
@@ -35,6 +44,11 @@ class WalletChain extends BaseActiveRecord
...
@@ -35,6 +44,11 @@ class WalletChain extends BaseActiveRecord
'host'
=>
'钱包服务IP'
,
'host'
=>
'钱包服务IP'
,
'port'
=>
'钱包服务端口'
,
'port'
=>
'钱包服务端口'
,
'wallet_address'
=>
'钱包地址'
,
'wallet_address'
=>
'钱包地址'
,
<<<<<<<
HEAD
=======
'status'
=>
'申请状态'
,
'origin'
=>
'创建人'
,
>>>>>>>
feature
/
ticker
'hash'
=>
'申请费用hash'
'hash'
=>
'申请费用hash'
];
];
}
}
...
@@ -42,19 +56,32 @@ class WalletChain extends BaseActiveRecord
...
@@ -42,19 +56,32 @@ class WalletChain extends BaseActiveRecord
public
function
rules
()
public
function
rules
()
{
{
return
[
return
[
<<<<<<<
HEAD
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
,
'port'
,
'fee'
],
'required'
],
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
,
'port'
,
'fee'
],
'required'
],
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
],
'string'
],
[[
'platform'
,
'address'
,
'private_key'
,
'execer'
,
'brower_url'
,
'token'
,
'host'
,
'wallet_address'
,
'hash'
],
'string'
],
[[
'platform'
],
'string'
,
'length'
=>
[
1
,
30
]],
[[
'platform'
],
'string'
,
'length'
=>
[
1
,
30
]],
[[
'token'
],
'string'
,
'length'
=>
[
1
,
10
]],
[[
'token'
],
'string'
,
'length'
=>
[
1
,
10
]],
[[
'port'
],
'integer'
]
[[
'port'
],
'integer'
]
=======
[[
'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'
]
>>>>>>>
feature
/
ticker
];
];
}
}
public
function
scenarios
()
public
function
scenarios
()
{
{
$scenarios
=
[
$scenarios
=
[
<<<<<<<
HEAD
self
::
SCENARIOS_CREATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'hash'
],
self
::
SCENARIOS_CREATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'hash'
],
self
::
SCENARIOS_UPDATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'hash'
],
self
::
SCENARIOS_UPDATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'hash'
],
=======
self
::
SCENARIOS_CREATE
=>
[
'platform'
,
'token'
,
'address'
,
'private_key'
,
'fee'
,
'host'
,
'port'
,
'wallet_address'
,
'status'
,
'origin'
,
'hash'
],
self
::
SCENARIOS_UPDATE
=>
[
'status'
],
>>>>>>>
feature
/
ticker
];
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
...
...
common/service/chain33/Chain33Service.php
View file @
b9594ab6
...
@@ -54,12 +54,8 @@ class Chain33Service
...
@@ -54,12 +54,8 @@ class Chain33Service
return
json_encode
(
$data
);
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
);
$ch
=
new
Curl
(
$timeout
);
$jsonrpc
=
self
::
jsonRpcBuild
(
$params
,
$method
);
$jsonrpc
=
self
::
jsonRpcBuild
(
$params
,
$method
);
$ch
->
setHeader
(
'Content-Type'
,
'application/json'
);
$ch
->
setHeader
(
'Content-Type'
,
'application/json'
);
...
@@ -449,4 +445,23 @@ class Chain33Service
...
@@ -449,4 +445,23 @@ class Chain33Service
];
];
return
$this
->
send
(
$params
,
'Chain33.UnLock'
);
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
);
}
}
}
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