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
ebffcd28
Commit
ebffcd28
authored
Oct 31, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 update issuance
parent
adb27358
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
268 additions
and
222 deletions
+268
-222
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+1
-1
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+0
-0
exec_del_local.go
plugin/dapp/collateralize/executor/exec_del_local.go
+42
-38
exec_local.go
plugin/dapp/collateralize/executor/exec_local.go
+40
-36
keys.go
plugin/dapp/collateralize/executor/keys.go
+13
-12
query.go
plugin/dapp/collateralize/executor/query.go
+8
-17
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+0
-1
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+2
-1
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
tx.go
plugin/dapp/collateralize/types/tx.go
+2
-1
cmd.go
plugin/dapp/issuance/commands/cmd.go
+23
-16
exec.go
plugin/dapp/issuance/executor/exec.go
+7
-1
exec_del_local.go
plugin/dapp/issuance/executor/exec_del_local.go
+37
-32
exec_local.go
plugin/dapp/issuance/executor/exec_local.go
+37
-32
issuance.go
plugin/dapp/issuance/executor/issuance.go
+20
-0
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+0
-0
keys.go
plugin/dapp/issuance/executor/keys.go
+9
-13
query.go
plugin/dapp/issuance/executor/query.go
+13
-11
issuance.proto
plugin/dapp/issuance/proto/issuance.proto
+9
-7
issuance.go
plugin/dapp/issuance/types/issuance.go
+3
-2
issuance.pb.go
plugin/dapp/issuance/types/issuance.pb.go
+0
-0
tx.go
plugin/dapp/issuance/types/tx.go
+1
-0
types.go
plugin/dapp/issuance/types/types.go
+1
-1
No files found.
plugin/dapp/collateralize/commands/cmd.go
View file @
ebffcd28
...
...
@@ -258,7 +258,7 @@ func CollateralizeManage(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
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
)),
}
...
...
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
ebffcd28
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/executor/exec_del_local.go
View file @
ebffcd28
...
...
@@ -12,47 +12,51 @@ import (
func
(
c
*
Collateralize
)
execDelLocal
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receiptData
.
Logs
{
var
collateralizeLog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizeLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogCollateralizeCreate
||
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
||
item
.
Ty
==
pty
.
TyLogCollateralizeAppend
||
item
.
Ty
==
pty
.
TyLogCollateralizeRepay
||
item
.
Ty
==
pty
.
TyLogCollateralizeFeed
||
item
.
Ty
==
pty
.
TyLogCollateralizeClose
{
var
collateralizeLog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizeLog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeAddr
(
collateralizeLog
.
CreateAddr
,
collateralizeLog
.
Index
)
...
)
break
case
pty
.
TyLogCollateralizeBorrow
:
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
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeStatus
(
collateralizeLog
.
Status
,
collateralizeLog
.
Index
)
...
)
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteCollateralizeAddr
(
collateralizeLog
.
CreateAddr
,
collateralizeLog
.
Index
)
...
)
break
case
pty
.
TyLogCollateralizeBorrow
:
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
)
...
)
}
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
...
...
plugin/dapp/collateralize/executor/exec_local.go
View file @
ebffcd28
...
...
@@ -13,46 +13,50 @@ import (
func
(
c
*
Collateralize
)
execLocal
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receipt
.
Logs
{
var
collateralizeLog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizeLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogCollateralizeCreate
||
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
||
item
.
Ty
==
pty
.
TyLogCollateralizeAppend
||
item
.
Ty
==
pty
.
TyLogCollateralizeRepay
||
item
.
Ty
==
pty
.
TyLogCollateralizeFeed
||
item
.
Ty
==
pty
.
TyLogCollateralizeClose
{
var
collateralizeLog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizeLog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
:
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
)
...
)
break
case
pty
.
TyLogCollateralizeBorrow
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
RecordStatus
,
collateralizeLog
.
CollateralizeId
,
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
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
:
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
)
...
)
break
case
pty
.
TyLogCollateralizeBorrow
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addCollateralizeRecordStatus
(
collateralizeLog
.
RecordStatus
,
collateralizeLog
.
CollateralizeId
,
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
,
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
...
...
plugin/dapp/collateralize/executor/keys.go
View file @
ebffcd28
...
...
@@ -7,56 +7,56 @@ package executor
import
"fmt"
func
calcCollateralizeKey
(
collateralizeID
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-ID:%s:%018d"
,
collateralizeID
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-ID:%s:%018d"
,
collateralizeID
,
index
)
return
[]
byte
(
key
)
}
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
)
}
func
calcCollateralizeStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-status:%d:%018d"
,
status
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-status:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
func
calcCollateralizeAddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-addr:%s"
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-addr:%s"
,
addr
)
return
[]
byte
(
key
)
}
func
calcCollateralizeAddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-addr:%s:%018d"
,
addr
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-addr:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
func
calcCollateralizePriceKey
(
time
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-price:%s"
,
time
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-price:%s"
,
time
)
return
[]
byte
(
key
)
}
func
calcCollateralizeLatestPriceKey
()
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-latest-price"
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-latest-price"
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRecordAddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-record-addr:%d"
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-record-addr:%d"
,
addr
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRecordAddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-record-addr:%d:%018d"
,
addr
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-record-addr:%d:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRecordStatusPrefix
(
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
Collateralize-record-status:%d
"
,
status
)
func
calcCollateralizeRecordStatusPrefix
(
status
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
collateralize-record-status:%s
"
,
status
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRecordStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
C
ollateralize-record-status:%d:%018d"
,
status
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
c
ollateralize-record-status:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
\ No newline at end of file
plugin/dapp/collateralize/executor/query.go
View file @
ebffcd28
...
...
@@ -58,10 +58,7 @@ func (c *Collateralize) Query_CollateralizeByStatus(req *pty.ReqCollateralizeByS
return
nil
,
err
}
for
_
,
record
:=
range
collIDRecords
{
ids
.
IDs
=
append
(
ids
.
IDs
,
record
.
CollateralizeId
)
}
ids
.
IDs
=
append
(
ids
.
IDs
,
collIDRecords
...
)
return
ids
,
nil
}
...
...
@@ -73,47 +70,42 @@ func (c *Collateralize) Query_CollateralizeByAddr(req *pty.ReqCollateralizeByAdd
return
nil
,
err
}
for
_
,
record
:=
range
collIDRecords
{
ids
.
IDs
=
append
(
ids
.
IDs
,
record
.
CollateralizeId
)
}
ids
.
IDs
=
append
(
ids
.
IDs
,
collIDRecords
...
)
return
ids
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeRecordByID
(
req
*
pty
.
ReqCollateralizeRecord
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepCollateralizeRecord
{}
issuRecord
,
err
:=
queryCollateralizeRecordByID
(
c
.
GetStateDB
(),
req
.
CollateralizeId
,
req
.
RecordId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceRecordByID"
,
"get
issuanc
e record error"
,
err
)
clog
.
Error
(
"Query_IssuanceRecordByID"
,
"get
collateraliz
e record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepCollateralizeRecord
{}
ret
.
Record
=
issuRecord
return
issuRecord
,
nil
return
ret
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeRecordByAddr
(
req
*
pty
.
ReqCollateralizeRecordByAddr
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepCollateralizeRecords
{}
records
,
err
:=
queryCollateralizeRecordByAddr
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Addr
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeRecordByAddr"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepCollateralizeRecords
{}
ret
.
Records
=
records
return
ret
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeRecordByStatus
(
req
*
pty
.
ReqCollateralizeRecordByStatus
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepCollateralizeRecords
{}
records
,
err
:=
queryCollateralizeRecordByStatus
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Status
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeRecordBy
Addr
"
,
"get collateralize record error"
,
err
)
clog
.
Error
(
"Query_CollateralizeRecordBy
Status
"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepCollateralizeRecords
{}
ret
.
Records
=
records
return
ret
,
nil
}
\ No newline at end of file
plugin/dapp/collateralize/proto/collateralize.proto
View file @
ebffcd28
...
...
@@ -85,7 +85,6 @@ message CollateralizeBorrow {
message
CollateralizeRepay
{
string
collateralizeId
=
1
;
//借贷期数ID
string
recordId
=
2
;
//借贷ID
int64
value
=
3
;
//借贷价值(ccny)
}
// 追加抵押物
...
...
plugin/dapp/collateralize/types/collateralize.go
View file @
ebffcd28
...
...
@@ -201,7 +201,7 @@ func CreateRawCollateralizeRepayTx(parm *CollateralizeRepayTx) (*types.Transacti
v
:=
&
CollateralizeRepay
{
CollateralizeId
:
parm
.
CollateralizeID
,
Value
:
parm
.
Value
,
RecordId
:
parm
.
RecordID
,
}
repay
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionRepay
,
...
...
@@ -230,6 +230,7 @@ func CreateRawCollateralizeAppendTx(parm *CollateralizeAppendTx) (*types.Transac
v
:=
&
CollateralizeAppend
{
CollateralizeId
:
parm
.
CollateralizeID
,
RecordId
:
parm
.
RecordID
,
CollateralValue
:
parm
.
Value
,
}
append
:=
&
CollateralizeAction
{
...
...
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
ebffcd28
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/types/tx.go
View file @
ebffcd28
...
...
@@ -20,13 +20,14 @@ type CollateralizeBorrowTx struct {
// CollateralizeRepayTx for construction
type
CollateralizeRepayTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
int64
`json:"value
"`
RecordID
string
`json:"recordID
"`
Fee
int64
`json:"fee"`
}
// CollateralizeAppednTx for construction
type
CollateralizeAppendTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
RecordID
string
`json:"recordID"`
Value
int64
`json:"value"`
Fee
int64
`json:"fee"`
}
...
...
plugin/dapp/issuance/commands/cmd.go
View file @
ebffcd28
...
...
@@ -2,11 +2,11 @@ package commands
import
(
"fmt"
"github.com/spf13/cobra"
jsonrpc
"github.com/33cn/chain33/rpc/jsonclient"
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/issuance/types"
"github.com/spf13/cobra"
"strconv"
)
...
...
@@ -44,6 +44,7 @@ func IssuanceCreateRawTxCmd() *cobra.Command {
func
addIssuanceCreateFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
cmd
.
Flags
()
.
Uint64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float32P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Uint64P
(
"period"
,
"p"
,
0
,
"period"
)
...
...
@@ -56,11 +57,10 @@ func IssuanceCreate(cmd *cobra.Command, args []string) {
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"liquidationRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
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
)),
}
...
...
@@ -95,7 +95,7 @@ func IssuanceDebt(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
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
...
...
@@ -117,16 +117,19 @@ func IssuanceRepayRawTxCmd() *cobra.Command {
func
addIssuanceRepayFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"issuanceID"
,
"g"
,
""
,
"issuance ID"
)
cmd
.
MarkFlagRequired
(
"issuanceID"
)
cmd
.
Flags
()
.
StringP
(
"debtID"
,
"d"
,
""
,
"debt ID"
)
cmd
.
MarkFlagRequired
(
"debtID"
)
}
func
IssuanceRepay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
debtID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"debtID"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceRepay"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
%s}"
,
issuance
ID
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
\"
%s
\"
,
\"
debtID
\"
:
\"
%s
\"
}"
,
issuanceID
,
debt
ID
)),
}
var
res
string
...
...
@@ -160,7 +163,7 @@ func IssuancePriceFeed(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
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
...
...
@@ -191,7 +194,7 @@ func IssuanceClose(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceClose"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceI
D
\"
:%s
}"
,
issuanceID
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceI
d
\"
:
\"
%s
\"
}"
,
issuanceID
)),
}
var
res
string
...
...
@@ -212,6 +215,7 @@ func IssuanceManageRawTxCmd() *cobra.Command {
func
addIssuanceManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"addr"
)
cmd
.
MarkFlagRequired
(
"addr"
)
}
func
IssuanceManage
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
...
...
@@ -221,7 +225,7 @@ func IssuanceManage(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
[
\"
addr
\"
:%s
]}"
,
addr
)),
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
addr
\"
:[
\"
%s
\"
]}"
,
addr
)),
}
var
res
string
...
...
@@ -270,11 +274,15 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
// req.Index = index
//}
status
,
err
:=
strconv
.
ParseInt
(
statusStr
,
10
,
32
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
cmd
.
Help
()
return
var
status
int64
var
err
error
if
statusStr
!=
""
{
status
,
err
=
strconv
.
ParseInt
(
statusStr
,
10
,
32
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
cmd
.
Help
()
return
}
}
if
issuanceID
!=
""
{
...
...
@@ -297,7 +305,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
Addr
:
address
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuance
DebtInfo
var
res
pkt
.
RepIssuance
Records
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
debtID
!=
""
{
...
...
@@ -308,7 +316,7 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
DebtId
:
debtID
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuance
Curren
tInfo
var
res
pkt
.
RepIssuance
Deb
tInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
...
...
@@ -342,7 +350,6 @@ func IssuanceQuery(cmd *cobra.Command, args []string) {
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
fmt
.
Println
(
"Error: requeres at least one of gameID, address or status"
)
cmd
.
Help
()
}
}
plugin/dapp/issuance/executor/exec.go
View file @
ebffcd28
...
...
@@ -16,7 +16,7 @@ func (c *Issuance) Exec_Create(payload *pty.IssuanceCreate, tx *types.Transactio
}
// 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
)
return
actiondb
.
IssuanceDebt
(
payload
)
}
...
...
@@ -38,3 +38,9 @@ func (c *Issuance) Exec_Close(payload *pty.IssuanceClose, tx *types.Transaction,
actiondb
:=
NewIssuanceAction
(
c
,
tx
,
index
)
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
)
}
plugin/dapp/issuance/executor/exec_del_local.go
View file @
ebffcd28
...
...
@@ -12,41 +12,46 @@ import (
func
(
c
*
Issuance
)
execDelLocal
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receiptData
.
Logs
{
var
issuanceLog
pty
.
ReceiptIssuance
err
:=
types
.
Decode
(
item
.
Log
,
&
issuanceLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogIssuanceCreate
||
item
.
Ty
==
pty
.
TyLogIssuanceDebt
||
item
.
Ty
==
pty
.
TyLogIssuanceRepay
||
item
.
Ty
==
pty
.
TyLogIssuanceFeed
||
item
.
Ty
==
pty
.
TyLogIssuanceClose
{
var
issuanceLog
pty
.
ReceiptIssuance
err
:=
types
.
Decode
(
item
.
Log
,
&
issuanceLog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
case
pty
.
TyLogIssuanceCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteIssuanceStatus
(
issuanceLog
.
Status
,
issuanceLog
.
Index
)
...
)
break
case
pty
.
TyLogIssuanceDebt
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteIssuanceRecordStatus
(
issuanceLog
.
RecordStatus
,
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
{
switch
item
.
Ty
{
case
pty
.
TyLogIssuanceCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
deleteIssuanceStatus
(
issuanceLog
.
Status
,
issuanceLog
.
Index
)
...
)
break
case
pty
.
TyLogIssuanceDebt
:
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
.
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
...
...
plugin/dapp/issuance/executor/exec_local.go
View file @
ebffcd28
...
...
@@ -13,42 +13,47 @@ import (
func
(
c
*
Issuance
)
execLocal
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receipt
.
Logs
{
var
issuanceLog
pty
.
ReceiptIssuance
err
:=
types
.
Decode
(
item
.
Log
,
&
issuanceLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogIssuanceCreate
||
item
.
Ty
==
pty
.
TyLogIssuanceDebt
||
item
.
Ty
==
pty
.
TyLogIssuanceRepay
||
item
.
Ty
==
pty
.
TyLogIssuanceFeed
||
item
.
Ty
==
pty
.
TyLogIssuanceClose
{
var
issuanceLog
pty
.
ReceiptIssuance
err
:=
types
.
Decode
(
item
.
Log
,
&
issuanceLog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
case
pty
.
TyLogIssuanceCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addIssuanceStatus
(
issuanceLog
.
Status
,
issuanceLog
.
Index
,
issuanceLog
.
IssuanceId
)
...
)
break
case
pty
.
TyLogIssuanceDebt
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addIssuanceRecordStatus
(
issuanceLog
.
RecordStatus
,
issuanceLog
.
AccountAddr
,
issuanceLog
.
Index
,
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
{
switch
item
.
Ty
{
case
pty
.
TyLogIssuanceCreate
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addIssuanceStatus
(
issuanceLog
.
Status
,
issuanceLog
.
Index
,
issuanceLog
.
IssuanceId
)
...
)
break
case
pty
.
TyLogIssuanceDebt
:
set
.
KV
=
append
(
set
.
KV
,
c
.
addIssuanceRecordStatus
(
issuanceLog
.
Status
,
issuanceLog
.
AccountAddr
,
issuanceLog
.
Index
,
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
.
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
...
...
plugin/dapp/issuance/executor/issuance.go
View file @
ebffcd28
...
...
@@ -143,6 +143,26 @@ func (c *Issuance) deleteIssuanceRecordStatus(status int32, index int64) (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
func
(
c
*
Issuance
)
CheckReceiptExecOk
()
bool
{
return
true
...
...
plugin/dapp/issuance/executor/issuancedb.go
View file @
ebffcd28
This diff is collapsed.
Click to expand it.
plugin/dapp/issuance/executor/keys.go
View file @
ebffcd28
...
...
@@ -7,46 +7,41 @@ package executor
import
"fmt"
func
calcIssuanceKey
(
issuanceID
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-ID:%s:%018d"
,
issuanceID
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-ID:%s:%018d"
,
issuanceID
,
index
)
return
[]
byte
(
key
)
}
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
)
}
func
calcIssuanceStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-status:%d:%018d"
,
status
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-status:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
func
calcIssuanceRecordAddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-record-addr:%s"
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-record-addr:%s"
,
addr
)
return
[]
byte
(
key
)
}
func
calcIssuanceRecordAddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-record-addr:%s:%018d"
,
addr
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-record-addr:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
}
func
calcIssuancePriceKey
(
time
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Issuance-price:%s"
,
time
)
return
[]
byte
(
key
)
}
func
calcIssuanceLatestPriceKey
()
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Issuance-latest-price"
)
key
:=
fmt
.
Sprintf
(
"LODB-issuance-price:%s"
,
time
)
return
[]
byte
(
key
)
}
func
calcIssuanceRecordStatusPrefix
(
status
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-record-status:%s"
,
status
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-record-status:%s"
,
status
)
return
[]
byte
(
key
)
}
func
calcIssuanceRecordStatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-
I
ssuance-record-status:%d:%018d"
,
status
,
index
)
key
:=
fmt
.
Sprintf
(
"LODB-
i
ssuance-record-status:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
}
\ No newline at end of file
plugin/dapp/issuance/executor/query.go
View file @
ebffcd28
...
...
@@ -22,6 +22,8 @@ func (c *Issuance) Query_IssuanceInfoByID(req *pty.ReqIssuanceInfo) (types.Messa
DebtCeiling
:
issu
.
DebtCeiling
,
LiquidationRatio
:
issu
.
LiquidationRatio
,
Balance
:
issu
.
Balance
,
CollateralValue
:
issu
.
CollateralValue
,
DebtValue
:
issu
.
DebtValue
,
},
nil
}
...
...
@@ -40,6 +42,8 @@ func (c *Issuance) Query_IssuanceInfoByIDs(req *pty.ReqIssuanceInfos) (types.Mes
DebtCeiling
:
issu
.
DebtCeiling
,
LiquidationRatio
:
issu
.
LiquidationRatio
,
Balance
:
issu
.
Balance
,
CollateralValue
:
issu
.
CollateralValue
,
DebtValue
:
issu
.
DebtValue
,
})
}
...
...
@@ -50,49 +54,46 @@ func (c *Issuance) Query_IssuanceByStatus(req *pty.ReqIssuanceByStatus) (types.M
ids
:=
&
pty
.
RepIssuanceIDs
{}
issuIDRecords
,
err
:=
queryIssuanceByStatus
(
c
.
GetLocalDB
(),
req
.
Status
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceByStatus"
,
"get issuance
record
error"
,
err
)
clog
.
Error
(
"Query_IssuanceByStatus"
,
"get issuance error"
,
err
)
return
nil
,
err
}
for
_
,
record
:=
range
issuIDRecords
{
ids
.
IDs
=
append
(
ids
.
IDs
,
record
.
IssuanceId
)
}
ids
.
IDs
=
append
(
ids
.
IDs
,
issuIDRecords
...
)
return
ids
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordByID
(
req
*
pty
.
ReqIssuanceDebtInfo
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepIssuanceDebtInfo
{}
issuRecord
,
err
:=
queryIssuanceRecordByID
(
c
.
GetStateDB
(),
req
.
IssuanceId
,
req
.
DebtId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceRecordByID"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepIssuanceDebtInfo
{}
ret
.
Record
=
issuRecord
return
issuRecord
,
nil
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordsByAddr
(
req
*
pty
.
ReqIssuanceRecordsByAddr
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepIssuanceRecords
{}
records
,
err
:=
queryIssuanceRecordByAddr
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Addr
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceDebtInfoByAddr"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepIssuanceRecords
{}
ret
.
Records
=
records
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordsByStatus
(
req
*
pty
.
ReqIssuanceRecordsByStatus
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepIssuanceRecords
{}
records
,
err
:=
queryIssuanceRecordsByStatus
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Status
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceDebtInfoBy
Addr
"
,
"get issuance record error"
,
err
)
clog
.
Error
(
"Query_IssuanceDebtInfoBy
Status
"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepIssuanceRecords
{}
ret
.
Records
=
records
ret
.
Records
=
append
(
ret
.
Records
,
records
...
)
return
ret
,
nil
}
\ No newline at end of file
plugin/dapp/issuance/proto/issuance.proto
View file @
ebffcd28
...
...
@@ -21,7 +21,6 @@ message Issuance {
string
issuerAddr
=
15
;
//发行地址
int64
index
=
16
;
//当前索引
int64
preIndex
=
17
;
//上级索引
int64
createIndex
=
18
;
//创建索引,用于close删除状态
}
// 抵押记录
...
...
@@ -37,6 +36,8 @@ message DebtRecord {
int64
expireTime
=
9
;
//超时清算时间
int32
preStatus
=
10
;
//上一次抵押状态,用于告警恢复
string
debtId
=
11
;
//借贷id
int64
index
=
12
;
//当前索引
int64
preIndex
=
13
;
//上级索引
}
// 资产价格记录
...
...
@@ -98,12 +99,13 @@ message IssuanceClose {
message
ReceiptIssuance
{
string
issuanceId
=
1
;
string
accountAddr
=
2
;
int32
status
=
3
;
string
debtId
=
4
;
int32
recordStatus
=
5
;
int32
recordPreStatus
=
6
;
int64
index
=
7
;
int64
preIndex
=
8
;
string
debtId
=
3
;
int32
status
=
4
;
int32
preStatus
=
5
;
int64
index
=
6
;
int64
preIndex
=
7
;
int64
recordTime
=
8
;
//价格记录时间
float
btyPrice
=
9
;
//bty价格
}
// exec_local 借贷记录信息
...
...
plugin/dapp/issuance/types/issuance.go
View file @
ebffcd28
...
...
@@ -84,7 +84,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (*
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceRepayTx
(
&
param
)
}
else
if
action
==
"IssuanceFeed"
{
}
else
if
action
==
"Issuance
Price
Feed"
{
var
param
IssuanceFeedTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
...
...
@@ -117,7 +117,7 @@ func (Issuance IssuanceType) CreateTx(action string, message json.RawMessage) (*
func
(
Issuance
IssuanceType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Create"
:
IssuanceActionCreate
,
"
Borrow
"
:
IssuanceActionDebt
,
"
Debt
"
:
IssuanceActionDebt
,
"Repay"
:
IssuanceActionRepay
,
"Feed"
:
IssuanceActionFeed
,
"Close"
:
IssuanceActionClose
,
...
...
@@ -191,6 +191,7 @@ func CreateRawIssuanceRepayTx(parm *IssuanceRepayTx) (*types.Transaction, error)
v
:=
&
IssuanceRepay
{
IssuanceId
:
parm
.
IssuanceID
,
DebtId
:
parm
.
DebtID
,
}
repay
:=
&
IssuanceAction
{
Ty
:
IssuanceActionRepay
,
...
...
plugin/dapp/issuance/types/issuance.pb.go
View file @
ebffcd28
This diff is collapsed.
Click to expand it.
plugin/dapp/issuance/types/tx.go
View file @
ebffcd28
...
...
@@ -23,6 +23,7 @@ type IssuanceDebtTx struct {
// IssuanceRepayTx for construction
type
IssuanceRepayTx
struct
{
IssuanceID
string
`json:"issuanceId"`
DebtID
string
`json:"debtId"`
Fee
int64
`json:"fee"`
}
...
...
plugin/dapp/issuance/types/types.go
View file @
ebffcd28
...
...
@@ -24,7 +24,7 @@ const (
// Issuance name
const
(
IssuanceX
=
"issuance"
CCNYTokenName
=
"
ccny
"
CCNYTokenName
=
"
CCNY
"
IssuancePreLiquidationRatio
=
1.1
//TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
...
...
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