Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
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
link33
plugin
Commits
172ed60e
Commit
172ed60e
authored
Nov 09, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 add price query api
parent
f4596d49
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
85 additions
and
5 deletions
+85
-5
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+22
-0
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+3
-3
query.go
plugin/dapp/collateralize/executor/query.go
+11
-0
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+6
-0
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
cmd.go
plugin/dapp/issuance/commands/cmd.go
+24
-0
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+2
-2
query.go
plugin/dapp/issuance/executor/query.go
+11
-0
issuance.proto
plugin/dapp/issuance/proto/issuance.proto
+6
-0
issuance.pb.go
plugin/dapp/issuance/types/issuance.pb.go
+0
-0
No files found.
plugin/dapp/collateralize/commands/cmd.go
View file @
172ed60e
...
@@ -335,6 +335,27 @@ func CollateralizeQueryConfig(cmd *cobra.Command, args []string) {
...
@@ -335,6 +335,27 @@ func CollateralizeQueryConfig(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
func
CollateralizeQueryPriceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"price"
,
Short
:
"Query latest price"
,
Run
:
CollateralizeQueryPrice
,
}
return
cmd
}
func
CollateralizeQueryPrice
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
params
.
FuncName
=
"CollateralizePrice"
var
res
pkt
.
RepCollateralizePrice
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
// CollateralizeQueryCmd 查询命令行
// CollateralizeQueryCmd 查询命令行
func
CollateralizeQueryCmd
()
*
cobra
.
Command
{
func
CollateralizeQueryCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
@@ -345,6 +366,7 @@ func CollateralizeQueryCmd() *cobra.Command {
...
@@ -345,6 +366,7 @@ func CollateralizeQueryCmd() *cobra.Command {
addCollateralizeQueryFlags
(
cmd
)
addCollateralizeQueryFlags
(
cmd
)
cmd
.
AddCommand
(
cmd
.
AddCommand
(
CollateralizeQueryCfgCmd
(),
CollateralizeQueryCfgCmd
(),
CollateralizeQueryPriceCmd
(),
)
)
return
cmd
return
cmd
}
}
...
...
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
172ed60e
...
@@ -457,7 +457,7 @@ func calcLiquidationPrice(value int64, colValue int64) float32 {
...
@@ -457,7 +457,7 @@ func calcLiquidationPrice(value int64, colValue int64) float32 {
}
}
// 获取最近抵押物价格
// 获取最近抵押物价格
func
(
action
*
Action
)
getLatestPrice
(
db
dbm
.
KV
)
(
float32
,
error
)
{
func
getLatestPrice
(
db
dbm
.
KV
)
(
float32
,
error
)
{
data
,
err
:=
db
.
Get
(
PriceKey
())
data
,
err
:=
db
.
Get
(
PriceKey
())
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
...
@@ -537,7 +537,7 @@ func (action *Action) CollateralizeBorrow(borrow *pty.CollateralizeBorrow) (*typ
...
@@ -537,7 +537,7 @@ func (action *Action) CollateralizeBorrow(borrow *pty.CollateralizeBorrow) (*typ
clog
.
Debug
(
"CollateralizeBorrow"
,
"value"
,
borrow
.
GetValue
())
clog
.
Debug
(
"CollateralizeBorrow"
,
"value"
,
borrow
.
GetValue
())
// 获取抵押物价格
// 获取抵押物价格
lastPrice
,
err
:=
action
.
getLatestPrice
(
action
.
db
)
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
...
@@ -740,7 +740,7 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
...
@@ -740,7 +740,7 @@ func (action *Action) CollateralizeAppend(cAppend *pty.CollateralizeAppend) (*ty
clog
.
Debug
(
"CollateralizeAppend"
,
"value"
,
cAppend
.
CollateralValue
)
clog
.
Debug
(
"CollateralizeAppend"
,
"value"
,
cAppend
.
CollateralValue
)
// 获取抵押物价格
// 获取抵押物价格
lastPrice
,
err
:=
action
.
getLatestPrice
(
action
.
db
)
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
...
...
plugin/dapp/collateralize/executor/query.go
View file @
172ed60e
...
@@ -157,4 +157,14 @@ func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecor
...
@@ -157,4 +157,14 @@ func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecor
}
}
return
ret
,
nil
return
ret
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizePrice
(
req
*
pty
.
ReqCollateralizeRecordByAddr
)
(
types
.
Message
,
error
)
{
price
,
err
:=
getLatestPrice
(
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizePrice"
,
"error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepCollateralizePrice
{
Price
:
price
},
nil
}
}
\ No newline at end of file
plugin/dapp/collateralize/proto/collateralize.proto
View file @
172ed60e
...
@@ -223,4 +223,9 @@ message RepCollateralizeConfig {
...
@@ -223,4 +223,9 @@ message RepCollateralizeConfig {
int64
collTotalBalance
=
5
;
//放贷总量
int64
collTotalBalance
=
5
;
//放贷总量
int64
collBalance
=
6
;
//剩余放贷额度
int64
collBalance
=
6
;
//剩余放贷额度
int64
currentTime
=
7
;
//设置时间
int64
currentTime
=
7
;
//设置时间
}
// 返回最新抵押物价格
message
RepCollateralizePrice
{
float
price
=
1
;
//当前抵押物最新价格
}
}
\ No newline at end of file
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
172ed60e
This diff is collapsed.
Click to expand it.
plugin/dapp/issuance/commands/cmd.go
View file @
172ed60e
...
@@ -269,6 +269,27 @@ func IssuanceManage(cmd *cobra.Command, args []string) {
...
@@ -269,6 +269,27 @@ func IssuanceManage(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
ctx
.
RunWithoutMarshal
()
}
}
func
IssuacneQueryPriceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"price"
,
Short
:
"Query latest price"
,
Run
:
IssuanceQueryPrice
,
}
return
cmd
}
func
IssuanceQueryPrice
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
IssuanceX
params
.
FuncName
=
"IssuancePrice"
var
res
pkt
.
RepIssuancePrice
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
// IssuanceQueryCmd 查询命令行
// IssuanceQueryCmd 查询命令行
func
IssuanceQueryCmd
()
*
cobra
.
Command
{
func
IssuanceQueryCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
...
@@ -277,6 +298,9 @@ func IssuanceQueryCmd() *cobra.Command {
...
@@ -277,6 +298,9 @@ func IssuanceQueryCmd() *cobra.Command {
Run
:
IssuanceQuery
,
Run
:
IssuanceQuery
,
}
}
addIssuanceQueryFlags
(
cmd
)
addIssuanceQueryFlags
(
cmd
)
cmd
.
AddCommand
(
IssuacneQueryPriceCmd
(),
)
return
cmd
return
cmd
}
}
...
...
plugin/dapp/issuance/executor/issuancedb.go
View file @
172ed60e
...
@@ -458,7 +458,7 @@ func getBtyNumToFrozen(value int64, price float32, ratio float32) (int64,error)
...
@@ -458,7 +458,7 @@ func getBtyNumToFrozen(value int64, price float32, ratio float32) (int64,error)
}
}
// 获取最近抵押物价格
// 获取最近抵押物价格
func
(
action
*
Action
)
getLatestPrice
(
db
dbm
.
KV
)
(
float32
,
error
)
{
func
getLatestPrice
(
db
dbm
.
KV
)
(
float32
,
error
)
{
data
,
err
:=
db
.
Get
(
PriceKey
())
data
,
err
:=
db
.
Get
(
PriceKey
())
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
...
@@ -544,7 +544,7 @@ func (action *Action) IssuanceDebt(debt *pty.IssuanceDebt) (*types.Receipt, erro
...
@@ -544,7 +544,7 @@ func (action *Action) IssuanceDebt(debt *pty.IssuanceDebt) (*types.Receipt, erro
clog
.
Debug
(
"IssuanceDebt"
,
"value"
,
debt
.
GetValue
())
clog
.
Debug
(
"IssuanceDebt"
,
"value"
,
debt
.
GetValue
())
// 获取抵押物价格
// 获取抵押物价格
lastPrice
,
err
:=
action
.
getLatestPrice
(
action
.
db
)
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"err"
,
err
)
return
nil
,
err
return
nil
,
err
...
...
plugin/dapp/issuance/executor/query.go
View file @
172ed60e
...
@@ -111,4 +111,14 @@ func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecordsBySt
...
@@ -111,4 +111,14 @@ func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecordsBySt
ret
.
Records
=
append
(
ret
.
Records
,
records
...
)
ret
.
Records
=
append
(
ret
.
Records
,
records
...
)
return
ret
,
nil
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuancePrice
(
req
*
pty
.
ReqIssuanceRecordsByStatus
)
(
types
.
Message
,
error
)
{
price
,
err
:=
getLatestPrice
(
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizePrice"
,
"error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepIssuancePrice
{
Price
:
price
},
nil
}
}
\ No newline at end of file
plugin/dapp/issuance/proto/issuance.proto
View file @
172ed60e
...
@@ -192,3 +192,8 @@ message ReqIssuanceDebtInfo {
...
@@ -192,3 +192,8 @@ message ReqIssuanceDebtInfo {
message
RepIssuanceDebtInfo
{
message
RepIssuanceDebtInfo
{
DebtRecord
record
=
1
;
DebtRecord
record
=
1
;
}
}
// 返回最新抵押物价格
message
RepIssuancePrice
{
float
price
=
1
;
//当前抵押物最新价格
}
\ No newline at end of file
plugin/dapp/issuance/types/issuance.pb.go
View file @
172ed60e
This diff is collapsed.
Click to expand it.
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