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
961263a5
Commit
961263a5
authored
Oct 11, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 update collateralize exec local
parent
4bf2e915
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
81 additions
and
116 deletions
+81
-116
collateralize.go
plugin/dapp/collateralize/executor/collateralize.go
+18
-52
exec_del_local.go
plugin/dapp/collateralize/executor/exec_del_local.go
+24
-17
exec_local.go
plugin/dapp/collateralize/executor/exec_local.go
+24
-18
keys.go
plugin/dapp/collateralize/executor/keys.go
+9
-9
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+6
-20
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
No files found.
plugin/dapp/collateralize/executor/collateralize.go
View file @
961263a5
...
@@ -59,76 +59,42 @@ func (Coll *Collateralize) GetDriverName() string {
...
@@ -59,76 +59,42 @@ func (Coll *Collateralize) GetDriverName() string {
return
pty
.
CollateralizeX
return
pty
.
CollateralizeX
}
}
func
(
Coll
*
Collateralize
)
saveCollateralizeBorrow
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
Coll
*
Collateralize
)
addCollateralizeStatus
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeBorrowKey
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
AccountAddr
)
key
:=
calcCollateralizeStatusKey
(
collateralizelog
.
Status
,
collateralizelog
.
Index
)
record
:=
&
pty
.
CollateralizeBorrowRecord
{
CollateralizeId
:
collateralizelog
.
CollateralizeId
,}
record
:=
&
pty
.
CollateralizeRecord
{
CollateralizeId
:
collateralizelog
.
CollateralizeId
,
Index
:
collateralizelog
.
Index
,
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
kvs
=
append
(
kvs
,
kv
)
return
kvs
return
kvs
}
}
func
(
Coll
*
Collateralize
)
deleteCollateralize
Borrow
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
Coll
*
Collateralize
)
deleteCollateralize
Status
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralize
BorrowKey
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
AccountAddr
)
key
:=
calcCollateralize
StatusKey
(
collateralizelog
.
Status
,
collateralizelog
.
Index
)
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kvs
=
append
(
kvs
,
kv
)
kvs
=
append
(
kvs
,
kv
)
return
kvs
return
kvs
}
}
func
(
Coll
*
Collateralize
)
saveCollateralizeRepay
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
Coll
*
Collateralize
)
addCollateralizeAddr
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeRepayKey
(
collateralizelog
.
CollateralizeId
)
key
:=
calcCollateralizeAddrKey
(
collateralizelog
.
AccountAddr
,
collateralizelog
.
Index
)
record
:=
&
pty
.
CollateralizeRepayRecord
{}
record
:=
&
pty
.
CollateralizeRecord
{
CollateralizeId
:
collateralizelog
.
CollateralizeId
,
Index
:
collateralizelog
.
Index
,
}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
func
(
Coll
*
Collateralize
)
deleteCollateralizeRepay
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeRepayKey
(
collateralizelog
.
CollateralizeId
)
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kvs
=
append
(
kvs
,
kv
)
kvs
=
append
(
kvs
,
kv
)
return
kvs
return
kvs
}
}
func
(
Coll
*
Collateralize
)
saveCollateralize
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
func
(
Coll
*
Collateralize
)
deleteCollateralizeAddr
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
if
collateralizelog
.
PreStatus
>
0
{
key
:=
calcCollateralizeAddrKey
(
collateralizelog
.
AccountAddr
,
collateralizelog
.
Index
)
kv
:=
delCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
PreStatus
)
kvs
=
append
(
kvs
,
kv
)
}
kvs
=
append
(
kvs
,
addCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
Status
))
return
kvs
}
func
(
Coll
*
Collateralize
)
deleteCollateralize
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
if
collateralizelog
.
PreStatus
>
0
{
kvs
=
append
(
kvs
,
kv
)
kv
:=
addCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
PreStatus
)
kvs
=
append
(
kvs
,
kv
)
}
kvs
=
append
(
kvs
,
delCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
Status
))
return
kvs
return
kvs
}
}
func
addCollateralize
(
collateralizeID
string
,
status
int32
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcCollateralizeKey
(
collateralizeID
)
kv
.
Value
=
[]
byte
(
collateralizeID
)
return
kv
}
func
delCollateralize
(
collateralizeID
string
,
status
int32
)
*
types
.
KeyValue
{
kv
:=
&
types
.
KeyValue
{}
kv
.
Key
=
calcCollateralizeKey
(
collateralizeID
)
kv
.
Value
=
nil
return
kv
}
// GetPayloadValue CollateralizeAction
func
(
Coll
*
Collateralize
)
GetPayloadValue
()
types
.
Message
{
return
&
pty
.
CollateralizeAction
{}
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func
(
Coll
*
Collateralize
)
CheckReceiptExecOk
()
bool
{
return
true
}
plugin/dapp/collateralize/executor/exec_del_local.go
View file @
961263a5
...
@@ -13,25 +13,32 @@ import (
...
@@ -13,25 +13,32 @@ 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
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizelog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
,
pty
.
TyLogCollateralizeBorrow
,
pty
.
TyLogCollateralizeAppend
,
case
pty
.
TyLogCollateralizeCreate
:
pty
.
TyLogCollateralizeRepay
,
pty
.
TyLogCollateralizeFeed
,
pty
.
TyLogCollateralizeClose
:
kv
:=
c
.
deleteCollateralizeStatus
(
&
collateralizelog
)
var
collateralizelog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizelog
)
if
err
!=
nil
{
return
nil
,
err
}
kv
:=
c
.
deleteCollateralize
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
if
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
{
case
pty
.
TyLogCollateralizeBorrow
:
kv
:=
c
.
deleteCollateralizeBorrow
(
&
collateralizelog
)
kv
:=
c
.
deleteCollateralizeAddr
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogCollateralizeAppend
{
break
kv
:=
c
.
deleteCollateralizeRepay
(
&
collateralizelog
)
case
pty
.
TyLogCollateralizeAppend
:
// append没有状态变化
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
//TODO
case
pty
.
TyLogCollateralizeRepay
:
}
kv
:=
c
.
addCollateralizeAddr
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
/*case pty.TyLogCollateralizeFeed:*/
// TODO
case
pty
.
TyLogCollateralizeClose
:
kv
:=
c
.
addCollateralizeStatus
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
}
}
}
}
return
set
,
nil
return
set
,
nil
...
...
plugin/dapp/collateralize/executor/exec_local.go
View file @
961263a5
...
@@ -13,26 +13,32 @@ import (
...
@@ -13,26 +13,32 @@ 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
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizelog
)
if
err
!=
nil
{
return
nil
,
err
}
switch
item
.
Ty
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
,
pty
.
TyLogCollateralizeBorrow
,
pty
.
TyLogCollateralizeRepay
,
pty
.
TyLogCollateralizeAppend
,
case
pty
.
TyLogCollateralizeCreate
:
pty
.
TyLogCollateralizeFeed
,
pty
.
TyLogCollateralizeClose
:
kv
:=
c
.
addCollateralizeStatus
(
&
collateralizelog
)
var
Collateralizelog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
Collateralizelog
)
if
err
!=
nil
{
return
nil
,
err
}
kv
:=
c
.
saveCollateralize
(
&
Collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
if
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
{
case
pty
.
TyLogCollateralizeBorrow
:
kv
:=
c
.
saveCollateralizeBorrow
(
&
Collateralizelog
)
kv
:=
c
.
addCollateralizeAddr
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogCollateralizeRepay
{
break
kv
:=
c
.
saveCollateralizeRepay
(
&
Collateralizelog
)
case
pty
.
TyLogCollateralizeAppend
:
//append没有状态变化
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
}
else
{
case
pty
.
TyLogCollateralizeRepay
:
//TODO
kv
:=
c
.
deleteCollateralizeAddr
(
&
collateralizelog
)
}
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
/*case pty.TyLogCollateralizeFeed:*/
// TODO
case
pty
.
TyLogCollateralizeClose
:
kv
:=
c
.
deleteCollateralizeStatus
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
break
}
}
}
}
return
set
,
nil
return
set
,
nil
...
...
plugin/dapp/collateralize/executor/keys.go
View file @
961263a5
...
@@ -7,27 +7,27 @@ package executor
...
@@ -7,27 +7,27 @@ package executor
import
"fmt"
import
"fmt"
func
calcCollateralizeKey
(
CollateralizeID
string
)
[]
byte
{
func
calcCollateralizeKey
(
CollateralizeID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
create
:%s"
,
CollateralizeID
)
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
ID
:%s"
,
CollateralizeID
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcCollateralize
BorrowPrefix
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
func
calcCollateralize
StatusPrefix
(
status
int32
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
borrow:%s:%s"
,
CollateralizeID
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
status-index:%d"
,
status
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcCollateralize
BorrowKey
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
func
calcCollateralize
StatusKey
(
status
int32
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
buy:%s:%s:%18d"
,
CollateralizeID
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
status:%d:%018d"
,
status
,
index
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcCollateralize
RepayPrefix
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
func
calcCollateralize
AddrPrefix
(
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
repay:%s:%s"
,
CollateralizeID
,
addr
)
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
addr:%s"
,
addr
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
func
calcCollateralize
RepayKey
(
CollateralizeID
string
)
[]
byte
{
func
calcCollateralize
AddrKey
(
addr
string
,
index
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
repay:%s:%10d"
,
CollateralizeID
)
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-
addr:%s:%018d"
,
addr
,
index
)
return
[]
byte
(
key
)
return
[]
byte
(
key
)
}
}
...
...
plugin/dapp/collateralize/proto/collateralize.proto
View file @
961263a5
...
@@ -84,8 +84,9 @@ message ReceiptCollateralize {
...
@@ -84,8 +84,9 @@ message ReceiptCollateralize {
string
collateralizeId
=
1
;
string
collateralizeId
=
1
;
string
createAddr
=
3
;
string
createAddr
=
3
;
string
accountAddr
=
4
;
string
accountAddr
=
4
;
int32
status
=
9
;
int32
status
=
5
;
int32
preStatus
=
10
;
int32
preStatus
=
6
;
int64
index
=
7
;
}
}
message
ReqCollateralizeInfo
{
message
ReqCollateralizeInfo
{
...
@@ -125,26 +126,11 @@ message ReplyCollateralizeBadDebt {
...
@@ -125,26 +126,11 @@ message ReplyCollateralizeBadDebt {
}
}
// used for execlocal
// used for execlocal
message
Collateralize
Borrow
Record
{
message
CollateralizeRecord
{
string
collateralizeId
=
1
;
string
collateralizeId
=
1
;
int64
value
=
2
;
int64
index
=
3
;
int64
index
=
3
;
int64
time
=
4
;
string
txHash
=
5
;
}
}
message
CollateralizeBorrowRecords
{
message
CollateralizeRecords
{
repeated
CollateralizeBorrowRecord
records
=
1
;
repeated
CollateralizeRecord
records
=
1
;
}
message
CollateralizeRepayRecord
{
string
collateralizeId
=
1
;
int64
value
=
2
;
int64
index
=
3
;
int64
time
=
4
;
string
txHash
=
5
;
}
message
CollateralizeRepayRecords
{
repeated
CollateralizeRepayRecord
records
=
1
;
}
}
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
961263a5
This diff is collapsed.
Click to expand it.
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