Commit ebffcd28 authored by pengjun's avatar pengjun

#627 update issuance

parent adb27358
...@@ -258,7 +258,7 @@ func CollateralizeManage(cmd *cobra.Command, args []string) { ...@@ -258,7 +258,7 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.CollateralizeX), Execer: types.ExecName(pkt.CollateralizeX),
ActionName: "CollateralizeManage", ActionName: "CollateralizeManage",
Payload: []byte(fmt.Sprintf("{\"debtCeiling\":%d, \"liquidationRatio\":%f, \"stabilityFeeRatio\":%f, \"period\":%s,}", Payload: []byte(fmt.Sprintf("{\"debtCeiling\":%d, \"liquidationRatio\":%f, \"stabilityFeeRatio\":%f, \"period\":%s}",
debtCeiling, liquidationRatio, stabilityFeeRatio, period)), debtCeiling, liquidationRatio, stabilityFeeRatio, period)),
} }
......
...@@ -12,47 +12,51 @@ import ( ...@@ -12,47 +12,51 @@ import (
func (c *Collateralize) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) { func (c *Collateralize) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{} set := &types.LocalDBSet{}
for _, item := range receiptData.Logs { for _, item := range receiptData.Logs {
var collateralizeLog pty.ReceiptCollateralize if item.Ty == pty.TyLogCollateralizeCreate || item.Ty == pty.TyLogCollateralizeBorrow || item.Ty == pty.TyLogCollateralizeAppend ||
err := types.Decode(item.Log, &collateralizeLog) item.Ty == pty.TyLogCollateralizeRepay || item.Ty == pty.TyLogCollateralizeFeed || item.Ty == pty.TyLogCollateralizeClose {
if err != nil { var collateralizeLog pty.ReceiptCollateralize
return nil, err err := types.Decode(item.Log, &collateralizeLog)
} if err != nil {
return nil, err
}
switch item.Ty { switch item.Ty {
case pty.TyLogCollateralizeCreate: case pty.TyLogCollateralizeCreate:
set.KV = append(set.KV, c.deleteCollateralizeStatus(collateralizeLog.Status, collateralizeLog.Index)...) set.KV = append(set.KV, c.deleteCollateralizeStatus(collateralizeLog.Status, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.Index)...) set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.Index)...)
break break
case pty.TyLogCollateralizeBorrow: case pty.TyLogCollateralizeBorrow:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...) set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.Index)...)
break
case pty.TyLogCollateralizeAppend: // append没有状态变化
break
case pty.TyLogCollateralizeRepay:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusWarning || collateralizeLog.RecordStatus == pty.CollateralizeUserStatusExpire {
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.Index)...) set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.Index)...)
break
case pty.TyLogCollateralizeAppend: // append没有状态变化
break
case pty.TyLogCollateralizeRepay:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusWarning || collateralizeLog.RecordStatus == pty.CollateralizeUserStatusExpire {
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.Index)...)
}
break
case pty.TyLogCollateralizeClose:
set.KV = append(set.KV, c.deleteCollateralizeStatus(collateralizeLog.Status, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeStatus(pty.CollateralizeStatusCreated, collateralizeLog.CollateralizeId,
collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.CollateralizeId,
collateralizeLog.PreIndex)...)
break
} }
break
case pty.TyLogCollateralizeClose:
set.KV = append(set.KV, c.addCollateralizeStatus(pty.CollateralizeStatusCreated, collateralizeLog.CollateralizeId,
collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.CollateralizeId,
collateralizeLog.PreIndex)...)
break
} }
} }
return set, nil return set, nil
......
...@@ -13,46 +13,50 @@ import ( ...@@ -13,46 +13,50 @@ import (
func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) { func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{} set := &types.LocalDBSet{}
for _, item := range receipt.Logs { for _, item := range receipt.Logs {
var collateralizeLog pty.ReceiptCollateralize if item.Ty == pty.TyLogCollateralizeCreate || item.Ty == pty.TyLogCollateralizeBorrow || item.Ty == pty.TyLogCollateralizeAppend ||
err := types.Decode(item.Log, &collateralizeLog) item.Ty == pty.TyLogCollateralizeRepay || item.Ty == pty.TyLogCollateralizeFeed || item.Ty == pty.TyLogCollateralizeClose {
if err != nil { var collateralizeLog pty.ReceiptCollateralize
return nil, err err := types.Decode(item.Log, &collateralizeLog)
} if err != nil {
return nil, err
}
switch item.Ty { switch item.Ty {
case pty.TyLogCollateralizeCreate: case pty.TyLogCollateralizeCreate:
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.addCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.CollateralizeId, collateralizeLog.Index)...) set.KV = append(set.KV, c.addCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.CollateralizeId, collateralizeLog.Index)...)
break break
case pty.TyLogCollateralizeBorrow: case pty.TyLogCollateralizeBorrow:
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId, set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...) collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
break
case pty.TyLogCollateralizeAppend: //append没有状态变化
break
case pty.TyLogCollateralizeRepay:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusWarning || collateralizeLog.RecordStatus == 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
case pty.TyLogCollateralizeAppend: //append没有状态变化
break
case pty.TyLogCollateralizeRepay:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
break
case pty.TyLogCollateralizeFeed:
set.KV = append(set.KV, c.deleteCollateralizeRecordStatus(collateralizeLog.RecordPreStatus, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.addCollateralizeRecordStatus(collateralizeLog.RecordStatus, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if collateralizeLog.RecordStatus == pty.CollateralizeUserStatusWarning || collateralizeLog.RecordStatus == pty.CollateralizeUserStatusExpire {
set.KV = append(set.KV, c.addCollateralizeRecordAddr(collateralizeLog.AccountAddr, collateralizeLog.CollateralizeId,
collateralizeLog.RecordId, collateralizeLog.Index)...)
}
break
case pty.TyLogCollateralizeClose:
set.KV = append(set.KV, c.addCollateralizeStatus(collateralizeLog.Status, collateralizeLog.CollateralizeId, collateralizeLog.Index)...)
set.KV = append(set.KV, c.deleteCollateralizeStatus(pty.CollateralizeStatusCreated, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.PreIndex)...)
break
} }
break
case pty.TyLogCollateralizeClose:
set.KV = append(set.KV, c.deleteCollateralizeStatus(pty.CollateralizeStatusCreated, collateralizeLog.PreIndex)...)
set.KV = append(set.KV, c.deleteCollateralizeAddr(collateralizeLog.CreateAddr, collateralizeLog.PreIndex)...)
break
} }
} }
return set, nil return set, nil
......
...@@ -7,56 +7,56 @@ package executor ...@@ -7,56 +7,56 @@ package executor
import "fmt" import "fmt"
func calcCollateralizeKey(collateralizeID string, index int64) []byte { func calcCollateralizeKey(collateralizeID string, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-ID:%s:%018d", collateralizeID, index) key := fmt.Sprintf("LODB-collateralize-ID:%s:%018d", collateralizeID, index)
return []byte(key) return []byte(key)
} }
func calcCollateralizeStatusPrefix(status int32) []byte { func calcCollateralizeStatusPrefix(status int32) []byte {
key := fmt.Sprintf("LODB-Collateralize-status-index:%d", status) key := fmt.Sprintf("LODB-collateralize-status:%d", status)
return []byte(key) return []byte(key)
} }
func calcCollateralizeStatusKey(status int32, index int64) []byte { func calcCollateralizeStatusKey(status int32, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-status:%d:%018d", status, index) key := fmt.Sprintf("LODB-collateralize-status:%d:%018d", status, index)
return []byte(key) return []byte(key)
} }
func calcCollateralizeAddrPrefix(addr string) []byte { func calcCollateralizeAddrPrefix(addr string) []byte {
key := fmt.Sprintf("LODB-Collateralize-addr:%s", addr) key := fmt.Sprintf("LODB-collateralize-addr:%s", addr)
return []byte(key) return []byte(key)
} }
func calcCollateralizeAddrKey(addr string, index int64) []byte { func calcCollateralizeAddrKey(addr string, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-addr:%s:%018d", addr, index) key := fmt.Sprintf("LODB-collateralize-addr:%s:%018d", addr, index)
return []byte(key) return []byte(key)
} }
func calcCollateralizePriceKey(time string) []byte { func calcCollateralizePriceKey(time string) []byte {
key := fmt.Sprintf("LODB-Collateralize-price:%s", time) key := fmt.Sprintf("LODB-collateralize-price:%s", time)
return []byte(key) return []byte(key)
} }
func calcCollateralizeLatestPriceKey() []byte { func calcCollateralizeLatestPriceKey() []byte {
key := fmt.Sprintf("LODB-Collateralize-latest-price") key := fmt.Sprintf("LODB-collateralize-latest-price")
return []byte(key) return []byte(key)
} }
func calcCollateralizeRecordAddrPrefix(addr string) []byte { func calcCollateralizeRecordAddrPrefix(addr string) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-addr:%d", addr) key := fmt.Sprintf("LODB-collateralize-record-addr:%d", addr)
return []byte(key) return []byte(key)
} }
func calcCollateralizeRecordAddrKey(addr string, index int64) []byte { func calcCollateralizeRecordAddrKey(addr string, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-addr:%d:%018d", addr, index) key := fmt.Sprintf("LODB-collateralize-record-addr:%d:%018d", addr, index)
return []byte(key) return []byte(key)
} }
func calcCollateralizeRecordStatusPrefix(status int32) []byte { func calcCollateralizeRecordStatusPrefix(status string) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-status:%d", status) key := fmt.Sprintf("LODB-collateralize-record-status:%s", status)
return []byte(key) return []byte(key)
} }
func calcCollateralizeRecordStatusKey(status int32, index int64) []byte { func calcCollateralizeRecordStatusKey(status int32, index int64) []byte {
key := fmt.Sprintf("LODB-Collateralize-record-status:%d:%018d", status, index) key := fmt.Sprintf("LODB-collateralize-record-status:%d:%018d", status, index)
return []byte(key) return []byte(key)
} }
\ No newline at end of file
...@@ -58,10 +58,7 @@ func (c *Collateralize) Query_CollateralizeByStatus(req *pty.ReqCollateralizeByS ...@@ -58,10 +58,7 @@ func (c *Collateralize) Query_CollateralizeByStatus(req *pty.ReqCollateralizeByS
return nil, err return nil, err
} }
for _, record := range collIDRecords { ids.IDs = append(ids.IDs, collIDRecords...)
ids.IDs = append(ids.IDs, record.CollateralizeId)
}
return ids, nil return ids, nil
} }
...@@ -73,47 +70,42 @@ func (c *Collateralize) Query_CollateralizeByAddr(req *pty.ReqCollateralizeByAdd ...@@ -73,47 +70,42 @@ func (c *Collateralize) Query_CollateralizeByAddr(req *pty.ReqCollateralizeByAdd
return nil, err return nil, err
} }
for _, record := range collIDRecords { ids.IDs = append(ids.IDs, collIDRecords...)
ids.IDs = append(ids.IDs, record.CollateralizeId)
}
return ids, nil return ids, nil
} }
func (c *Collateralize) Query_CollateralizeRecordByID(req *pty.ReqCollateralizeRecord) (types.Message, error) { func (c *Collateralize) Query_CollateralizeRecordByID(req *pty.ReqCollateralizeRecord) (types.Message, error) {
ret := &pty.RepCollateralizeRecord{}
issuRecord, err := queryCollateralizeRecordByID(c.GetStateDB(), req.CollateralizeId, req.RecordId) issuRecord, err := queryCollateralizeRecordByID(c.GetStateDB(), req.CollateralizeId, req.RecordId)
if err != nil { if err != nil {
clog.Error("Query_IssuanceRecordByID", "get issuance record error", err) clog.Error("Query_IssuanceRecordByID", "get collateralize record error", err)
return nil, err return nil, err
} }
ret := &pty.RepCollateralizeRecord{}
ret.Record = issuRecord ret.Record = issuRecord
return issuRecord, nil return ret, nil
} }
func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) { func (c *Collateralize) Query_CollateralizeRecordByAddr(req *pty.ReqCollateralizeRecordByAddr) (types.Message, error) {
ret := &pty.RepCollateralizeRecords{}
records, err := queryCollateralizeRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr) records, err := queryCollateralizeRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr)
if err != nil { if err != nil {
clog.Error("Query_CollateralizeRecordByAddr", "get collateralize record error", err) clog.Error("Query_CollateralizeRecordByAddr", "get collateralize record error", err)
return nil, err return nil, err
} }
ret := &pty.RepCollateralizeRecords{}
ret.Records = records ret.Records = records
return ret, nil return ret, nil
} }
func (c *Collateralize) Query_CollateralizeRecordByStatus(req *pty.ReqCollateralizeRecordByStatus) (types.Message, error) { func (c *Collateralize) Query_CollateralizeRecordByStatus(req *pty.ReqCollateralizeRecordByStatus) (types.Message, error) {
ret := &pty.RepCollateralizeRecords{}
records, err := queryCollateralizeRecordByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status) records, err := queryCollateralizeRecordByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status)
if err != nil { if err != nil {
clog.Error("Query_CollateralizeRecordByAddr", "get collateralize record error", err) clog.Error("Query_CollateralizeRecordByStatus", "get collateralize record error", err)
return nil, err return nil, err
} }
ret := &pty.RepCollateralizeRecords{}
ret.Records = records ret.Records = records
return ret, nil return ret, nil
} }
\ No newline at end of file
...@@ -85,7 +85,6 @@ message CollateralizeBorrow { ...@@ -85,7 +85,6 @@ message CollateralizeBorrow {
message CollateralizeRepay { message CollateralizeRepay {
string collateralizeId = 1; //借贷期数ID string collateralizeId = 1; //借贷期数ID
string recordId = 2; //借贷ID string recordId = 2; //借贷ID
int64 value = 3; //借贷价值(ccny)
} }
// 追加抵押物 // 追加抵押物
......
...@@ -201,7 +201,7 @@ func CreateRawCollateralizeRepayTx(parm *CollateralizeRepayTx) (*types.Transacti ...@@ -201,7 +201,7 @@ func CreateRawCollateralizeRepayTx(parm *CollateralizeRepayTx) (*types.Transacti
v := &CollateralizeRepay{ v := &CollateralizeRepay{
CollateralizeId: parm.CollateralizeID, CollateralizeId: parm.CollateralizeID,
Value: parm.Value, RecordId:parm.RecordID,
} }
repay := &CollateralizeAction{ repay := &CollateralizeAction{
Ty: CollateralizeActionRepay, Ty: CollateralizeActionRepay,
...@@ -230,6 +230,7 @@ func CreateRawCollateralizeAppendTx(parm *CollateralizeAppendTx) (*types.Transac ...@@ -230,6 +230,7 @@ func CreateRawCollateralizeAppendTx(parm *CollateralizeAppendTx) (*types.Transac
v := &CollateralizeAppend{ v := &CollateralizeAppend{
CollateralizeId: parm.CollateralizeID, CollateralizeId: parm.CollateralizeID,
RecordId:parm.RecordID,
CollateralValue: parm.Value, CollateralValue: parm.Value,
} }
append := &CollateralizeAction{ append := &CollateralizeAction{
......
...@@ -20,13 +20,14 @@ type CollateralizeBorrowTx struct { ...@@ -20,13 +20,14 @@ type CollateralizeBorrowTx struct {
// CollateralizeRepayTx for construction // CollateralizeRepayTx for construction
type CollateralizeRepayTx struct { type CollateralizeRepayTx struct {
CollateralizeID string `json:"collateralizeId"` CollateralizeID string `json:"collateralizeId"`
Value int64 `json:"value"` RecordID string `json:"recordID"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
// CollateralizeAppednTx for construction // CollateralizeAppednTx for construction
type CollateralizeAppendTx struct { type CollateralizeAppendTx struct {
CollateralizeID string `json:"collateralizeId"` CollateralizeID string `json:"collateralizeId"`
RecordID string `json:"recordID"`
Value int64 `json:"value"` Value int64 `json:"value"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
......
...@@ -2,11 +2,11 @@ package commands ...@@ -2,11 +2,11 @@ package commands
import ( import (
"fmt" "fmt"
"github.com/spf13/cobra"
jsonrpc "github.com/33cn/chain33/rpc/jsonclient" jsonrpc "github.com/33cn/chain33/rpc/jsonclient"
rpctypes "github.com/33cn/chain33/rpc/types" rpctypes "github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types" "github.com/33cn/chain33/types"
pkt "github.com/33cn/plugin/plugin/dapp/issuance/types" pkt "github.com/33cn/plugin/plugin/dapp/issuance/types"
"github.com/spf13/cobra"
"strconv" "strconv"
) )
...@@ -44,6 +44,7 @@ func IssuanceCreateRawTxCmd() *cobra.Command { ...@@ -44,6 +44,7 @@ func IssuanceCreateRawTxCmd() *cobra.Command {
func addIssuanceCreateFlags(cmd *cobra.Command) { func addIssuanceCreateFlags(cmd *cobra.Command) {
cmd.Flags().Uint64P("balance", "b", 0, "balance") cmd.Flags().Uint64P("balance", "b", 0, "balance")
cmd.MarkFlagRequired("balance")
cmd.Flags().Uint64P("debtCeiling", "d", 0, "debtCeiling") cmd.Flags().Uint64P("debtCeiling", "d", 0, "debtCeiling")
cmd.Flags().Float32P("liquidationRatio", "l", 0, "liquidationRatio") cmd.Flags().Float32P("liquidationRatio", "l", 0, "liquidationRatio")
cmd.Flags().Uint64P("period", "p", 0, "period") cmd.Flags().Uint64P("period", "p", 0, "period")
...@@ -56,11 +57,10 @@ func IssuanceCreate(cmd *cobra.Command, args []string) { ...@@ -56,11 +57,10 @@ func IssuanceCreate(cmd *cobra.Command, args []string) {
liquidationRatio, _ := cmd.Flags().GetFloat32("liquidationRatio") liquidationRatio, _ := cmd.Flags().GetFloat32("liquidationRatio")
period, _ := cmd.Flags().GetUint64("period") period, _ := cmd.Flags().GetUint64("period")
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuanceCreate", ActionName: "IssuanceCreate",
Payload: []byte(fmt.Sprintf("{\"balance\":%d, \"debtCeiling\":%d, \"liquidationRatio\":%f, \"period\":%d,}", Payload: []byte(fmt.Sprintf("{\"totalBalance\":%d, \"debtCeiling\":%d, \"liquidationRatio\":%f, \"period\":%d}",
balance, debtCeiling, liquidationRatio, period)), balance, debtCeiling, liquidationRatio, period)),
} }
...@@ -95,7 +95,7 @@ func IssuanceDebt(cmd *cobra.Command, args []string) { ...@@ -95,7 +95,7 @@ func IssuanceDebt(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuanceDebt", ActionName: "IssuanceDebt",
Payload: []byte(fmt.Sprintf("{\"issuanceID\":%s,\"value\":%d}", issuanceID, value)), Payload: []byte(fmt.Sprintf("{\"issuanceID\":\"%s\",\"value\":%d}", issuanceID, value)),
} }
var res string var res string
...@@ -117,16 +117,19 @@ func IssuanceRepayRawTxCmd() *cobra.Command { ...@@ -117,16 +117,19 @@ func IssuanceRepayRawTxCmd() *cobra.Command {
func addIssuanceRepayFlags(cmd *cobra.Command) { func addIssuanceRepayFlags(cmd *cobra.Command) {
cmd.Flags().StringP("issuanceID", "g", "", "issuance ID") cmd.Flags().StringP("issuanceID", "g", "", "issuance ID")
cmd.MarkFlagRequired("issuanceID") cmd.MarkFlagRequired("issuanceID")
cmd.Flags().StringP("debtID", "d", "", "debt ID")
cmd.MarkFlagRequired("debtID")
} }
func IssuanceRepay(cmd *cobra.Command, args []string) { func IssuanceRepay(cmd *cobra.Command, args []string) {
rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr") rpcLaddr, _ := cmd.Flags().GetString("rpc_laddr")
issuanceID, _ := cmd.Flags().GetString("issuanceID") issuanceID, _ := cmd.Flags().GetString("issuanceID")
debtID, _ := cmd.Flags().GetString("debtID")
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuanceRepay", ActionName: "IssuanceRepay",
Payload: []byte(fmt.Sprintf("{\"issuanceID\":%s}", issuanceID)), Payload: []byte(fmt.Sprintf("{\"issuanceID\":\"%s\", \"debtID\":\"%s\"}", issuanceID, debtID)),
} }
var res string var res string
...@@ -160,7 +163,7 @@ func IssuancePriceFeed(cmd *cobra.Command, args []string) { ...@@ -160,7 +163,7 @@ func IssuancePriceFeed(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuancePriceFeed", ActionName: "IssuancePriceFeed",
Payload: []byte(fmt.Sprintf("{[\"price\":%s],[\"volume\":%d]}", price, volume)), Payload: []byte(fmt.Sprintf("{\"price\":[ %f ], \"volume\":[ %d ]}", price, volume)),
} }
var res string var res string
...@@ -191,7 +194,7 @@ func IssuanceClose(cmd *cobra.Command, args []string) { ...@@ -191,7 +194,7 @@ func IssuanceClose(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuanceClose", ActionName: "IssuanceClose",
Payload: []byte(fmt.Sprintf("{\"issuanceID\":%s}", issuanceID)), Payload: []byte(fmt.Sprintf("{\"issuanceId\":\"%s\"}", issuanceID)),
} }
var res string var res string
...@@ -212,6 +215,7 @@ func IssuanceManageRawTxCmd() *cobra.Command { ...@@ -212,6 +215,7 @@ func IssuanceManageRawTxCmd() *cobra.Command {
func addIssuanceManageFlags(cmd *cobra.Command) { func addIssuanceManageFlags(cmd *cobra.Command) {
cmd.Flags().StringP("addr", "a", "", "addr") cmd.Flags().StringP("addr", "a", "", "addr")
cmd.MarkFlagRequired("addr")
} }
func IssuanceManage(cmd *cobra.Command, args []string) { func IssuanceManage(cmd *cobra.Command, args []string) {
...@@ -221,7 +225,7 @@ func IssuanceManage(cmd *cobra.Command, args []string) { ...@@ -221,7 +225,7 @@ func IssuanceManage(cmd *cobra.Command, args []string) {
params := &rpctypes.CreateTxIn{ params := &rpctypes.CreateTxIn{
Execer: types.ExecName(pkt.IssuanceX), Execer: types.ExecName(pkt.IssuanceX),
ActionName: "IssuanceManage", ActionName: "IssuanceManage",
Payload: []byte(fmt.Sprintf("{[\"addr\":%s]}", addr)), Payload: []byte(fmt.Sprintf("{\"addr\":[\"%s\"]}", addr)),
} }
var res string var res string
...@@ -270,11 +274,15 @@ func IssuanceQuery(cmd *cobra.Command, args []string) { ...@@ -270,11 +274,15 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
// req.Index = index // req.Index = index
//} //}
status, err := strconv.ParseInt(statusStr, 10, 32) var status int64
if err != nil { var err error
fmt.Println(err) if statusStr != "" {
cmd.Help() status, err = strconv.ParseInt(statusStr, 10, 32)
return if err != nil {
fmt.Println(err)
cmd.Help()
return
}
} }
if issuanceID != "" { if issuanceID != "" {
...@@ -297,7 +305,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) { ...@@ -297,7 +305,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
Addr: address, Addr: address,
} }
params.Payload = types.MustPBToJSON(req) params.Payload = types.MustPBToJSON(req)
var res pkt.RepIssuanceDebtInfo var res pkt.RepIssuanceRecords
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else if debtID != ""{ } else if debtID != ""{
...@@ -308,7 +316,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) { ...@@ -308,7 +316,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
DebtId: debtID, DebtId: debtID,
} }
params.Payload = types.MustPBToJSON(req) params.Payload = types.MustPBToJSON(req)
var res pkt.RepIssuanceCurrentInfo var res pkt.RepIssuanceDebtInfo
ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res) ctx := jsonrpc.NewRPCCtx(rpcLaddr, "Chain33.Query", params, &res)
ctx.Run() ctx.Run()
} else { } else {
...@@ -342,7 +350,6 @@ func IssuanceQuery(cmd *cobra.Command, args []string) { ...@@ -342,7 +350,6 @@ func IssuanceQuery(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")
cmd.Help() cmd.Help()
} }
} }
...@@ -16,7 +16,7 @@ func (c *Issuance) Exec_Create(payload *pty.IssuanceCreate, tx *types.Transactio ...@@ -16,7 +16,7 @@ func (c *Issuance) Exec_Create(payload *pty.IssuanceCreate, tx *types.Transactio
} }
// Exec_Borrow Action // Exec_Borrow Action
func (c *Issuance) Exec_Borrow(payload *pty.IssuanceDebt, tx *types.Transaction, index int) (*types.Receipt, error) { func (c *Issuance) Exec_Debt(payload *pty.IssuanceDebt, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewIssuanceAction(c, tx, index) actiondb := NewIssuanceAction(c, tx, index)
return actiondb.IssuanceDebt(payload) return actiondb.IssuanceDebt(payload)
} }
...@@ -38,3 +38,9 @@ func (c *Issuance) Exec_Close(payload *pty.IssuanceClose, tx *types.Transaction, ...@@ -38,3 +38,9 @@ func (c *Issuance) Exec_Close(payload *pty.IssuanceClose, tx *types.Transaction,
actiondb := NewIssuanceAction(c, tx, index) actiondb := NewIssuanceAction(c, tx, index)
return actiondb.IssuanceClose(payload) return actiondb.IssuanceClose(payload)
} }
// Exec_Manage Action
func (c *Issuance) Exec_Manage(payload *pty.IssuanceManage, tx *types.Transaction, index int) (*types.Receipt, error) {
actiondb := NewIssuanceAction(c, tx, index)
return actiondb.IssuanceManage(payload)
}
...@@ -12,41 +12,46 @@ import ( ...@@ -12,41 +12,46 @@ import (
func (c *Issuance) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) { func (c *Issuance) execDelLocal(tx *types.Transaction, receiptData *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{} set := &types.LocalDBSet{}
for _, item := range receiptData.Logs { for _, item := range receiptData.Logs {
var issuanceLog pty.ReceiptIssuance if item.Ty == pty.TyLogIssuanceCreate || item.Ty == pty.TyLogIssuanceDebt || item.Ty == pty.TyLogIssuanceRepay ||
err := types.Decode(item.Log, &issuanceLog) item.Ty == pty.TyLogIssuanceFeed || item.Ty == pty.TyLogIssuanceClose {
if err != nil { var issuanceLog pty.ReceiptIssuance
return nil, err err := types.Decode(item.Log, &issuanceLog)
} if err != nil {
return nil, err
}
switch item.Ty { switch item.Ty {
case pty.TyLogIssuanceCreate: case pty.TyLogIssuanceCreate:
set.KV = append(set.KV, c.deleteIssuanceStatus(issuanceLog.Status, issuanceLog.Index)...) set.KV = append(set.KV, c.deleteIssuanceStatus(issuanceLog.Status, issuanceLog.Index)...)
break break
case pty.TyLogIssuanceDebt: case pty.TyLogIssuanceDebt:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.Index)...) set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index)...)
break
case pty.TyLogIssuanceRepay:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.RecordPreStatus, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
break
case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
// 如果没有被清算,需要把地址索引更新
if issuanceLog.RecordStatus == pty.IssuanceUserStatusWarning || issuanceLog.RecordStatus == pty.IssuanceUserStatusExpire {
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index)...) set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index)...)
break
case pty.TyLogIssuanceRepay:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
break
case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.PreIndex,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
// 如果没有被清算,需要把地址索引更新
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.deleteIssuancePriceRecord(issuanceLog.RecordTime)...)
break
case pty.TyLogIssuanceClose:
set.KV = append(set.KV, c.deleteIssuanceStatus(issuanceLog.Status, issuanceLog.Index)...)
set.KV = append(set.KV, c.addIssuanceStatus(issuanceLog.PreStatus, issuanceLog.PreIndex, issuanceLog.IssuanceId)...)
break
} }
break
case pty.TyLogIssuanceClose:
set.KV = append(set.KV, c.addIssuanceStatus(pty.IssuanceStatusCreated, issuanceLog.PreIndex, issuanceLog.IssuanceId)...)
break
} }
} }
return set, nil return set, nil
......
...@@ -13,42 +13,47 @@ import ( ...@@ -13,42 +13,47 @@ import (
func (c *Issuance) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) { func (c *Issuance) execLocal(tx *types.Transaction, receipt *types.ReceiptData) (*types.LocalDBSet, error) {
set := &types.LocalDBSet{} set := &types.LocalDBSet{}
for _, item := range receipt.Logs { for _, item := range receipt.Logs {
var issuanceLog pty.ReceiptIssuance if item.Ty == pty.TyLogIssuanceCreate || item.Ty == pty.TyLogIssuanceDebt || item.Ty == pty.TyLogIssuanceRepay ||
err := types.Decode(item.Log, &issuanceLog) item.Ty == pty.TyLogIssuanceFeed || item.Ty == pty.TyLogIssuanceClose {
if err != nil { var issuanceLog pty.ReceiptIssuance
return nil, err err := types.Decode(item.Log, &issuanceLog)
} if err != nil {
return nil, err
}
switch item.Ty { switch item.Ty {
case pty.TyLogIssuanceCreate: case pty.TyLogIssuanceCreate:
set.KV = append(set.KV, c.addIssuanceStatus(issuanceLog.Status, issuanceLog.Index, issuanceLog.IssuanceId)...) set.KV = append(set.KV, c.addIssuanceStatus(issuanceLog.Status, issuanceLog.Index, issuanceLog.IssuanceId)...)
break break
case pty.TyLogIssuanceDebt: case pty.TyLogIssuanceDebt:
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.RecordStatus, 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.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
break
case pty.TyLogIssuanceRepay:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.RecordPreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
break
case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.RecordPreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.RecordStatus, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if issuanceLog.RecordStatus == pty.IssuanceUserStatusWarning || issuanceLog.RecordStatus == 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)...)
break
case pty.TyLogIssuanceRepay:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
break
case pty.TyLogIssuanceFeed:
set.KV = append(set.KV, c.deleteIssuanceRecordStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...)
set.KV = append(set.KV, c.addIssuanceRecordStatus(issuanceLog.Status, issuanceLog.AccountAddr, issuanceLog.Index,
issuanceLog.DebtId, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.PreIndex)...)
// 如果没有被清算,需要把地址索引更新
if issuanceLog.Status == pty.IssuanceUserStatusWarning || issuanceLog.Status == pty.IssuanceUserStatusExpire {
set.KV = append(set.KV, c.addIssuanceRecordAddr(issuanceLog.AccountAddr, issuanceLog.Index, issuanceLog.DebtId,
issuanceLog.IssuanceId)...)
}
set.KV = append(set.KV, c.addIssuancePriceRecord(issuanceLog.RecordTime, issuanceLog.BtyPrice)...)
break
case pty.TyLogIssuanceClose:
set.KV = append(set.KV, c.addIssuanceStatus(issuanceLog.Status, issuanceLog.Index, issuanceLog.IssuanceId)...)
set.KV = append(set.KV, c.deleteIssuanceStatus(issuanceLog.PreStatus, issuanceLog.PreIndex)...)
break
} }
break
case pty.TyLogIssuanceClose:
set.KV = append(set.KV, c.deleteIssuanceStatus(issuanceLog.Status, issuanceLog.PreIndex)...)
break
} }
} }
return set, nil return set, nil
......
...@@ -143,6 +143,26 @@ func (c *Issuance) deleteIssuanceRecordStatus(status int32, index int64) (kvs [] ...@@ -143,6 +143,26 @@ func (c *Issuance) deleteIssuanceRecordStatus(status int32, index int64) (kvs []
return kvs return kvs
} }
func (c *Issuance) addIssuancePriceRecord(recordTime int64, price float32) (kvs []*types.KeyValue) {
key := calcIssuancePriceKey(string(recordTime))
record := &pty.IssuanceAssetPriceRecord{
RecordTime:recordTime,
BtyPrice:price,
}
kv := &types.KeyValue{Key: key, Value: types.Encode(record)}
kvs = append(kvs, kv)
return kvs
}
func (c *Issuance) deleteIssuancePriceRecord(recordTime int64) (kvs []*types.KeyValue) {
key := calcIssuancePriceKey(string(recordTime))
kv := &types.KeyValue{Key: key, Value:nil}
kvs = append(kvs, kv)
return kvs
}
// CheckReceiptExecOk return true to check if receipt ty is ok // CheckReceiptExecOk return true to check if receipt ty is ok
func (c *Issuance) CheckReceiptExecOk() bool { func (c *Issuance) CheckReceiptExecOk() bool {
return true return true
......
This diff is collapsed.
...@@ -7,46 +7,41 @@ package executor ...@@ -7,46 +7,41 @@ package executor
import "fmt" import "fmt"
func calcIssuanceKey(issuanceID string, index int64) []byte { func calcIssuanceKey(issuanceID string, index int64) []byte {
key := fmt.Sprintf("LODB-Issuance-ID:%s:%018d", issuanceID, index) key := fmt.Sprintf("LODB-issuance-ID:%s:%018d", issuanceID, index)
return []byte(key) return []byte(key)
} }
func calcIssuanceStatusPrefix(status int32) []byte { func calcIssuanceStatusPrefix(status int32) []byte {
key := fmt.Sprintf("LODB-Issuance-status-index:%d", status) key := fmt.Sprintf("LODB-issuance-status:%d", status)
return []byte(key) return []byte(key)
} }
func calcIssuanceStatusKey(status int32, index int64) []byte { func calcIssuanceStatusKey(status int32, index int64) []byte {
key := fmt.Sprintf("LODB-Issuance-status:%d:%018d", status, index) key := fmt.Sprintf("LODB-issuance-status:%d:%018d", status, index)
return []byte(key) return []byte(key)
} }
func calcIssuanceRecordAddrPrefix(addr string) []byte { func calcIssuanceRecordAddrPrefix(addr string) []byte {
key := fmt.Sprintf("LODB-Issuance-record-addr:%s", addr) key := fmt.Sprintf("LODB-issuance-record-addr:%s", addr)
return []byte(key) return []byte(key)
} }
func calcIssuanceRecordAddrKey(addr string, index int64) []byte { func calcIssuanceRecordAddrKey(addr string, index int64) []byte {
key := fmt.Sprintf("LODB-Issuance-record-addr:%s:%018d", addr, index) key := fmt.Sprintf("LODB-issuance-record-addr:%s:%018d", addr, index)
return []byte(key) return []byte(key)
} }
func calcIssuancePriceKey(time string) []byte { func calcIssuancePriceKey(time string) []byte {
key := fmt.Sprintf("LODB-Issuance-price:%s", time) key := fmt.Sprintf("LODB-issuance-price:%s", time)
return []byte(key)
}
func calcIssuanceLatestPriceKey() []byte {
key := fmt.Sprintf("LODB-Issuance-latest-price")
return []byte(key) return []byte(key)
} }
func calcIssuanceRecordStatusPrefix(status string) []byte { func calcIssuanceRecordStatusPrefix(status string) []byte {
key := fmt.Sprintf("LODB-Issuance-record-status:%s", status) key := fmt.Sprintf("LODB-issuance-record-status:%s", status)
return []byte(key) return []byte(key)
} }
func calcIssuanceRecordStatusKey(status int32, index int64) []byte { func calcIssuanceRecordStatusKey(status int32, index int64) []byte {
key := fmt.Sprintf("LODB-Issuance-record-status:%d:%018d", status, index) key := fmt.Sprintf("LODB-issuance-record-status:%d:%018d", status, index)
return []byte(key) return []byte(key)
} }
\ No newline at end of file
...@@ -22,6 +22,8 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa ...@@ -22,6 +22,8 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa
DebtCeiling: issu.DebtCeiling, DebtCeiling: issu.DebtCeiling,
LiquidationRatio: issu.LiquidationRatio, LiquidationRatio: issu.LiquidationRatio,
Balance: issu.Balance, Balance: issu.Balance,
CollateralValue: issu.CollateralValue,
DebtValue: issu.DebtValue,
}, nil }, nil
} }
...@@ -40,6 +42,8 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes ...@@ -40,6 +42,8 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes
DebtCeiling: issu.DebtCeiling, DebtCeiling: issu.DebtCeiling,
LiquidationRatio: issu.LiquidationRatio, LiquidationRatio: issu.LiquidationRatio,
Balance: issu.Balance, Balance: issu.Balance,
CollateralValue: issu.CollateralValue,
DebtValue: issu.DebtValue,
}) })
} }
...@@ -50,49 +54,46 @@ func (c *Issuance) Query_IssuanceByStatus(req *pty.ReqIssuanceByStatus) (types.M ...@@ -50,49 +54,46 @@ func (c *Issuance) Query_IssuanceByStatus(req *pty.ReqIssuanceByStatus) (types.M
ids := &pty.RepIssuanceIDs{} ids := &pty.RepIssuanceIDs{}
issuIDRecords, err := queryIssuanceByStatus(c.GetLocalDB(), req.Status) issuIDRecords, err := queryIssuanceByStatus(c.GetLocalDB(), req.Status)
if err != nil { if err != nil {
clog.Error("Query_IssuanceByStatus", "get issuance record error", err) clog.Error("Query_IssuanceByStatus", "get issuance error", err)
return nil, err return nil, err
} }
ids.IDs = append(ids.IDs, issuIDRecords...)
for _, record := range issuIDRecords {
ids.IDs = append(ids.IDs, record.IssuanceId)
}
return ids, nil return ids, nil
} }
func (c *Issuance) Query_IssuanceRecordByID(req *pty.ReqIssuanceDebtInfo) (types.Message, error) { func (c *Issuance) Query_IssuanceRecordByID(req *pty.ReqIssuanceDebtInfo) (types.Message, error) {
ret := &pty.RepIssuanceDebtInfo{}
issuRecord, err := queryIssuanceRecordByID(c.GetStateDB(), req.IssuanceId, req.DebtId) issuRecord, err := queryIssuanceRecordByID(c.GetStateDB(), req.IssuanceId, req.DebtId)
if err != nil { if err != nil {
clog.Error("Query_IssuanceRecordByID", "get issuance record error", err) clog.Error("Query_IssuanceRecordByID", "get issuance record error", err)
return nil, err return nil, err
} }
ret := &pty.RepIssuanceDebtInfo{}
ret.Record = issuRecord ret.Record = issuRecord
return issuRecord, nil return ret, nil
} }
func (c *Issuance) Query_IssuanceRecordsByAddr(req *pty.ReqIssuanceRecordsByAddr) (types.Message, error) { func (c *Issuance) Query_IssuanceRecordsByAddr(req *pty.ReqIssuanceRecordsByAddr) (types.Message, error) {
ret := &pty.RepIssuanceRecords{}
records, err := queryIssuanceRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr) records, err := queryIssuanceRecordByAddr(c.GetStateDB(), c.GetLocalDB(), req.Addr)
if err != nil { if err != nil {
clog.Error("Query_IssuanceDebtInfoByAddr", "get issuance record error", err) clog.Error("Query_IssuanceDebtInfoByAddr", "get issuance record error", err)
return nil, err return nil, err
} }
ret := &pty.RepIssuanceRecords{}
ret.Records = records ret.Records = records
return ret, nil return ret, nil
} }
func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecordsByStatus) (types.Message, error) { func (c *Issuance) Query_IssuanceRecordsByStatus(req *pty.ReqIssuanceRecordsByStatus) (types.Message, error) {
ret := &pty.RepIssuanceRecords{}
records, err := queryIssuanceRecordsByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status) records, err := queryIssuanceRecordsByStatus(c.GetStateDB(), c.GetLocalDB(), req.Status)
if err != nil { if err != nil {
clog.Error("Query_IssuanceDebtInfoByAddr", "get issuance record error", err) clog.Error("Query_IssuanceDebtInfoByStatus", "get issuance record error", err)
return nil, err return nil, err
} }
ret := &pty.RepIssuanceRecords{} ret.Records = append(ret.Records, records...)
ret.Records = records
return ret, nil return ret, nil
} }
\ No newline at end of file
...@@ -21,7 +21,6 @@ message Issuance { ...@@ -21,7 +21,6 @@ message Issuance {
string issuerAddr = 15;//发行地址 string issuerAddr = 15;//发行地址
int64 index = 16;//当前索引 int64 index = 16;//当前索引
int64 preIndex = 17;//上级索引 int64 preIndex = 17;//上级索引
int64 createIndex = 18;//创建索引,用于close删除状态
} }
// 抵押记录 // 抵押记录
...@@ -37,6 +36,8 @@ message DebtRecord { ...@@ -37,6 +36,8 @@ message DebtRecord {
int64 expireTime = 9; //超时清算时间 int64 expireTime = 9; //超时清算时间
int32 preStatus = 10;//上一次抵押状态,用于告警恢复 int32 preStatus = 10;//上一次抵押状态,用于告警恢复
string debtId = 11;//借贷id string debtId = 11;//借贷id
int64 index = 12;//当前索引
int64 preIndex = 13;//上级索引
} }
// 资产价格记录 // 资产价格记录
...@@ -98,12 +99,13 @@ message IssuanceClose { ...@@ -98,12 +99,13 @@ message IssuanceClose {
message ReceiptIssuance { message ReceiptIssuance {
string issuanceId = 1; string issuanceId = 1;
string accountAddr = 2; string accountAddr = 2;
int32 status = 3; string debtId = 3;
string debtId = 4; int32 status = 4;
int32 recordStatus = 5; int32 preStatus = 5;
int32 recordPreStatus = 6; int64 index = 6;
int64 index = 7; int64 preIndex = 7;
int64 preIndex = 8; int64 recordTime = 8; //价格记录时间
float btyPrice = 9; //bty价格
} }
// exec_local 借贷记录信息 // exec_local 借贷记录信息
......
...@@ -84,7 +84,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (* ...@@ -84,7 +84,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (*
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
return CreateRawIssuanceRepayTx(&param) return CreateRawIssuanceRepayTx(&param)
} else if action == "IssuanceFeed" { } else if action == "IssuancePriceFeed" {
var param IssuanceFeedTx var param IssuanceFeedTx
err := json.Unmarshal(message, &param) err := json.Unmarshal(message, &param)
if err != nil { if err != nil {
...@@ -117,7 +117,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (* ...@@ -117,7 +117,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (*
func (Issuance IssuanceType) GetTypeMap() map[string]int32 { func (Issuance IssuanceType) GetTypeMap() map[string]int32 {
return map[string]int32{ return map[string]int32{
"Create": IssuanceActionCreate, "Create": IssuanceActionCreate,
"Borrow": IssuanceActionDebt, "Debt": IssuanceActionDebt,
"Repay": IssuanceActionRepay, "Repay": IssuanceActionRepay,
"Feed": IssuanceActionFeed, "Feed": IssuanceActionFeed,
"Close": IssuanceActionClose, "Close": IssuanceActionClose,
...@@ -191,6 +191,7 @@ func CreateRawIssuanceRepayTx(parm *IssuanceRepayTx) (*types.Transaction, error) ...@@ -191,6 +191,7 @@ func CreateRawIssuanceRepayTx(parm *IssuanceRepayTx) (*types.Transaction, error)
v := &IssuanceRepay{ v := &IssuanceRepay{
IssuanceId: parm.IssuanceID, IssuanceId: parm.IssuanceID,
DebtId: parm.DebtID,
} }
repay := &IssuanceAction{ repay := &IssuanceAction{
Ty: IssuanceActionRepay, Ty: IssuanceActionRepay,
......
This diff is collapsed.
...@@ -23,6 +23,7 @@ type IssuanceDebtTx struct { ...@@ -23,6 +23,7 @@ type IssuanceDebtTx struct {
// IssuanceRepayTx for construction // IssuanceRepayTx for construction
type IssuanceRepayTx struct { type IssuanceRepayTx struct {
IssuanceID string `json:"issuanceId"` IssuanceID string `json:"issuanceId"`
DebtID string `json:"debtId"`
Fee int64 `json:"fee"` Fee int64 `json:"fee"`
} }
......
...@@ -24,7 +24,7 @@ const ( ...@@ -24,7 +24,7 @@ const (
// Issuance name // Issuance name
const ( const (
IssuanceX = "issuance" IssuanceX = "issuance"
CCNYTokenName = "ccny" CCNYTokenName = "CCNY"
IssuancePreLiquidationRatio = 1.1 //TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算 IssuancePreLiquidationRatio = 1.1 //TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
) )
......
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