Commit b48db05f authored by pengjun's avatar pengjun

#627 fix test error

parent 1330dd41
...@@ -285,6 +285,7 @@ func addCollateralizeManageFlags(cmd *cobra.Command) { ...@@ -285,6 +285,7 @@ func addCollateralizeManageFlags(cmd *cobra.Command) {
cmd.Flags().Float32P("liquidationRatio", "l", 0, "liquidationRatio") cmd.Flags().Float32P("liquidationRatio", "l", 0, "liquidationRatio")
cmd.Flags().Float32P("stabilityFeeRatio", "s", 0, "stabilityFeeRatio") cmd.Flags().Float32P("stabilityFeeRatio", "s", 0, "stabilityFeeRatio")
cmd.Flags().Uint64P("period", "p", 0, "period") cmd.Flags().Uint64P("period", "p", 0, "period")
cmd.Flags().Uint64P("totalBalance", "t", 0, "totalBalance")
} }
func CollateralizeManage(cmd *cobra.Command, args []string) { func CollateralizeManage(cmd *cobra.Command, args []string) {
...@@ -299,12 +300,13 @@ func CollateralizeManage(cmd *cobra.Command, args []string) { ...@@ -299,12 +300,13 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
liquidationRatio, _ := cmd.Flags().GetFloat32("liquidationRatio") liquidationRatio, _ := cmd.Flags().GetFloat32("liquidationRatio")
stabilityFeeRatio, _ := cmd.Flags().GetFloat32("stabilityFeeRatio") stabilityFeeRatio, _ := cmd.Flags().GetFloat32("stabilityFeeRatio")
period, _ := cmd.Flags().GetUint64("period") period, _ := cmd.Flags().GetUint64("period")
totalBalance, _ := cmd.Flags().GetUint64("totalBalance")
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: cfg.ExecName(pkt.CollateralizeX), Execer: cfg.ExecName(pkt.CollateralizeX),
ActionName: "CollateralizeManage", ActionName: "CollateralizeManage",
Payload: []byte(fmt.Sprintf("{\"debtCeiling\":%d, \"liquidationRatio\":%f, \"stabilityFeeRatio\":%f, \"period\":%d}", Payload: []byte(fmt.Sprintf("{\"debtCeiling\":%d, \"liquidationRatio\":%f, \"stabilityFeeRatio\":%f, \"period\":%d, \"totalBalance\":%d,}",
debtCeiling, liquidationRatio, stabilityFeeRatio, period)), debtCeiling, liquidationRatio, stabilityFeeRatio, period, totalBalance)),
} }
var res string var res string
...@@ -312,6 +314,27 @@ func CollateralizeManage(cmd *cobra.Command, args []string) { ...@@ -312,6 +314,27 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
ctx.RunWithoutMarshal() ctx.RunWithoutMarshal()
} }
func CollateralizeQueryCfgCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Query config result",
Run: CollateralizeQueryConfig,
}
return cmd
}
func CollateralizeQueryConfig(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
var params rpctypes.Query4Jrpc
params.Execer = pkt.CollateralizeX
params.FuncName = "CollateralizeConfig"
var res pkt.RepCollateralizeConfig
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{
...@@ -320,6 +343,9 @@ func CollateralizeQueryCmd() *cobra.Command { ...@@ -320,6 +343,9 @@ func CollateralizeQueryCmd() *cobra.Command {
Run: CollateralizeQuery, Run: CollateralizeQuery,
} }
addCollateralizeQueryFlags(cmd) addCollateralizeQueryFlags(cmd)
cmd.AddCommand(
CollateralizeQueryCfgCmd(),
)
return cmd return cmd
} }
...@@ -437,7 +463,7 @@ func CollateralizeQuery(cmd *cobra.Command, args []string) { ...@@ -437,7 +463,7 @@ func CollateralizeQuery(cmd *cobra.Command, args []string) {
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else { } else {
fmt.Println("Error: requeres at least one of gameID, address or status") fmt.Println("Error: requeres at least one of collId, address or status")
cmd.Help() cmd.Help()
} }
} }
...@@ -30,6 +30,7 @@ const ( ...@@ -30,6 +30,7 @@ const (
DefaultLiquidationRatio = 0.4 // 默认质押比 DefaultLiquidationRatio = 0.4 // 默认质押比
DefaultStabilityFeeRation = 0.08 // 默认稳定费 DefaultStabilityFeeRation = 0.08 // 默认稳定费
DefaultPeriod = 3600 * 24 * 365 // 默认合约限期 DefaultPeriod = 3600 * 24 * 365 // 默认合约限期
DefaultCollTotalBalance = 0 // 默认放贷总额
PriceWarningRate = 1.3 // 价格提前预警率 PriceWarningRate = 1.3 // 价格提前预警率
ExpireWarningTime = 3600 * 24 * 10 // 提前10天超时预警 ExpireWarningTime = 3600 * 24 * 10 // 提前10天超时预警
) )
...@@ -265,29 +266,46 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ ...@@ -265,29 +266,46 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ
return nil, pty.ErrRiskParam return nil, pty.ErrRiskParam
} }
collConfig := &pty.CollateralizeManage{} var collConfig *pty.CollateralizeManage
manConfig, _ := getCollateralizeConfig(action.db)
if manConfig == nil {
manConfig = &pty.CollateralizeManage{
DebtCeiling: DefaultDebtCeiling,
LiquidationRatio: DefaultLiquidationRatio,
StabilityFeeRatio: DefaultStabilityFeeRation,
Period: DefaultPeriod,
CollTotalBalance: DefaultCollTotalBalance,
}
}
if manage.StabilityFeeRatio != 0 { if manage.StabilityFeeRatio != 0 {
collConfig.StabilityFeeRatio = manage.StabilityFeeRatio collConfig.StabilityFeeRatio = manage.StabilityFeeRatio
} else { } else {
collConfig.StabilityFeeRatio = DefaultStabilityFeeRation collConfig.StabilityFeeRatio = manConfig.StabilityFeeRatio
} }
if manage.Period != 0 { if manage.Period != 0 {
collConfig.Period = manage.Period collConfig.Period = manage.Period
} else { } else {
collConfig.Period = DefaultPeriod collConfig.Period = manConfig.Period
} }
if manage.LiquidationRatio != 0 { if manage.LiquidationRatio != 0 {
collConfig.LiquidationRatio = manage.LiquidationRatio collConfig.LiquidationRatio = manage.LiquidationRatio
} else { } else {
collConfig.LiquidationRatio = DefaultLiquidationRatio collConfig.LiquidationRatio = manConfig.LiquidationRatio
} }
if manage.DebtCeiling != 0 { if manage.DebtCeiling != 0 {
collConfig.DebtCeiling = manage.DebtCeiling collConfig.DebtCeiling = manage.DebtCeiling
} else { } else {
collConfig.DebtCeiling = DefaultDebtCeiling collConfig.DebtCeiling = manConfig.DebtCeiling
}
if manage.CollTotalBalance != 0 {
collConfig.CollTotalBalance = manage.CollTotalBalance
} else {
collConfig.CollTotalBalance = manConfig.CollTotalBalance
} }
value := types.Encode(collConfig) value := types.Encode(collConfig)
...@@ -298,8 +316,8 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ ...@@ -298,8 +316,8 @@ func (action *Action) CollateralizeManage(manage *pty.CollateralizeManage) (*typ
return receipt, nil return receipt, nil
} }
func (action *Action) getCollateralizeConfig() (*pty.CollateralizeManage, error) { func getCollateralizeConfig(db dbm.KV) (*pty.CollateralizeManage, error) {
data, err := action.db.Get(ConfigKey()) data, err := db.Get(ConfigKey())
if err != nil { if err != nil {
clog.Debug("getCollateralizeConfig", "error", err) clog.Debug("getCollateralizeConfig", "error", err)
return nil, err return nil, err
...@@ -375,9 +393,15 @@ func (action *Action) CollateralizeCreate(create *pty.CollateralizeCreate) (*typ ...@@ -375,9 +393,15 @@ func (action *Action) CollateralizeCreate(create *pty.CollateralizeCreate) (*typ
// 获取借贷配置 // 获取借贷配置
var collcfg *pty.CollateralizeManage var collcfg *pty.CollateralizeManage
cfg, err := action.getCollateralizeConfig() cfg, err := getCollateralizeConfig(action.db)
if err != nil { if cfg == nil {
collcfg = &pty.CollateralizeManage{DebtCeiling:DefaultDebtCeiling, LiquidationRatio:DefaultLiquidationRatio, StabilityFeeRatio:DefaultStabilityFeeRation, Period:DefaultPeriod} collcfg = &pty.CollateralizeManage{
DebtCeiling:DefaultDebtCeiling,
LiquidationRatio:DefaultLiquidationRatio,
StabilityFeeRatio:DefaultStabilityFeeRation,
Period:DefaultPeriod,
CollTotalBalance:DefaultCollTotalBalance,
}
} else { } else {
collcfg = cfg collcfg = cfg
} }
...@@ -835,9 +859,9 @@ func (action *Action) systemLiquidation(coll *pty.Collateralize, price float32) ...@@ -835,9 +859,9 @@ func (action *Action) systemLiquidation(coll *pty.Collateralize, price float32)
collDB := &CollateralizeDB{*coll} collDB := &CollateralizeDB{*coll}
for index, borrowRecord := range coll.BorrowRecords { for index, borrowRecord := range coll.BorrowRecords {
if borrowRecord.LiquidationPrice * PriceWarningRate < price { if borrowRecord.LiquidationPrice * PriceWarningRate < price {
if borrowRecord.Status == pty.CollateralizeUserStatusSystemLiquidate { if borrowRecord.Status == pty.CollateralizeUserStatusWarning {
borrowRecord.Status = borrowRecord.PreStatus borrowRecord.PreStatus = borrowRecord.Status
borrowRecord.PreStatus = pty.CollateralizeUserStatusSystemLiquidate borrowRecord.Status = pty.CollateralizeUserStatusCreate
} }
continue continue
} }
......
...@@ -37,32 +37,32 @@ func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptD ...@@ -37,32 +37,32 @@ func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptD
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...) set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...) //set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId, //set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) // collateralizeLog.RecordId, collateralizeLog.Index)...)
} }
break break
case pty.TyLogCollateralizeRepay: case pty.TyLogCollateralizeRepay:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...) set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...) //set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
break break
case pty.TyLogCollateralizeFeed: case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...) set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...) //set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新 //// 如果没有被清算,需要把地址索引更新
if collateralizeLog.Status == pty.CollateralizeUserStatusWarning || collateralizeLog.Status == pty.CollateralizeUserStatusExpire { //if collateralizeLog.Status == pty.CollateralizeUserStatusWarning || collateralizeLog.Status == pty.CollateralizeUserStatusExpire {
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId, // set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) // collateralizeLog.RecordId, collateralizeLog.Index)...)
} //}
break break
case pty.TyLogCollateralizeClose: case pty.TyLogCollateralizeClose:
set.KV = append(set.KV, c.addCollateralizeStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, collateralizeLog.Index)...) set.KV = append(set.KV, c.addCollateralizeStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...) set.KV = append(set.KV, c.deleteCollateralizeStatus(collateralizeLog.PreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.PreIndex)...) //set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.PreIndex)...)
break break
} }
} }
......
...@@ -24,6 +24,7 @@ func (c *Collateralize) Query_CollateralizeInfoByID(req *pty.ReqCollateralizeInf ...@@ -24,6 +24,7 @@ func (c *Collateralize) Query_CollateralizeInfoByID(req *pty.ReqCollateralizeInf
StabilityFeeRatio: coll.StabilityFeeRatio, StabilityFeeRatio: coll.StabilityFeeRatio,
CreateAddr: coll.CreateAddr, CreateAddr: coll.CreateAddr,
Balance: coll.Balance, Balance: coll.Balance,
Period: coll.Period,
}, nil }, nil
} }
...@@ -44,6 +45,7 @@ func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeIn ...@@ -44,6 +45,7 @@ func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeIn
StabilityFeeRatio: coll.StabilityFeeRatio, StabilityFeeRatio: coll.StabilityFeeRatio,
CreateAddr: coll.CreateAddr, CreateAddr: coll.CreateAddr,
Balance: coll.Balance, Balance: coll.Balance,
Period: coll.Period,
}) })
} }
...@@ -98,14 +100,37 @@ func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateraliz ...@@ -98,14 +100,37 @@ func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateraliz
return ret, nil return ret, nil
} }
func (c *Collateralize) Query_CollateralizeRecordByStatus(req *pty.ReqCollateralizeRecordByStatus) (types.Message, error) { func (c *Collateralize) Query_CollateralizeConfig(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
ret := &pty.RepCollateralizeRecords{} config, err := getCollateralizeConfig(c.GetStateDB())
records, err := queryCollateralizeRecordByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status, req.Index)
if err != nil { if err != nil {
clog.Error("Query_CollateralizeRecordByStatus", "get collateralize record error", err) clog.Error("Query_CollateralizeConfig", "get collateralize config error", err)
return nil, err return nil, err
} }
ret.Records = records collIDRecords, err := queryCollateralizeByStatus(c.GetLocalDB(), pty.CollateralizeStatusCreated, 0)
if err != nil {
clog.Error("Query_CollateralizeByStatus", "get collateralize record error", err)
return nil, err
}
collBalance := config.CollTotalBalance
for _, id := range collIDRecords {
coll, err := queryCollateralizeByID(c.GetStateDB(), id)
if err != nil {
clog.Error("Query_CollateralizeInfoByID", "id", id, "error", err)
return nil, err
}
collBalance -= coll.TotalBalance
}
ret := &pty.RepCollateralizeConfig{
CollTotalBalance:config.CollTotalBalance,
DebtCeiling: config.DebtCeiling,
LiquidationRatio: config.LiquidationRatio,
StabilityFeeRatio: config.StabilityFeeRatio,
Period: config.Period,
CollBalance: collBalance,
}
return ret, nil return ret, nil
} }
\ No newline at end of file
...@@ -65,6 +65,7 @@ message CollateralizeManage { ...@@ -65,6 +65,7 @@ message CollateralizeManage {
float liquidationRatio = 2; //清算比例 float liquidationRatio = 2; //清算比例
float stabilityFeeRatio = 3; //稳定费 float stabilityFeeRatio = 3; //稳定费
int64 period = 4; //合约期限 int64 period = 4; //合约期限
int64 collTotalBalance = 5; //放贷总量
} }
message CollateralizeAddr { message CollateralizeAddr {
...@@ -145,6 +146,7 @@ message RepCollateralizeCurrentInfo { ...@@ -145,6 +146,7 @@ message RepCollateralizeCurrentInfo {
float stabilityFeeRatio = 5; //稳定费 float stabilityFeeRatio = 5; //稳定费
string createAddr = 6; //创建人地址 string createAddr = 6; //创建人地址
int64 balance = 7; //剩余可借贷金额(ccny) int64 balance = 7; //剩余可借贷金额(ccny)
int64 period = 8; //合约期限
} }
// 根据ID列表查询多期借贷信息 // 根据ID列表查询多期借贷信息
...@@ -203,3 +205,13 @@ message ReqCollateralizeRecord { ...@@ -203,3 +205,13 @@ message ReqCollateralizeRecord {
message RepCollateralizeRecord { message RepCollateralizeRecord {
BorrowRecord record = 1; BorrowRecord record = 1;
} }
// 返回放贷配置
message RepCollateralizeConfig {
int64 debtCeiling = 1; //单用户可借出的限额(ccny)
float liquidationRatio = 2; //清算比例
float stabilityFeeRatio = 3; //稳定费
int64 period = 4; //合约期限
int64 collTotalBalance = 5; //放贷总量
int64 collBalance = 6; //剩余放贷额度
}
\ No newline at end of file
...@@ -331,6 +331,7 @@ func CreateRawCollateralizeManageTx(cfg *types.Chain33Config, parm *Collateraliz ...@@ -331,6 +331,7 @@ func CreateRawCollateralizeManageTx(cfg *types.Chain33Config, parm *Collateraliz
LiquidationRatio: parm.LiquidationRatio, LiquidationRatio: parm.LiquidationRatio,
StabilityFeeRatio: parm.StabilityFeeRatio, StabilityFeeRatio: parm.StabilityFeeRatio,
Period: parm.Period, Period: parm.Period,
CollTotalBalance: parm.TotalBalance,
} }
manage := &CollateralizeAction{ manage := &CollateralizeAction{
......
...@@ -51,5 +51,6 @@ type CollateralizeManageTx struct { ...@@ -51,5 +51,6 @@ type CollateralizeManageTx struct {
LiquidationRatio float32 `json:"liquidationRatio"` LiquidationRatio float32 `json:"liquidationRatio"`
StabilityFeeRatio float32 `json:"stabilityFeeRatio"` StabilityFeeRatio float32 `json:"stabilityFeeRatio"`
Period int64 `json:"period"` Period int64 `json:"period"`
TotalBalance int64 `json:"totalBalance"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
...@@ -382,6 +382,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) { ...@@ -382,6 +382,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
issuanceIDsS = append(issuanceIDsS, issuanceIDs) issuanceIDsS = append(issuanceIDsS, issuanceIDs)
req := &pkt.ReqIssuanceInfos{IssuanceIds: issuanceIDsS} req := &pkt.ReqIssuanceInfos{IssuanceIds: issuanceIDsS}
params.Payload = types.MustPBToJSON(req) params.Payload = types.MustPBToJSON(req)
fmt.Println(params.Payload)
var res pkt.RepIssuanceCurrentInfos var res pkt.RepIssuanceCurrentInfos
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
......
...@@ -32,19 +32,19 @@ func (c *Issuance) execDelLocal(tx *types.Transaction, receiptData *types.Receip ...@@ -32,19 +32,19 @@ func (c *Issuance) execDelLocal(tx *types.Transaction, receiptData *types.Receip
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.AccountAddr, issuanceLog.PreIndex, set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...) issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...) set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId, //set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...) // issuanceLog.IssuanceId)...)
break break
case pty.TyLogIssuanceFeed: case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.PreIndex, set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...) issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...) set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId, //set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...) // issuanceLog.IssuanceId)...)
// 如果没有被清算,需要把地址索引更新 //// 如果没有被清算,需要把地址索引更新
if issuanceLog.Status == pty.IssuanceUserStatusWarning || issuanceLog.Status == pty.IssuanceUserStatusExpire { //if issuanceLog.Status == pty.IssuanceUserStatusWarning || issuanceLog.Status == pty.IssuanceUserStatusExpire {
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index)...) // set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index)...)
} //}
set.KV = append(set.KV, c.deleteIssuancePriceRecord(issuanceLog.RecordTime)...) set.KV = append(set.KV, c.deleteIssuancePriceRecord(issuanceLog.RecordTime)...)
break break
case pty.TyLogIssuanceClose: case pty.TyLogIssuanceClose:
......
...@@ -35,18 +35,18 @@ func (c *Issuance) execLocal(tx *types.Transaction, receipt *types.ReceiptData) ...@@ -35,18 +35,18 @@ func (c *Issuance) execLocal(tx *types.Transaction, receipt *types.ReceiptData)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...) set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index, set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...) issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...) //set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
break break
case pty.TyLogIssuanceFeed: case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...) set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index, set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...) issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...) //set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新 //// 如果没有被清算,需要把地址索引更新
if issuanceLog.Status == pty.IssuanceUserStatusWarning || issuanceLog.Status == pty.IssuanceUserStatusExpire { //if issuanceLog.Status == pty.IssuanceUserStatusWarning || issuanceLog.Status == pty.IssuanceUserStatusExpire {
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index, issuanceLog.DebtId, // set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index, issuanceLog.DebtId,
issuanceLog.IssuanceId)...) // issuanceLog.IssuanceId)...)
} //}
set.KV = append(set.KV, c.addIssuancePriceRecord(issuanceLog.RecordTime, issuanceLog.BtyPrice)...) set.KV = append(set.KV, c.addIssuancePriceRecord(issuanceLog.RecordTime, issuanceLog.BtyPrice)...)
break break
case pty.TyLogIssuanceClose: case pty.TyLogIssuanceClose:
......
...@@ -716,9 +716,9 @@ func (action *Action) systemLiquidation(issu *pty.Issuance, price float32) (*typ ...@@ -716,9 +716,9 @@ func (action *Action) systemLiquidation(issu *pty.Issuance, price float32) (*typ
collDB := &IssuanceDB{*issu} collDB := &IssuanceDB{*issu}
for index, debtRecord := range issu.DebtRecords { for index, debtRecord := range issu.DebtRecords {
if debtRecord.LiquidationPrice * PriceWarningRate < price { if debtRecord.LiquidationPrice * PriceWarningRate < price {
if debtRecord.Status == pty.IssuanceUserStatusSystemLiquidate { if debtRecord.Status == pty.IssuanceUserStatusWarning {
debtRecord.Status = debtRecord.PreStatus debtRecord.PreStatus = debtRecord.Status
debtRecord.PreStatus = pty.IssuanceUserStatusSystemLiquidate debtRecord.Status = pty.IssuanceUserStatusCreate
} }
continue continue
} }
......
...@@ -24,6 +24,7 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa ...@@ -24,6 +24,7 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa
Balance: issu.Balance, Balance: issu.Balance,
CollateralValue: issu.CollateralValue, CollateralValue: issu.CollateralValue,
DebtValue: issu.DebtValue, DebtValue: issu.DebtValue,
Period: issu.Period,
}, nil }, nil
} }
...@@ -44,6 +45,7 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes ...@@ -44,6 +45,7 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes
Balance: issu.Balance, Balance: issu.Balance,
CollateralValue: issu.CollateralValue, CollateralValue: issu.CollateralValue,
DebtValue: issu.DebtValue, DebtValue: issu.DebtValue,
Period: issu.Period,
}) })
} }
......
...@@ -135,6 +135,7 @@ message RepIssuanceCurrentInfo { ...@@ -135,6 +135,7 @@ message RepIssuanceCurrentInfo {
int64 balance = 5; //剩余可借贷金额(ccny) int64 balance = 5; //剩余可借贷金额(ccny)
int64 collateralValue = 6; //抵押物总数量(bty) int64 collateralValue = 6; //抵押物总数量(bty)
int64 debtValue = 7; //产生的ccny数量 int64 debtValue = 7; //产生的ccny数量
int64 period = 8;//借贷最大期限
} }
// 根据ID列表查询多期借贷信息 // 根据ID列表查询多期借贷信息
......
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