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
85aa1039
Commit
85aa1039
authored
Oct 21, 2019
by
pengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#627 add commands
parent
be7eb574
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
339 additions
and
10 deletions
+339
-10
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+338
-9
query.go
plugin/dapp/collateralize/executor/query.go
+1
-1
No files found.
plugin/dapp/collateralize/commands/cmd.go
View file @
85aa1039
...
...
@@ -7,6 +7,7 @@ import (
rpctypes
"github.com/33cn/chain33/rpc/types"
"github.com/33cn/chain33/types"
pkt
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
"strconv"
)
// CollateralizeCmd 斗牛游戏命令行
...
...
@@ -19,12 +20,13 @@ func CollateralizeCmd() *cobra.Command {
cmd
.
AddCommand
(
CollateralizeCreateRawTxCmd
(),
//CollateralizeBorrowRawTxCmd(),
//CollateralizeAppendRawTxCmd(),
//CollateralizeRepayRawTxCmd(),
//CollateralizePriceFeedRawTxCmd(),
//CollateralizeCloseRawTxCmd(),
//CollateralizeManageRawTxCmd(),
CollateralizeBorrowRawTxCmd
(),
CollateralizeAppendRawTxCmd
(),
CollateralizeRepayRawTxCmd
(),
CollateralizePriceFeedRawTxCmd
(),
CollateralizeCloseRawTxCmd
(),
CollateralizeManageRawTxCmd
(),
CollateralizeQueryCmd
(),
)
return
cmd
...
...
@@ -52,11 +54,339 @@ func CollateralizeCreate(cmd *cobra.Command, args []string) {
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"Create"
,
ActionName
:
"C
ollateralizeC
reate"
,
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
}
// CollateralizeBorrowRawTxCmd 生成开始交易命令行
func
CollateralizeBorrowRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"borrow"
,
Short
:
"Borrow a collateralize"
,
Run
:
CollateralizeBorrow
,
}
addCollateralizeBorrowFlags
(
cmd
)
return
cmd
}
func
addCollateralizeBorrowFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
CollateralizeBorrow
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeBorrow"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:%s,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeAppendRawTxCmd 生成开始交易命令行
func
CollateralizeAppendRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"append"
,
Short
:
"Append a collateralize"
,
Run
:
CollateralizeAppend
,
}
addCollateralizeAppendFlags
(
cmd
)
return
cmd
}
func
addCollateralizeAppendFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
CollateralizeAppend
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeAppend"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:%s,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeRepayRawTxCmd 生成开始交易命令行
func
CollateralizeRepayRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"repay"
,
Short
:
"Repay a collateralize"
,
Run
:
CollateralizeRepay
,
}
addCollateralizeRepayFlags
(
cmd
)
return
cmd
}
func
addCollateralizeRepayFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Uint64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
CollateralizeRepay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeRepay"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:%s,
\"
value
\"
:%d}"
,
collateralizeID
,
value
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizePriceFeedRawTxCmd 生成开始交易命令行
func
CollateralizePriceFeedRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"feed"
,
Short
:
"price feed"
,
Run
:
CollateralizePriceFeed
,
}
addCollateralizePriceFeedFlags
(
cmd
)
return
cmd
}
func
addCollateralizePriceFeedFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Float32P
(
"price"
,
"p"
,
0
,
"price"
)
cmd
.
MarkFlagRequired
(
"price"
)
cmd
.
Flags
()
.
Uint64P
(
"volume"
,
"v"
,
0
,
"volume"
)
cmd
.
MarkFlagRequired
(
"volume"
)
}
func
CollateralizePriceFeed
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
price
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"price"
)
volume
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"volume"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizePriceFeed"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{[
\"
price
\"
:%s],[
\"
volume
\"
:%d]}"
,
price
,
volume
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeCloseRawTxCmd 生成开始交易命令行
func
CollateralizeCloseRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"close"
,
Short
:
"close a collateralize"
,
Run
:
CollateralizeClose
,
}
addCollateralizeCloseFlags
(
cmd
)
return
cmd
}
func
addCollateralizeCloseFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
}
func
CollateralizeClose
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeClose"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:%s}"
,
collateralizeID
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeManageRawTxCmd 生成开始交易命令行
func
CollateralizeManageRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"manage"
,
Short
:
"manage a collateralize"
,
Run
:
CollateralizeManage
,
}
addCollateralizeCloseFlags
(
cmd
)
return
cmd
}
func
addCollateralizeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Uint64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float32P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Float32P
(
"stabilityFeeRatio"
,
"s"
,
0
,
"stabilityFeeRatio"
)
cmd
.
Flags
()
.
Uint64P
(
"period"
,
"p"
,
0
,
"period"
)
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"addr"
)
}
func
CollateralizeManage
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"debtCeiling"
)
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"liquidationRatio"
)
stabilityFeeRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat32
(
"stabilityFeeRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
var
params
*
rpctypes
.
CreateTxIn
if
addr
==
""
{
params
=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
debtCeiling
\"
:%d,
\"
liquidationRatio
\"
:%f,
\"
stabilityFeeRatio
\"
:%f,
\"
period
\"
:%s,}"
,
debtCeiling
,
liquidationRatio
,
stabilityFeeRatio
,
period
)),
}
}
else
{
params
=
&
rpctypes
.
CreateTxIn
{
Execer
:
types
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{[
\"
addr
\"
:%s]}"
,
addr
)),
}
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeQueryCmd 查询命令行
func
CollateralizeQueryCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"query"
,
Short
:
"Query result"
,
Run
:
CollateralizeQuery
,
}
addCollateralizeQueryFlags
(
cmd
)
return
cmd
}
func
addCollateralizeQueryFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
Flags
()
.
StringP
(
"address"
,
"a"
,
""
,
"address"
)
cmd
.
Flags
()
.
StringP
(
"index"
,
"i"
,
""
,
"index"
)
cmd
.
Flags
()
.
StringP
(
"status"
,
"s"
,
""
,
"status"
)
cmd
.
Flags
()
.
StringP
(
"collateralizeIDs"
,
"d"
,
""
,
"collateralize IDs"
)
}
func
CollateralizeQuery
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"address"
)
statusStr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"status"
)
// indexstr, _ := cmd.Flags().GetString("index")
collateralizeIDs
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeIDs"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
//if indexstr != "" {
// index, err := strconv.ParseInt(indexstr, 10, 64)
// if err != nil {
// fmt.Println(err)
// cmd.Help()
// return
// }
// req.Index = index
//}
status
,
err
:=
strconv
.
ParseInt
(
statusStr
,
10
,
32
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
cmd
.
Help
()
return
}
if
collateralizeID
!=
""
{
if
statusStr
!=
""
{
params
.
FuncName
=
"CollateralizeBorrowInfoByStatus"
req
:=
&
pkt
.
ReqCollateralizeBorrowInfoByStatus
{
CollateralizeId
:
collateralizeID
,
Status
:
int32
(
status
),
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeBorrowInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
address
!=
""
{
params
.
FuncName
=
"CollateralizeBorrowInfoByAddr"
req
:=
&
pkt
.
ReqCollateralizeBorrowInfoByAddr
{
CollateralizeId
:
collateralizeID
,
Addr
:
address
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeBorrowInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
params
.
FuncName
=
"CollateralizeInfoByID"
req
:=
&
pkt
.
ReqCollateralizeInfo
{
CollateralizeId
:
collateralizeID
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeCurrentInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
}
else
if
address
!=
""
{
params
.
FuncName
=
"CollateralizeByAddr"
req
:=
&
pkt
.
ReqCollateralizeByAddr
{
Addr
:
address
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeIDs
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
statusStr
!=
""
{
params
.
FuncName
=
"CollateralizeByStatus"
req
:=
&
pkt
.
ReqCollateralizeByStatus
{
Status
:
int32
(
status
)}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeIDs
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
collateralizeIDs
!=
""
{
params
.
FuncName
=
"CollateralizeInfoByIDs"
var
collateralizeIDsS
[]
string
collateralizeIDsS
=
append
(
collateralizeIDsS
,
collateralizeIDs
)
collateralizeIDsS
=
append
(
collateralizeIDsS
,
collateralizeIDs
)
req
:=
&
pkt
.
ReqCollateralizeInfos
{
CollateralizeIds
:
collateralizeIDsS
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeCurrentInfos
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/collateralize/executor/query.go
View file @
85aa1039
...
...
@@ -52,7 +52,7 @@ func (c *Collateralize) Query_CollateralizeInfoByIDs(req *pty.ReqCollateralizeIn
func
(
c
*
Collateralize
)
Query_CollateralizeByStatus
(
req
*
pty
.
ReqCollateralizeByStatus
)
(
types
.
Message
,
error
)
{
ids
:=
&
pty
.
RepCollateralizeIDs
{}
collIDRecords
,
err
:=
queryCollateralizeByStatus
(
c
.
GetLocalDB
(),
pty
.
CollateralizeStatusCreated
)
collIDRecords
,
err
:=
queryCollateralizeByStatus
(
c
.
GetLocalDB
(),
req
.
Status
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeByStatus"
,
"get collateralize record error"
,
err
)
return
nil
,
err
...
...
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