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
491ce6b8
Commit
491ce6b8
authored
Nov 01, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 update collateralize
parent
ebffcd28
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
86 additions
and
67 deletions
+86
-67
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+22
-15
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+0
-0
exec_del_local.go
plugin/dapp/collateralize/executor/exec_del_local.go
+15
-7
exec_local.go
plugin/dapp/collateralize/executor/exec_local.go
+16
-8
keys.go
plugin/dapp/collateralize/executor/keys.go
+0
-5
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+13
-14
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+1
-1
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
types.go
plugin/dapp/collateralize/types/types.go
+7
-6
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+5
-11
types.go
plugin/dapp/issuance/types/types.go
+7
-0
No files found.
plugin/dapp/collateralize/commands/cmd.go
View file @
491ce6b8
...
@@ -55,7 +55,7 @@ func CollateralizeCreate(cmd *cobra.Command, args []string) {
...
@@ -55,7 +55,7 @@ func CollateralizeCreate(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeCreate"
,
ActionName
:
"CollateralizeCreate"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
b
alance
\"
:%d}"
,
balance
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalB
alance
\"
:%d}"
,
balance
)),
}
}
var
res
string
var
res
string
...
@@ -89,7 +89,7 @@ func CollateralizeBorrow(cmd *cobra.Command, args []string) {
...
@@ -89,7 +89,7 @@ func CollateralizeBorrow(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeBorrow"
,
ActionName
:
"CollateralizeBorrow"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
%s
,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
}
}
var
res
string
var
res
string
...
@@ -111,6 +111,8 @@ func CollateralizeAppendRawTxCmd() *cobra.Command {
...
@@ -111,6 +111,8 @@ func CollateralizeAppendRawTxCmd() *cobra.Command {
func
addCollateralizeAppendFlags
(
cmd
*
cobra
.
Command
)
{
func
addCollateralizeAppendFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
StringP
(
"recordID"
,
"r"
,
""
,
"recordID"
)
cmd
.
MarkFlagRequired
(
"recordID"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
}
...
@@ -118,12 +120,13 @@ func addCollateralizeAppendFlags(cmd *cobra.Command) {
...
@@ -118,12 +120,13 @@ func addCollateralizeAppendFlags(cmd *cobra.Command) {
func
CollateralizeAppend
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
CollateralizeAppend
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
recordID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"recordID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeAppend"
,
ActionName
:
"CollateralizeAppend"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
%s,
\"
value
\"
:%d}"
,
collateralize
ID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
,
\"
value
\"
:%d}"
,
collateralizeID
,
record
ID
,
value
)),
}
}
var
res
string
var
res
string
...
@@ -145,19 +148,19 @@ func CollateralizeRepayRawTxCmd() *cobra.Command {
...
@@ -145,19 +148,19 @@ func CollateralizeRepayRawTxCmd() *cobra.Command {
func
addCollateralizeRepayFlags
(
cmd
*
cobra
.
Command
)
{
func
addCollateralizeRepayFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value
"
)
cmd
.
Flags
()
.
StringP
(
"recordID"
,
"r"
,
""
,
"recordID
"
)
cmd
.
MarkFlagRequired
(
"
value
"
)
cmd
.
MarkFlagRequired
(
"
recordID
"
)
}
}
func
CollateralizeRepay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
func
CollateralizeRepay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value
"
)
recordID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"recordID
"
)
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeRepay"
,
ActionName
:
"CollateralizeRepay"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
%s,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
}"
,
collateralizeID
,
recordID
)),
}
}
var
res
string
var
res
string
...
@@ -191,7 +194,7 @@ func CollateralizePriceFeed(cmd *cobra.Command, args []string) {
...
@@ -191,7 +194,7 @@ func CollateralizePriceFeed(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizePriceFeed"
,
ActionName
:
"CollateralizePriceFeed"
,
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
...
@@ -222,7 +225,7 @@ func CollateralizeClose(cmd *cobra.Command, args []string) {
...
@@ -222,7 +225,7 @@ func CollateralizeClose(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeClose"
,
ActionName
:
"CollateralizeClose"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
%s
}"
,
collateralizeID
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
}"
,
collateralizeID
)),
}
}
var
res
string
var
res
string
...
@@ -258,7 +261,7 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
...
@@ -258,7 +261,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
\"
:%
d
}"
,
debtCeiling
,
liquidationRatio
,
stabilityFeeRatio
,
period
)),
debtCeiling
,
liquidationRatio
,
stabilityFeeRatio
,
period
)),
}
}
...
@@ -308,11 +311,15 @@ func CollateralizeQuery(cmd *cobra.Command, args []string) {
...
@@ -308,11 +311,15 @@ func CollateralizeQuery(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
collateralizeID
!=
""
{
if
collateralizeID
!=
""
{
...
...
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
491ce6b8
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/executor/exec_del_local.go
View file @
491ce6b8
...
@@ -26,26 +26,34 @@ func (c *Collateralize) execDelLocal(tx *types.Transaction, receiptData *types.R
...
@@ -26,26 +26,34 @@ func (c *Collateralize) execDelLocal(tx *types.Transaction, receiptData *types.R
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
.
Record
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
Index
)
...
)
break
break
case
pty
.
TyLogCollateralizeAppend
:
// append没有状态变化
case
pty
.
TyLogCollateralizeAppend
:
if
collateralizeLog
.
Status
==
pty
.
CollateralizeUserStatusWarning
{
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
PreStatus
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
Index
)
...
)
}
break
break
case
pty
.
TyLogCollateralizeRepay
:
case
pty
.
TyLogCollateralizeRepay
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Record
PreStatus
,
collateralizeLog
.
CollateralizeId
,
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
PreStatus
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Record
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
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
.
PreIndex
)
...
)
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
break
break
case
pty
.
TyLogCollateralizeFeed
:
case
pty
.
TyLogCollateralizeFeed
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Record
Status
,
collateralizeLog
.
CollateralizeId
,
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Record
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
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
.
PreIndex
)
...
)
collateralizeLog
.
RecordId
,
collateralizeLog
.
PreIndex
)
...
)
// 如果没有被清算,需要把地址索引更新
// 如果没有被清算,需要把地址索引更新
if
collateralizeLog
.
RecordStatus
==
pty
.
CollateralizeUserStatusWarning
||
collateralizeLog
.
Record
Status
==
pty
.
CollateralizeUserStatusExpire
{
if
collateralizeLog
.
Status
==
pty
.
CollateralizeUserStatusWarning
||
collateralizeLog
.
Status
==
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
break
...
...
plugin/dapp/collateralize/executor/exec_local.go
View file @
491ce6b8
...
@@ -27,33 +27,41 @@ func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptD
...
@@ -27,33 +27,41 @@ func (c *Collateralize) execLocal(tx *types.Transaction, receipt *types.ReceiptD
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
.
Record
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
.
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
.
TyLogCollateralizeAppend
:
//append没有状态变化
case
pty
.
TyLogCollateralizeAppend
:
if
collateralizeLog
.
Status
==
pty
.
CollateralizeUserStatusWarning
{
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
PreStatus
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordAddr
(
collateralizeLog
.
AccountAddr
,
collateralizeLog
.
CollateralizeId
,
collateralizeLog
.
RecordId
,
collateralizeLog
.
Index
)
...
)
}
break
break
case
pty
.
TyLogCollateralizeRepay
:
case
pty
.
TyLogCollateralizeRepay
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
Record
PreStatus
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
PreStatus
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Record
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
.
Record
PreStatus
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeRecordStatus
(
collateralizeLog
.
PreStatus
,
collateralizeLog
.
PreIndex
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
Record
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
.
RecordStatus
==
pty
.
CollateralizeUserStatusWarning
||
collateralizeLog
.
Record
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
(
pty
.
CollateralizeStatusCreated
,
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
}
}
...
...
plugin/dapp/collateralize/executor/keys.go
View file @
491ce6b8
...
@@ -36,11 +36,6 @@ func calcCollateralizePriceKey(time string) []byte {
...
@@ -36,11 +36,6 @@ func calcCollateralizePriceKey(time string) []byte {
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcCollateralizeLatestPriceKey
()
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-collateralize-latest-price"
)
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
)
...
...
plugin/dapp/collateralize/proto/collateralize.proto
View file @
491ce6b8
...
@@ -14,13 +14,11 @@ message Collateralize {
...
@@ -14,13 +14,11 @@ message Collateralize {
repeated
BorrowRecord
borrowRecords
=
8
;
//借贷记录
repeated
BorrowRecord
borrowRecords
=
8
;
//借贷记录
repeated
BorrowRecord
InvalidRecords
=
9
;
//失效的借贷记录
repeated
BorrowRecord
InvalidRecords
=
9
;
//失效的借贷记录
int32
status
=
10
;
//当期借贷的状态,是否关闭
int32
status
=
10
;
//当期借贷的状态,是否关闭
int32
collType
=
11
;
//质押资产类型(1,bty,2,btc,3,eth...)
float
latestLiquidationPrice
=
11
;
//最高清算价格
float
latestLiquidationPrice
=
12
;
//最高清算价格
int64
period
=
12
;
//借贷最大期限
int64
period
=
13
;
//借贷最大期限
int64
latestExpireTime
=
13
;
//最近超期时间
int64
latestExpireTime
=
14
;
//最近超期时间
int64
index
=
14
;
//当前索引
int64
index
=
15
;
//当前索引
int64
preIndex
=
15
;
//上一个索引
int64
preIndex
=
16
;
//上一个索引
int64
createIndex
=
17
;
//创建时的索引,用于close删除记录
}
}
// 借出记录
// 借出记录
...
@@ -36,6 +34,8 @@ message BorrowRecord {
...
@@ -36,6 +34,8 @@ message BorrowRecord {
int64
expireTime
=
9
;
//超时清算时间
int64
expireTime
=
9
;
//超时清算时间
int32
preStatus
=
10
;
//上一次抵押状态,用于告警恢复
int32
preStatus
=
10
;
//上一次抵押状态,用于告警恢复
string
recordId
=
11
;
//借出id,标识一次借出记录
string
recordId
=
11
;
//借出id,标识一次借出记录
int64
index
=
12
;
//当前索引
int64
preIndex
=
13
;
//上级索引
}
}
// 资产价格记录
// 资产价格记录
...
@@ -111,13 +111,12 @@ message ReceiptCollateralize {
...
@@ -111,13 +111,12 @@ message ReceiptCollateralize {
string
collateralizeId
=
1
;
string
collateralizeId
=
1
;
string
createAddr
=
2
;
string
createAddr
=
2
;
string
accountAddr
=
3
;
string
accountAddr
=
3
;
int32
status
=
4
;
string
recordId
=
4
;
int64
index
=
5
;
int32
status
=
5
;
int32
recordStatus
=
6
;
int32
PreStatus
=
6
;
int32
recordPreStatus
=
7
;
int64
index
=
7
;
string
recordId
=
8
;
int64
preIndex
=
8
;
int64
preIndex
=
9
;
}
}
// exec_local 借贷记录信息
// exec_local 借贷记录信息
message
CollateralizeRecord
{
message
CollateralizeRecord
{
...
...
plugin/dapp/collateralize/types/collateralize.go
View file @
491ce6b8
...
@@ -93,7 +93,7 @@ func (Collateralize CollateralizeType) CreateTx(action string, message json.RawM
...
@@ -93,7 +93,7 @@ func (Collateralize CollateralizeType) CreateTx(action string, message json.RawM
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
return
CreateRawCollateralizeAppendTx
(
&
param
)
return
CreateRawCollateralizeAppendTx
(
&
param
)
}
else
if
action
==
"CollateralizeFeed"
{
}
else
if
action
==
"Collateralize
Price
Feed"
{
var
param
CollateralizeFeedTx
var
param
CollateralizeFeedTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
491ce6b8
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/types/types.go
View file @
491ce6b8
...
@@ -26,7 +26,7 @@ const (
...
@@ -26,7 +26,7 @@ const (
// Collateralize name
// Collateralize name
const
(
const
(
CollateralizeX
=
"collateralize"
CollateralizeX
=
"collateralize"
CCNYTokenName
=
"
ccny
"
CCNYTokenName
=
"
CCNY
"
CollateralizePreLiquidationRatio
=
1.1
//TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
CollateralizePreLiquidationRatio
=
1.1
//TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
)
...
@@ -36,11 +36,12 @@ const (
...
@@ -36,11 +36,12 @@ const (
CollateralizeStatusClose
CollateralizeStatusClose
)
)
const
(
//暂时只支持bty
CollateralizeAssetTypeBty
=
1
+
iota
//const (
CollateralizeAssetTypeBtc
// CollateralizeAssetTypeBty = 1 + iota
CollateralizeAssetTypeEth
// CollateralizeAssetTypeBtc
)
// CollateralizeAssetTypeEth
//)
const
(
const
(
CollateralizeUserStatusCreate
=
1
+
iota
CollateralizeUserStatusCreate
=
1
+
iota
...
...
plugin/dapp/issuance/executor/issuancedb.go
View file @
491ce6b8
...
@@ -32,12 +32,6 @@ const (
...
@@ -32,12 +32,6 @@ const (
ExpireWarningTime
=
3600
*
24
*
10
// 提前10天超时预警
ExpireWarningTime
=
3600
*
24
*
10
// 提前10天超时预警
)
)
const
(
priceFeedKey
=
"issuance-price-feed"
guarantorKey
=
"issuance-guarantor"
manageKey
=
"issuance-manage"
)
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
manageKey
:=
types
.
ManageKey
(
key
)
manageKey
:=
types
.
ManageKey
(
key
)
value
,
err
:=
db
.
Get
([]
byte
(
manageKey
))
value
,
err
:=
db
.
Get
([]
byte
(
manageKey
))
...
@@ -48,7 +42,7 @@ func getManageKey(key string, db dbm.KV) ([]byte, error) {
...
@@ -48,7 +42,7 @@ func getManageKey(key string, db dbm.KV) ([]byte, error) {
}
}
func
getGuarantorAddr
(
db
dbm
.
KV
)
(
string
,
error
)
{
func
getGuarantorAddr
(
db
dbm
.
KV
)
(
string
,
error
)
{
value
,
err
:=
getManageKey
(
g
uarantorKey
,
db
)
value
,
err
:=
getManageKey
(
pty
.
G
uarantorKey
,
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"getGuarantorAddr"
,
err
)
clog
.
Error
(
"IssuancePriceFeed"
,
"getGuarantorAddr"
,
err
)
return
""
,
err
return
""
,
err
...
@@ -323,7 +317,7 @@ func (action *Action) IssuanceManage(manage *pty.IssuanceManage) (*types.Receipt
...
@@ -323,7 +317,7 @@ func (action *Action) IssuanceManage(manage *pty.IssuanceManage) (*types.Receipt
var
receipt
*
types
.
Receipt
var
receipt
*
types
.
Receipt
// 是否配置管理用户
// 是否配置管理用户
if
!
isRightAddr
(
m
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
if
!
isRightAddr
(
pty
.
M
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceManage"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to config"
)
clog
.
Error
(
"IssuanceManage"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to config"
)
return
nil
,
pty
.
ErrPermissionDeny
return
nil
,
pty
.
ErrPermissionDeny
}
}
...
@@ -384,7 +378,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
...
@@ -384,7 +378,7 @@ func (action *Action) IssuanceCreate(create *pty.IssuanceCreate) (*types.Receipt
var
receipt
*
types
.
Receipt
var
receipt
*
types
.
Receipt
// 是否配置管理用户
// 是否配置管理用户
if
!
isRightAddr
(
m
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
if
!
isRightAddr
(
pty
.
M
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to create"
)
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to create"
)
return
nil
,
pty
.
ErrPermissionDeny
return
nil
,
pty
.
ErrPermissionDeny
}
}
...
@@ -859,7 +853,7 @@ func (action *Action) IssuanceFeed(feed *pty.IssuanceFeed) (*types.Receipt, erro
...
@@ -859,7 +853,7 @@ func (action *Action) IssuanceFeed(feed *pty.IssuanceFeed) (*types.Receipt, erro
}
}
// 是否后台管理用户
// 是否后台管理用户
if
!
isRightAddr
(
priceFeedKey
,
action
.
fromaddr
,
action
.
db
)
{
if
!
isRightAddr
(
p
ty
.
P
riceFeedKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuancePriceFeed"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to feed price"
)
clog
.
Error
(
"IssuancePriceFeed"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to feed price"
)
return
nil
,
pty
.
ErrPermissionDeny
return
nil
,
pty
.
ErrPermissionDeny
}
}
...
@@ -933,7 +927,7 @@ func (action *Action) IssuanceClose(close *pty.IssuanceClose) (*types.Receipt, e
...
@@ -933,7 +927,7 @@ func (action *Action) IssuanceClose(close *pty.IssuanceClose) (*types.Receipt, e
return
nil
,
err
return
nil
,
err
}
}
if
!
isRightAddr
(
m
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
if
!
isRightAddr
(
pty
.
M
anageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceClose"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to close"
)
clog
.
Error
(
"IssuanceClose"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to close"
)
return
nil
,
pty
.
ErrPermissionDeny
return
nil
,
pty
.
ErrPermissionDeny
}
}
...
...
plugin/dapp/issuance/types/types.go
View file @
491ce6b8
...
@@ -41,4 +41,10 @@ const (
...
@@ -41,4 +41,10 @@ const (
IssuanceUserStatusExpire
IssuanceUserStatusExpire
IssuanceUserStatusExpireLiquidate
IssuanceUserStatusExpireLiquidate
IssuanceUserStatusClose
IssuanceUserStatusClose
)
const
(
PriceFeedKey
=
"issuance-price-feed"
GuarantorKey
=
"issuance-guarantor"
ManageKey
=
"issuance-manage"
)
)
\ No newline at end of file
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