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
dcd41a85
Commit
dcd41a85
authored
Oct 08, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init collateralize contract
parent
10ae4b09
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
994 additions
and
0 deletions
+994
-0
Makefile
plugin/dapp/collateralize/cmd/Makefile
+4
-0
build.sh
plugin/dapp/collateralize/cmd/build.sh
+15
-0
collateralize.go
plugin/dapp/collateralize/executor/collateralize.go
+134
-0
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+0
-0
doc.go
plugin/dapp/collateralize/executor/doc.go
+9
-0
exec.go
plugin/dapp/collateralize/executor/exec.go
+46
-0
exec_del_local.go
plugin/dapp/collateralize/executor/exec_del_local.go
+70
-0
exec_local.go
plugin/dapp/collateralize/executor/exec_local.go
+69
-0
keys.go
plugin/dapp/collateralize/executor/keys.go
+42
-0
query.go
plugin/dapp/collateralize/executor/query.go
+5
-0
plugin.go
plugin/dapp/collateralize/plugin.go
+21
-0
Makefile
plugin/dapp/collateralize/proto/Makefile
+2
-0
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+150
-0
create_protobuf.sh
plugin/dapp/collateralize/proto/create_protobuf.sh
+4
-0
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+304
-0
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
errors.go
plugin/dapp/collateralize/types/errors.go
+20
-0
tx.go
plugin/dapp/collateralize/types/tx.go
+49
-0
types.go
plugin/dapp/collateralize/types/types.go
+50
-0
No files found.
plugin/dapp/collateralize/cmd/Makefile
0 → 100644
View file @
dcd41a85
all
:
chmod
+x ./build.sh
./build.sh
$(OUT)
$(FLAG)
\ No newline at end of file
plugin/dapp/collateralize/cmd/build.sh
0 → 100644
View file @
dcd41a85
#!/bin/sh
strpwd
=
$(
pwd
)
strcmd
=
${
strpwd
##*dapp/
}
strapp
=
${
strcmd
%/cmd*
}
OUT_DIR
=
"
${
1
}
/
$strapp
"
#FLAG=$2
mkdir
-p
"
${
OUT_DIR
}
"
cp
./build/
*
"
${
OUT_DIR
}
"
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
cp
./build/test-rpc.sh
"
${
OUT_TESTDIR
}
"
plugin/dapp/collateralize/executor/collateralize.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
var
clog
=
log
.
New
(
"module"
,
"execs.collateralize"
)
var
driverName
=
pty
.
CollateralizeX
func
init
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Collateralize
{}))
}
type
subConfig
struct
{
ParaRemoteGrpcClient
string
`json:"paraRemoteGrpcClient"`
}
var
cfg
subConfig
// Init collateralize
func
Init
(
name
string
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
driverName
,
newCollateralize
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
// GetName for Collateralize
func
GetName
()
string
{
return
newCollateralize
()
.
GetName
()
}
// Collateralize driver
type
Collateralize
struct
{
drivers
.
DriverBase
}
func
newCollateralize
()
drivers
.
Driver
{
c
:=
&
Collateralize
{}
c
.
SetChild
(
c
)
c
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
return
c
}
// GetDriverName for Collateralize
func
(
Coll
*
Collateralize
)
GetDriverName
()
string
{
return
pty
.
CollateralizeX
}
func
(
Coll
*
Collateralize
)
saveCollateralizeBorrow
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeBorrowKey
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
AccountAddr
)
record
:=
&
pty
.
CollateralizeBorrowRecord
{
CollateralizeId
:
collateralizelog
.
CollateralizeId
,}
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
types
.
Encode
(
record
)}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
func
(
Coll
*
Collateralize
)
deleteCollateralizeBorrow
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeBorrowKey
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
AccountAddr
)
kv
:=
&
types
.
KeyValue
{
Key
:
key
,
Value
:
nil
}
kvs
=
append
(
kvs
,
kv
)
return
kvs
}
func
(
Coll
*
Collateralize
)
saveCollateralizeRepay
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
key
:=
calcCollateralizeRepayKey
(
collateralizelog
.
CollateralizeId
)
record
:=
&
pty
.
CollateralizeRepayRecord
{}
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
)
return
kvs
}
func
(
Coll
*
Collateralize
)
saveCollateralize
(
collateralizelog
*
pty
.
ReceiptCollateralize
)
(
kvs
[]
*
types
.
KeyValue
)
{
if
collateralizelog
.
PreStatus
>
0
{
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
)
{
if
collateralizelog
.
PreStatus
>
0
{
kv
:=
addCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
PreStatus
)
kvs
=
append
(
kvs
,
kv
)
}
kvs
=
append
(
kvs
,
delCollateralize
(
collateralizelog
.
CollateralizeId
,
collateralizelog
.
Status
))
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/collateralizedb.go
0 → 100644
View file @
dcd41a85
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/executor/doc.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
/*
waiting for update
*/
plugin/dapp/collateralize/executor/exec.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
// Exec_Create Action
func
(
c
*
Collateralize
)
Exec_Create
(
payload
*
pty
.
CollateralizeCreate
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeCreate
(
payload
)
}
// Exec_Borrow Action
func
(
c
*
Collateralize
)
Exec_Borrow
(
payload
*
pty
.
CollateralizeBorrow
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeBorrow
(
payload
)
}
// Exec_Repay Action
func
(
c
*
Collateralize
)
Exec_Repay
(
payload
*
pty
.
CollateralizeRepay
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeRepay
(
payload
)
}
// Exec_Repay Action
func
(
c
*
Collateralize
)
Exec_Append
(
payload
*
pty
.
CollateralizeAppend
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeAppend
(
payload
)
}
// Exec_Feed Action
func
(
c
*
Collateralize
)
Exec_Feed
(
payload
*
pty
.
CollateralizeFeed
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeFeed
(
payload
)
}
// Exec_Close Action
func
(
c
*
Collateralize
)
Exec_Close
(
payload
*
pty
.
CollateralizeClose
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeClose
(
payload
)
}
plugin/dapp/collateralize/executor/exec_del_local.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
//"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
func
(
c
*
Collateralize
)
execDelLocal
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receiptData
.
Logs
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
,
pty
.
TyLogCollateralizeBorrow
,
pty
.
TyLogCollateralizeAppend
,
pty
.
TyLogCollateralizeRepay
,
pty
.
TyLogCollateralizeFeed
,
pty
.
TyLogCollateralizeClose
:
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
...
)
if
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
{
kv
:=
c
.
deleteCollateralizeBorrow
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogCollateralizeAppend
{
kv
:=
c
.
deleteCollateralizeRepay
(
&
collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
//TODO
}
}
}
return
set
,
nil
}
// ExecDelLocal_Create Action
func
(
c
*
Collateralize
)
ExecDelLocal_Create
(
payload
*
pty
.
CollateralizeCreate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Borrow Action
func
(
c
*
Collateralize
)
ExecDelLocal_Borrow
(
payload
*
pty
.
CollateralizeBorrow
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Repay Action
func
(
c
*
Collateralize
)
ExecDelLocal_Repay
(
payload
*
pty
.
CollateralizeRepay
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Append Action
func
(
c
*
Collateralize
)
ExecDelLocal_Append
(
payload
*
pty
.
CollateralizeAppend
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Feed Action
func
(
c
*
Collateralize
)
ExecDelLocal_Feed
(
payload
*
pty
.
CollateralizeFeed
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Close Action
func
(
c
*
Collateralize
)
ExecDelLocal_Close
(
payload
*
pty
.
CollateralizeClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
\ No newline at end of file
plugin/dapp/collateralize/executor/exec_local.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
//"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
func
(
c
*
Collateralize
)
execLocal
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receipt
.
Logs
{
switch
item
.
Ty
{
case
pty
.
TyLogCollateralizeCreate
,
pty
.
TyLogCollateralizeBorrow
,
pty
.
TyLogCollateralizeRepay
,
pty
.
TyLogCollateralizeAppend
,
pty
.
TyLogCollateralizeFeed
,
pty
.
TyLogCollateralizeClose
:
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
...
)
if
item
.
Ty
==
pty
.
TyLogCollateralizeBorrow
{
kv
:=
c
.
saveCollateralizeBorrow
(
&
Collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogCollateralizeRepay
{
kv
:=
c
.
saveCollateralizeRepay
(
&
Collateralizelog
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
{
//TODO
}
}
}
return
set
,
nil
}
// ExecLocal_Create Action
func
(
c
*
Collateralize
)
ExecLocal_Create
(
payload
*
pty
.
CollateralizeCreate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Borrow Action
func
(
c
*
Collateralize
)
ExecLocal_Borrow
(
payload
*
pty
.
CollateralizeBorrow
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Repay Action
func
(
c
*
Collateralize
)
ExecLocal_Repay
(
payload
*
pty
.
CollateralizeRepay
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Repay Action
func
(
c
*
Collateralize
)
ExecLocal_Append
(
payload
*
pty
.
CollateralizeAppend
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Feed Action
func
(
c
*
Collateralize
)
ExecLocal_Feed
(
payload
*
pty
.
CollateralizeFeed
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Close Action
func
(
c
*
Collateralize
)
ExecLocal_Close
(
payload
*
pty
.
CollateralizeClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
plugin/dapp/collateralize/executor/keys.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
"fmt"
func
calcCollateralizeKey
(
CollateralizeID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-create:%s"
,
CollateralizeID
)
return
[]
byte
(
key
)
}
func
calcCollateralizeBorrowPrefix
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-borrow:%s:%s"
,
CollateralizeID
,
addr
)
return
[]
byte
(
key
)
}
func
calcCollateralizeBorrowKey
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-buy:%s:%s:%18d"
,
CollateralizeID
,
addr
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRepayPrefix
(
CollateralizeID
string
,
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-repay:%s:%s"
,
CollateralizeID
,
addr
)
return
[]
byte
(
key
)
}
func
calcCollateralizeRepayKey
(
CollateralizeID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-repay:%s:%10d"
,
CollateralizeID
)
return
[]
byte
(
key
)
}
func
calcCollateralizePriceKey
(
time
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-price:%s"
,
time
)
return
[]
byte
(
key
)
}
func
calcCollateralizeLatestPriceKey
()
[]
byte
{
key
:=
fmt
.
Sprintf
(
"LODB-Collateralize-latest-price"
)
return
[]
byte
(
key
)
}
plugin/dapp/collateralize/executor/query.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
plugin/dapp/collateralize/plugin.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
collateralize
import
(
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/collateralize/executor"
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
func
init
()
{
pluginmgr
.
Register
(
&
pluginmgr
.
PluginBase
{
Name
:
types
.
CollateralizeX
,
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
nil
,
RPC
:
nil
,
})
}
plugin/dapp/collateralize/proto/Makefile
0 → 100644
View file @
dcd41a85
all
:
sh ./create_protobuf.sh
plugin/dapp/collateralize/proto/collateralize.proto
0 → 100644
View file @
dcd41a85
syntax
=
"proto3"
;
package
types
;
message
Collateralize
{
string
collateralizeId
=
1
;
//借贷ID,一期借贷对应一个ID
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
int64
stabilityFee
=
5
;
//稳定费
int64
liquidationPenalty
=
6
;
//清算罚金
string
createAddr
=
7
;
//创建人地址
int64
balance
=
8
;
//剩余可借贷金额(ccny)
repeated
BorrowRecord
borrowRecords
=
9
;
//借贷记录
repeated
BorrowRecord
badRecords
=
10
;
//被系统清算的借贷
int32
status
=
11
;
//当期借贷的状态,是否关闭
int32
collType
=
12
;
//质押资产类型(1,bty,2,btc,3,eth...)
float
latestRepayPrice
=
13
;
//最大清算价格
}
message
BorrowRecord
{
string
accountAddr
=
1
;
//借贷人地址
int64
startTime
=
2
;
//借贷时间
int64
collateralValue
=
3
;
//抵押物价值(bty)
float
collateralPrice
=
4
;
//抵押物价格
int64
debtValue
=
5
;
//债务价值(ccny)
float
liquidationPrice
=
6
;
//抵押物清算价格
int32
status
=
7
;
//抵押状态,是否被清算
}
message
AssetPriceRecord
{
string
recordTime
=
1
;
//价格记录时间
float
btyPrice
=
2
;
//bty价格
float
btcPrice
=
3
;
//btc价格
float
ethPrice
=
4
;
//eth价格
string
preRecordTime
=
5
;
//上一次记录时间
}
message
CollateralizeAction
{
oneof
value
{
CollateralizeCreate
create
=
1
;
//创建一期借贷
CollateralizeBorrow
borrow
=
2
;
//借贷
CollateralizeRepay
repay
=
3
;
//清算
CollateralizeAppend
append
=
4
;
//追加
CollateralizeFeed
feed
=
5
;
//喂价
CollateralizeClose
close
=
6
;
//关闭
}
int32
ty
=
10
;
}
message
CollateralizeCreate
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
2
;
//清算比例
int64
stabilityFee
=
3
;
//稳定费
int64
liquidationPenalty
=
4
;
//清算罚金
int64
totalBalance
=
5
;
//可借贷总金额
}
message
CollateralizeBorrow
{
string
collateralizeId
=
1
;
//借贷期数ID
int64
value
=
2
;
//借贷价值(ccny)
}
message
CollateralizeRepay
{
string
collateralizeId
=
1
;
//借贷期数ID
int64
value
=
2
;
//借贷价值(ccny)
}
message
CollateralizeAppend
{
string
collateralizeId
=
1
;
//借贷期数ID
int64
collateralValue
=
2
;
//追加价值(bty)
}
message
CollateralizeFeed
{
repeated
int64
price
=
1
;
//喂价
repeated
int64
volume
=
2
;
//成交量
}
message
CollateralizeClose
{
string
collateralizeId
=
1
;
//借贷期数ID
}
message
ReceiptCollateralize
{
string
collateralizeId
=
1
;
string
createAddr
=
3
;
string
accountAddr
=
4
;
int32
status
=
9
;
int32
preStatus
=
10
;
}
message
ReqCollateralizeInfo
{
string
collateralizeId
=
1
;
}
message
ReqCollateralizeBorrowInfo
{
string
collateralizeId
=
1
;
string
addr
=
2
;
}
message
ReqCollateralizeBadDebt
{
string
collateralizeId
=
1
;
}
message
ReqCollateralizeBorrowHistory
{
string
collateralizeId
=
1
;
string
addr
=
2
;
int32
count
=
4
;
int32
direction
=
5
;
int64
index
=
6
;
}
message
ReplyCollateralizeCurrentInfo
{
int32
status
=
1
;
//当期借贷的状态,是否关闭
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
int64
stabilityFee
=
5
;
//稳定费
int64
liquidationPenalty
=
6
;
//清算罚金
string
createAddr
=
7
;
//创建人地址
int64
balance
=
8
;
//剩余可借贷金额(ccny)
}
message
ReplyCollateralizeBadDebt
{
repeated
BorrowRecord
records
=
1
;
}
// used for execlocal
message
CollateralizeBorrowRecord
{
string
collateralizeId
=
1
;
int64
value
=
2
;
int64
index
=
3
;
int64
time
=
4
;
string
txHash
=
5
;
}
message
CollateralizeBorrowRecords
{
repeated
CollateralizeBorrowRecord
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/proto/create_protobuf.sh
0 → 100644
View file @
dcd41a85
#!/bin/sh
chain33_path
=
$(
go list
-f
'{{.Dir}}'
"github.com/33cn/chain33"
)
protoc
--go_out
=
plugins
=
grpc:../types ./
*
.proto
--proto_path
=
.
--proto_path
=
"
${
chain33_path
}
/types/proto/"
plugin/dapp/collateralize/types/collateralize.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
types
import
(
"encoding/json"
"reflect"
"github.com/33cn/chain33/common/address"
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
)
var
(
llog
=
log
.
New
(
"module"
,
"exectype."
+
CollateralizeX
)
)
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
CollateralizeX
))
types
.
RegistorExecutor
(
CollateralizeX
,
NewType
())
types
.
RegisterDappFork
(
CollateralizeX
,
"Enable"
,
0
)
}
// CollateralizeType def
type
CollateralizeType
struct
{
types
.
ExecTypeBase
}
// NewType method
func
NewType
()
*
CollateralizeType
{
c
:=
&
CollateralizeType
{}
c
.
SetChild
(
c
)
return
c
}
// GetName 获取执行器名称
func
(
Collateralize
*
CollateralizeType
)
GetName
()
string
{
return
CollateralizeX
}
// GetLogMap method
func
(
Collateralize
*
CollateralizeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
TyLogCollateralizeCreate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeCreate"
},
TyLogCollateralizeBorrow
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeBorrow"
},
TyLogCollateralizeRepay
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeRepay"
},
TyLogCollateralizeAppend
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeAppend"
},
TyLogCollateralizeFeed
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeFeed"
},
TyLogCollateralizeClose
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeClose"
},
}
}
// GetPayload method
func
(
Collateralize
*
CollateralizeType
)
GetPayload
()
types
.
Message
{
return
&
CollateralizeAction
{}
}
// CreateTx method
func
(
Collateralize
CollateralizeType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"Collateralize.CreateTx"
,
"action"
,
action
)
if
action
==
"CollateralizeCreate"
{
var
param
CollateralizeCreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeCreateTx
(
&
param
)
}
else
if
action
==
"CollateralizeBorrow"
{
var
param
CollateralizeBorrowTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeBorrowTx
(
&
param
)
}
else
if
action
==
"CollateralizeRepay"
{
var
param
CollateralizeRepayTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeRepayTx
(
&
param
)
}
else
if
action
==
"CollateralizeAppend"
{
var
param
CollateralizeAppendTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeAppendTx
(
&
param
)
}
else
if
action
==
"CollateralizeFeed"
{
var
param
CollateralizeFeedTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeFeedTx
(
&
param
)
}
else
if
action
==
"CollateralizeClose"
{
var
param
CollateralizeCloseTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeCloseTx
(
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
}
// GetTypeMap method
func
(
Collateralize
CollateralizeType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Create"
:
CollateralizeActionCreate
,
"Borrow"
:
CollateralizeActionBorrow
,
"Repay"
:
CollateralizeActionRepay
,
"Append"
:
CollateralizeActionAppend
,
"Feed"
:
CollateralizeActionFeed
,
"Close"
:
CollateralizeActionClose
,
}
}
// CreateRawCollateralizeCreateTx method
func
CreateRawCollateralizeCreateTx
(
parm
*
CollateralizeCreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeCreateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeCreate
{
DebtCeiling
:
parm
.
DebtCeiling
,
LiquidationRatio
:
parm
.
LiquidationRatio
,
StabilityFee
:
parm
.
StabilityFee
,
LiquidationPenalty
:
parm
.
LiquidationPenalty
,
TotalBalance
:
parm
.
TotalBalance
,
}
create
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionCreate
,
Value
:
&
CollateralizeAction_Create
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
create
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeBorrowTx method
func
CreateRawCollateralizeBorrowTx
(
parm
*
CollateralizeBorrowTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeBorrowTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeBorrow
{
CollateralizeId
:
parm
.
CollateralizeID
,
Value
:
parm
.
Value
,
}
Borrow
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionBorrow
,
Value
:
&
CollateralizeAction_Borrow
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
Borrow
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeRepayTx method
func
CreateRawCollateralizeRepayTx
(
parm
*
CollateralizeRepayTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeRepayTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeRepay
{
CollateralizeId
:
parm
.
CollateralizeID
,
Value
:
parm
.
Value
,
}
Repay
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionRepay
,
Value
:
&
CollateralizeAction_Repay
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
Repay
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeAppendTx method
func
CreateRawCollateralizeAppendTx
(
parm
*
CollateralizeAppendTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeAppendTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeAppend
{
CollateralizeId
:
parm
.
CollateralizeID
,
CollateralValue
:
parm
.
Value
,
}
Repay
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionAppend
,
Value
:
&
CollateralizeAction_Append
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
Repay
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeFeedTx method
func
CreateRawCollateralizeFeedTx
(
parm
*
CollateralizeFeedTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizePriceFeedTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeFeed
{
Price
:
parm
.
Price
,
Volume
:
parm
.
Volume
,
}
Feed
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionFeed
,
Value
:
&
CollateralizeAction_Feed
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
Feed
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeCloseTx method
func
CreateRawCollateralizeCloseTx
(
parm
*
CollateralizeCloseTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeCloseTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeClose
{
CollateralizeId
:
parm
.
CollateralizeID
,
}
close
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionClose
,
Value
:
&
CollateralizeAction_Close
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
types
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
close
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
types
.
ExecName
(
CollateralizeX
)),
}
name
:=
types
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
plugin/dapp/collateralize/types/collateralize.pb.go
0 → 100644
View file @
dcd41a85
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/types/errors.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
types
import
"errors"
// Errors for lottery
var
(
ErrRiskParam
=
errors
.
New
(
"ErrRiskParam"
)
ErrCollateralizeRepeatHash
=
errors
.
New
(
"ErrCollateralizeRepeatHash"
)
ErrCollateralizeStatus
=
errors
.
New
(
"ErrCollateralizeStatus"
)
ErrCollateralizeExceedDebtCeiling
=
errors
.
New
(
"ErrCollateralizeExceedDebtCeiling"
)
ErrPriceZero
=
errors
.
New
(
"ErrPriceZero"
)
ErrAssetType
=
errors
.
New
(
"ErrAssetType"
)
ErrRecordNotExist
=
errors
.
New
(
"ErrRecordNotExist"
)
ErrCollateralizeErrCloser
=
errors
.
New
(
"ErrCollateralizeErrCloser"
)
ErrRepayValueInsufficient
=
errors
.
New
(
"ErrRepayValueInsufficient"
)
)
plugin/dapp/collateralize/types/tx.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
types
// CollateralizeCreateTx for construction
type
CollateralizeCreateTx
struct
{
DebtCeiling
int64
`json:"debtCeiling"`
LiquidationRatio
float32
`json:"liquidationRatio"`
StabilityFee
int64
`json:"stabilityFee"`
LiquidationPenalty
int64
`json:"liquidationPenalty"`
TotalBalance
int64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
// CollateralizeBorrowTx for construction
type
CollateralizeBorrowTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
int64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeRepayTx for construction
type
CollateralizeRepayTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
int64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeAppednTx for construction
type
CollateralizeAppendTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
int64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeFeedTx for construction
type
CollateralizeFeedTx
struct
{
Price
[]
int64
`json:"price"`
Volume
[]
int64
`json:"volume"`
Fee
int64
`json:"fee"`
}
// CollateralizeCloseTx for construction
type
CollateralizeCloseTx
struct
{
CollateralizeID
string
`json:"CollateralizeId"`
Fee
int64
`json:"fee"`
}
plugin/dapp/collateralize/types/types.go
0 → 100644
View file @
dcd41a85
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
types
//Collateralize op
const
(
CollateralizeActionCreate
=
1
+
iota
CollateralizeActionBorrow
CollateralizeActionRepay
CollateralizeActionAppend
CollateralizeActionFeed
CollateralizeActionClose
//log for Collateralize
TyLogCollateralizeCreate
=
801
TyLogCollateralizeBorrow
=
802
TyLogCollateralizeRepay
=
803
TyLogCollateralizeAppend
=
804
TyLogCollateralizeFeed
=
805
TyLogCollateralizeClose
=
806
)
// Collateralize name
const
(
CollateralizeX
=
"collateralize"
CCNYTokenName
=
"ccny"
CollateralizeRepayRatio
=
1.1
//TODO 清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
//Collateralize status
const
(
CollateralizeStatusCreated
=
1
+
iota
CollateralizeStatusClose
)
const
(
CollateralizeAssetTypeBty
=
1
+
iota
CollateralizeAssetTypeBtc
CollateralizeAssetTypeEth
)
const
(
CollateralizeUserStatusCreate
=
1
+
iota
CollateralizeUserStatusWarning
CollateralizeUserStatusSystemRepayed
CollateralizeUserStatusClose
)
\ 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