Commit 172ed60e authored by pengjun's avatar pengjun

#627 add price query api

parent f4596d49
...@@ -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
} }
......
...@@ -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
......
...@@ -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
...@@ -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
...@@ -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
} }
......
...@@ -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
......
...@@ -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
...@@ -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
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment