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
be7eb574
Commit
be7eb574
authored
Oct 21, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 add manage action
parent
fd703948
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
359 additions
and
70 deletions
+359
-70
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+63
-0
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+156
-28
query.go
plugin/dapp/collateralize/executor/query.go
+2
-2
plugin.go
plugin/dapp/collateralize/plugin.go
+2
-2
collateralize.proto
plugin/dapp/collateralize/proto/collateralize.proto
+19
-6
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+77
-3
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+0
-0
errors.go
plugin/dapp/collateralize/types/errors.go
+1
-1
tx.go
plugin/dapp/collateralize/types/tx.go
+11
-4
types.go
plugin/dapp/collateralize/types/types.go
+3
-0
init.go
plugin/dapp/init/init.go
+25
-24
No files found.
plugin/dapp/collateralize/commands/cmd.go
0 → 100644
View file @
be7eb574
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/collateralize/types"
)
// CollateralizeCmd 斗牛游戏命令行
func
CollateralizeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"collateralize"
,
Short
:
"Collateralize command"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
CollateralizeCreateRawTxCmd
(),
//CollateralizeBorrowRawTxCmd(),
//CollateralizeAppendRawTxCmd(),
//CollateralizeRepayRawTxCmd(),
//CollateralizePriceFeedRawTxCmd(),
//CollateralizeCloseRawTxCmd(),
//CollateralizeManageRawTxCmd(),
)
return
cmd
}
// CollateralizeCreateRawTxCmd 生成开始交易命令行
func
CollateralizeCreateRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"create"
,
Short
:
"Create a collateralize"
,
Run
:
CollateralizeCreate
,
}
addCollateralizeCreateFlags
(
cmd
)
return
cmd
}
func
addCollateralizeCreateFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
}
func
CollateralizeCreate
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
balance
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"balance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"Create"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
balance
\"
:%d}"
,
balance
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
\ No newline at end of file
plugin/dapp/collateralize/executor/collateralizedb.go
View file @
be7eb574
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/executor/query.go
View file @
be7eb574
...
...
@@ -21,7 +21,7 @@ func (c *Collateralize) Query_CollateralizeInfoByID(req *pty.ReqCollateralizeInf
TotalBalance
:
coll
.
TotalBalance
,
DebtCeiling
:
coll
.
DebtCeiling
,
LiquidationRatio
:
coll
.
LiquidationRatio
,
StabilityFee
:
coll
.
StabilityFee
,
StabilityFee
Ratio
:
coll
.
StabilityFeeRatio
,
CreateAddr
:
coll
.
CreateAddr
,
Balance
:
coll
.
Balance
,
},
nil
...
...
@@ -41,7 +41,7 @@ func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeIn
TotalBalance
:
coll
.
TotalBalance
,
DebtCeiling
:
coll
.
DebtCeiling
,
LiquidationRatio
:
coll
.
LiquidationRatio
,
StabilityFee
:
coll
.
StabilityFee
,
StabilityFee
Ratio
:
coll
.
StabilityFeeRatio
,
CreateAddr
:
coll
.
CreateAddr
,
Balance
:
coll
.
Balance
,
})
...
...
plugin/dapp/collateralize/plugin.go
View file @
be7eb574
...
...
@@ -6,6 +6,7 @@ package collateralize
import
(
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/collateralize/commands"
"github.com/33cn/plugin/plugin/dapp/collateralize/executor"
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
)
...
...
@@ -15,7 +16,6 @@ func init() {
Name
:
types
.
CollateralizeX
,
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
nil
,
RPC
:
nil
,
Cmd
:
commands
.
CollateralizeCmd
,
})
}
plugin/dapp/collateralize/proto/collateralize.proto
View file @
be7eb574
...
...
@@ -8,7 +8,7 @@ message Collateralize {
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
int64
stabilityFee
=
5
;
//稳定费
float
stabilityFeeRatio
=
5
;
//稳定费率
string
createAddr
=
6
;
//创建人地址
int64
balance
=
7
;
//剩余可借贷金额(ccny)
repeated
BorrowRecord
borrowRecords
=
8
;
//借贷记录
...
...
@@ -51,16 +51,29 @@ message CollateralizeAction {
CollateralizeAppend
append
=
4
;
//追加
CollateralizeFeed
feed
=
5
;
//喂价
CollateralizeClose
close
=
6
;
//关闭
CollateralizeManage
manage
=
7
;
//全局配置
}
int32
ty
=
10
;
}
// 创建借贷
message
CollateralizeCreate
{
message
CollateralizeManage
{
CollateralizeConfig
cfg
=
1
;
//借贷配置
CollateralizeAddr
addr
=
2
;
//地址配置
}
message
CollateralizeConfig
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
2
;
//清算比例
int64
stabilityFee
=
3
;
//稳定费
int64
totalBalance
=
4
;
//可借贷总金额
float
stabilityFeeRatio
=
3
;
//稳定费
int64
period
=
4
;
//合约期限
}
message
CollateralizeAddr
{
repeated
string
superAddrs
=
1
;
//大户地址
}
// 创建借贷
message
CollateralizeCreate
{
int64
totalBalance
=
1
;
//可借贷总金额
}
// 质押借出
...
...
@@ -127,7 +140,7 @@ message RepCollateralizeCurrentInfo {
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
float
liquidationRatio
=
4
;
//清算比例
int64
stabilityFee
=
5
;
//稳定费
float
stabilityFeeRatio
=
5
;
//稳定费
int64
liquidationPenalty
=
6
;
//清算罚金
string
createAddr
=
7
;
//创建人地址
int64
balance
=
8
;
//剩余可借贷金额(ccny)
...
...
plugin/dapp/collateralize/types/collateralize.go
View file @
be7eb574
...
...
@@ -109,6 +109,18 @@ func (Collateralize CollateralizeType) CreateTx(action string, message json.RawM
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeCloseTx
(
&
param
)
}
else
if
action
==
"CollateralizeManage"
{
var
param
CollateralizeManageTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
if
param
.
Addr
!=
nil
{
return
CreateRawCollateralizeManageAddrTx
(
&
param
)
}
return
CreateRawCollateralizeManageConfigTx
(
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
...
...
@@ -123,6 +135,7 @@ func (Collateralize CollateralizeType) GetTypeMap() map[string]int32 {
"Append"
:
CollateralizeActionAppend
,
"Feed"
:
CollateralizeActionFeed
,
"Close"
:
CollateralizeActionClose
,
"Manage"
:
CollateralizeActionManage
,
}
}
...
...
@@ -134,9 +147,6 @@ func CreateRawCollateralizeCreateTx(parm *CollateralizeCreateTx) (*types.Transac
}
v
:=
&
CollateralizeCreate
{
DebtCeiling
:
parm
.
DebtCeiling
,
LiquidationRatio
:
parm
.
LiquidationRatio
,
StabilityFee
:
parm
.
StabilityFee
,
TotalBalance
:
parm
.
TotalBalance
,
}
create
:=
&
CollateralizeAction
{
...
...
@@ -301,3 +311,66 @@ func CreateRawCollateralizeCloseTx(parm *CollateralizeCloseTx) (*types.Transacti
}
return
tx
,
nil
}
// CreateRawCollateralizeManageConfigTx method
func
CreateRawCollateralizeManageConfigTx
(
parm
*
CollateralizeManageTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeManageTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeManage
{}
v
.
Cfg
=
&
CollateralizeConfig
{
DebtCeiling
:
parm
.
DebtCeiling
,
LiquidationRatio
:
parm
.
LiquidationRatio
,
StabilityFeeRatio
:
parm
.
StabilityFeeRatio
,
Period
:
parm
.
Period
,
}
close
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionManage
,
Value
:
&
CollateralizeAction_Manage
{
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
}
// CreateRawCollateralizeManageAddrTx method
func
CreateRawCollateralizeManageAddrTx
(
parm
*
CollateralizeManageTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeManageTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeManage
{}
v
.
Addr
=
&
CollateralizeAddr
{
SuperAddrs
:
parm
.
Addr
}
close
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionManage
,
Value
:
&
CollateralizeAction_Manage
{
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
}
\ No newline at end of file
plugin/dapp/collateralize/types/collateralize.pb.go
View file @
be7eb574
This diff is collapsed.
Click to expand it.
plugin/dapp/collateralize/types/errors.go
View file @
be7eb574
...
...
@@ -20,6 +20,6 @@ var (
ErrCollateralizeAccountExist
=
errors
.
New
(
"ErrCollateralizeAccountExist"
)
ErrCollateralizeLowBalance
=
errors
.
New
(
"ErrCollateralizeLowBalance"
)
ErrCollateralizeBalanceInvalid
=
errors
.
New
(
"ErrCollateralizeBalanceInvalid"
)
ErrP
riceFeedPermissionDeny
=
errors
.
New
(
"ErrPriceFeed
PermissionDeny"
)
ErrP
ermissionDeny
=
errors
.
New
(
"Err
PermissionDeny"
)
ErrCollateralizeRecordNotEmpty
=
errors
.
New
(
"ErrCollateralizeRecordNotEmpty"
)
)
plugin/dapp/collateralize/types/tx.go
View file @
be7eb574
...
...
@@ -6,9 +6,6 @@ package types
// CollateralizeCreateTx for construction
type
CollateralizeCreateTx
struct
{
DebtCeiling
int64
`json:"debtCeiling"`
LiquidationRatio
float32
`json:"liquidationRatio"`
StabilityFee
int64
`json:"stabilityFee"`
TotalBalance
int64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
...
...
@@ -43,6 +40,16 @@ type CollateralizeFeedTx struct {
// CollateralizeCloseTx for construction
type
CollateralizeCloseTx
struct
{
CollateralizeID
string
`json:"
C
ollateralizeId"`
CollateralizeID
string
`json:"
c
ollateralizeId"`
Fee
int64
`json:"fee"`
}
// CollateralizeManageTx for construction
type
CollateralizeManageTx
struct
{
DebtCeiling
int64
`json:"debtCeiling"`
LiquidationRatio
float32
`json:"liquidationRatio"`
StabilityFeeRatio
float32
`json:"stabilityFeeRatio"`
Period
int64
`json:"period"`
Addr
[]
string
`json:"addr"`
Fee
int64
`json:"fee"`
}
plugin/dapp/collateralize/types/types.go
View file @
be7eb574
...
...
@@ -12,6 +12,7 @@ const (
CollateralizeActionAppend
CollateralizeActionFeed
CollateralizeActionClose
CollateralizeActionManage
//log for Collateralize
TyLogCollateralizeCreate
=
731
...
...
@@ -46,5 +47,6 @@ const (
CollateralizeUserStatusWarning
CollateralizeUserStatusSystemLiquidate
CollateralizeUserStatusExpire
CollateralizeUserStatusExpireLiquidate
CollateralizeUserStatusClose
)
\ No newline at end of file
plugin/dapp/init/init.go
View file @
be7eb574
package
init
import
(
_
"github.com/33cn/plugin/plugin/dapp/autonomy"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/blackwhite"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/cert"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/dposvote"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/echo"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/evm"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/game"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/guess"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/hashlock"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/js"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/lottery"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/multisig"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/norm"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/oracle"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/paracross"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/pokerbull"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/privacy"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/relay"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/retrieve"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/ticket"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/token"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/trade"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/unfreeze"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/valnode"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/autonomy"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/blackwhite"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/cert"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/collateralize"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/dposvote"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/echo"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/evm"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/game"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/guess"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/hashlock"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/js"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/lottery"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/multisig"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/norm"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/oracle"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/paracross"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/pokerbull"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/privacy"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/relay"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/retrieve"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/ticket"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/token"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/trade"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/unfreeze"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/valnode"
//auto gen
)
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