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
a717a020
Unverified
Commit
a717a020
authored
Jan 10, 2020
by
vipwzw
Committed by
GitHub
Jan 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #736 from jpeng-go/master
#627 去中心化发行借贷合约
parents
1a47e08d
d4c38318
Show whitespace changes
Inline
Side-by-side
Showing
48 changed files
with
11577 additions
and
0 deletions
+11577
-0
chain33.para.toml
chain33.para.toml
+6
-0
Makefile
plugin/dapp/collateralize/cmd/Makefile
+4
-0
build.sh
plugin/dapp/collateralize/cmd/build.sh
+9
-0
test-rpc.sh
plugin/dapp/collateralize/cmd/test/test-rpc.sh
+13
-0
cmd.go
plugin/dapp/collateralize/commands/cmd.go
+519
-0
collateralize.go
plugin/dapp/collateralize/executor/collateralize.go
+69
-0
collateralize_test.go
plugin/dapp/collateralize/executor/collateralize_test.go
+605
-0
collateralizedb.go
plugin/dapp/collateralize/executor/collateralizedb.go
+1398
-0
doc.go
plugin/dapp/collateralize/executor/doc.go
+9
-0
exec.go
plugin/dapp/collateralize/executor/exec.go
+52
-0
exec_del_local.go
plugin/dapp/collateralize/executor/exec_del_local.go
+55
-0
exec_local.go
plugin/dapp/collateralize/executor/exec_local.go
+88
-0
query.go
plugin/dapp/collateralize/executor/query.go
+179
-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
+223
-0
create_protobuf.sh
plugin/dapp/collateralize/proto/create_protobuf.sh
+4
-0
readme.md
plugin/dapp/collateralize/readme.md
+34
-0
collateralize.go
plugin/dapp/collateralize/types/collateralize.go
+360
-0
collateralize.pb.go
plugin/dapp/collateralize/types/collateralize.pb.go
+2090
-0
errors.go
plugin/dapp/collateralize/types/errors.go
+24
-0
table.go
plugin/dapp/collateralize/types/table.go
+124
-0
tx.go
plugin/dapp/collateralize/types/tx.go
+57
-0
types.go
plugin/dapp/collateralize/types/types.go
+53
-0
init.go
plugin/dapp/init/init.go
+2
-0
Makefile
plugin/dapp/issuance/cmd/Makefile
+4
-0
build.sh
plugin/dapp/issuance/cmd/build.sh
+9
-0
test-rpc.sh
plugin/dapp/issuance/cmd/test/test-rpc.sh
+560
-0
cmd.go
plugin/dapp/issuance/commands/cmd.go
+441
-0
doc.go
plugin/dapp/issuance/executor/doc.go
+9
-0
exec.go
plugin/dapp/issuance/executor/exec.go
+46
-0
exec_del_local.go
plugin/dapp/issuance/executor/exec_del_local.go
+50
-0
exec_local.go
plugin/dapp/issuance/executor/exec_local.go
+82
-0
issuance.go
plugin/dapp/issuance/executor/issuance.go
+69
-0
issuance_test.go
plugin/dapp/issuance/executor/issuance_test.go
+534
-0
issuancedb.go
plugin/dapp/issuance/executor/issuancedb.go
+1147
-0
query.go
plugin/dapp/issuance/executor/query.go
+134
-0
plugin.go
plugin/dapp/issuance/plugin.go
+21
-0
Makefile
plugin/dapp/issuance/proto/Makefile
+2
-0
create_protobuf.sh
plugin/dapp/issuance/proto/create_protobuf.sh
+4
-0
issuance.proto
plugin/dapp/issuance/proto/issuance.proto
+181
-0
readme.md
plugin/dapp/issuance/readme.md
+27
-0
errors.go
plugin/dapp/issuance/types/errors.go
+25
-0
issuance.go
plugin/dapp/issuance/types/issuance.go
+315
-0
issuance.pb.go
plugin/dapp/issuance/types/issuance.pb.go
+1704
-0
table.go
plugin/dapp/issuance/types/table.go
+116
-0
tx.go
plugin/dapp/issuance/types/tx.go
+47
-0
types.go
plugin/dapp/issuance/types/types.go
+50
-0
No files found.
chain33.para.toml
View file @
a717a020
...
@@ -312,6 +312,12 @@ Enable=0
...
@@ -312,6 +312,12 @@ Enable=0
[fork.sub.jsvm]
[fork.sub.jsvm]
Enable
=
0
Enable
=
0
[fork.sub.issuance]
Enable
=
0
[fork.sub.collateralize]
Enable
=
0
#对已有的平行链如果不是从0开始同步数据,需要设置这个kvmvccmavl的对应平行链高度的fork,如果从0开始同步,statehash会跟以前mavl的不同
#对已有的平行链如果不是从0开始同步数据,需要设置这个kvmvccmavl的对应平行链高度的fork,如果从0开始同步,statehash会跟以前mavl的不同
[fork.sub.store-kvmvccmavl]
[fork.sub.store-kvmvccmavl]
ForkKvmvccmavl
=
0
ForkKvmvccmavl
=
0
...
...
plugin/dapp/collateralize/cmd/Makefile
0 → 100644
View file @
a717a020
all
:
chmod
+x ./build.sh
./build.sh
$(OUT)
$(FLAG)
\ No newline at end of file
plugin/dapp/collateralize/cmd/build.sh
0 → 100755
View file @
a717a020
#!/usr/bin/env bash
strpwd
=
$(
pwd
)
strcmd
=
${
strpwd
##*dapp/
}
strapp
=
${
strcmd
%/cmd*
}
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
cp
./test/test-rpc.sh
"
${
OUT_TESTDIR
}
"
plugin/dapp/collateralize/cmd/test/test-rpc.sh
0 → 100755
View file @
a717a020
#!/usr/bin/env bash
# shellcheck disable=SC2128
set
-e
set
-o
pipefail
# shellcheck source=/dev/null
source
../dapp-test-common.sh
function
main
()
{
echo
"Collateralize cases has integrated in Issuance test"
}
chain33_debug_function main
"
$1
"
plugin/dapp/collateralize/commands/cmd.go
0 → 100644
View file @
a717a020
package
commands
import
(
"fmt"
"strconv"
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"
"github.com/spf13/cobra"
)
// CollateralizeCmd 斗牛游戏命令行
func
CollateralizeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"collateralize"
,
Short
:
"Collateralize command"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
CollateralizeCreateRawTxCmd
(),
CollateralizeBorrowRawTxCmd
(),
CollateralizeAppendRawTxCmd
(),
CollateralizeRepayRawTxCmd
(),
CollateralizePriceFeedRawTxCmd
(),
CollateralizeRetrieveRawTxCmd
(),
CollateralizeManageRawTxCmd
(),
CollateralizeQueryCmd
(),
)
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
()
.
Float64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
}
func
CollateralizeCreate
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
balance
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"balance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeCreate"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%f}"
,
balance
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// 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
()
.
Float64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
CollateralizeBorrow
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeBorrow"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
value
\"
:%f}"
,
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
()
.
StringP
(
"recordID"
,
"r"
,
""
,
"recordID"
)
cmd
.
MarkFlagRequired
(
"recordID"
)
cmd
.
Flags
()
.
Float64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
CollateralizeAppend
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
recordID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"recordID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeAppend"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
,
\"
value
\"
:%f}"
,
collateralizeID
,
recordID
,
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
()
.
StringP
(
"recordID"
,
"r"
,
""
,
"recordID"
)
cmd
.
MarkFlagRequired
(
"recordID"
)
}
func
CollateralizeRepay
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
recordID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"recordID"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeRepay"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
recordID
\"
:
\"
%s
\"
}"
,
collateralizeID
,
recordID
)),
}
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
()
.
Float64P
(
"price"
,
"p"
,
0
,
"price"
)
cmd
.
MarkFlagRequired
(
"price"
)
cmd
.
Flags
()
.
Uint64P
(
"volume"
,
"v"
,
0
,
"volume"
)
cmd
.
MarkFlagRequired
(
"volume"
)
}
func
CollateralizePriceFeed
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
price
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"price"
)
volume
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"volume"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizePriceFeed"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
price
\"
:[ %f ],
\"
volume
\"
:[ %d ]}"
,
price
,
volume
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// CollateralizeCloseRawTxCmd 生成开始交易命令行
func
CollateralizeRetrieveRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"retrieve"
,
Short
:
"retrieve balance"
,
Run
:
CollateralizeRetrieve
,
}
addCollateralizeRetrieveFlags
(
cmd
)
return
cmd
}
func
addCollateralizeRetrieveFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"collateralizeID"
,
"g"
,
""
,
"collateralize ID"
)
cmd
.
MarkFlagRequired
(
"collateralizeID"
)
cmd
.
Flags
()
.
Float64P
(
"balance"
,
"b"
,
0
,
"retrieve balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
}
func
CollateralizeRetrieve
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
collateralizeID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeID"
)
balance
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"balance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeRetrieve"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
collateralizeID
\"
:
\"
%s
\"
,
\"
balance
\"
: %f}"
,
collateralizeID
,
balance
)),
}
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
,
}
addCollateralizeManageFlags
(
cmd
)
return
cmd
}
func
addCollateralizeManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Float64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float64P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Float64P
(
"stabilityFeeRatio"
,
"s"
,
0
,
"stabilityFeeRatio"
)
cmd
.
Flags
()
.
Uint64P
(
"period"
,
"p"
,
0
,
"period"
)
cmd
.
Flags
()
.
Float64P
(
"totalBalance"
,
"t"
,
0
,
"totalBalance"
)
}
func
CollateralizeManage
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"debtCeiling"
)
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"liquidationRatio"
)
stabilityFeeRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"stabilityFeeRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
totalBalance
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"totalBalance"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
CollateralizeX
),
ActionName
:
"CollateralizeManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
debtCeiling
\"
:%f,
\"
liquidationRatio
\"
:%f,
\"
stabilityFeeRatio
\"
:%f,
\"
period
\"
:%d,
\"
totalBalance
\"
:%f}"
,
debtCeiling
,
liquidationRatio
,
stabilityFeeRatio
,
period
,
totalBalance
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
func
CollateralizeQueryCfgCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"config"
,
Short
:
"Query config result"
,
Run
:
CollateralizeQueryConfig
,
}
return
cmd
}
func
CollateralizeQueryConfig
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
params
.
FuncName
=
"CollateralizeConfig"
var
res
pkt
.
RepCollateralizeConfig
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
func
CollateralizeQueryPriceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"price"
,
Short
:
"Query latest price"
,
Run
:
CollateralizeQueryPrice
,
}
return
cmd
}
func
CollateralizeQueryPrice
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
params
.
FuncName
=
"CollateralizePrice"
var
res
pkt
.
RepCollateralizePrice
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
func
CollateralizeQueryUserBalanceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"balance"
,
Short
:
"Query user balance"
,
Run
:
CollateralizeQueryUserBalance
,
}
addCollateralizeQueryBalanceFlags
(
cmd
)
return
cmd
}
func
addCollateralizeQueryBalanceFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"address"
,
"a"
,
""
,
"address"
)
cmd
.
MarkFlagRequired
(
"address"
)
}
func
CollateralizeQueryUserBalance
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"address"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
params
.
FuncName
=
"CollateralizeUserBalance"
req
:=
&
pkt
.
ReqCollateralizeRecordByAddr
{
Addr
:
addr
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeUserBalance
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
// CollateralizeQueryCmd 查询命令行
func
CollateralizeQueryCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"query"
,
Short
:
"Query result"
,
Run
:
CollateralizeQuery
,
}
addCollateralizeQueryFlags
(
cmd
)
cmd
.
AddCommand
(
CollateralizeQueryCfgCmd
(),
CollateralizeQueryPriceCmd
(),
CollateralizeQueryUserBalanceCmd
(),
)
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"
)
cmd
.
Flags
()
.
StringP
(
"borrowID"
,
"b"
,
""
,
"borrow ID"
)
}
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"
)
collateralizeIDs
,
_
:=
cmd
.
Flags
()
.
GetString
(
"collateralizeIDs"
)
borrowID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"borrowID"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
CollateralizeX
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
collateralizeID
!=
""
{
if
address
!=
""
{
params
.
FuncName
=
"CollateralizeRecordByAddr"
req
:=
&
pkt
.
ReqCollateralizeRecordByAddr
{
CollateralizeId
:
collateralizeID
,
Status
:
int32
(
status
),
Addr
:
address
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
statusStr
!=
""
{
params
.
FuncName
=
"CollateralizeRecordByStatus"
req
:=
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
collateralizeID
,
Status
:
int32
(
status
),
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
borrowID
!=
""
{
params
.
FuncName
=
"CollateralizeRecordByID"
req
:=
&
pkt
.
ReqCollateralizeRecord
{
CollateralizeId
:
collateralizeID
,
RecordId
:
borrowID
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepCollateralizeRecord
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 collId, address or status"
)
cmd
.
Help
()
}
}
plugin/dapp/collateralize/executor/collateralize.go
0 → 100644
View file @
a717a020
// 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
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Collateralize
{}))
}
// Init collateralize
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
cfg
,
driverName
,
newCollateralize
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// 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
(
c
*
Collateralize
)
GetDriverName
()
string
{
return
pty
.
CollateralizeX
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func
(
c
*
Collateralize
)
CheckReceiptExecOk
()
bool
{
return
true
}
// ExecutorOrder 设置localdb的EnableRead
func
(
c
*
Collateralize
)
ExecutorOrder
()
int64
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
c
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
return
drivers
.
ExecLocalSameTime
}
return
c
.
DriverBase
.
ExecutorOrder
()
}
plugin/dapp/collateralize/executor/collateralize_test.go
0 → 100644
View file @
a717a020
package
executor
import
(
"testing"
"time"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/account"
apimock
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
pty
"github.com/33cn/chain33/system/dapp/manage/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pkt
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
tokenE
"github.com/33cn/plugin/plugin/dapp/token/executor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type
execEnv
struct
{
blockTime
int64
blockHeight
int64
difficulty
uint64
kvdb
dbm
.
KVDB
api
client
.
QueueProtocolAPI
db
dbm
.
KV
execAddr
string
cfg
*
types
.
Chain33Config
}
var
(
PrivKeyA
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
// 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
PrivKeyB
=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
// 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
PrivKeyC
=
"0xc2b31057b8692a56c7dd18199df71c1d21b781c0b6858c52997c9dbf778e8550"
// 12evczYyX9ZKPYvwSEvRkRyTjpSrJuLudg
Nodes
=
[][]
byte
{
[]
byte
(
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
),
[]
byte
(
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
),
[]
byte
(
"12evczYyX9ZKPYvwSEvRkRyTjpSrJuLudg"
),
}
total
=
10000
*
types
.
Coin
totalToken
=
100000
*
types
.
Coin
)
func
manageKeySet
(
key
string
,
value
string
,
db
dbm
.
KV
)
{
var
item
types
.
ConfigItem
item
.
Key
=
key
item
.
Addr
=
value
item
.
Ty
=
pty
.
ConfigItemArrayConfig
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
item
.
GetArr
()
.
Value
=
append
(
item
.
GetArr
()
.
Value
,
value
)
manageKey
:=
types
.
ManageKey
(
key
)
valueSave
:=
types
.
Encode
(
&
item
)
db
.
Set
([]
byte
(
manageKey
),
valueSave
)
}
func
addrKeySet
(
value
string
,
db
dbm
.
KV
)
{
var
item
types
.
ConfigItem
item
.
Addr
=
value
item
.
Ty
=
pty
.
ConfigItemArrayConfig
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
item
.
GetArr
()
.
Value
=
append
(
item
.
GetArr
()
.
Value
,
value
)
valueSave
:=
types
.
Encode
(
&
item
)
db
.
Set
(
AddrKey
(),
valueSave
)
}
func
initEnv
()
*
execEnv
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
SetTitleOnlyForTest
(
"chain33"
)
Init
(
pkt
.
CollateralizeX
,
cfg
,
nil
)
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
accountA
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountAToken
:=
types
.
Account
{
Balance
:
totalToken
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountB
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
accountBToken
:=
types
.
Account
{
Balance
:
types
.
Coin
/
10
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
accountC
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
2
]),
}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
execAddr
:=
dapp
.
ExecAddress
(
pkt
.
CollateralizeX
)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"1"
,
"2"
,
100
)
accA
:=
account
.
NewCoinsAccount
(
cfg
)
accA
.
SetDB
(
stateDB
)
accA
.
SaveExecAccount
(
execAddr
,
&
accountA
)
manageKeySet
(
"issuance-manage"
,
accountA
.
Addr
,
stateDB
)
addrKeySet
(
accountA
.
Addr
,
stateDB
)
tokenAccA
,
_
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pkt
.
CCNYTokenName
,
stateDB
)
tokenAccA
.
SaveExecAccount
(
execAddr
,
&
accountAToken
)
accB
:=
account
.
NewCoinsAccount
(
cfg
)
accB
.
SetDB
(
stateDB
)
accB
.
SaveExecAccount
(
execAddr
,
&
accountB
)
manageKeySet
(
"issuance-price-feed"
,
accountB
.
Addr
,
stateDB
)
tokenAccB
,
_
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pkt
.
CCNYTokenName
,
stateDB
)
tokenAccB
.
SaveExecAccount
(
execAddr
,
&
accountBToken
)
accC
:=
account
.
NewCoinsAccount
(
cfg
)
accC
.
SetDB
(
stateDB
)
accC
.
SaveExecAccount
(
execAddr
,
&
accountC
)
manageKeySet
(
"issuance-guarantor"
,
accountC
.
Addr
,
stateDB
)
return
&
execEnv
{
blockTime
:
time
.
Now
()
.
Unix
(),
blockHeight
:
cfg
.
GetDappFork
(
pkt
.
CollateralizeX
,
"Enable"
),
difficulty
:
1539918074
,
kvdb
:
kvdb
,
api
:
api
,
db
:
stateDB
,
execAddr
:
execAddr
,
cfg
:
cfg
,
}
}
func
TestCollateralize
(
t
*
testing
.
T
)
{
env
:=
initEnv
()
// collateralize manage
p3
:=
&
pkt
.
CollateralizeManageTx
{}
p3
.
Period
=
5
p3
.
LiquidationRatio
=
0.25
p3
.
DebtCeiling
=
100
p3
.
StabilityFeeRatio
=
0.0001
p3
.
TotalBalance
=
10000
createTx
,
err
:=
pkt
.
CreateRawCollateralizeManageTx
(
env
.
cfg
,
p3
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
:=
newCollateralize
()
exec
.
SetAPI
(
env
.
api
)
exec
.
SetStateDB
(
env
.
db
)
assert
.
Equal
(
t
,
exec
.
GetCoinsAccount
()
.
LoadExecAccount
(
string
(
Nodes
[
0
]),
env
.
execAddr
)
.
GetBalance
(),
total
)
exec
.
SetLocalDB
(
env
.
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// collateralize create
p1
:=
&
pkt
.
CollateralizeCreateTx
{
TotalBalance
:
1000
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeCreateTx
(
env
.
cfg
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
collateralizeID
:=
createTx
.
Hash
()
// query collateralize by id
res
,
err
:=
exec
.
Query
(
"CollateralizeInfoByID"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeInfo
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeByStatus
{
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralizes by ids
var
collateralizeIDsS
[]
string
collateralizeIDsS
=
append
(
collateralizeIDsS
,
common
.
ToHex
(
collateralizeID
))
res
,
err
=
exec
.
Query
(
"CollateralizeInfoByIDs"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeInfos
{
CollateralizeIds
:
collateralizeIDsS
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// collateralize price
p2
:=
&
pkt
.
CollateralizeFeedTx
{}
p2
.
Price
=
append
(
p2
.
Price
,
1
)
p2
.
Volume
=
append
(
p2
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawCollateralizeFeedTx
(
env
.
cfg
,
p2
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by id
res
,
err
=
exec
.
Query
(
"CollateralizePrice"
,
nil
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// collateralize borrow
p4
:=
&
pkt
.
CollateralizeBorrowTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeBorrowTx
(
env
.
cfg
,
p4
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
borrowID
:=
createTx
.
Hash
()
// query collateralize by id
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByID"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecord
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
RecordId
:
common
.
ToHex
(
borrowID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by addr
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByAddr"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByAddr"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize user balance
res
,
err
=
exec
.
Query
(
"CollateralizeUserBalance"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
100
)
*
types
.
Coin
,
res
.
(
*
pkt
.
RepCollateralizeUserBalance
)
.
Balance
)
// collateralize append
p5
:=
&
pkt
.
CollateralizeAppendTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
RecordID
:
common
.
ToHex
(
borrowID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeAppendTx
(
env
.
cfg
,
p5
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by id
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByID"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecord
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
RecordId
:
common
.
ToHex
(
borrowID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by addr
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByAddr"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// collateralize repay
p6
:=
&
pkt
.
CollateralizeRepayTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
RecordID
:
common
.
ToHex
(
borrowID
),
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeRepayTx
(
env
.
cfg
,
p6
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Status
:
6
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize by addr
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByAddr"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Addr
:
string
(
Nodes
[
1
]),
Status
:
6
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByAddr"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
6
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query collateralize user balance
res
,
err
=
exec
.
Query
(
"CollateralizeUserBalance"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByAddr
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
0
),
res
.
(
*
pkt
.
RepCollateralizeUserBalance
)
.
Balance
)
// collateralize liquidate
p7
:=
&
pkt
.
CollateralizeBorrowTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeBorrowTx
(
env
.
cfg
,
p7
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
p8
:=
&
pkt
.
CollateralizeFeedTx
{}
p8
.
Price
=
append
(
p8
.
Price
,
0.25
)
p8
.
Volume
=
append
(
p8
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawCollateralizeFeedTx
(
env
.
cfg
,
p8
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Status
:
3
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// expire liquidate
p9
:=
&
pkt
.
CollateralizeBorrowTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeBorrowTx
(
env
.
cfg
,
p9
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
p10
:=
&
pkt
.
CollateralizeFeedTx
{}
p10
.
Price
=
append
(
p10
.
Price
,
1
)
p10
.
Volume
=
append
(
p10
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawCollateralizeFeedTx
(
env
.
cfg
,
p10
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
6
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeRecordByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeRecordByStatus
{
CollateralizeId
:
common
.
ToHex
(
collateralizeID
),
Status
:
5
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// collateralize retrieve
p11
:=
&
pkt
.
CollateralizeRetrieveTx
{
CollateralizeID
:
common
.
ToHex
(
collateralizeID
),
Balance
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawCollateralizeRetrieveTx
(
env
.
cfg
,
p11
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
CollateralizeX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
2
,
env
.
blockTime
+
2
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query collateralize by status
res
,
err
=
exec
.
Query
(
"CollateralizeByStatus"
,
types
.
Encode
(
&
pkt
.
ReqCollateralizeByStatus
{
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
pkt
.
CollateralizeX
,
signType
))
if
err
!=
nil
{
return
tx
,
err
}
bytes
,
err
:=
common
.
FromHex
(
hexPrivKey
[
:
])
if
err
!=
nil
{
return
tx
,
err
}
privKey
,
err
:=
c
.
PrivKeyFromBytes
(
bytes
)
if
err
!=
nil
{
return
tx
,
err
}
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
plugin/dapp/collateralize/executor/collateralizedb.go
0 → 100644
View file @
a717a020
// 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/db/table"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/collateralize/types"
issuanceE
"github.com/33cn/plugin/plugin/dapp/issuance/types"
tokenE
"github.com/33cn/plugin/plugin/dapp/token/executor"
)
// List control
const
(
ListDESC
=
int32
(
0
)
// list降序
ListASC
=
int32
(
1
)
// list升序
DefaultCount
=
int32
(
20
)
// 默认一次取多少条记录
MaxCount
=
int32
(
100
)
// 最多取100条
)
const
(
Coin
=
types
.
Coin
// 1e8
DefaultDebtCeiling
=
10000
*
Coin
// 默认借贷限额
DefaultLiquidationRatio
=
0.4
*
1e4
// 默认质押比
DefaultStabilityFeeRation
=
0.08
*
1e4
// 默认稳定费
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
DefaultTotalBalance
=
0
// 默认放贷总额
PriceWarningRate
=
1.3
*
1e4
// 价格提前预警率
ExpireWarningTime
=
3600
*
24
*
10
// 提前10天超时预警
)
// CollateralizeDB def
type
CollateralizeDB
struct
{
pty
.
Collateralize
}
// GetKVSet for CollateralizeDB
func
(
coll
*
CollateralizeDB
)
GetKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
coll
.
Collateralize
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
Key
(
coll
.
CollateralizeId
),
Value
:
value
})
return
kvset
}
// Save for CollateralizeDB
func
(
coll
*
CollateralizeDB
)
Save
(
db
dbm
.
KV
)
{
set
:=
coll
.
GetKVSet
()
for
i
:=
0
;
i
<
len
(
set
);
i
++
{
db
.
Set
(
set
[
i
]
.
GetKey
(),
set
[
i
]
.
Value
)
}
}
// Key for Collateralize
func
Key
(
id
string
)
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
CollateralizeX
+
"-"
)
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
return
key
}
// Key for CollateralizeConfig
func
ConfigKey
()
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
CollateralizeX
+
"-config"
)
...
)
return
key
}
// Key for CollateralizeAddrConfig
func
AddrKey
()
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
issuanceE
.
IssuanceX
+
"-addr"
)
...
)
return
key
}
// Key for IssuancePriceFeed
func
PriceKey
()
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
CollateralizeX
+
"-price"
)
...
)
return
key
}
// Action struct
type
Action
struct
{
coinsAccount
*
account
.
DB
// bty账户
tokenAccount
*
account
.
DB
// ccny账户
db
dbm
.
KV
localDB
dbm
.
KVDB
txhash
[]
byte
fromaddr
string
blocktime
int64
height
int64
execaddr
string
difficulty
uint64
index
int
Collateralize
*
Collateralize
}
// NewCollateralizeAction generate New Action
func
NewCollateralizeAction
(
c
*
Collateralize
,
tx
*
types
.
Transaction
,
index
int
)
*
Action
{
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
tokenDb
,
err
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pty
.
CCNYTokenName
,
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"NewCollateralizeAction"
,
"Get Account DB error"
,
"error"
,
err
)
return
nil
}
return
&
Action
{
coinsAccount
:
c
.
GetCoinsAccount
(),
tokenAccount
:
tokenDb
,
db
:
c
.
GetStateDB
(),
localDB
:
c
.
GetLocalDB
(),
txhash
:
hash
,
fromaddr
:
fromaddr
,
blocktime
:
c
.
GetBlockTime
(),
height
:
c
.
GetHeight
(),
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
difficulty
:
c
.
GetDifficulty
(),
index
:
index
,
Collateralize
:
c
}
}
// GetCreateReceiptLog generate logs for Collateralize create action
func
(
action
*
Action
)
GetCreateReceiptLog
(
collateralize
*
pty
.
Collateralize
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeCreate
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
Status
=
collateralize
.
Status
c
.
AccountAddr
=
action
.
fromaddr
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetBorrowReceiptLog generate logs for Collateralize borrow action
func
(
action
*
Action
)
GetBorrowReceiptLog
(
collateralize
*
pty
.
Collateralize
,
record
*
pty
.
BorrowRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeBorrow
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
AccountAddr
=
action
.
fromaddr
c
.
RecordId
=
record
.
RecordId
c
.
Status
=
record
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetRepayReceiptLog generate logs for Collateralize Repay action
func
(
action
*
Action
)
GetRepayReceiptLog
(
collateralize
*
pty
.
Collateralize
,
record
*
pty
.
BorrowRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeRepay
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
AccountAddr
=
action
.
fromaddr
c
.
RecordId
=
record
.
RecordId
c
.
Status
=
record
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetAppendReceiptLog generate logs for Collateralize append action
func
(
action
*
Action
)
GetAppendReceiptLog
(
collateralize
*
pty
.
Collateralize
,
record
*
pty
.
BorrowRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeAppend
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
AccountAddr
=
action
.
fromaddr
c
.
RecordId
=
record
.
RecordId
c
.
Status
=
record
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetFeedReceiptLog generate logs for Collateralize price feed action
func
(
action
*
Action
)
GetFeedReceiptLog
(
collateralize
*
pty
.
Collateralize
,
record
*
pty
.
BorrowRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeFeed
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
AccountAddr
=
record
.
AccountAddr
c
.
RecordId
=
record
.
RecordId
c
.
Status
=
record
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetCloseReceiptLog generate logs for Collateralize close action
func
(
action
*
Action
)
GetRetrieveReceiptLog
(
collateralize
*
pty
.
Collateralize
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogCollateralizeRetrieve
c
:=
&
pty
.
ReceiptCollateralize
{}
c
.
CollateralizeId
=
collateralize
.
CollateralizeId
c
.
Status
=
collateralize
.
Status
c
.
AccountAddr
=
action
.
fromaddr
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetIndex returns index in block
func
(
action
*
Action
)
GetIndex
()
int64
{
return
action
.
height
*
types
.
MaxTxsPerBlock
+
int64
(
action
.
index
)
}
func
getLatestLiquidationPrice
(
coll
*
pty
.
Collateralize
)
int64
{
var
latest
int64
for
_
,
collRecord
:=
range
coll
.
BorrowRecords
{
if
collRecord
.
LiquidationPrice
>
latest
{
latest
=
collRecord
.
LiquidationPrice
}
}
return
latest
}
func
getLatestExpireTime
(
coll
*
pty
.
Collateralize
)
int64
{
var
latest
int64
=
0x7fffffffffffffff
for
_
,
collRecord
:=
range
coll
.
BorrowRecords
{
if
collRecord
.
ExpireTime
<
latest
{
latest
=
collRecord
.
ExpireTime
}
}
return
latest
}
// CollateralizeConfig 设置全局借贷参数(管理员权限)
func
(
action
*
Action
)
CollateralizeManage
(
manage
*
pty
.
CollateralizeManage
)
(
*
types
.
Receipt
,
error
)
{
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
// 是否配置管理用户
if
!
isRightAddr
(
issuanceE
.
ManageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"CollateralizeManage"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to config"
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 配置借贷参数
if
manage
.
DebtCeiling
<
0
||
manage
.
LiquidationRatio
<
0
||
manage
.
LiquidationRatio
>=
10000
||
manage
.
StabilityFeeRatio
<
0
||
manage
.
StabilityFeeRatio
>=
10000
{
return
nil
,
pty
.
ErrRiskParam
}
manConfig
,
_
:=
getCollateralizeConfig
(
action
.
db
)
if
manConfig
==
nil
{
manConfig
=
&
pty
.
CollateralizeManage
{
DebtCeiling
:
DefaultDebtCeiling
,
LiquidationRatio
:
DefaultLiquidationRatio
,
StabilityFeeRatio
:
DefaultStabilityFeeRation
,
Period
:
DefaultPeriod
,
TotalBalance
:
DefaultTotalBalance
,
}
}
collConfig
:=
&
pty
.
CollateralizeManage
{}
if
manage
.
StabilityFeeRatio
!=
0
{
collConfig
.
StabilityFeeRatio
=
manage
.
StabilityFeeRatio
}
else
{
collConfig
.
StabilityFeeRatio
=
manConfig
.
StabilityFeeRatio
}
if
manage
.
Period
!=
0
{
collConfig
.
Period
=
manage
.
Period
}
else
{
collConfig
.
Period
=
manConfig
.
Period
}
if
manage
.
LiquidationRatio
!=
0
{
collConfig
.
LiquidationRatio
=
manage
.
LiquidationRatio
}
else
{
collConfig
.
LiquidationRatio
=
manConfig
.
LiquidationRatio
}
if
manage
.
DebtCeiling
!=
0
{
collConfig
.
DebtCeiling
=
manage
.
DebtCeiling
}
else
{
collConfig
.
DebtCeiling
=
manConfig
.
DebtCeiling
}
if
manage
.
TotalBalance
!=
0
{
collConfig
.
TotalBalance
=
manage
.
TotalBalance
}
else
{
collConfig
.
TotalBalance
=
manConfig
.
TotalBalance
}
collConfig
.
CurrentTime
=
action
.
blocktime
value
:=
types
.
Encode
(
collConfig
)
action
.
db
.
Set
(
ConfigKey
(),
value
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
ConfigKey
(),
Value
:
value
})
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
nil
}
return
receipt
,
nil
}
func
getCollateralizeConfig
(
db
dbm
.
KV
)
(
*
pty
.
CollateralizeManage
,
error
)
{
data
,
err
:=
db
.
Get
(
ConfigKey
())
if
err
!=
nil
{
clog
.
Debug
(
"getCollateralizeConfig"
,
"error"
,
err
)
return
nil
,
err
}
var
collCfg
pty
.
CollateralizeManage
err
=
types
.
Decode
(
data
,
&
collCfg
)
if
err
!=
nil
{
clog
.
Debug
(
"getCollateralizeConfig"
,
"decode"
,
err
)
return
nil
,
err
}
return
&
collCfg
,
nil
}
func
isSuperAddr
(
addr
string
,
db
dbm
.
KV
)
bool
{
data
,
err
:=
db
.
Get
(
AddrKey
())
if
err
!=
nil
{
clog
.
Error
(
"getSuperAddr"
,
"error"
,
err
)
return
false
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
data
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"isSuperAddr"
,
"Decode"
,
data
)
return
false
}
for
_
,
op
:=
range
item
.
GetArr
()
.
Value
{
if
op
==
addr
{
return
true
}
}
return
false
}
// 获取可放贷金额
func
getCollBalance
(
totalBalance
int64
,
localdb
dbm
.
KVDB
,
db
dbm
.
KV
)
(
int64
,
error
)
{
collIDRecords
,
err
:=
queryCollateralizeByStatus
(
localdb
,
pty
.
CollateralizeStatusCreated
,
""
)
if
err
!=
nil
{
clog
.
Debug
(
"Query_CollateralizeByStatus"
,
"get collateralize record error"
,
err
)
}
balance
:=
totalBalance
for
_
,
id
:=
range
collIDRecords
{
coll
,
err
:=
queryCollateralizeByID
(
db
,
id
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeInfoByID"
,
"id"
,
id
,
"error"
,
err
)
return
0
,
err
}
balance
-=
coll
.
TotalBalance
}
return
balance
,
nil
}
// CollateralizeCreate 创建借贷,持有一定数量ccny的用户可创建借贷,提供给其他用户借贷
func
(
action
*
Action
)
CollateralizeCreate
(
create
*
pty
.
CollateralizeCreate
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
if
!
isSuperAddr
(
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"CollateralizeCreate"
,
"error"
,
"CollateralizeCreate need super address"
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 参数检查
if
create
.
GetTotalBalance
()
<=
0
{
clog
.
Error
(
"CollateralizeCreate"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"total balance"
,
create
.
GetTotalBalance
(),
"error"
,
types
.
ErrAmount
)
return
nil
,
types
.
ErrAmount
}
// 获取借贷配置
collcfg
,
err
:=
getCollateralizeConfig
(
action
.
db
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeCreate.getCollateralizeConfig"
,
"addr"
,
action
.
fromaddr
,
"error"
,
err
)
return
nil
,
err
}
// 判断当前可放贷金额
reBalance
,
err
:=
getCollBalance
(
collcfg
.
TotalBalance
,
action
.
localDB
,
action
.
db
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeCreate.getCollBalance"
,
"addr"
,
action
.
fromaddr
,
"error"
,
err
)
return
nil
,
err
}
if
reBalance
<
create
.
GetTotalBalance
()
{
clog
.
Error
(
"CollateralizeCreate.getCollBalance"
,
"addr"
,
action
.
fromaddr
,
"collBalance"
,
reBalance
,
"create.balance"
,
create
.
GetTotalBalance
(),
"error"
,
pty
.
ErrCollateralizeLowBalance
)
return
nil
,
pty
.
ErrCollateralizeLowBalance
}
// 检查ccny余额
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
create
.
TotalBalance
,
false
)
{
clog
.
Error
(
"CollateralizeCreate.CheckExecTokenAccount"
,
"fromaddr"
,
action
.
fromaddr
,
"balance"
,
create
.
TotalBalance
,
"error"
,
types
.
ErrInsufficientBalance
)
return
nil
,
types
.
ErrInsufficientBalance
}
// 根据地址查找ID
collateralizeIDs
,
err
:=
queryCollateralizeByAddr
(
action
.
localDB
,
action
.
fromaddr
,
pty
.
CollateralizeStatusCreated
,
""
)
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
clog
.
Error
(
"CollateralizeCreate.queryCollateralizeByAddr"
,
"addr"
,
action
.
fromaddr
,
"error"
,
err
)
return
nil
,
err
}
// 冻结ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
action
.
fromaddr
,
action
.
execaddr
,
create
.
TotalBalance
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
create
.
TotalBalance
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
var
collateralizeID
string
coll
:=
&
CollateralizeDB
{}
if
collateralizeIDs
==
nil
{
collateralizeID
=
common
.
ToHex
(
action
.
txhash
)
// 构造coll结构
coll
.
CollateralizeId
=
collateralizeID
coll
.
LiquidationRatio
=
collcfg
.
LiquidationRatio
coll
.
TotalBalance
=
create
.
TotalBalance
coll
.
DebtCeiling
=
collcfg
.
DebtCeiling
coll
.
StabilityFeeRatio
=
collcfg
.
StabilityFeeRatio
coll
.
Period
=
collcfg
.
Period
coll
.
Balance
=
create
.
TotalBalance
coll
.
CreateAddr
=
action
.
fromaddr
coll
.
Status
=
pty
.
CollateralizeActionCreate
coll
.
CollBalance
=
0
}
else
{
collateralize
,
err
:=
queryCollateralizeByID
(
action
.
db
,
collateralizeIDs
[
0
])
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeCreate.queryCollateralizeByID"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"collId"
,
collateralizeIDs
[
0
])
return
nil
,
err
}
coll
.
Collateralize
=
*
collateralize
coll
.
TotalBalance
+=
create
.
TotalBalance
coll
.
Balance
+=
create
.
TotalBalance
coll
.
PreStatus
=
coll
.
Status
}
clog
.
Debug
(
"CollateralizeCreate created"
,
"CollateralizeID"
,
collateralizeID
,
"TotalBalance"
,
create
.
TotalBalance
)
// 保存
coll
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
coll
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetCreateReceiptLog
(
&
coll
.
Collateralize
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 根据最近抵押物价格计算需要冻结的BTY数量
func
getBtyNumToFrozen
(
value
int64
,
price
int64
,
ratio
int64
)
(
int64
,
error
)
{
if
price
==
0
{
clog
.
Error
(
"Bty price should greate to 0"
)
return
0
,
pty
.
ErrPriceInvalid
}
btyValue
:=
(
value
*
1e4
)
/
(
price
*
ratio
)
return
btyValue
*
1e4
,
nil
}
// 计算清算价格
// value:借出ccny数量, colValue:抵押物数量, price:抵押物价格
func
calcLiquidationPrice
(
value
int64
,
colValue
int64
)
int64
{
return
(
value
*
pty
.
CollateralizePreLiquidationRatio
)
/
colValue
}
// 获取最近抵押物价格
func
getLatestPrice
(
db
dbm
.
KV
)
(
int64
,
error
)
{
data
,
err
:=
db
.
Get
(
PriceKey
())
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
return
-
1
,
err
}
var
price
pty
.
AssetPriceRecord
//decode
err
=
types
.
Decode
(
data
,
&
price
)
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"decode"
,
err
)
return
-
1
,
err
}
return
price
.
BtyPrice
,
nil
}
// CheckExecAccountBalance 检查账户抵押物余额
func
(
action
*
Action
)
CheckExecAccountBalance
(
fromAddr
string
,
ToFrozen
,
ToActive
int64
)
bool
{
acc
:=
action
.
coinsAccount
.
LoadExecAccount
(
fromAddr
,
action
.
execaddr
)
if
acc
.
GetBalance
()
>=
ToFrozen
&&
acc
.
GetFrozen
()
>=
ToActive
{
return
true
}
return
false
}
// CheckExecAccount 检查账户token余额
func
(
action
*
Action
)
CheckExecTokenAccount
(
addr
string
,
amount
int64
,
isFrozen
bool
)
bool
{
acc
:=
action
.
tokenAccount
.
LoadExecAccount
(
addr
,
action
.
execaddr
)
if
isFrozen
{
if
acc
.
GetFrozen
()
>=
amount
{
return
true
}
}
else
{
if
acc
.
GetBalance
()
>=
amount
{
return
true
}
}
return
false
}
// CollateralizeBorrow 用户质押bty借出ccny
func
(
action
*
Action
)
CollateralizeBorrow
(
borrow
*
pty
.
CollateralizeBorrow
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
// 查找对应的借贷ID
collateralize
,
err
:=
queryCollateralizeByID
(
action
.
db
,
borrow
.
CollateralizeId
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollateralizeId"
,
borrow
.
CollateralizeId
,
"error"
,
err
)
return
nil
,
err
}
// 状态检查
if
collateralize
.
Status
==
pty
.
CollateralizeStatusClose
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
collateralize
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"status"
,
collateralize
.
Status
,
"error"
,
pty
.
ErrCollateralizeStatus
)
return
nil
,
pty
.
ErrCollateralizeStatus
}
coll
:=
&
CollateralizeDB
{
*
collateralize
}
// 借贷金额检查
if
borrow
.
GetValue
()
<=
0
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"borrow value"
,
borrow
.
GetValue
(),
"error"
,
types
.
ErrInvalidParam
)
return
nil
,
types
.
ErrAmount
}
// 借贷金额不超过个人限额
if
borrow
.
GetValue
()
>
coll
.
DebtCeiling
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"borrow value"
,
borrow
.
GetValue
(),
"error"
,
pty
.
ErrCollateralizeExceedDebtCeiling
)
return
nil
,
pty
.
ErrCollateralizeExceedDebtCeiling
}
// 借贷金额不超过当前可借贷金额
if
borrow
.
GetValue
()
>
coll
.
Balance
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"borrow value"
,
borrow
.
GetValue
(),
"error"
,
pty
.
ErrCollateralizeLowBalance
)
return
nil
,
pty
.
ErrCollateralizeLowBalance
}
clog
.
Debug
(
"CollateralizeBorrow"
,
"value"
,
borrow
.
GetValue
())
// 获取抵押物价格
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.getLatestPrice"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
// 根据价格和需要借贷的金额,计算需要质押的抵押物数量
btyFrozen
,
err
:=
getBtyNumToFrozen
(
borrow
.
GetValue
(),
lastPrice
,
coll
.
LiquidationRatio
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.getBtyNumToFrozen"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
// 检查抵押物账户余额
if
!
action
.
CheckExecAccountBalance
(
action
.
fromaddr
,
btyFrozen
,
0
)
{
clog
.
Error
(
"CollateralizeBorrow.CheckExecAccountBalance"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"balance"
,
btyFrozen
,
"error"
,
types
.
ErrNoBalance
)
return
nil
,
types
.
ErrNoBalance
}
// 抵押物转账
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
coll
.
CreateAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物冻结
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
coll
.
CreateAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.Frozen"
,
"addr"
,
coll
.
CreateAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借出ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecTransferFrozen
(
coll
.
CreateAddr
,
action
.
fromaddr
,
action
.
execaddr
,
borrow
.
GetValue
())
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
borrow
.
GetValue
())
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 构造借出记录
borrowRecord
:=
&
pty
.
BorrowRecord
{}
borrowRecord
.
RecordId
=
common
.
ToHex
(
action
.
txhash
)
borrowRecord
.
CollateralizeId
=
coll
.
CollateralizeId
borrowRecord
.
AccountAddr
=
action
.
fromaddr
borrowRecord
.
CollateralValue
=
btyFrozen
borrowRecord
.
StartTime
=
action
.
blocktime
borrowRecord
.
CollateralPrice
=
lastPrice
borrowRecord
.
DebtValue
=
borrow
.
GetValue
()
borrowRecord
.
LiquidationPrice
=
(
coll
.
LiquidationRatio
*
lastPrice
*
pty
.
CollateralizePreLiquidationRatio
)
/
1e8
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusCreate
borrowRecord
.
ExpireTime
=
action
.
blocktime
+
coll
.
Period
// 记录当前借贷的最高自动清算价格
if
coll
.
LatestLiquidationPrice
<
borrowRecord
.
LiquidationPrice
{
coll
.
LatestLiquidationPrice
=
borrowRecord
.
LiquidationPrice
}
// 保存
coll
.
BorrowRecords
=
append
(
coll
.
BorrowRecords
,
borrowRecord
)
coll
.
Status
=
pty
.
CollateralizeStatusCreated
coll
.
Balance
-=
borrow
.
GetValue
()
coll
.
CollBalance
+=
btyFrozen
coll
.
LatestExpireTime
=
getLatestExpireTime
(
&
coll
.
Collateralize
)
coll
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
coll
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetBorrowReceiptLog
(
&
coll
.
Collateralize
,
borrowRecord
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// CollateralizeRepay 用户主动清算
func
(
action
*
Action
)
CollateralizeRepay
(
repay
*
pty
.
CollateralizeRepay
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
// 找到相应的借贷
collateralize
,
err
:=
queryCollateralizeByID
(
action
.
db
,
repay
.
CollateralizeId
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeRepay"
,
"CollID"
,
repay
.
CollateralizeId
,
"error"
,
err
)
return
nil
,
err
}
coll
:=
&
CollateralizeDB
{
*
collateralize
}
// 状态检查
if
coll
.
Status
!=
pty
.
CollateralizeStatusCreated
{
clog
.
Error
(
"CollateralizeRepay"
,
"CollID"
,
repay
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
"status error"
,
"Status"
,
coll
.
Status
)
return
nil
,
pty
.
ErrCollateralizeStatus
}
// 查找借出记录
var
borrowRecord
*
pty
.
BorrowRecord
var
index
int
for
i
,
record
:=
range
coll
.
BorrowRecords
{
if
record
.
RecordId
==
repay
.
RecordId
{
borrowRecord
=
record
index
=
i
break
}
}
if
borrowRecord
==
nil
{
clog
.
Error
(
"CollateralizeRepay"
,
"CollID"
,
repay
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
"Can not find borrow record"
)
return
nil
,
pty
.
ErrRecordNotExist
}
// 借贷金额+利息
fee
:=
(
borrowRecord
.
DebtValue
*
coll
.
StabilityFeeRatio
)
/
1e4
realRepay
:=
borrowRecord
.
DebtValue
+
fee
// 检查
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
realRepay
,
false
)
{
clog
.
Error
(
"CollateralizeRepay.CheckExecTokenAccount"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
realRepay
,
"error"
,
types
.
ErrInsufficientBalance
)
return
nil
,
types
.
ErrNoBalance
}
// ccny转移
receipt
,
err
=
action
.
tokenAccount
.
ExecTransfer
(
action
.
fromaddr
,
coll
.
CreateAddr
,
action
.
execaddr
,
realRepay
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeRepay.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
realRepay
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// ccny冻结
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
coll
.
CreateAddr
,
action
.
execaddr
,
borrowRecord
.
DebtValue
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
borrowRecord
.
DebtValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物归还
receipt
,
err
=
action
.
coinsAccount
.
ExecTransferFrozen
(
coll
.
CreateAddr
,
action
.
fromaddr
,
action
.
execaddr
,
borrowRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeRepay.ExecTransferFrozen"
,
"addr"
,
coll
.
CreateAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
borrowRecord
.
CollateralValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录关闭
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusClose
// 保存
coll
.
Balance
+=
borrowRecord
.
DebtValue
coll
.
CollBalance
-=
borrowRecord
.
CollateralValue
coll
.
BorrowRecords
=
append
(
coll
.
BorrowRecords
[
:
index
],
coll
.
BorrowRecords
[
index
+
1
:
]
...
)
coll
.
InvalidRecords
=
append
(
coll
.
InvalidRecords
,
borrowRecord
)
coll
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
&
coll
.
Collateralize
)
coll
.
LatestExpireTime
=
getLatestExpireTime
(
&
coll
.
Collateralize
)
coll
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
coll
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetRepayReceiptLog
(
&
coll
.
Collateralize
,
borrowRecord
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// CollateralizeAppend 追加抵押物
func
(
action
*
Action
)
CollateralizeAppend
(
cAppend
*
pty
.
CollateralizeAppend
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
// 参数检查
if
cAppend
.
GetCollateralValue
()
<=
0
{
clog
.
Error
(
"CollateralizeAppend"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"append value"
,
cAppend
.
GetCollateralValue
(),
"error"
,
types
.
ErrAmount
)
return
nil
,
types
.
ErrAmount
}
// 查找对应的借贷ID
collateralize
,
err
:=
queryCollateralizeByID
(
action
.
db
,
cAppend
.
CollateralizeId
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeAppend"
,
"CollateralizeId"
,
cAppend
.
CollateralizeId
,
"error"
,
err
)
return
nil
,
err
}
coll
:=
&
CollateralizeDB
{
*
collateralize
}
// 状态检查
if
coll
.
Status
!=
pty
.
CollateralizeStatusCreated
{
clog
.
Error
(
"CollateralizeAppend"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"status"
,
coll
.
Status
,
"error"
,
pty
.
ErrCollateralizeStatus
)
return
nil
,
pty
.
ErrCollateralizeStatus
}
// 查找借出记录
var
borrowRecord
*
pty
.
BorrowRecord
for
_
,
record
:=
range
coll
.
BorrowRecords
{
if
record
.
RecordId
==
cAppend
.
RecordId
{
borrowRecord
=
record
}
}
if
borrowRecord
==
nil
{
clog
.
Error
(
"CollateralizeAppend"
,
"CollID"
,
cAppend
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
"Can not find borrow record"
)
return
nil
,
pty
.
ErrRecordNotExist
}
clog
.
Debug
(
"CollateralizeAppend"
,
"value"
,
cAppend
.
CollateralValue
)
// 获取抵押物价格
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
// 检查抵押物账户余额
if
!
action
.
CheckExecAccountBalance
(
action
.
fromaddr
,
cAppend
.
CollateralValue
,
0
)
{
clog
.
Error
(
"CollateralizeBorrow.CheckExecAccountBalance"
,
"CollID"
,
coll
.
CollateralizeId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
cAppend
.
CollateralValue
,
"error"
,
types
.
ErrNoBalance
)
return
nil
,
types
.
ErrNoBalance
}
// 抵押物转账
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
coll
.
CreateAddr
,
action
.
execaddr
,
cAppend
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
cAppend
.
CollateralValue
,
"error"
,
err
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物冻结
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
coll
.
CreateAddr
,
action
.
execaddr
,
cAppend
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeBorrow.Frozen"
,
"addr"
,
coll
.
CreateAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
cAppend
.
CollateralValue
,
"error"
,
err
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 构造借出记录
borrowRecord
.
CollateralValue
+=
cAppend
.
CollateralValue
borrowRecord
.
CollateralPrice
=
lastPrice
borrowRecord
.
LiquidationPrice
=
calcLiquidationPrice
(
borrowRecord
.
DebtValue
,
borrowRecord
.
CollateralValue
)
if
borrowRecord
.
LiquidationPrice
*
PriceWarningRate
<
lastPrice
{
// 告警解除
if
borrowRecord
.
Status
==
pty
.
CollateralizeUserStatusWarning
{
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeStatusCreated
}
}
// 记录当前借贷的最高自动清算价格
coll
.
CollBalance
+=
cAppend
.
CollateralValue
coll
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
&
coll
.
Collateralize
)
coll
.
LatestExpireTime
=
getLatestExpireTime
(
&
coll
.
Collateralize
)
// append操作不更新Index
coll
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
coll
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetAppendReceiptLog
(
&
coll
.
Collateralize
,
borrowRecord
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
manageKey
:=
types
.
ManageKey
(
key
)
value
,
err
:=
db
.
Get
([]
byte
(
manageKey
))
if
err
!=
nil
{
return
nil
,
err
}
return
value
,
nil
}
func
isRightAddr
(
key
string
,
addr
string
,
db
dbm
.
KV
)
bool
{
value
,
err
:=
getManageKey
(
key
,
db
)
if
err
!=
nil
{
clog
.
Error
(
"isRightAddr"
,
"Key"
,
key
)
return
false
}
if
value
==
nil
{
clog
.
Error
(
"isRightAddr"
,
"key"
,
key
,
"error"
,
"Found key nil value"
)
return
false
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"isRightAddr"
,
"Decode"
,
value
)
return
false
}
for
_
,
op
:=
range
item
.
GetArr
()
.
Value
{
if
op
==
addr
{
return
true
}
}
return
false
}
func
getGuarantorAddr
(
db
dbm
.
KV
)
(
string
,
error
)
{
value
,
err
:=
getManageKey
(
issuanceE
.
GuarantorKey
,
db
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"getGuarantorAddr"
,
err
)
return
""
,
err
}
if
value
==
nil
{
clog
.
Error
(
"CollateralizePriceFeed guarantorKey found nil value"
)
return
""
,
err
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"getGuarantorAddr"
,
err
)
return
""
,
err
}
return
item
.
GetArr
()
.
Value
[
0
],
nil
}
// 系统清算
func
(
action
*
Action
)
systemLiquidation
(
coll
*
pty
.
Collateralize
,
price
int64
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
for
index
,
borrowRecord
:=
range
coll
.
BorrowRecords
{
if
(
borrowRecord
.
LiquidationPrice
*
PriceWarningRate
)
/
1e4
<
price
{
if
borrowRecord
.
Status
==
pty
.
CollateralizeUserStatusWarning
{
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusCreate
}
continue
}
if
borrowRecord
.
LiquidationPrice
>=
price
{
getGuarantorAddr
,
err
:=
getGuarantorAddr
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"getGuarantorAddr"
,
err
)
continue
}
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
coll
.
CreateAddr
,
getGuarantorAddr
,
action
.
execaddr
,
borrowRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
borrowRecord
.
CollateralValue
,
"error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录清算
borrowRecord
.
LiquidateTime
=
action
.
blocktime
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusSystemLiquidate
coll
.
InvalidRecords
=
append
(
coll
.
InvalidRecords
,
borrowRecord
)
coll
.
BorrowRecords
=
append
(
coll
.
BorrowRecords
[
:
index
],
coll
.
BorrowRecords
[
index
+
1
:
]
...
)
coll
.
CollBalance
-=
borrowRecord
.
CollateralValue
}
else
{
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusWarning
}
log
:=
action
.
GetFeedReceiptLog
(
coll
,
borrowRecord
)
logs
=
append
(
logs
,
log
)
}
// 保存
coll
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
coll
)
coll
.
LatestExpireTime
=
getLatestExpireTime
(
coll
)
collDB
:=
&
CollateralizeDB
{
*
coll
}
collDB
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
collDB
.
GetKVSet
()
...
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 超时清算
func
(
action
*
Action
)
expireLiquidation
(
coll
*
pty
.
Collateralize
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
for
index
,
borrowRecord
:=
range
coll
.
BorrowRecords
{
if
borrowRecord
.
ExpireTime
-
ExpireWarningTime
>
action
.
blocktime
{
continue
}
if
borrowRecord
.
ExpireTime
<=
action
.
blocktime
{
getGuarantorAddr
,
err
:=
getGuarantorAddr
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"getGuarantorAddr"
,
err
)
continue
}
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
coll
.
CreateAddr
,
getGuarantorAddr
,
action
.
execaddr
,
borrowRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
borrowRecord
.
CollateralValue
,
"error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录清算
borrowRecord
.
LiquidateTime
=
action
.
blocktime
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusExpireLiquidate
coll
.
InvalidRecords
=
append
(
coll
.
InvalidRecords
,
borrowRecord
)
coll
.
BorrowRecords
=
append
(
coll
.
BorrowRecords
[
:
index
],
coll
.
BorrowRecords
[
index
+
1
:
]
...
)
coll
.
CollBalance
-=
borrowRecord
.
CollateralValue
}
else
{
borrowRecord
.
PreStatus
=
borrowRecord
.
Status
borrowRecord
.
Status
=
pty
.
CollateralizeUserStatusExpire
}
log
:=
action
.
GetFeedReceiptLog
(
coll
,
borrowRecord
)
logs
=
append
(
logs
,
log
)
}
// 保存
coll
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
coll
)
coll
.
LatestExpireTime
=
getLatestExpireTime
(
coll
)
collDB
:=
&
CollateralizeDB
{
*
coll
}
collDB
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
collDB
.
GetKVSet
()
...
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 价格计算策略
func
pricePolicy
(
feed
*
pty
.
CollateralizeFeed
)
int64
{
var
totalPrice
int64
var
totalVolume
int64
for
_
,
volume
:=
range
feed
.
Volume
{
totalVolume
+=
volume
}
if
totalVolume
==
0
{
clog
.
Error
(
"collateralize price feed volume empty"
)
return
0
}
for
i
,
price
:=
range
feed
.
Price
{
totalPrice
+=
(
price
*
feed
.
Volume
[
i
])
/
totalVolume
}
return
totalPrice
}
// CollateralizeFeed 喂价
func
(
action
*
Action
)
CollateralizeFeed
(
feed
*
pty
.
CollateralizeFeed
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
feed
==
nil
||
len
(
feed
.
Price
)
==
0
||
len
(
feed
.
Price
)
!=
len
(
feed
.
Volume
)
{
clog
.
Error
(
"CollateralizePriceFeed"
,
types
.
ErrInvalidParam
)
return
nil
,
types
.
ErrInvalidParam
}
// 是否后台管理用户
if
!
isRightAddr
(
issuanceE
.
PriceFeedKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to feed price"
)
return
nil
,
pty
.
ErrPermissionDeny
}
price
:=
pricePolicy
(
feed
)
if
price
<=
0
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"price"
,
price
,
"error"
,
pty
.
ErrPriceInvalid
)
return
nil
,
pty
.
ErrPriceInvalid
}
ids
,
err
:=
queryCollateralizeByStatus
(
action
.
localDB
,
pty
.
CollateralizeStatusCreated
,
""
)
if
err
!=
nil
{
clog
.
Debug
(
"CollateralizePriceFeed"
,
"get collateralize record error"
,
err
)
}
for
_
,
collID
:=
range
ids
{
coll
,
err
:=
queryCollateralizeByID
(
action
.
db
,
collID
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"Collateralize ID"
,
coll
.
CollateralizeId
,
"get collateralize record by id error"
,
err
)
continue
}
// 超时清算判断
if
coll
.
LatestExpireTime
-
ExpireWarningTime
<=
action
.
blocktime
{
receipt
,
err
:=
action
.
expireLiquidation
(
coll
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"Collateralize ID"
,
coll
.
CollateralizeId
,
"expire liquidation error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
// 系统清算判断
receipt
,
err
:=
action
.
systemLiquidation
(
coll
,
price
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizePriceFeed"
,
"Collateralize ID"
,
coll
.
CollateralizeId
,
"system liquidation error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
var
priceRecord
pty
.
AssetPriceRecord
priceRecord
.
BtyPrice
=
price
priceRecord
.
RecordTime
=
action
.
blocktime
// 最近喂价记录
pricekv
:=
&
types
.
KeyValue
{
Key
:
PriceKey
(),
Value
:
types
.
Encode
(
&
priceRecord
)}
action
.
db
.
Set
(
pricekv
.
Key
,
pricekv
.
Value
)
kv
=
append
(
kv
,
pricekv
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// CollateralizeRetrieve 收回未放贷
func
(
action
*
Action
)
CollateralizeRetrieve
(
retrieve
*
pty
.
CollateralizeRetrieve
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
collateralize
,
err
:=
queryCollateralizeByID
(
action
.
db
,
retrieve
.
CollateralizeId
)
if
err
!=
nil
{
clog
.
Error
(
"CollateralizeRetrieve"
,
"CollateralizeId"
,
retrieve
.
CollateralizeId
,
"error"
,
err
)
return
nil
,
err
}
if
action
.
fromaddr
!=
collateralize
.
CreateAddr
{
clog
.
Error
(
"CollateralizeRetrieve"
,
"CollateralizeId"
,
retrieve
.
CollateralizeId
,
"error"
,
"account error"
,
"create"
,
collateralize
.
CreateAddr
,
"from"
,
action
.
fromaddr
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 收回金额不能大于待放出金额
if
retrieve
.
Balance
>
collateralize
.
Balance
{
clog
.
Error
(
"CollateralizeRetrieve"
,
"CollateralizeId"
,
retrieve
.
CollateralizeId
,
"error"
,
"balance error"
,
"retrieve balance"
,
retrieve
.
Balance
,
"available balance"
,
collateralize
.
Balance
)
return
nil
,
types
.
ErrAmount
}
// 解冻ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecActive
(
action
.
fromaddr
,
action
.
execaddr
,
retrieve
.
Balance
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceClose.ExecActive"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"balance"
,
retrieve
.
Balance
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
clog
.
Debug
(
"CollateralizeRetrieve"
,
"ID"
,
retrieve
.
CollateralizeId
,
"balance"
,
retrieve
.
Balance
)
coll
:=
&
CollateralizeDB
{
*
collateralize
}
coll
.
TotalBalance
-=
retrieve
.
Balance
coll
.
Balance
-=
retrieve
.
Balance
coll
.
PreStatus
=
coll
.
Status
if
coll
.
TotalBalance
==
0
{
coll
.
Status
=
pty
.
CollateralizeStatusClose
}
coll
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
coll
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetRetrieveReceiptLog
(
&
coll
.
Collateralize
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
// 查找借贷
func
queryCollateralizeByID
(
db
dbm
.
KV
,
collateralizeID
string
)
(
*
pty
.
Collateralize
,
error
)
{
data
,
err
:=
db
.
Get
(
Key
(
collateralizeID
))
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeByID"
,
"error"
,
err
)
return
nil
,
err
}
var
coll
pty
.
Collateralize
err
=
types
.
Decode
(
data
,
&
coll
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeByID"
,
"decode"
,
err
)
return
nil
,
err
}
return
&
coll
,
nil
}
func
queryCollateralizeByStatus
(
localdb
dbm
.
KVDB
,
status
int32
,
collID
string
)
([]
string
,
error
)
{
query
:=
pty
.
NewCollateralizeTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
collID
)
>
0
{
primary
=
[]
byte
(
collID
)
}
var
data
=
&
pty
.
ReceiptCollateralize
{
CollateralizeId
:
collID
,
Status
:
status
,
}
rows
,
err
:=
query
.
List
(
"status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeByStatus.List"
,
"error"
,
err
)
return
nil
,
err
}
var
ids
[]
string
for
_
,
row
:=
range
rows
{
ids
=
append
(
ids
,
string
(
row
.
Primary
))
}
return
ids
,
nil
}
func
queryCollateralizeByAddr
(
localdb
dbm
.
KVDB
,
addr
string
,
status
int32
,
collID
string
)
([]
string
,
error
)
{
query
:=
pty
.
NewCollateralizeTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
collID
)
>
0
{
primary
=
[]
byte
(
collID
)
}
var
data
=
&
pty
.
ReceiptCollateralize
{
CollateralizeId
:
collID
,
Status
:
status
,
AccountAddr
:
addr
,
}
var
rows
[]
*
table
.
Row
var
err
error
if
status
==
0
{
rows
,
err
=
query
.
List
(
"addr"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeByAddr.List"
,
"index"
,
"addr"
,
"error"
,
err
)
return
nil
,
err
}
}
else
{
rows
,
err
=
query
.
List
(
"addr_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeByAddr.List"
,
"index"
,
"addr_status"
,
"error"
,
err
)
return
nil
,
err
}
}
var
ids
[]
string
for
_
,
row
:=
range
rows
{
ids
=
append
(
ids
,
string
(
row
.
Primary
))
}
return
ids
,
nil
}
// 精确查找发行记录
func
queryCollateralizeRecordByID
(
db
dbm
.
KV
,
collateralizeID
string
,
recordID
string
)
(
*
pty
.
BorrowRecord
,
error
)
{
coll
,
err
:=
queryCollateralizeByID
(
db
,
collateralizeID
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByID"
,
"error"
,
err
)
return
nil
,
err
}
for
_
,
record
:=
range
coll
.
BorrowRecords
{
if
record
.
RecordId
==
recordID
{
return
record
,
nil
}
}
for
_
,
record
:=
range
coll
.
InvalidRecords
{
if
record
.
RecordId
==
recordID
{
return
record
,
nil
}
}
return
nil
,
types
.
ErrNotFound
}
func
queryCollateralizeRecordByAddr
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
,
status
int32
,
collID
string
,
recordID
string
)
([]
*
pty
.
BorrowRecord
,
error
)
{
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
recordID
)
>
0
{
primary
=
[]
byte
(
recordID
)
}
var
data
=
&
pty
.
ReceiptCollateralize
{
AccountAddr
:
addr
,
Status
:
status
,
CollateralizeId
:
collID
,
}
var
rows
[]
*
table
.
Row
var
err
error
if
len
(
collID
)
!=
0
{
rows
,
err
=
query
.
List
(
"id_addr"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByAddr.List"
,
"index"
,
"id_addr"
,
"error"
,
err
)
return
nil
,
err
}
}
else
if
status
!=
0
{
rows
,
err
=
query
.
List
(
"addr_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByAddr.List"
,
"index"
,
"addr_status"
,
"error"
,
err
)
return
nil
,
err
}
}
else
{
rows
,
err
=
query
.
List
(
"addr"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByAddr.List"
,
"index"
,
"addr"
,
"error"
,
err
)
return
nil
,
err
}
}
var
records
[]
*
pty
.
BorrowRecord
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryCollateralizeRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
CollateralizeId
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
RecordId
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByAddr.queryCollateralizeRecordByID"
,
"error"
,
err
)
continue
}
records
=
append
(
records
,
record
)
}
return
records
,
nil
}
func
queryCollateralizeRecordByStatus
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
status
int32
,
collID
string
,
recordID
string
)
([]
*
pty
.
BorrowRecord
,
error
)
{
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
recordID
)
>
0
{
primary
=
[]
byte
(
recordID
)
}
var
data
=
&
pty
.
ReceiptCollateralize
{
Status
:
status
,
CollateralizeId
:
collID
,
}
var
rows
[]
*
table
.
Row
var
err
error
if
len
(
collID
)
==
0
{
rows
,
err
=
query
.
List
(
"status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByStatus.List"
,
"index"
,
"status"
,
"error"
,
err
)
return
nil
,
err
}
}
else
{
rows
,
err
=
query
.
List
(
"id_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByStatus.List"
,
"index"
,
"id_status"
,
"error"
,
err
)
return
nil
,
err
}
}
var
records
[]
*
pty
.
BorrowRecord
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryCollateralizeRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
CollateralizeId
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
RecordId
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByStatus.queryCollateralizeRecordByID"
,
"error"
,
err
)
continue
}
records
=
append
(
records
,
record
)
}
return
records
,
nil
}
func
queryCollateralizeUserBalanceStatus
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
,
status
int32
)
(
int64
,
error
)
{
var
totalBalance
int64
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
var
data
=
&
pty
.
ReceiptCollateralize
{
AccountAddr
:
addr
,
Status
:
status
,
}
var
rows
[]
*
table
.
Row
var
err
error
for
{
rows
,
err
=
query
.
List
(
"addr_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByAddr.List"
,
"index"
,
"addr"
,
"error"
,
err
)
return
-
1
,
err
}
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryCollateralizeRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
CollateralizeId
,
row
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
RecordId
)
if
err
!=
nil
{
clog
.
Debug
(
"queryCollateralizeRecordByStatus.queryCollateralizeRecordByID"
,
"error"
,
err
)
continue
}
totalBalance
+=
record
.
DebtValue
}
if
len
(
rows
)
<
int
(
DefaultCount
)
{
break
}
primary
=
[]
byte
(
rows
[
DefaultCount
-
1
]
.
Data
.
(
*
pty
.
ReceiptCollateralize
)
.
RecordId
)
}
return
totalBalance
,
nil
}
func
queryCollateralizeUserBalance
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
)
(
int64
,
error
)
{
var
totalBalance
int64
balance
,
err
:=
queryCollateralizeUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
CollateralizeUserStatusCreate
)
if
err
!=
nil
{
clog
.
Error
(
"queryCollateralizeUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
balance
,
err
=
queryCollateralizeUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
CollateralizeUserStatusWarning
)
if
err
!=
nil
{
clog
.
Error
(
"queryCollateralizeUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
balance
,
err
=
queryCollateralizeUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
CollateralizeUserStatusExpire
)
if
err
!=
nil
{
clog
.
Error
(
"queryCollateralizeUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
return
totalBalance
,
nil
}
plugin/dapp/collateralize/executor/doc.go
0 → 100644
View file @
a717a020
// 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 @
a717a020
// 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_Retrieve Action
func
(
c
*
Collateralize
)
Exec_Retrieve
(
payload
*
pty
.
CollateralizeRetrieve
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeRetrieve
(
payload
)
}
// Exec_Close Action
func
(
c
*
Collateralize
)
Exec_Manage
(
payload
*
pty
.
CollateralizeManage
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewCollateralizeAction
(
c
,
tx
,
index
)
return
actiondb
.
CollateralizeManage
(
payload
)
}
plugin/dapp/collateralize/executor/exec_del_local.go
0 → 100644
View file @
a717a020
// 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"
)
func
(
c
*
Collateralize
)
execDelLocal
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
kvs
,
err
:=
c
.
DelRollbackKV
(
tx
,
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
err
}
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
return
dbSet
,
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_Retrieve Action
func
(
c
*
Collateralize
)
ExecDelLocal_Retrieve
(
payload
*
pty
.
CollateralizeRetrieve
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Manage Action
func
(
c
*
Collateralize
)
ExecDelLocal_Manage
(
payload
*
pty
.
CollateralizeManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
plugin/dapp/collateralize/executor/exec_local.go
0 → 100644
View file @
a717a020
// 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
{
if
item
.
Ty
>=
pty
.
TyLogCollateralizeCreate
&&
item
.
Ty
<=
pty
.
TyLogCollateralizeRetrieve
{
var
collateralizeLog
pty
.
ReceiptCollateralize
err
:=
types
.
Decode
(
item
.
Log
,
&
collateralizeLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogCollateralizeCreate
||
item
.
Ty
==
pty
.
TyLogCollateralizeRetrieve
{
collTable
:=
pty
.
NewCollateralizeTable
(
c
.
GetLocalDB
())
err
=
collTable
.
Replace
(
&
pty
.
ReceiptCollateralize
{
CollateralizeId
:
collateralizeLog
.
CollateralizeId
,
Status
:
collateralizeLog
.
Status
,
AccountAddr
:
collateralizeLog
.
AccountAddr
})
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
collTable
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kvs
...
)
}
else
{
recordTable
:=
pty
.
NewRecordTable
(
c
.
GetLocalDB
())
err
=
recordTable
.
Replace
(
&
pty
.
ReceiptCollateralize
{
CollateralizeId
:
collateralizeLog
.
CollateralizeId
,
Status
:
collateralizeLog
.
Status
,
RecordId
:
collateralizeLog
.
RecordId
,
AccountAddr
:
collateralizeLog
.
AccountAddr
})
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
recordTable
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kvs
...
)
}
}
}
set
.
KV
=
c
.
AddRollbackKV
(
tx
,
[]
byte
(
pty
.
CollateralizeX
),
set
.
KV
)
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_Retrieve Action
func
(
c
*
Collateralize
)
ExecLocal_Retrieve
(
payload
*
pty
.
CollateralizeRetrieve
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Manage Action
func
(
c
*
Collateralize
)
ExecLocal_Manage
(
payload
*
pty
.
CollateralizeManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
plugin/dapp/collateralize/executor/query.go
0 → 100644
View file @
a717a020
// 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"
)
func
(
c
*
Collateralize
)
Query_CollateralizeInfoByID
(
req
*
pty
.
ReqCollateralizeInfo
)
(
types
.
Message
,
error
)
{
coll
,
err
:=
queryCollateralizeByID
(
c
.
GetStateDB
(),
req
.
CollateralizeId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeInfoByID"
,
"id"
,
req
.
CollateralizeId
,
"error"
,
err
)
return
nil
,
err
}
info
:=
&
pty
.
RepCollateralizeCurrentInfo
{
Status
:
coll
.
Status
,
TotalBalance
:
coll
.
TotalBalance
,
DebtCeiling
:
coll
.
DebtCeiling
,
LiquidationRatio
:
coll
.
LiquidationRatio
,
StabilityFeeRatio
:
coll
.
StabilityFeeRatio
,
CreateAddr
:
coll
.
CreateAddr
,
Balance
:
coll
.
Balance
,
Period
:
coll
.
Period
,
CollateralizeId
:
coll
.
CollateralizeId
,
CollBalance
:
coll
.
CollBalance
,
}
info
.
BorrowRecords
=
append
(
info
.
BorrowRecords
,
coll
.
BorrowRecords
...
)
info
.
BorrowRecords
=
append
(
info
.
BorrowRecords
,
coll
.
InvalidRecords
...
)
return
info
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeInfoByIDs
(
req
*
pty
.
ReqCollateralizeInfos
)
(
types
.
Message
,
error
)
{
infos
:=
&
pty
.
RepCollateralizeCurrentInfos
{}
for
_
,
id
:=
range
req
.
CollateralizeIds
{
coll
,
err
:=
queryCollateralizeByID
(
c
.
GetStateDB
(),
id
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeInfoByID"
,
"id"
,
id
,
"error"
,
err
)
return
nil
,
err
}
info
:=
&
pty
.
RepCollateralizeCurrentInfo
{
Status
:
coll
.
Status
,
TotalBalance
:
coll
.
TotalBalance
,
DebtCeiling
:
coll
.
DebtCeiling
,
LiquidationRatio
:
coll
.
LiquidationRatio
,
StabilityFeeRatio
:
coll
.
StabilityFeeRatio
,
CreateAddr
:
coll
.
CreateAddr
,
Balance
:
coll
.
Balance
,
Period
:
coll
.
Period
,
CollateralizeId
:
coll
.
CollateralizeId
,
CollBalance
:
coll
.
CollBalance
,
}
info
.
BorrowRecords
=
append
(
info
.
BorrowRecords
,
coll
.
BorrowRecords
...
)
info
.
BorrowRecords
=
append
(
info
.
BorrowRecords
,
coll
.
InvalidRecords
...
)
infos
.
Infos
=
append
(
infos
.
Infos
,
info
)
}
return
infos
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeByStatus
(
req
*
pty
.
ReqCollateralizeByStatus
)
(
types
.
Message
,
error
)
{
ids
:=
&
pty
.
RepCollateralizeIDs
{}
collIDRecords
,
err
:=
queryCollateralizeByStatus
(
c
.
GetLocalDB
(),
req
.
Status
,
req
.
CollID
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeByStatus"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
ids
.
IDs
=
append
(
ids
.
IDs
,
collIDRecords
...
)
return
ids
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeByAddr
(
req
*
pty
.
ReqCollateralizeByAddr
)
(
types
.
Message
,
error
)
{
ids
:=
&
pty
.
RepCollateralizeIDs
{}
collIDRecords
,
err
:=
queryCollateralizeByAddr
(
c
.
GetLocalDB
(),
req
.
Addr
,
req
.
Status
,
req
.
CollID
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeByAddr"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
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 collateralize record error"
,
err
)
return
nil
,
err
}
ret
.
Record
=
issuRecord
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
,
req
.
Status
,
req
.
CollateralizeId
,
req
.
RecordId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeRecordByAddr"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
if
req
.
Status
==
0
{
ret
.
Records
=
records
}
else
{
for
_
,
record
:=
range
records
{
if
record
.
Status
==
req
.
Status
{
ret
.
Records
=
append
(
ret
.
Records
,
record
)
}
}
}
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
,
req
.
CollateralizeId
,
req
.
RecordId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeRecordByStatus"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
ret
.
Records
=
records
return
ret
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeConfig
(
req
*
pty
.
ReqCollateralizeRecordByAddr
)
(
types
.
Message
,
error
)
{
config
,
err
:=
getCollateralizeConfig
(
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeConfig"
,
"get collateralize config error"
,
err
)
return
nil
,
err
}
balance
,
err
:=
getCollBalance
(
config
.
TotalBalance
,
c
.
GetLocalDB
(),
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeInfoByID"
,
"error"
,
err
)
return
nil
,
err
}
ret
:=
&
pty
.
RepCollateralizeConfig
{
TotalBalance
:
config
.
TotalBalance
,
DebtCeiling
:
config
.
DebtCeiling
,
LiquidationRatio
:
config
.
LiquidationRatio
,
StabilityFeeRatio
:
config
.
StabilityFeeRatio
,
Period
:
config
.
Period
,
Balance
:
balance
,
CurrentTime
:
config
.
CurrentTime
,
}
return
ret
,
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizePrice
(
req
*
pty
.
ReqCollateralizeRecordByAddr
)
(
types
.
Message
,
error
)
{
price
,
err
:=
getLatestPrice
(
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizePrice"
,
"error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepCollateralizePrice
{
Price
:
price
},
nil
}
func
(
c
*
Collateralize
)
Query_CollateralizeUserBalance
(
req
*
pty
.
ReqCollateralizeRecordByAddr
)
(
types
.
Message
,
error
)
{
balance
,
err
:=
queryCollateralizeUserBalance
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Addr
)
if
err
!=
nil
{
clog
.
Error
(
"Query_CollateralizeRecordByAddr"
,
"get collateralize record error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepCollateralizeUserBalance
{
Balance
:
balance
},
nil
}
plugin/dapp/collateralize/plugin.go
0 → 100644
View file @
a717a020
// 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/commands"
"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
:
commands
.
CollateralizeCmd
,
})
}
plugin/dapp/collateralize/proto/Makefile
0 → 100644
View file @
a717a020
all
:
sh ./create_protobuf.sh
plugin/dapp/collateralize/proto/collateralize.proto
0 → 100644
View file @
a717a020
syntax
=
"proto3"
;
package
types
;
// 放贷信息
message
Collateralize
{
string
collateralizeId
=
1
;
//放贷ID,一期放贷对应一个ID
int64
totalBalance
=
2
;
//当期放贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
4
;
//清算比例
int64
stabilityFeeRatio
=
5
;
//稳定费率
string
createAddr
=
6
;
//创建人地址
int64
balance
=
7
;
//放贷剩余金额(ccny)
repeated
BorrowRecord
borrowRecords
=
8
;
//借贷记录
repeated
BorrowRecord
InvalidRecords
=
9
;
//失效的借贷记录
int32
status
=
10
;
//当期借贷的状态,是否关闭
int64
latestLiquidationPrice
=
11
;
//最高清算价格
int64
period
=
12
;
//借贷最大期限
int64
latestExpireTime
=
13
;
//最近超期时间
int64
collBalance
=
14
;
//抵押bty
int32
preStatus
=
15
;
//上一个状态
}
// 借出记录
message
BorrowRecord
{
string
accountAddr
=
1
;
//借贷人地址
int64
startTime
=
2
;
//借贷时间
int64
collateralValue
=
3
;
//抵押物价值(bty)
int64
collateralPrice
=
4
;
//抵押物价格
int64
debtValue
=
5
;
//债务价值(ccny)
int64
liquidationPrice
=
6
;
//抵押物清算价格
int32
status
=
7
;
//抵押状态,是否被清算
int64
liquidateTime
=
8
;
//清算时间
int64
expireTime
=
9
;
//超时清算时间
int32
preStatus
=
10
;
//上一次抵押状态,用于告警恢复
string
recordId
=
11
;
//借贷id,标识一次借出记录
string
collateralizeId
=
12
;
//放贷id
}
// 资产价格记录
message
AssetPriceRecord
{
int64
recordTime
=
1
;
//价格记录时间
int64
btyPrice
=
2
;
//bty价格
int64
btcPrice
=
3
;
//btc价格
int64
ethPrice
=
4
;
//eth价格
}
// action
message
CollateralizeAction
{
oneof
value
{
CollateralizeCreate
create
=
1
;
//创建一期借贷
CollateralizeBorrow
borrow
=
2
;
//借贷
CollateralizeRepay
repay
=
3
;
//清算
CollateralizeAppend
append
=
4
;
//追加
CollateralizeFeed
feed
=
5
;
//喂价
CollateralizeRetrieve
retrieve
=
6
;
//收回
CollateralizeManage
manage
=
7
;
//全局配置
}
int32
ty
=
10
;
}
message
CollateralizeManage
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
2
;
//清算比例
int64
stabilityFeeRatio
=
3
;
//稳定费
int64
period
=
4
;
//合约期限
int64
totalBalance
=
5
;
//放贷总量
int64
currentTime
=
6
;
//设置时间
}
message
CollateralizeAddr
{
repeated
string
superAddrs
=
1
;
//大户地址
}
// 创建放贷
message
CollateralizeCreate
{
int64
totalBalance
=
1
;
//可借贷总金额
}
// 质押借出
message
CollateralizeBorrow
{
string
collateralizeId
=
1
;
//借贷期数ID
int64
value
=
2
;
//借贷价值(ccny)
}
// 质押清算
message
CollateralizeRepay
{
string
collateralizeId
=
1
;
//借贷期数ID
string
recordId
=
2
;
//借贷ID
}
// 追加抵押物
message
CollateralizeAppend
{
string
collateralizeId
=
1
;
//借贷期数ID
string
recordId
=
2
;
//借贷ID
int64
collateralValue
=
3
;
//追加价值(bty)
}
// 喂价
message
CollateralizeFeed
{
int32
collType
=
1
;
//抵押物价格类型(1,bty,2,btc,3,eth...)
repeated
int64
price
=
2
;
//喂价
repeated
int64
volume
=
3
;
//成交量
}
// 收回
message
CollateralizeRetrieve
{
string
collateralizeId
=
1
;
//借贷期数ID
int64
balance
=
2
;
//收回金额
}
// exec_local 放贷信息
message
ReceiptCollateralize
{
string
collateralizeId
=
1
;
string
accountAddr
=
3
;
string
recordId
=
4
;
int32
status
=
5
;
}
// exec_local 放贷记录信息列表
message
CollateralizeRecords
{
repeated
ReceiptCollateralize
records
=
1
;
}
// 根据ID查询一期放贷信息
message
ReqCollateralizeInfo
{
string
collateralizeId
=
1
;
}
// 返回一期放贷信息
message
RepCollateralizeCurrentInfo
{
int32
status
=
1
;
//当期借贷的状态,是否关闭
int64
totalBalance
=
2
;
//当期可借贷的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
4
;
//清算比例
int64
stabilityFeeRatio
=
5
;
//稳定费
string
createAddr
=
6
;
//创建人地址
int64
balance
=
7
;
//剩余可借贷金额(ccny)
int64
period
=
8
;
//合约期限
string
collateralizeId
=
9
;
//放贷ID
int64
collBalance
=
10
;
//抵押bty
repeated
BorrowRecord
borrowRecords
=
11
;
//借贷记录
}
// 根据ID列表查询多期放贷信息
message
ReqCollateralizeInfos
{
repeated
string
collateralizeIds
=
1
;
}
// 返回多期放贷信息
message
RepCollateralizeCurrentInfos
{
repeated
RepCollateralizeCurrentInfo
infos
=
1
;
}
// 根据放贷状态查询
message
ReqCollateralizeByStatus
{
int32
status
=
1
;
string
collID
=
2
;
}
// 根据用户地址查询
message
ReqCollateralizeByAddr
{
string
addr
=
1
;
int32
status
=
2
;
string
collID
=
3
;
}
// 返回放贷ID列表
message
RepCollateralizeIDs
{
repeated
string
IDs
=
1
;
}
// 根据地址和借贷ID混合查询具体借贷记录
message
ReqCollateralizeRecordByAddr
{
string
collateralizeId
=
1
;
string
addr
=
2
;
int32
status
=
3
;
string
recordId
=
4
;
}
// 根据状态和借贷ID混合查询具体借贷记录
message
ReqCollateralizeRecordByStatus
{
string
collateralizeId
=
1
;
int32
status
=
2
;
string
recordId
=
3
;
}
// 返回借贷记录
message
RepCollateralizeRecords
{
repeated
BorrowRecord
records
=
1
;
}
// 精确查找借贷记录
message
ReqCollateralizeRecord
{
string
collateralizeId
=
1
;
string
recordId
=
2
;
}
// 返回借贷记录
message
RepCollateralizeRecord
{
BorrowRecord
record
=
1
;
}
// 返回放贷配置
message
RepCollateralizeConfig
{
int64
debtCeiling
=
1
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
2
;
//清算比例
int64
stabilityFeeRatio
=
3
;
//稳定费
int64
period
=
4
;
//合约期限
int64
totalBalance
=
5
;
//放贷总量
int64
balance
=
6
;
//剩余放贷额度
int64
currentTime
=
7
;
//设置时间
}
// 返回最新抵押物价格
message
RepCollateralizePrice
{
int64
price
=
1
;
//当前抵押物最新价格
}
// 返回用户借贷总额
message
RepCollateralizeUserBalance
{
int64
balance
=
1
;
//返回用户借贷总额
}
\ No newline at end of file
plugin/dapp/collateralize/proto/create_protobuf.sh
0 → 100644
View file @
a717a020
#!/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/readme.md
0 → 100644
View file @
a717a020
## 借贷合约表结构
### 放贷表coller表结构
字段名称|类型|说明
---|---|---
collateralizeId|string|放贷ID,主键
accountAddr|string|大户地址
recordId|string|借贷ID
status|int32|放贷状态(1:已放贷 2:已收回)
### 放贷表coller表索引
索引名|说明
---|---
status|根据放贷状态查询放贷ID
addr|根据大户地址查询放贷ID
addr_status|根据放贷状态和大户地址查询放贷ID
### 借贷表borrow表结构
字段名称|类型|说明
---|---|---
recordId|string|借贷ID,主键
collateralizeId|string|放贷ID
accountAddr|string|用户地址
status|int32|借贷状态(1:已发行 2:价格清算告警 3:价格清算 4:超时清算告警 5:超时清算 6:已清算)
### 放贷表borrow表索引
索引名|说明
---|---
status|根据借贷状态查询借贷ID
addr|根据大户地址查询借贷ID
addr_status|根据借贷状态和用户地址查询借贷ID
id_status|根据放贷ID和借贷状态查询借贷ID
id_addr|根据放贷ID和用户地址查询借贷ID
\ No newline at end of file
plugin/dapp/collateralize/types/collateralize.go
0 → 100644
View file @
a717a020
// 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"
"math"
"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
.
RegFork
(
CollateralizeX
,
InitFork
)
types
.
RegExec
(
CollateralizeX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
CollateralizeX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
CollateralizeX
,
NewType
(
cfg
))
}
// CollateralizeType def
type
CollateralizeType
struct
{
types
.
ExecTypeBase
}
// NewType method
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
CollateralizeType
{
c
:=
&
CollateralizeType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
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"
},
TyLogCollateralizeRetrieve
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptCollateralize
{}),
Name
:
"LogCollateralizeRetrieve"
},
}
}
// 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
)
cfg
:=
collateralize
.
GetConfig
()
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
(
cfg
,
&
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
(
cfg
,
&
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
(
cfg
,
&
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
(
cfg
,
&
param
)
}
else
if
action
==
"CollateralizePriceFeed"
{
var
param
CollateralizeFeedTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeFeedTx
(
cfg
,
&
param
)
}
else
if
action
==
"CollateralizeRetrieve"
{
var
param
CollateralizeRetrieveTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawCollateralizeRetrieveTx
(
cfg
,
&
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
}
return
CreateRawCollateralizeManageTx
(
cfg
,
&
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
,
"Retrieve"
:
CollateralizeActionRetrieve
,
"Manage"
:
CollateralizeActionManage
,
}
}
// CreateRawCollateralizeCreateTx method
func
CreateRawCollateralizeCreateTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeCreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeCreateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeCreate
{
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
create
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionCreate
,
Value
:
&
CollateralizeAction_Create
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
create
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeBorrowTx method
func
CreateRawCollateralizeBorrowTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeBorrowTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeBorrowTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeBorrow
{
CollateralizeId
:
parm
.
CollateralizeID
,
Value
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
borrow
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionBorrow
,
Value
:
&
CollateralizeAction_Borrow
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
borrow
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeRepayTx method
func
CreateRawCollateralizeRepayTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeRepayTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeRepayTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeRepay
{
CollateralizeId
:
parm
.
CollateralizeID
,
RecordId
:
parm
.
RecordID
,
}
repay
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionRepay
,
Value
:
&
CollateralizeAction_Repay
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
repay
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeAppendTx method
func
CreateRawCollateralizeAppendTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeAppendTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeAppendTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeAppend
{
CollateralizeId
:
parm
.
CollateralizeID
,
RecordId
:
parm
.
RecordID
,
CollateralValue
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
append
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionAppend
,
Value
:
&
CollateralizeAction_Append
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
append
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeFeedTx method
func
CreateRawCollateralizeFeedTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeFeedTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizePriceFeedTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeFeed
{
Volume
:
parm
.
Volume
,
}
for
_
,
r
:=
range
parm
.
Price
{
v
.
Price
=
append
(
v
.
Price
,
int64
(
math
.
Trunc
(
r
*
1e4
)))
}
feed
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionFeed
,
Value
:
&
CollateralizeAction_Feed
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
feed
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeRetrieveTx method
func
CreateRawCollateralizeRetrieveTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeRetrieveTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeCloseTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeRetrieve
{
CollateralizeId
:
parm
.
CollateralizeID
,
Balance
:
int64
(
math
.
Trunc
((
parm
.
Balance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
close
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionRetrieve
,
Value
:
&
CollateralizeAction_Retrieve
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
close
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawCollateralizeManageTx method
func
CreateRawCollateralizeManageTx
(
cfg
*
types
.
Chain33Config
,
parm
*
CollateralizeManageTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawCollateralizeManageTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
CollateralizeManage
{
DebtCeiling
:
int64
(
math
.
Trunc
((
parm
.
DebtCeiling
+
0.0000001
)
*
1e4
))
*
1e4
,
LiquidationRatio
:
int64
(
math
.
Trunc
((
parm
.
LiquidationRatio
+
0.0000001
)
*
1e4
)),
StabilityFeeRatio
:
int64
(
math
.
Trunc
((
parm
.
StabilityFeeRatio
+
0.0000001
)
*
1e4
)),
Period
:
parm
.
Period
,
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
}
manage
:=
&
CollateralizeAction
{
Ty
:
CollateralizeActionManage
,
Value
:
&
CollateralizeAction_Manage
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
CollateralizeX
)),
Payload
:
types
.
Encode
(
manage
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
CollateralizeX
)),
}
name
:=
cfg
.
ExecName
(
CollateralizeX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
plugin/dapp/collateralize/types/collateralize.pb.go
0 → 100644
View file @
a717a020
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: collateralize.proto
package
types
import
(
fmt
"fmt"
proto
"github.com/golang/protobuf/proto"
math
"math"
)
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const
_
=
proto
.
ProtoPackageIsVersion2
// please upgrade the proto package
// 放贷信息
type
Collateralize
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
TotalBalance
int64
`protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling
int64
`protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFeeRatio
int64
`protobuf:"varint,5,opt,name=stabilityFeeRatio,proto3" json:"stabilityFeeRatio,omitempty"`
CreateAddr
string
`protobuf:"bytes,6,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
Balance
int64
`protobuf:"varint,7,opt,name=balance,proto3" json:"balance,omitempty"`
BorrowRecords
[]
*
BorrowRecord
`protobuf:"bytes,8,rep,name=borrowRecords,proto3" json:"borrowRecords,omitempty"`
InvalidRecords
[]
*
BorrowRecord
`protobuf:"bytes,9,rep,name=InvalidRecords,proto3" json:"InvalidRecords,omitempty"`
Status
int32
`protobuf:"varint,10,opt,name=status,proto3" json:"status,omitempty"`
LatestLiquidationPrice
int64
`protobuf:"varint,11,opt,name=latestLiquidationPrice,proto3" json:"latestLiquidationPrice,omitempty"`
Period
int64
`protobuf:"varint,12,opt,name=period,proto3" json:"period,omitempty"`
LatestExpireTime
int64
`protobuf:"varint,13,opt,name=latestExpireTime,proto3" json:"latestExpireTime,omitempty"`
CollBalance
int64
`protobuf:"varint,14,opt,name=collBalance,proto3" json:"collBalance,omitempty"`
PreStatus
int32
`protobuf:"varint,15,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
Collateralize
)
Reset
()
{
*
m
=
Collateralize
{}
}
func
(
m
*
Collateralize
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Collateralize
)
ProtoMessage
()
{}
func
(
*
Collateralize
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
0
}
}
func
(
m
*
Collateralize
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_Collateralize
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
Collateralize
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_Collateralize
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
Collateralize
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_Collateralize
.
Merge
(
dst
,
src
)
}
func
(
m
*
Collateralize
)
XXX_Size
()
int
{
return
xxx_messageInfo_Collateralize
.
Size
(
m
)
}
func
(
m
*
Collateralize
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_Collateralize
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_Collateralize
proto
.
InternalMessageInfo
func
(
m
*
Collateralize
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
Collateralize
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
Collateralize
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
Collateralize
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
Collateralize
)
GetStabilityFeeRatio
()
int64
{
if
m
!=
nil
{
return
m
.
StabilityFeeRatio
}
return
0
}
func
(
m
*
Collateralize
)
GetCreateAddr
()
string
{
if
m
!=
nil
{
return
m
.
CreateAddr
}
return
""
}
func
(
m
*
Collateralize
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
(
m
*
Collateralize
)
GetBorrowRecords
()
[]
*
BorrowRecord
{
if
m
!=
nil
{
return
m
.
BorrowRecords
}
return
nil
}
func
(
m
*
Collateralize
)
GetInvalidRecords
()
[]
*
BorrowRecord
{
if
m
!=
nil
{
return
m
.
InvalidRecords
}
return
nil
}
func
(
m
*
Collateralize
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
Collateralize
)
GetLatestLiquidationPrice
()
int64
{
if
m
!=
nil
{
return
m
.
LatestLiquidationPrice
}
return
0
}
func
(
m
*
Collateralize
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
Collateralize
)
GetLatestExpireTime
()
int64
{
if
m
!=
nil
{
return
m
.
LatestExpireTime
}
return
0
}
func
(
m
*
Collateralize
)
GetCollBalance
()
int64
{
if
m
!=
nil
{
return
m
.
CollBalance
}
return
0
}
func
(
m
*
Collateralize
)
GetPreStatus
()
int32
{
if
m
!=
nil
{
return
m
.
PreStatus
}
return
0
}
// 借出记录
type
BorrowRecord
struct
{
AccountAddr
string
`protobuf:"bytes,1,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
StartTime
int64
`protobuf:"varint,2,opt,name=startTime,proto3" json:"startTime,omitempty"`
CollateralValue
int64
`protobuf:"varint,3,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
CollateralPrice
int64
`protobuf:"varint,4,opt,name=collateralPrice,proto3" json:"collateralPrice,omitempty"`
DebtValue
int64
`protobuf:"varint,5,opt,name=debtValue,proto3" json:"debtValue,omitempty"`
LiquidationPrice
int64
`protobuf:"varint,6,opt,name=liquidationPrice,proto3" json:"liquidationPrice,omitempty"`
Status
int32
`protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`
LiquidateTime
int64
`protobuf:"varint,8,opt,name=liquidateTime,proto3" json:"liquidateTime,omitempty"`
ExpireTime
int64
`protobuf:"varint,9,opt,name=expireTime,proto3" json:"expireTime,omitempty"`
PreStatus
int32
`protobuf:"varint,10,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
RecordId
string
`protobuf:"bytes,11,opt,name=recordId,proto3" json:"recordId,omitempty"`
CollateralizeId
string
`protobuf:"bytes,12,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
BorrowRecord
)
Reset
()
{
*
m
=
BorrowRecord
{}
}
func
(
m
*
BorrowRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
BorrowRecord
)
ProtoMessage
()
{}
func
(
*
BorrowRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
1
}
}
func
(
m
*
BorrowRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_BorrowRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
BorrowRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_BorrowRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
BorrowRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_BorrowRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
BorrowRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_BorrowRecord
.
Size
(
m
)
}
func
(
m
*
BorrowRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_BorrowRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_BorrowRecord
proto
.
InternalMessageInfo
func
(
m
*
BorrowRecord
)
GetAccountAddr
()
string
{
if
m
!=
nil
{
return
m
.
AccountAddr
}
return
""
}
func
(
m
*
BorrowRecord
)
GetStartTime
()
int64
{
if
m
!=
nil
{
return
m
.
StartTime
}
return
0
}
func
(
m
*
BorrowRecord
)
GetCollateralValue
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralValue
}
return
0
}
func
(
m
*
BorrowRecord
)
GetCollateralPrice
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralPrice
}
return
0
}
func
(
m
*
BorrowRecord
)
GetDebtValue
()
int64
{
if
m
!=
nil
{
return
m
.
DebtValue
}
return
0
}
func
(
m
*
BorrowRecord
)
GetLiquidationPrice
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationPrice
}
return
0
}
func
(
m
*
BorrowRecord
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
BorrowRecord
)
GetLiquidateTime
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidateTime
}
return
0
}
func
(
m
*
BorrowRecord
)
GetExpireTime
()
int64
{
if
m
!=
nil
{
return
m
.
ExpireTime
}
return
0
}
func
(
m
*
BorrowRecord
)
GetPreStatus
()
int32
{
if
m
!=
nil
{
return
m
.
PreStatus
}
return
0
}
func
(
m
*
BorrowRecord
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
func
(
m
*
BorrowRecord
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
// 资产价格记录
type
AssetPriceRecord
struct
{
RecordTime
int64
`protobuf:"varint,1,opt,name=recordTime,proto3" json:"recordTime,omitempty"`
BtyPrice
int64
`protobuf:"varint,2,opt,name=btyPrice,proto3" json:"btyPrice,omitempty"`
BtcPrice
int64
`protobuf:"varint,3,opt,name=btcPrice,proto3" json:"btcPrice,omitempty"`
EthPrice
int64
`protobuf:"varint,4,opt,name=ethPrice,proto3" json:"ethPrice,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
AssetPriceRecord
)
Reset
()
{
*
m
=
AssetPriceRecord
{}
}
func
(
m
*
AssetPriceRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
AssetPriceRecord
)
ProtoMessage
()
{}
func
(
*
AssetPriceRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
2
}
}
func
(
m
*
AssetPriceRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_AssetPriceRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
AssetPriceRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_AssetPriceRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
AssetPriceRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_AssetPriceRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
AssetPriceRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_AssetPriceRecord
.
Size
(
m
)
}
func
(
m
*
AssetPriceRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_AssetPriceRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_AssetPriceRecord
proto
.
InternalMessageInfo
func
(
m
*
AssetPriceRecord
)
GetRecordTime
()
int64
{
if
m
!=
nil
{
return
m
.
RecordTime
}
return
0
}
func
(
m
*
AssetPriceRecord
)
GetBtyPrice
()
int64
{
if
m
!=
nil
{
return
m
.
BtyPrice
}
return
0
}
func
(
m
*
AssetPriceRecord
)
GetBtcPrice
()
int64
{
if
m
!=
nil
{
return
m
.
BtcPrice
}
return
0
}
func
(
m
*
AssetPriceRecord
)
GetEthPrice
()
int64
{
if
m
!=
nil
{
return
m
.
EthPrice
}
return
0
}
// action
type
CollateralizeAction
struct
{
// Types that are valid to be assigned to Value:
// *CollateralizeAction_Create
// *CollateralizeAction_Borrow
// *CollateralizeAction_Repay
// *CollateralizeAction_Append
// *CollateralizeAction_Feed
// *CollateralizeAction_Retrieve
// *CollateralizeAction_Manage
Value
isCollateralizeAction_Value
`protobuf_oneof:"value"`
Ty
int32
`protobuf:"varint,10,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeAction
)
Reset
()
{
*
m
=
CollateralizeAction
{}
}
func
(
m
*
CollateralizeAction
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeAction
)
ProtoMessage
()
{}
func
(
*
CollateralizeAction
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
3
}
}
func
(
m
*
CollateralizeAction
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeAction
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeAction
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeAction
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeAction
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeAction
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeAction
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeAction
.
Size
(
m
)
}
func
(
m
*
CollateralizeAction
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeAction
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeAction
proto
.
InternalMessageInfo
type
isCollateralizeAction_Value
interface
{
isCollateralizeAction_Value
()
}
type
CollateralizeAction_Create
struct
{
Create
*
CollateralizeCreate
`protobuf:"bytes,1,opt,name=create,proto3,oneof"`
}
type
CollateralizeAction_Borrow
struct
{
Borrow
*
CollateralizeBorrow
`protobuf:"bytes,2,opt,name=borrow,proto3,oneof"`
}
type
CollateralizeAction_Repay
struct
{
Repay
*
CollateralizeRepay
`protobuf:"bytes,3,opt,name=repay,proto3,oneof"`
}
type
CollateralizeAction_Append
struct
{
Append
*
CollateralizeAppend
`protobuf:"bytes,4,opt,name=append,proto3,oneof"`
}
type
CollateralizeAction_Feed
struct
{
Feed
*
CollateralizeFeed
`protobuf:"bytes,5,opt,name=feed,proto3,oneof"`
}
type
CollateralizeAction_Retrieve
struct
{
Retrieve
*
CollateralizeRetrieve
`protobuf:"bytes,6,opt,name=retrieve,proto3,oneof"`
}
type
CollateralizeAction_Manage
struct
{
Manage
*
CollateralizeManage
`protobuf:"bytes,7,opt,name=manage,proto3,oneof"`
}
func
(
*
CollateralizeAction_Create
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Borrow
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Repay
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Append
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Feed
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Retrieve
)
isCollateralizeAction_Value
()
{}
func
(
*
CollateralizeAction_Manage
)
isCollateralizeAction_Value
()
{}
func
(
m
*
CollateralizeAction
)
GetValue
()
isCollateralizeAction_Value
{
if
m
!=
nil
{
return
m
.
Value
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetCreate
()
*
CollateralizeCreate
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Create
);
ok
{
return
x
.
Create
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetBorrow
()
*
CollateralizeBorrow
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Borrow
);
ok
{
return
x
.
Borrow
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetRepay
()
*
CollateralizeRepay
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Repay
);
ok
{
return
x
.
Repay
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetAppend
()
*
CollateralizeAppend
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Append
);
ok
{
return
x
.
Append
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetFeed
()
*
CollateralizeFeed
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Feed
);
ok
{
return
x
.
Feed
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetRetrieve
()
*
CollateralizeRetrieve
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Retrieve
);
ok
{
return
x
.
Retrieve
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetManage
()
*
CollateralizeManage
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
CollateralizeAction_Manage
);
ok
{
return
x
.
Manage
}
return
nil
}
func
(
m
*
CollateralizeAction
)
GetTy
()
int32
{
if
m
!=
nil
{
return
m
.
Ty
}
return
0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func
(
*
CollateralizeAction
)
XXX_OneofFuncs
()
(
func
(
msg
proto
.
Message
,
b
*
proto
.
Buffer
)
error
,
func
(
msg
proto
.
Message
,
tag
,
wire
int
,
b
*
proto
.
Buffer
)
(
bool
,
error
),
func
(
msg
proto
.
Message
)
(
n
int
),
[]
interface
{})
{
return
_CollateralizeAction_OneofMarshaler
,
_CollateralizeAction_OneofUnmarshaler
,
_CollateralizeAction_OneofSizer
,
[]
interface
{}{
(
*
CollateralizeAction_Create
)(
nil
),
(
*
CollateralizeAction_Borrow
)(
nil
),
(
*
CollateralizeAction_Repay
)(
nil
),
(
*
CollateralizeAction_Append
)(
nil
),
(
*
CollateralizeAction_Feed
)(
nil
),
(
*
CollateralizeAction_Retrieve
)(
nil
),
(
*
CollateralizeAction_Manage
)(
nil
),
}
}
func
_CollateralizeAction_OneofMarshaler
(
msg
proto
.
Message
,
b
*
proto
.
Buffer
)
error
{
m
:=
msg
.
(
*
CollateralizeAction
)
// value
switch
x
:=
m
.
Value
.
(
type
)
{
case
*
CollateralizeAction_Create
:
b
.
EncodeVarint
(
1
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Create
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Borrow
:
b
.
EncodeVarint
(
2
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Borrow
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Repay
:
b
.
EncodeVarint
(
3
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Repay
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Append
:
b
.
EncodeVarint
(
4
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Append
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Feed
:
b
.
EncodeVarint
(
5
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Feed
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Retrieve
:
b
.
EncodeVarint
(
6
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Retrieve
);
err
!=
nil
{
return
err
}
case
*
CollateralizeAction_Manage
:
b
.
EncodeVarint
(
7
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Manage
);
err
!=
nil
{
return
err
}
case
nil
:
default
:
return
fmt
.
Errorf
(
"CollateralizeAction.Value has unexpected type %T"
,
x
)
}
return
nil
}
func
_CollateralizeAction_OneofUnmarshaler
(
msg
proto
.
Message
,
tag
,
wire
int
,
b
*
proto
.
Buffer
)
(
bool
,
error
)
{
m
:=
msg
.
(
*
CollateralizeAction
)
switch
tag
{
case
1
:
// value.create
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeCreate
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Create
{
msg
}
return
true
,
err
case
2
:
// value.borrow
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeBorrow
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Borrow
{
msg
}
return
true
,
err
case
3
:
// value.repay
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeRepay
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Repay
{
msg
}
return
true
,
err
case
4
:
// value.append
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeAppend
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Append
{
msg
}
return
true
,
err
case
5
:
// value.feed
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeFeed
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Feed
{
msg
}
return
true
,
err
case
6
:
// value.retrieve
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeRetrieve
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Retrieve
{
msg
}
return
true
,
err
case
7
:
// value.manage
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
CollateralizeManage
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
CollateralizeAction_Manage
{
msg
}
return
true
,
err
default
:
return
false
,
nil
}
}
func
_CollateralizeAction_OneofSizer
(
msg
proto
.
Message
)
(
n
int
)
{
m
:=
msg
.
(
*
CollateralizeAction
)
// value
switch
x
:=
m
.
Value
.
(
type
)
{
case
*
CollateralizeAction_Create
:
s
:=
proto
.
Size
(
x
.
Create
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Borrow
:
s
:=
proto
.
Size
(
x
.
Borrow
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Repay
:
s
:=
proto
.
Size
(
x
.
Repay
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Append
:
s
:=
proto
.
Size
(
x
.
Append
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Feed
:
s
:=
proto
.
Size
(
x
.
Feed
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Retrieve
:
s
:=
proto
.
Size
(
x
.
Retrieve
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
CollateralizeAction_Manage
:
s
:=
proto
.
Size
(
x
.
Manage
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
nil
:
default
:
panic
(
fmt
.
Sprintf
(
"proto: unexpected type %T in oneof"
,
x
))
}
return
n
}
type
CollateralizeManage
struct
{
DebtCeiling
int64
`protobuf:"varint,1,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,2,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFeeRatio
int64
`protobuf:"varint,3,opt,name=stabilityFeeRatio,proto3" json:"stabilityFeeRatio,omitempty"`
Period
int64
`protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"`
TotalBalance
int64
`protobuf:"varint,5,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
CurrentTime
int64
`protobuf:"varint,6,opt,name=currentTime,proto3" json:"currentTime,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeManage
)
Reset
()
{
*
m
=
CollateralizeManage
{}
}
func
(
m
*
CollateralizeManage
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeManage
)
ProtoMessage
()
{}
func
(
*
CollateralizeManage
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
4
}
}
func
(
m
*
CollateralizeManage
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeManage
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeManage
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeManage
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeManage
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeManage
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeManage
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeManage
.
Size
(
m
)
}
func
(
m
*
CollateralizeManage
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeManage
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeManage
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeManage
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
CollateralizeManage
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
CollateralizeManage
)
GetStabilityFeeRatio
()
int64
{
if
m
!=
nil
{
return
m
.
StabilityFeeRatio
}
return
0
}
func
(
m
*
CollateralizeManage
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
CollateralizeManage
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
CollateralizeManage
)
GetCurrentTime
()
int64
{
if
m
!=
nil
{
return
m
.
CurrentTime
}
return
0
}
type
CollateralizeAddr
struct
{
SuperAddrs
[]
string
`protobuf:"bytes,1,rep,name=superAddrs,proto3" json:"superAddrs,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeAddr
)
Reset
()
{
*
m
=
CollateralizeAddr
{}
}
func
(
m
*
CollateralizeAddr
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeAddr
)
ProtoMessage
()
{}
func
(
*
CollateralizeAddr
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
5
}
}
func
(
m
*
CollateralizeAddr
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeAddr
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeAddr
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeAddr
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeAddr
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeAddr
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeAddr
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeAddr
.
Size
(
m
)
}
func
(
m
*
CollateralizeAddr
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeAddr
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeAddr
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeAddr
)
GetSuperAddrs
()
[]
string
{
if
m
!=
nil
{
return
m
.
SuperAddrs
}
return
nil
}
// 创建放贷
type
CollateralizeCreate
struct
{
TotalBalance
int64
`protobuf:"varint,1,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeCreate
)
Reset
()
{
*
m
=
CollateralizeCreate
{}
}
func
(
m
*
CollateralizeCreate
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeCreate
)
ProtoMessage
()
{}
func
(
*
CollateralizeCreate
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
6
}
}
func
(
m
*
CollateralizeCreate
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeCreate
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeCreate
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeCreate
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeCreate
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeCreate
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeCreate
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeCreate
.
Size
(
m
)
}
func
(
m
*
CollateralizeCreate
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeCreate
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeCreate
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeCreate
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
// 质押借出
type
CollateralizeBorrow
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Value
int64
`protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeBorrow
)
Reset
()
{
*
m
=
CollateralizeBorrow
{}
}
func
(
m
*
CollateralizeBorrow
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeBorrow
)
ProtoMessage
()
{}
func
(
*
CollateralizeBorrow
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
7
}
}
func
(
m
*
CollateralizeBorrow
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeBorrow
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeBorrow
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeBorrow
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeBorrow
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeBorrow
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeBorrow
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeBorrow
.
Size
(
m
)
}
func
(
m
*
CollateralizeBorrow
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeBorrow
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeBorrow
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeBorrow
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
CollateralizeBorrow
)
GetValue
()
int64
{
if
m
!=
nil
{
return
m
.
Value
}
return
0
}
// 质押清算
type
CollateralizeRepay
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
RecordId
string
`protobuf:"bytes,2,opt,name=recordId,proto3" json:"recordId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeRepay
)
Reset
()
{
*
m
=
CollateralizeRepay
{}
}
func
(
m
*
CollateralizeRepay
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeRepay
)
ProtoMessage
()
{}
func
(
*
CollateralizeRepay
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
8
}
}
func
(
m
*
CollateralizeRepay
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeRepay
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeRepay
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeRepay
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeRepay
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeRepay
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeRepay
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeRepay
.
Size
(
m
)
}
func
(
m
*
CollateralizeRepay
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeRepay
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeRepay
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeRepay
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
CollateralizeRepay
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
// 追加抵押物
type
CollateralizeAppend
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
RecordId
string
`protobuf:"bytes,2,opt,name=recordId,proto3" json:"recordId,omitempty"`
CollateralValue
int64
`protobuf:"varint,3,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeAppend
)
Reset
()
{
*
m
=
CollateralizeAppend
{}
}
func
(
m
*
CollateralizeAppend
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeAppend
)
ProtoMessage
()
{}
func
(
*
CollateralizeAppend
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
9
}
}
func
(
m
*
CollateralizeAppend
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeAppend
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeAppend
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeAppend
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeAppend
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeAppend
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeAppend
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeAppend
.
Size
(
m
)
}
func
(
m
*
CollateralizeAppend
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeAppend
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeAppend
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeAppend
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
CollateralizeAppend
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
func
(
m
*
CollateralizeAppend
)
GetCollateralValue
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralValue
}
return
0
}
// 喂价
type
CollateralizeFeed
struct
{
CollType
int32
`protobuf:"varint,1,opt,name=collType,proto3" json:"collType,omitempty"`
Price
[]
int64
`protobuf:"varint,2,rep,packed,name=price,proto3" json:"price,omitempty"`
Volume
[]
int64
`protobuf:"varint,3,rep,packed,name=volume,proto3" json:"volume,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeFeed
)
Reset
()
{
*
m
=
CollateralizeFeed
{}
}
func
(
m
*
CollateralizeFeed
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeFeed
)
ProtoMessage
()
{}
func
(
*
CollateralizeFeed
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
10
}
}
func
(
m
*
CollateralizeFeed
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeFeed
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeFeed
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeFeed
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeFeed
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeFeed
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeFeed
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeFeed
.
Size
(
m
)
}
func
(
m
*
CollateralizeFeed
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeFeed
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeFeed
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeFeed
)
GetCollType
()
int32
{
if
m
!=
nil
{
return
m
.
CollType
}
return
0
}
func
(
m
*
CollateralizeFeed
)
GetPrice
()
[]
int64
{
if
m
!=
nil
{
return
m
.
Price
}
return
nil
}
func
(
m
*
CollateralizeFeed
)
GetVolume
()
[]
int64
{
if
m
!=
nil
{
return
m
.
Volume
}
return
nil
}
// 收回
type
CollateralizeRetrieve
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Balance
int64
`protobuf:"varint,2,opt,name=balance,proto3" json:"balance,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeRetrieve
)
Reset
()
{
*
m
=
CollateralizeRetrieve
{}
}
func
(
m
*
CollateralizeRetrieve
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeRetrieve
)
ProtoMessage
()
{}
func
(
*
CollateralizeRetrieve
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
11
}
}
func
(
m
*
CollateralizeRetrieve
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeRetrieve
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeRetrieve
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeRetrieve
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeRetrieve
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeRetrieve
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeRetrieve
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeRetrieve
.
Size
(
m
)
}
func
(
m
*
CollateralizeRetrieve
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeRetrieve
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeRetrieve
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeRetrieve
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
CollateralizeRetrieve
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
// exec_local 放贷信息
type
ReceiptCollateralize
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
AccountAddr
string
`protobuf:"bytes,3,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
RecordId
string
`protobuf:"bytes,4,opt,name=recordId,proto3" json:"recordId,omitempty"`
Status
int32
`protobuf:"varint,5,opt,name=status,proto3" json:"status,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReceiptCollateralize
)
Reset
()
{
*
m
=
ReceiptCollateralize
{}
}
func
(
m
*
ReceiptCollateralize
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReceiptCollateralize
)
ProtoMessage
()
{}
func
(
*
ReceiptCollateralize
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
12
}
}
func
(
m
*
ReceiptCollateralize
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReceiptCollateralize
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReceiptCollateralize
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReceiptCollateralize
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReceiptCollateralize
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReceiptCollateralize
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReceiptCollateralize
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReceiptCollateralize
.
Size
(
m
)
}
func
(
m
*
ReceiptCollateralize
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReceiptCollateralize
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReceiptCollateralize
proto
.
InternalMessageInfo
func
(
m
*
ReceiptCollateralize
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
ReceiptCollateralize
)
GetAccountAddr
()
string
{
if
m
!=
nil
{
return
m
.
AccountAddr
}
return
""
}
func
(
m
*
ReceiptCollateralize
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
func
(
m
*
ReceiptCollateralize
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
// exec_local 放贷记录信息列表
type
CollateralizeRecords
struct
{
Records
[]
*
ReceiptCollateralize
`protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
CollateralizeRecords
)
Reset
()
{
*
m
=
CollateralizeRecords
{}
}
func
(
m
*
CollateralizeRecords
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CollateralizeRecords
)
ProtoMessage
()
{}
func
(
*
CollateralizeRecords
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
13
}
}
func
(
m
*
CollateralizeRecords
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_CollateralizeRecords
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
CollateralizeRecords
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_CollateralizeRecords
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
CollateralizeRecords
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_CollateralizeRecords
.
Merge
(
dst
,
src
)
}
func
(
m
*
CollateralizeRecords
)
XXX_Size
()
int
{
return
xxx_messageInfo_CollateralizeRecords
.
Size
(
m
)
}
func
(
m
*
CollateralizeRecords
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_CollateralizeRecords
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_CollateralizeRecords
proto
.
InternalMessageInfo
func
(
m
*
CollateralizeRecords
)
GetRecords
()
[]
*
ReceiptCollateralize
{
if
m
!=
nil
{
return
m
.
Records
}
return
nil
}
// 根据ID查询一期放贷信息
type
ReqCollateralizeInfo
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeInfo
)
Reset
()
{
*
m
=
ReqCollateralizeInfo
{}
}
func
(
m
*
ReqCollateralizeInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeInfo
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeInfo
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
14
}
}
func
(
m
*
ReqCollateralizeInfo
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeInfo
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeInfo
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeInfo
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeInfo
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeInfo
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeInfo
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeInfo
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeInfo
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeInfo
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeInfo
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeInfo
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
// 返回一期放贷信息
type
RepCollateralizeCurrentInfo
struct
{
Status
int32
`protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
TotalBalance
int64
`protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling
int64
`protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFeeRatio
int64
`protobuf:"varint,5,opt,name=stabilityFeeRatio,proto3" json:"stabilityFeeRatio,omitempty"`
CreateAddr
string
`protobuf:"bytes,6,opt,name=createAddr,proto3" json:"createAddr,omitempty"`
Balance
int64
`protobuf:"varint,7,opt,name=balance,proto3" json:"balance,omitempty"`
Period
int64
`protobuf:"varint,8,opt,name=period,proto3" json:"period,omitempty"`
CollateralizeId
string
`protobuf:"bytes,9,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
CollBalance
int64
`protobuf:"varint,10,opt,name=collBalance,proto3" json:"collBalance,omitempty"`
BorrowRecords
[]
*
BorrowRecord
`protobuf:"bytes,11,rep,name=borrowRecords,proto3" json:"borrowRecords,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeCurrentInfo
)
Reset
()
{
*
m
=
RepCollateralizeCurrentInfo
{}
}
func
(
m
*
RepCollateralizeCurrentInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeCurrentInfo
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeCurrentInfo
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
15
}
}
func
(
m
*
RepCollateralizeCurrentInfo
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeCurrentInfo
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeCurrentInfo
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeCurrentInfo
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeCurrentInfo
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeCurrentInfo
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeCurrentInfo
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeCurrentInfo
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeCurrentInfo
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeCurrentInfo
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeCurrentInfo
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeCurrentInfo
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetStabilityFeeRatio
()
int64
{
if
m
!=
nil
{
return
m
.
StabilityFeeRatio
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetCreateAddr
()
string
{
if
m
!=
nil
{
return
m
.
CreateAddr
}
return
""
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetCollBalance
()
int64
{
if
m
!=
nil
{
return
m
.
CollBalance
}
return
0
}
func
(
m
*
RepCollateralizeCurrentInfo
)
GetBorrowRecords
()
[]
*
BorrowRecord
{
if
m
!=
nil
{
return
m
.
BorrowRecords
}
return
nil
}
// 根据ID列表查询多期放贷信息
type
ReqCollateralizeInfos
struct
{
CollateralizeIds
[]
string
`protobuf:"bytes,1,rep,name=collateralizeIds,proto3" json:"collateralizeIds,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeInfos
)
Reset
()
{
*
m
=
ReqCollateralizeInfos
{}
}
func
(
m
*
ReqCollateralizeInfos
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeInfos
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeInfos
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
16
}
}
func
(
m
*
ReqCollateralizeInfos
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeInfos
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeInfos
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeInfos
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeInfos
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeInfos
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeInfos
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeInfos
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeInfos
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeInfos
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeInfos
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeInfos
)
GetCollateralizeIds
()
[]
string
{
if
m
!=
nil
{
return
m
.
CollateralizeIds
}
return
nil
}
// 返回多期放贷信息
type
RepCollateralizeCurrentInfos
struct
{
Infos
[]
*
RepCollateralizeCurrentInfo
`protobuf:"bytes,1,rep,name=infos,proto3" json:"infos,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeCurrentInfos
)
Reset
()
{
*
m
=
RepCollateralizeCurrentInfos
{}
}
func
(
m
*
RepCollateralizeCurrentInfos
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeCurrentInfos
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeCurrentInfos
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
17
}
}
func
(
m
*
RepCollateralizeCurrentInfos
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeCurrentInfos
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeCurrentInfos
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeCurrentInfos
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeCurrentInfos
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeCurrentInfos
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeCurrentInfos
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeCurrentInfos
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeCurrentInfos
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeCurrentInfos
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeCurrentInfos
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeCurrentInfos
)
GetInfos
()
[]
*
RepCollateralizeCurrentInfo
{
if
m
!=
nil
{
return
m
.
Infos
}
return
nil
}
// 根据放贷状态查询
type
ReqCollateralizeByStatus
struct
{
Status
int32
`protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
CollID
string
`protobuf:"bytes,2,opt,name=collID,proto3" json:"collID,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeByStatus
)
Reset
()
{
*
m
=
ReqCollateralizeByStatus
{}
}
func
(
m
*
ReqCollateralizeByStatus
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeByStatus
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeByStatus
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
18
}
}
func
(
m
*
ReqCollateralizeByStatus
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeByStatus
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeByStatus
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeByStatus
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeByStatus
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeByStatus
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeByStatus
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeByStatus
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeByStatus
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeByStatus
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeByStatus
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeByStatus
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqCollateralizeByStatus
)
GetCollID
()
string
{
if
m
!=
nil
{
return
m
.
CollID
}
return
""
}
// 根据用户地址查询
type
ReqCollateralizeByAddr
struct
{
Addr
string
`protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"`
Status
int32
`protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
CollID
string
`protobuf:"bytes,3,opt,name=collID,proto3" json:"collID,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeByAddr
)
Reset
()
{
*
m
=
ReqCollateralizeByAddr
{}
}
func
(
m
*
ReqCollateralizeByAddr
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeByAddr
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeByAddr
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
19
}
}
func
(
m
*
ReqCollateralizeByAddr
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeByAddr
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeByAddr
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeByAddr
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeByAddr
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeByAddr
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeByAddr
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeByAddr
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeByAddr
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeByAddr
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeByAddr
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeByAddr
)
GetAddr
()
string
{
if
m
!=
nil
{
return
m
.
Addr
}
return
""
}
func
(
m
*
ReqCollateralizeByAddr
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqCollateralizeByAddr
)
GetCollID
()
string
{
if
m
!=
nil
{
return
m
.
CollID
}
return
""
}
// 返回放贷ID列表
type
RepCollateralizeIDs
struct
{
IDs
[]
string
`protobuf:"bytes,1,rep,name=IDs,proto3" json:"IDs,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeIDs
)
Reset
()
{
*
m
=
RepCollateralizeIDs
{}
}
func
(
m
*
RepCollateralizeIDs
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeIDs
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeIDs
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
20
}
}
func
(
m
*
RepCollateralizeIDs
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeIDs
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeIDs
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeIDs
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeIDs
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeIDs
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeIDs
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeIDs
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeIDs
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeIDs
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeIDs
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeIDs
)
GetIDs
()
[]
string
{
if
m
!=
nil
{
return
m
.
IDs
}
return
nil
}
// 根据地址和借贷ID混合查询具体借贷记录
type
ReqCollateralizeRecordByAddr
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Addr
string
`protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Status
int32
`protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"`
RecordId
string
`protobuf:"bytes,4,opt,name=recordId,proto3" json:"recordId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
Reset
()
{
*
m
=
ReqCollateralizeRecordByAddr
{}
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeRecordByAddr
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeRecordByAddr
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
21
}
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeRecordByAddr
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeRecordByAddr
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeRecordByAddr
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeRecordByAddr
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeRecordByAddr
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeRecordByAddr
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeRecordByAddr
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeRecordByAddr
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
GetAddr
()
string
{
if
m
!=
nil
{
return
m
.
Addr
}
return
""
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqCollateralizeRecordByAddr
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
// 根据状态和借贷ID混合查询具体借贷记录
type
ReqCollateralizeRecordByStatus
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
Status
int32
`protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
RecordId
string
`protobuf:"bytes,3,opt,name=recordId,proto3" json:"recordId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
Reset
()
{
*
m
=
ReqCollateralizeRecordByStatus
{}
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeRecordByStatus
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeRecordByStatus
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
22
}
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeRecordByStatus
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeRecordByStatus
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeRecordByStatus
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeRecordByStatus
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeRecordByStatus
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeRecordByStatus
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeRecordByStatus
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeRecordByStatus
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqCollateralizeRecordByStatus
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
// 返回借贷记录
type
RepCollateralizeRecords
struct
{
Records
[]
*
BorrowRecord
`protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeRecords
)
Reset
()
{
*
m
=
RepCollateralizeRecords
{}
}
func
(
m
*
RepCollateralizeRecords
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeRecords
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeRecords
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
23
}
}
func
(
m
*
RepCollateralizeRecords
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeRecords
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeRecords
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeRecords
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeRecords
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeRecords
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeRecords
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeRecords
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeRecords
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeRecords
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeRecords
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeRecords
)
GetRecords
()
[]
*
BorrowRecord
{
if
m
!=
nil
{
return
m
.
Records
}
return
nil
}
// 精确查找借贷记录
type
ReqCollateralizeRecord
struct
{
CollateralizeId
string
`protobuf:"bytes,1,opt,name=collateralizeId,proto3" json:"collateralizeId,omitempty"`
RecordId
string
`protobuf:"bytes,2,opt,name=recordId,proto3" json:"recordId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqCollateralizeRecord
)
Reset
()
{
*
m
=
ReqCollateralizeRecord
{}
}
func
(
m
*
ReqCollateralizeRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqCollateralizeRecord
)
ProtoMessage
()
{}
func
(
*
ReqCollateralizeRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
24
}
}
func
(
m
*
ReqCollateralizeRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqCollateralizeRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqCollateralizeRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqCollateralizeRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqCollateralizeRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqCollateralizeRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqCollateralizeRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqCollateralizeRecord
.
Size
(
m
)
}
func
(
m
*
ReqCollateralizeRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqCollateralizeRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqCollateralizeRecord
proto
.
InternalMessageInfo
func
(
m
*
ReqCollateralizeRecord
)
GetCollateralizeId
()
string
{
if
m
!=
nil
{
return
m
.
CollateralizeId
}
return
""
}
func
(
m
*
ReqCollateralizeRecord
)
GetRecordId
()
string
{
if
m
!=
nil
{
return
m
.
RecordId
}
return
""
}
// 返回借贷记录
type
RepCollateralizeRecord
struct
{
Record
*
BorrowRecord
`protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeRecord
)
Reset
()
{
*
m
=
RepCollateralizeRecord
{}
}
func
(
m
*
RepCollateralizeRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeRecord
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
25
}
}
func
(
m
*
RepCollateralizeRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeRecord
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeRecord
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeRecord
)
GetRecord
()
*
BorrowRecord
{
if
m
!=
nil
{
return
m
.
Record
}
return
nil
}
// 返回放贷配置
type
RepCollateralizeConfig
struct
{
DebtCeiling
int64
`protobuf:"varint,1,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,2,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
StabilityFeeRatio
int64
`protobuf:"varint,3,opt,name=stabilityFeeRatio,proto3" json:"stabilityFeeRatio,omitempty"`
Period
int64
`protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"`
TotalBalance
int64
`protobuf:"varint,5,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
Balance
int64
`protobuf:"varint,6,opt,name=balance,proto3" json:"balance,omitempty"`
CurrentTime
int64
`protobuf:"varint,7,opt,name=currentTime,proto3" json:"currentTime,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeConfig
)
Reset
()
{
*
m
=
RepCollateralizeConfig
{}
}
func
(
m
*
RepCollateralizeConfig
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeConfig
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeConfig
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
26
}
}
func
(
m
*
RepCollateralizeConfig
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeConfig
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeConfig
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeConfig
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeConfig
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeConfig
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeConfig
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeConfig
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeConfig
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeConfig
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeConfig
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeConfig
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetStabilityFeeRatio
()
int64
{
if
m
!=
nil
{
return
m
.
StabilityFeeRatio
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
(
m
*
RepCollateralizeConfig
)
GetCurrentTime
()
int64
{
if
m
!=
nil
{
return
m
.
CurrentTime
}
return
0
}
// 返回最新抵押物价格
type
RepCollateralizePrice
struct
{
Price
int64
`protobuf:"varint,1,opt,name=price,proto3" json:"price,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizePrice
)
Reset
()
{
*
m
=
RepCollateralizePrice
{}
}
func
(
m
*
RepCollateralizePrice
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizePrice
)
ProtoMessage
()
{}
func
(
*
RepCollateralizePrice
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
27
}
}
func
(
m
*
RepCollateralizePrice
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizePrice
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizePrice
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizePrice
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizePrice
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizePrice
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizePrice
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizePrice
.
Size
(
m
)
}
func
(
m
*
RepCollateralizePrice
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizePrice
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizePrice
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizePrice
)
GetPrice
()
int64
{
if
m
!=
nil
{
return
m
.
Price
}
return
0
}
// 返回用户借贷总额
type
RepCollateralizeUserBalance
struct
{
Balance
int64
`protobuf:"varint,1,opt,name=balance,proto3" json:"balance,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepCollateralizeUserBalance
)
Reset
()
{
*
m
=
RepCollateralizeUserBalance
{}
}
func
(
m
*
RepCollateralizeUserBalance
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepCollateralizeUserBalance
)
ProtoMessage
()
{}
func
(
*
RepCollateralizeUserBalance
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_collateralize_eee08d5094b5a295
,
[]
int
{
28
}
}
func
(
m
*
RepCollateralizeUserBalance
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepCollateralizeUserBalance
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepCollateralizeUserBalance
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepCollateralizeUserBalance
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepCollateralizeUserBalance
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepCollateralizeUserBalance
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepCollateralizeUserBalance
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepCollateralizeUserBalance
.
Size
(
m
)
}
func
(
m
*
RepCollateralizeUserBalance
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepCollateralizeUserBalance
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepCollateralizeUserBalance
proto
.
InternalMessageInfo
func
(
m
*
RepCollateralizeUserBalance
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
init
()
{
proto
.
RegisterType
((
*
Collateralize
)(
nil
),
"types.Collateralize"
)
proto
.
RegisterType
((
*
BorrowRecord
)(
nil
),
"types.BorrowRecord"
)
proto
.
RegisterType
((
*
AssetPriceRecord
)(
nil
),
"types.AssetPriceRecord"
)
proto
.
RegisterType
((
*
CollateralizeAction
)(
nil
),
"types.CollateralizeAction"
)
proto
.
RegisterType
((
*
CollateralizeManage
)(
nil
),
"types.CollateralizeManage"
)
proto
.
RegisterType
((
*
CollateralizeAddr
)(
nil
),
"types.CollateralizeAddr"
)
proto
.
RegisterType
((
*
CollateralizeCreate
)(
nil
),
"types.CollateralizeCreate"
)
proto
.
RegisterType
((
*
CollateralizeBorrow
)(
nil
),
"types.CollateralizeBorrow"
)
proto
.
RegisterType
((
*
CollateralizeRepay
)(
nil
),
"types.CollateralizeRepay"
)
proto
.
RegisterType
((
*
CollateralizeAppend
)(
nil
),
"types.CollateralizeAppend"
)
proto
.
RegisterType
((
*
CollateralizeFeed
)(
nil
),
"types.CollateralizeFeed"
)
proto
.
RegisterType
((
*
CollateralizeRetrieve
)(
nil
),
"types.CollateralizeRetrieve"
)
proto
.
RegisterType
((
*
ReceiptCollateralize
)(
nil
),
"types.ReceiptCollateralize"
)
proto
.
RegisterType
((
*
CollateralizeRecords
)(
nil
),
"types.CollateralizeRecords"
)
proto
.
RegisterType
((
*
ReqCollateralizeInfo
)(
nil
),
"types.ReqCollateralizeInfo"
)
proto
.
RegisterType
((
*
RepCollateralizeCurrentInfo
)(
nil
),
"types.RepCollateralizeCurrentInfo"
)
proto
.
RegisterType
((
*
ReqCollateralizeInfos
)(
nil
),
"types.ReqCollateralizeInfos"
)
proto
.
RegisterType
((
*
RepCollateralizeCurrentInfos
)(
nil
),
"types.RepCollateralizeCurrentInfos"
)
proto
.
RegisterType
((
*
ReqCollateralizeByStatus
)(
nil
),
"types.ReqCollateralizeByStatus"
)
proto
.
RegisterType
((
*
ReqCollateralizeByAddr
)(
nil
),
"types.ReqCollateralizeByAddr"
)
proto
.
RegisterType
((
*
RepCollateralizeIDs
)(
nil
),
"types.RepCollateralizeIDs"
)
proto
.
RegisterType
((
*
ReqCollateralizeRecordByAddr
)(
nil
),
"types.ReqCollateralizeRecordByAddr"
)
proto
.
RegisterType
((
*
ReqCollateralizeRecordByStatus
)(
nil
),
"types.ReqCollateralizeRecordByStatus"
)
proto
.
RegisterType
((
*
RepCollateralizeRecords
)(
nil
),
"types.RepCollateralizeRecords"
)
proto
.
RegisterType
((
*
ReqCollateralizeRecord
)(
nil
),
"types.ReqCollateralizeRecord"
)
proto
.
RegisterType
((
*
RepCollateralizeRecord
)(
nil
),
"types.RepCollateralizeRecord"
)
proto
.
RegisterType
((
*
RepCollateralizeConfig
)(
nil
),
"types.RepCollateralizeConfig"
)
proto
.
RegisterType
((
*
RepCollateralizePrice
)(
nil
),
"types.RepCollateralizePrice"
)
proto
.
RegisterType
((
*
RepCollateralizeUserBalance
)(
nil
),
"types.RepCollateralizeUserBalance"
)
}
func
init
()
{
proto
.
RegisterFile
(
"collateralize.proto"
,
fileDescriptor_collateralize_eee08d5094b5a295
)
}
var
fileDescriptor_collateralize_eee08d5094b5a295
=
[]
byte
{
// 1208 bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0xff
,
0xdc
,
0x58
,
0x5b
,
0x6f
,
0xdc
,
0x44
,
0x14
,
0x8e
,
0xd7
,
0x7b
,
0xc9
,
0x9e
,
0x4d
,
0xd2
,
0x74
,
0x92
,
0x06
,
0xd3
,
0x46
,
0xd1
,
0x6a
,
0x84
,
0x44
,
0x04
,
0x34
,
0x12
,
0x29
,
0xb7
,
0xc2
,
0x0b
,
0xb9
,
0xb4
,
0xca
,
0x22
,
0x2a
,
0x21
,
0xd3
,
0x22
,
0xc4
,
0x4d
,
0xf2
,
0xda
,
0x93
,
0x60
,
0xc9
,
0x59
,
0x3b
,
0xf6
,
0x6c
,
0x60
,
0x79
,
0xe0
,
0x0d
,
0x9e
,
0x78
,
0xe0
,
0x89
,
0x7f
,
0xc0
,
0x2b
,
0x7f
,
0x89
,
0x9f
,
0xc0
,
0x5f
,
0x40
,
0x33
,
0x67
,
0x7c
,
0x99
,
0xb1
,
0x5d
,
0x6d
,
0x50
,
0x5f
,
0xe8
,
0x4b
,
0xb5
,
0x73
,
0xe6
,
0x3b
,
0xc7
,
0xdf
,
0x7c
,
0xe7
,
0xcc
,
0x99
,
0xd3
,
0xc0
,
0x96
,
0x1f
,
0x47
,
0x91
,
0xc7
,
0x59
,
0xea
,
0x45
,
0xe1
,
0x4f
,
0xec
,
0x20
,
0x49
,
0x63
,
0x1e
,
0x93
,
0x1e
,
0x5f
,
0x24
,
0x2c
,
0xa3
,
0x7f
,
0x77
,
0x61
,
0xfd
,
0xa4
,
0xba
,
0x4d
,
0xf6
,
0xe1
,
0x96
,
0x86
,
0x9f
,
0x04
,
0x8e
,
0x35
,
0xb6
,
0xf6
,
0x87
,
0xae
,
0x69
,
0x26
,
0x14
,
0xd6
,
0x78
,
0xcc
,
0xbd
,
0xe8
,
0xd8
,
0x8b
,
0xbc
,
0x99
,
0xcf
,
0x9c
,
0xce
,
0xd8
,
0xda
,
0xb7
,
0x5d
,
0xcd
,
0x46
,
0xc6
,
0x30
,
0x0a
,
0xd8
,
0x94
,
0x9f
,
0xb0
,
0x30
,
0x0a
,
0x67
,
0x17
,
0x8e
,
0x2d
,
0x21
,
0x55
,
0x13
,
0x79
,
0x03
,
0x36
,
0xa3
,
0xf0
,
0x6a
,
0x1e
,
0x06
,
0x1e
,
0x0f
,
0xe3
,
0x99
,
0x2b
,
0xfe
,
0x75
,
0xba
,
0x12
,
0x56
,
0xb3
,
0x93
,
0xb7
,
0xe0
,
0x76
,
0xc6
,
0xbd
,
0x69
,
0x18
,
0x85
,
0x7c
,
0xf1
,
0x98
,
0x31
,
0x04
,
0xf7
,
0x24
,
0xb8
,
0xbe
,
0x41
,
0xf6
,
0x00
,
0xfc
,
0x94
,
0x79
,
0x9c
,
0x1d
,
0x05
,
0x41
,
0xea
,
0xf4
,
0xe5
,
0x21
,
0x2a
,
0x16
,
0xe2
,
0xc0
,
0x60
,
0xaa
,
0xa8
,
0x0f
,
0x64
,
0x8c
,
0x7c
,
0x49
,
0x1e
,
0xc2
,
0xfa
,
0x34
,
0x4e
,
0xd3
,
0xf8
,
0x07
,
0x97
,
0xf9
,
0x71
,
0x1a
,
0x64
,
0xce
,
0xea
,
0xd8
,
0xde
,
0x1f
,
0x1d
,
0x6e
,
0x1d
,
0x48
,
0xd1
,
0x0e
,
0x8e
,
0x2b
,
0x7b
,
0xae
,
0x8e
,
0x24
,
0x1f
,
0xc1
,
0xc6
,
0x64
,
0x76
,
0xed
,
0x45
,
0x61
,
0x90
,
0xfb
,
0x0e
,
0xdb
,
0x7d
,
0x0d
,
0x28
,
0xd9
,
0x81
,
0x7e
,
0xc6
,
0x3d
,
0x3e
,
0xcf
,
0x1c
,
0x18
,
0x5b
,
0xfb
,
0x3d
,
0x57
,
0xad
,
0xc8
,
0x7b
,
0xb0
,
0x23
,
0x94
,
0xcf
,
0xf8
,
0xa7
,
0xa5
,
0x22
,
0x9f
,
0xa5
,
0xa1
,
0xcf
,
0x9c
,
0x91
,
0x24
,
0xde
,
0xb2
,
0x2b
,
0xe2
,
0x25
,
0x2c
,
0x0d
,
0xe3
,
0xc0
,
0x59
,
0x93
,
0x38
,
0xb5
,
0x92
,
0x9a
,
0x4b
,
0x8f
,
0x47
,
0x3f
,
0x26
,
0x61
,
0xca
,
0x9e
,
0x86
,
0x97
,
0xcc
,
0x59
,
0x57
,
0x9a
,
0x1b
,
0x76
,
0x91
,
0x41
,
0x91
,
0xf8
,
0x3c
,
0xc9
,
0x1b
,
0x98
,
0xc1
,
0x8a
,
0x89
,
0xec
,
0xc2
,
0x30
,
0x49
,
0xd9
,
0xe7
,
0x48
,
0xfc
,
0x96
,
0x24
,
0x5e
,
0x1a
,
0xe8
,
0x5f
,
0x36
,
0xac
,
0x55
,
0x0f
,
0x2d
,
0x02
,
0x7a
,
0xbe
,
0x1f
,
0xcf
,
0x67
,
0x5c
,
0xe6
,
0x05
,
0x8b
,
0xab
,
0x6a
,
0x12
,
0x01
,
0x33
,
0xee
,
0xa5
,
0x5c
,
0xf2
,
0xc2
,
0xaa
,
0x2a
,
0x0d
,
0x7a
,
0x81
,
0x7e
,
0xe1
,
0x45
,
0x73
,
0xa6
,
0xca
,
0xca
,
0x34
,
0xeb
,
0x48
,
0xd4
,
0xab
,
0x6b
,
0x22
,
0x51
,
0xa8
,
0x5d
,
0x18
,
0x8a
,
0x9a
,
0xc4
,
0x68
,
0x58
,
0x50
,
0xa5
,
0xc1
,
0x28
,
0x51
,
0x0c
,
0xd4
,
0xaf
,
0x95
,
0x68
,
0x21
,
0xb9
,
0x4a
,
0xe1
,
0x40
,
0x4b
,
0xe1
,
0x6b
,
0xb0
,
0x9e
,
0x63
,
0x51
,
0xef
,
0x55
,
0x19
,
0x40
,
0x37
,
0x8a
,
0x92
,
0x65
,
0x65
,
0x4a
,
0x86
,
0x12
,
0x52
,
0xb1
,
0xe8
,
0x52
,
0x83
,
0x21
,
0x35
,
0xb9
,
0x0b
,
0xab
,
0xa9
,
0xd4
,
0x78
,
0x12
,
0xc8
,
0xc2
,
0x18
,
0xba
,
0xc5
,
0xba
,
0xe9
,
0x5a
,
0xaf
,
0x35
,
0x5e
,
0x6b
,
0xfa
,
0xab
,
0x05
,
0x9b
,
0x47
,
0x59
,
0xc6
,
0xb8
,
0x3c
,
0x90
,
0x4a
,
0xda
,
0x1e
,
0x00
,
0x86
,
0x92
,
0xc4
,
0x2c
,
0x24
,
0x56
,
0x5a
,
0xc4
,
0xa7
,
0xa7
,
0x7c
,
0x81
,
0xd2
,
0x60
,
0xc6
,
0x8a
,
0x35
,
0xee
,
0xf9
,
0xb8
,
0x67
,
0xe7
,
0x7b
,
0x7e
,
0xb1
,
0xc7
,
0xf8
,
0xf7
,
0xd5
,
0xdc
,
0x14
,
0x6b
,
0xfa
,
0xa7
,
0x0d
,
0x5b
,
0x5a
,
0x6f
,
0x3a
,
0xf2
,
0x85
,
0xce
,
0xe4
,
0x1d
,
0xe8
,
0xe3
,
0x2d
,
0x96
,
0x3c
,
0x46
,
0x87
,
0x77
,
0xd5
,
0xd5
,
0xd2
,
0xb0
,
0x27
,
0x12
,
0x71
,
0xb6
,
0xe2
,
0x2a
,
0xac
,
0xf0
,
0xc2
,
0x9b
,
0x2a
,
0xf9
,
0xb5
,
0x78
,
0x61
,
0xa1
,
0x0a
,
0x2f
,
0xc4
,
0x92
,
0xb7
,
0xa1
,
0x97
,
0xb2
,
0xc4
,
0x5b
,
0x48
,
0xe2
,
0xa3
,
0xc3
,
0x57
,
0x9b
,
0x9c
,
0x5c
,
0x01
,
0x38
,
0x5b
,
0x71
,
0x11
,
0x29
,
0x3e
,
0xe4
,
0x25
,
0x09
,
0x9b
,
0x05
,
0xf2
,
0x40
,
0x2d
,
0x1f
,
0x3a
,
0x92
,
0x08
,
0xf1
,
0x21
,
0xc4
,
0x92
,
0x03
,
0xe8
,
0x9e
,
0x33
,
0x16
,
0xc8
,
0xe2
,
0x1b
,
0x1d
,
0x3a
,
0x4d
,
0x3e
,
0x8f
,
0x19
,
0x13
,
0x1e
,
0x12
,
0x47
,
0x3e
,
0x14
,
0xb9
,
0xe6
,
0x69
,
0xc8
,
0xae
,
0xb1
,
0x16
,
0x47
,
0x87
,
0xbb
,
0xcd
,
0xdc
,
0x10
,
0x73
,
0xb6
,
0xe2
,
0x16
,
0x78
,
0xc1
,
0xf0
,
0xd2
,
0x9b
,
0x79
,
0x17
,
0xd8
,
0xf7
,
0x5a
,
0x18
,
0x3e
,
0x91
,
0x08
,
0xc1
,
0x10
,
0xb1
,
0x64
,
0x03
,
0x3a
,
0x7c
,
0xa1
,
0x8a
,
0xae
,
0xc3
,
0x17
,
0xc7
,
0x03
,
0xe8
,
0x5d
,
0x8b
,
0xeb
,
0x41
,
0xff
,
0xb1
,
0x8c
,
0x3c
,
0xa1
,
0xab
,
0xd9
,
0xfb
,
0xad
,
0xe5
,
0x7a
,
0x7f
,
0xe7
,
0x26
,
0xbd
,
0xdf
,
0x6e
,
0xeb
,
0xfd
,
0x65
,
0xe7
,
0xeb
,
0x6a
,
0x9d
,
0xcf
,
0x7c
,
0xb3
,
0x7a
,
0xcd
,
0x6f
,
0x96
,
0x3f
,
0x4f
,
0x53
,
0x36
,
0xc3
,
0x06
,
0xd4
,
0x57
,
0x1d
,
0xaf
,
0x34
,
0xd1
,
0x07
,
0x70
,
0x5b
,
0xcf
,
0xa6
,
0xe8
,
0x5a
,
0x7b
,
0x00
,
0xd9
,
0x3c
,
0x61
,
0xa9
,
0x58
,
0x64
,
0x8e
,
0x35
,
0xb6
,
0xc5
,
0x73
,
0x53
,
0x5a
,
0xe8
,
0x43
,
0x43
,
0x25
,
0xac
,
0xd0
,
0x1a
,
0x23
,
0xab
,
0xce
,
0x88
,
0x3e
,
0x33
,
0x5c
,
0xb1
,
0x4c
,
0x6f
,
0xf0
,
0x54
,
0x6f
,
0xab
,
0x5c
,
0x29
,
0x75
,
0x55
,
0xe2
,
0xbe
,
0x02
,
0x52
,
0x2f
,
0xe4
,
0x1b
,
0x44
,
0xad
,
0xf6
,
0x9b
,
0x8e
,
0xde
,
0x6f
,
0xe8
,
0x2f
,
0x66
,
0x51
,
0x60
,
0xc5
,
0xbf
,
0x98
,
0xe8
,
0xcb
,
0xbf
,
0x01
,
0xf4
,
0x5b
,
0x23
,
0x55
,
0xe2
,
0x12
,
0x89
,
0xd0
,
0x02
,
0xf7
,
0x74
,
0x91
,
0xa0
,
0xde
,
0x3d
,
0xb7
,
0x58
,
0x0b
,
0xa9
,
0x12
,
0xd5
,
0xc6
,
0x6c
,
0x21
,
0x55
,
0x92
,
0xb7
,
0xf5
,
0xeb
,
0x38
,
0x9a
,
0x5f
,
0x8a
,
0xef
,
0x08
,
0xb3
,
0x5a
,
0xd1
,
0xaf
,
0xe1
,
0x4e
,
0xe3
,
0x7d
,
0xbb
,
0xc1
,
0x39
,
0x2b
,
0x63
,
0x48
,
0x47
,
0x1b
,
0x43
,
0xe8
,
0x1f
,
0x16
,
0x6c
,
0xbb
,
0xcc
,
0x67
,
0x61
,
0xc2
,
0xff
,
0xeb
,
0x8c
,
0x66
,
0x3c
,
0xb6
,
0x76
,
0xfd
,
0xb1
,
0xad
,
0xca
,
0xdc
,
0x35
,
0x64
,
0x2e
,
0x1f
,
0xb3
,
0x5e
,
0xf5
,
0x31
,
0xa3
,
0x4f
,
0x60
,
0xdb
,
0x38
,
0x35
,
0xce
,
0x2f
,
0xef
,
0xc2
,
0x20
,
0x55
,
0x53
,
0x8f
,
0x25
,
0xa7
,
0x9e
,
0x7b
,
0xaa
,
0xb3
,
0x34
,
0x9d
,
0xc2
,
0xcd
,
0xb1
,
0xf4
,
0x63
,
0x71
,
0xcc
,
0x2b
,
0x6d
,
0x73
,
0x32
,
0x3b
,
0x8f
,
0x97
,
0x3f
,
0xa6
,
0x18
,
0x32
,
0xee
,
0xb9
,
0x2c
,
0xd1
,
0xef
,
0x17
,
0x5e
,
0x58
,
0x19
,
0xa9
,
0x3c
,
0x88
,
0xa5
,
0xbd
,
0xca
,
0x2f
,
0xef
,
0x08
,
0x5b
,
0x36
,
0xc0
,
0x55
,
0xad
,
0x01
,
0x36
,
0x68
,
0x3a
,
0x6c
,
0x2d
,
0x9d
,
0xea
,
0xe0
,
0x07
,
0xf5
,
0xc1
,
0xaf
,
0x36
,
0x26
,
0x8f
,
0x96
,
0x1d
,
0x93
,
0xe9
,
0x09
,
0xdc
,
0x69
,
0x4a
,
0x79
,
0x26
,
0xb4
,
0x34
,
0x88
,
0xe4
,
0xbd
,
0xb4
,
0x66
,
0xa7
,
0x5f
,
0xc2
,
0xee
,
0x73
,
0x92
,
0x9e
,
0x91
,
0x0f
,
0xa0
,
0x17
,
0x8a
,
0x1f
,
0xaa
,
0x18
,
0x69
,
0x51
,
0x8c
,
0xad
,
0x3e
,
0x2e
,
0x3a
,
0xd0
,
0x4f
,
0xc0
,
0x31
,
0xe9
,
0x1d
,
0x2f
,
0xd4
,
0x94
,
0xd5
,
0x56
,
0x4b
,
0x3b
,
0xd0
,
0x17
,
0x0c
,
0x27
,
0xa7
,
0xaa
,
0x5b
,
0xa9
,
0x15
,
0xfd
,
0x06
,
0x76
,
0xea
,
0xb1
,
0x64
,
0xf6
,
0x08
,
0x74
,
0xbd
,
0x72
,
0x04
,
0x96
,
0xbf
,
0x2b
,
0xd1
,
0x3b
,
0x2d
,
0xd1
,
0x6d
,
0x2d
,
0xfa
,
0xeb
,
0xb0
,
0x65
,
0x9e
,
0x67
,
0x72
,
0x9a
,
0x91
,
0x4d
,
0xb0
,
0x27
,
0xa7
,
0xb9
,
0x72
,
0xe2
,
0x27
,
0xfd
,
0xdd
,
0x12
,
0x6a
,
0x5d
,
0x35
,
0xdc
,
0x5b
,
0xc5
,
0x66
,
0xf9
,
0xa6
,
0x92
,
0xf3
,
0xee
,
0x34
,
0xf2
,
0xb6
,
0x35
,
0xde
,
0xcf
,
0x69
,
0x2f
,
0xf4
,
0x67
,
0xd8
,
0x6b
,
0x63
,
0xa4
,
0xb4
,
0x5e
,
0x9e
,
0x53
,
0x9b
,
0x6e
,
0xd5
,
0xef
,
0xdb
,
0xc6
,
0xf7
,
0xcf
,
0xe0
,
0x15
,
0x53
,
0xbb
,
0xbc
,
0x93
,
0xdd
,
0x37
,
0x3b
,
0x59
,
0x63
,
0x51
,
0x17
,
0x1d
,
0xec
,
0xbb
,
0x7a
,
0x8e
,
0xd5
,
0xe0
,
0xfc
,
0x62
,
0x5e
,
0xd3
,
0x47
,
0x22
,
0x7e
,
0x13
,
0x53
,
0xf2
,
0x26
,
0xf4
,
0x11
,
0xa5
,
0x86
,
0xe1
,
0x46
,
0x9e
,
0x0a
,
0x42
,
0x7f
,
0xeb
,
0xd4
,
0xe3
,
0x9c
,
0xc4
,
0xb3
,
0xf3
,
0xf0
,
0xe2
,
0x7f
,
0x3b
,
0xac
,
0x55
,
0x3a
,
0x60
,
0x5f
,
0xef
,
0x80
,
0xc6
,
0x18
,
0x37
,
0xa8
,
0x8f
,
0x71
,
0xf7
,
0x45
,
0x13
,
0xd2
,
0xd5
,
0xc0
,
0xff
,
0x95
,
0x14
,
0x33
,
0x00
,
0xca
,
0x80
,
0x0b
,
0xfa
,
0x7e
,
0xfd
,
0x8d
,
0x79
,
0x96
,
0xb1
,
0xb4
,
0x81
,
0x89
,
0xa5
,
0x31
,
0x99
,
0xf6
,
0xe5
,
0x9f
,
0x5c
,
0x1e
,
0xfc
,
0x1b
,
0x00
,
0x00
,
0xff
,
0xff
,
0x0c
,
0xfe
,
0xe3
,
0xa0
,
0x89
,
0x11
,
0x00
,
0x00
,
}
plugin/dapp/collateralize/types/errors.go
0 → 100644
View file @
a717a020
// 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"
)
ErrCollateralizeStatus
=
errors
.
New
(
"ErrCollateralizeStatus"
)
ErrCollateralizeExceedDebtCeiling
=
errors
.
New
(
"ErrCollateralizeExceedDebtCeiling"
)
ErrPriceInvalid
=
errors
.
New
(
"ErrPriceInvalid"
)
ErrAssetType
=
errors
.
New
(
"ErrAssetType"
)
ErrRecordNotExist
=
errors
.
New
(
"ErrRecordNotExist"
)
ErrCollateralizeErrCloser
=
errors
.
New
(
"ErrCollateralizeErrCloser"
)
ErrRepayValueInsufficient
=
errors
.
New
(
"ErrRepayValueInsufficient"
)
ErrCollateralizeAccountExist
=
errors
.
New
(
"ErrCollateralizeAccountExist"
)
ErrCollateralizeLowBalance
=
errors
.
New
(
"ErrCollateralizeLowBalance"
)
ErrCollateralizeBalanceInvalid
=
errors
.
New
(
"ErrCollateralizeBalanceInvalid"
)
ErrPermissionDeny
=
errors
.
New
(
"ErrPermissionDeny"
)
ErrCollateralizeRecordNotEmpty
=
errors
.
New
(
"ErrCollateralizeRecordNotEmpty"
)
)
plugin/dapp/collateralize/types/table.go
0 → 100644
View file @
a717a020
package
types
import
(
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
)
var
opt
=
&
table
.
Option
{
Prefix
:
"LODB-collateralize"
,
Name
:
"coller"
,
Primary
:
"collateralizeid"
,
Index
:
[]
string
{
"status"
,
"addr"
,
"addr_status"
},
}
//NewTable 新建表
func
NewCollateralizeTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewCollatetalizeRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
opt
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//CollatetalizeRow table meta 结构
type
CollatetalizeRow
struct
{
*
ReceiptCollateralize
}
//NewIssuanceRow 新建一个meta 结构
func
NewCollatetalizeRow
()
*
CollatetalizeRow
{
return
&
CollatetalizeRow
{
ReceiptCollateralize
:
&
ReceiptCollateralize
{}}
}
//CreateRow 新建数据行
func
(
tx
*
CollatetalizeRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
ReceiptCollateralize
{}}
}
//SetPayload 设置数据
func
(
tx
*
CollatetalizeRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
txdata
,
ok
:=
data
.
(
*
ReceiptCollateralize
);
ok
{
tx
.
ReceiptCollateralize
=
txdata
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
tx
*
CollatetalizeRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"collateralizeid"
{
return
[]
byte
(
tx
.
CollateralizeId
),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
tx
.
Status
)),
nil
}
else
if
key
==
"addr"
{
return
[]
byte
(
tx
.
AccountAddr
),
nil
}
else
if
key
==
"addr_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
AccountAddr
,
tx
.
Status
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
var
optRecord
=
&
table
.
Option
{
Prefix
:
"LODB-collateralize"
,
Name
:
"borrow"
,
Primary
:
"borrowid"
,
Index
:
[]
string
{
"status"
,
"addr"
,
"addr_status"
,
"id_status"
,
"id_addr"
},
}
// NewRecordTable 借贷记录表
func
NewRecordTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewRecordRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
optRecord
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//CollatetalizeRow table meta 结构
type
CollateralizeRecordRow
struct
{
*
ReceiptCollateralize
}
//NewIssuanceRow 新建一个meta 结构
func
NewRecordRow
()
*
CollateralizeRecordRow
{
return
&
CollateralizeRecordRow
{
ReceiptCollateralize
:
&
ReceiptCollateralize
{}}
}
//CreateRow 新建数据行
func
(
tx
*
CollateralizeRecordRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
ReceiptCollateralize
{}}
}
//SetPayload 设置数据
func
(
tx
*
CollateralizeRecordRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
txdata
,
ok
:=
data
.
(
*
ReceiptCollateralize
);
ok
{
tx
.
ReceiptCollateralize
=
txdata
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
tx
*
CollateralizeRecordRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"borrowid"
{
return
[]
byte
(
tx
.
RecordId
),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
tx
.
Status
)),
nil
}
else
if
key
==
"addr"
{
return
[]
byte
(
tx
.
AccountAddr
),
nil
}
else
if
key
==
"addr_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
AccountAddr
,
tx
.
Status
)),
nil
}
else
if
key
==
"id_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
CollateralizeId
,
tx
.
Status
)),
nil
}
else
if
key
==
"id_addr"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%s"
,
tx
.
CollateralizeId
,
tx
.
AccountAddr
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
plugin/dapp/collateralize/types/tx.go
0 → 100644
View file @
a717a020
// 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
{
TotalBalance
float64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
// CollateralizeBorrowTx for construction
type
CollateralizeBorrowTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Value
float64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeRepayTx for construction
type
CollateralizeRepayTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
RecordID
string
`json:"recordID"`
Fee
int64
`json:"fee"`
}
// CollateralizeAppednTx for construction
type
CollateralizeAppendTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
RecordID
string
`json:"recordID"`
Value
float64
`json:"value"`
Fee
int64
`json:"fee"`
}
// CollateralizeFeedTx for construction
type
CollateralizeFeedTx
struct
{
Price
[]
float64
`json:"price"`
Volume
[]
int64
`json:"volume"`
Fee
int64
`json:"fee"`
}
// CollateralizeRetrieveTx for construction
type
CollateralizeRetrieveTx
struct
{
CollateralizeID
string
`json:"collateralizeId"`
Balance
float64
`json:"Balance"`
Fee
int64
`json:"fee"`
}
// CollateralizeManageTx for construction
type
CollateralizeManageTx
struct
{
DebtCeiling
float64
`json:"debtCeiling"`
LiquidationRatio
float64
`json:"liquidationRatio"`
StabilityFeeRatio
float64
`json:"stabilityFeeRatio"`
Period
int64
`json:"period"`
TotalBalance
float64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
plugin/dapp/collateralize/types/types.go
0 → 100644
View file @
a717a020
// 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
CollateralizeActionRetrieve
CollateralizeActionManage
//log for Collateralize
TyLogCollateralizeCreate
=
731
TyLogCollateralizeBorrow
=
732
TyLogCollateralizeRepay
=
733
TyLogCollateralizeAppend
=
734
TyLogCollateralizeFeed
=
735
TyLogCollateralizeRetrieve
=
736
)
// Collateralize name
const
(
CollateralizeX
=
"collateralize"
CCNYTokenName
=
"CCNY"
CollateralizePreLiquidationRatio
=
1.1
*
1e4
//TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
//Collateralize status
const
(
CollateralizeStatusCreated
=
1
+
iota
CollateralizeStatusClose
)
//暂时只支持bty
//const (
// CollateralizeAssetTypeBty = 1 + iota
// CollateralizeAssetTypeBtc
// CollateralizeAssetTypeEth
//)
const
(
CollateralizeUserStatusCreate
=
1
+
iota
CollateralizeUserStatusWarning
CollateralizeUserStatusSystemLiquidate
CollateralizeUserStatusExpire
CollateralizeUserStatusExpireLiquidate
CollateralizeUserStatusClose
)
plugin/dapp/init/init.go
View file @
a717a020
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
_
"github.com/33cn/plugin/plugin/dapp/autonomy"
//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/blackwhite"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/cert"
//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/dposvote"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/echo"
//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/evm"
//auto gen
...
@@ -11,6 +12,7 @@ import (
...
@@ -11,6 +12,7 @@ import (
_
"github.com/33cn/plugin/plugin/dapp/game"
//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/guess"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/hashlock"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/hashlock"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/issuance"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/js"
//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/lottery"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/multisig"
//auto gen
_
"github.com/33cn/plugin/plugin/dapp/multisig"
//auto gen
...
...
plugin/dapp/issuance/cmd/Makefile
0 → 100644
View file @
a717a020
all
:
chmod
+x ./build.sh
./build.sh
$(OUT)
$(FLAG)
\ No newline at end of file
plugin/dapp/issuance/cmd/build.sh
0 → 100755
View file @
a717a020
#!/usr/bin/env bash
strpwd
=
$(
pwd
)
strcmd
=
${
strpwd
##*dapp/
}
strapp
=
${
strcmd
%/cmd*
}
OUT_TESTDIR
=
"
${
1
}
/dapptest/
$strapp
"
mkdir
-p
"
${
OUT_TESTDIR
}
"
cp
./test/test-rpc.sh
"
${
OUT_TESTDIR
}
"
plugin/dapp/issuance/cmd/test/test-rpc.sh
0 → 100755
View file @
a717a020
#!/usr/bin/env bash
# shellcheck disable=SC2128
set
-e
set
-o
pipefail
MAIN_HTTP
=
""
ISSU_ID
=
""
DEBT_ID
=
""
COLL_ID
=
""
BORROW_ID
=
""
issuance_addr
=
""
collateralize_addr
=
""
SystemManager
=
"0x4257d8692ef7fe13c68b65d6a52f03933db2fa5ce8faf210b5b8b80c721ced01"
TokenSuperManager
=
"0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc"
TokenAddr
=
"1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK"
IssuanceAddr1
=
"1C9t6uNcmbUgebt9HZfKweNb58hUcq5MZY"
IssuancePriv1
=
"0x6bbfe2c8933ad56d244b68f267da576e9df539bcabc160d2ef29acc2838d5d81"
IssuanceAddr2
=
"16pjXn7vMVPqKjuVnYV44ANQGD1TRaw3ct"
IssuancePriv2
=
"0xa099f50ca616017000f338fb00c8eda133b1616f6d62f2ea3e361cc71e6c92d6"
IssuanceAddr3
=
"1CQMn9B5Rh6s8wtnYEhuQwtVxPjcXSC4qC"
IssuancePriv3
=
"0xb4c158903f373636765a0c6226b91980c5a403a37f21bc8248d45c09569e6ad3"
CollateralizeAddr
=
"1BLfkPaAGqSiXyovx3Pm9xUTMHmusLXtLZ"
CollateralizePriv
=
"0xf860db5178e6436cabd499c142084515966f88f581936ee9ccbfc0a6a77c0e70"
# shellcheck source=/dev/null
source
../dapp-test-common.sh
issuance_Create
()
{
echo
"========== # issuance create begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuanceCreate","payload":{"debtCeiling":1000.1, "totalBalance":10000.1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv1
}
"
${
MAIN_HTTP
}
ISSU_ID
=
$RAW_TX_HASH
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceInfoByID","payload":{"issuanceId":"'
"
$ISSU_ID
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceByStatus","payload":{"status":1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # issuance create end =========="
}
issuance_Manage
()
{
echo
"========== # issuance manage begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuanceManage","payload":{"addr":["'
"
${
IssuanceAddr3
}
"
'"]}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv1
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance manage end =========="
}
issuance_Feed
()
{
echo
"========== # issuance feed begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuancePriceFeed","payload":{"Price":[1], "Volume":[100]}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv2
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuancePrice","payload":{}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # issuance feed end =========="
}
issuance_Debt
()
{
echo
"========== # issuance debt begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuanceDebt","payload":{"issuanceId":"'
"
${
ISSU_ID
}
"
'", "value":10}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv3
}
"
${
MAIN_HTTP
}
DEBT_ID
=
$RAW_TX_HASH
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceRecordByID","payload":{"issuanceId": "'
"
${
ISSU_ID
}
"
'", "debtId": "'
"
${
DEBT_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceRecordsByAddr","payload":{"issuanceId": "'
"
${
ISSU_ID
}
"
'", "addr": "'
"
${
IssuanceAddr3
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceRecordsByStatus","payload":{"issuanceId": "'
"
${
ISSU_ID
}
"
'", "status": 1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # issuance debt end =========="
}
issuance_Repay
()
{
echo
"========== # issuance repay begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuanceRepay","payload":{"issuanceId":"'
"
${
ISSU_ID
}
"
'", "debtId":"'
"
${
DEBT_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv3
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceRecordsByStatus","payload":{"issuanceId": "'
"
${
ISSU_ID
}
"
'", "status": 6}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # issuance repay end =========="
}
issuance_Close
()
{
echo
"========== # issuance close begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"issuance","actionName":"IssuanceClose","payload":{"issuanceId":"'
"
${
ISSU_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv1
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"issuance","funcName":"IssuanceByStatus","payload":{"status": 2}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # issuance close end =========="
}
collateralize_Manage
()
{
echo
"========== # collateralize manage begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeManage","payload":{"debtCeiling":1000.1, "totalBalance":10000.1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv1
}
"
${
MAIN_HTTP
}
ISSU_ID
=
$RAW_TX_HASH
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeConfig","payload":{}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # collateralize manage end =========="
}
collateralize_Create
()
{
echo
"========== # collateralize create begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeCreate","payload":{"debtCeiling":1000.1, "totalBalance":10000.1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv3
}
"
${
MAIN_HTTP
}
COLL_ID
=
$RAW_TX_HASH
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeInfoByID","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeByStatus","payload":{"status":1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeByAddr","payload":{"addr":"'
"
${
IssuanceAddr3
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # collateralize create end =========="
}
collateralize_Feed
()
{
echo
"========== # collateralize feed begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizePriceFeed","payload":{"Price":[1], "Volume":[100]}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv2
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizePrice","payload":{}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # collateralize feed end =========="
}
collateralize_Borrow
()
{
echo
"========== # collateralize borrow begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeBorrow","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "value":10.1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
CollateralizePriv
}
"
${
MAIN_HTTP
}
BORROW_ID
=
$RAW_TX_HASH
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeRecordByID","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "recordId":"'
"
${
BORROW_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeRecordByStatus","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "status":1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeRecordByAddr","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "addr":"'
"
${
CollateralizeAddr
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo_rst
"
$FUNCNAME
"
"
$?
"
echo
"========== # collateralize borrow end =========="
}
collateralize_Append
()
{
echo
"========== # collateralize append begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeAppend","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "recordID":"'
"
${
BORROW_ID
}
"
'", "value":10}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
CollateralizePriv
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # collateralize append end =========="
}
collateralize_Repay
()
{
echo
"========== # collateralize repay begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeRepay","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "recordID":"'
"
${
BORROW_ID
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
CollateralizePriv
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeRecordByStatus","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "status":6}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo
"========== # collateralize repay end =========="
}
collateralize_Retrieve
()
{
echo
"========== # collateralize retrieve begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"collateralize","actionName":"CollateralizeRetrieve","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "balance":100.1}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
"
${
IssuancePriv3
}
"
${
MAIN_HTTP
}
chain33_BlockWait 1
${
MAIN_HTTP
}
data
=
$(
curl
-ksd
'{"method":"Chain33.Query","params":[{"execer":"collateralize","funcName":"CollateralizeRecordByStatus","payload":{"collateralizeId":"'
"
${
COLL_ID
}
"
'", "status":6}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
[
"
$data
"
!=
null
]
echo
"========== # collateralize retrieve end =========="
}
init
()
{
ispara
=
$(
echo
'"'
"
${
MAIN_HTTP
}
"
'"'
| jq
'.|contains("8901")'
)
echo
"ipara=
$ispara
"
if
[
"
$ispara
"
==
true
]
;
then
issuance_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.issuance"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
collateralize_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"user.p.para.collateralize"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
else
issuance_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"issuance"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
collateralize_addr
=
$(
curl
-ksd
'{"method":"Chain33.ConvertExectoAddr","params":[{"execname":"collateralize"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
fi
local
main_ip
=
${
MAIN_HTTP
//8901/8801
}
#main chain import pri key
#1C9t6uNcmbUgebt9HZfKweNb58hUcq5MZY
chain33_ImportPrivkey
${
IssuancePriv1
}
${
IssuanceAddr1
}
"issuance1"
"
${
main_ip
}
"
#16pjXn7vMVPqKjuVnYV44ANQGD1TRaw3ct
chain33_ImportPrivkey
${
IssuancePriv2
}
${
IssuanceAddr2
}
"issuance2"
"
${
main_ip
}
"
#1CQMn9B5Rh6s8wtnYEhuQwtVxPjcXSC4qC
chain33_ImportPrivkey
${
IssuancePriv3
}
${
IssuanceAddr3
}
"issuance3"
"
${
main_ip
}
"
#1BLfkPaAGqSiXyovx3Pm9xUTMHmusLXtLZ
chain33_ImportPrivkey
${
CollateralizePriv
}
${
CollateralizeAddr
}
"coll"
"
${
main_ip
}
"
if
[
"
$ispara
"
==
false
]
;
then
chain33_applyCoins
"
${
IssuanceAddr1
}
"
12000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr1
}
"
"
$main_ip
"
chain33_applyCoins
"
${
IssuanceAddr2
}
"
12000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr2
}
"
"
$main_ip
"
chain33_applyCoins
"
${
IssuanceAddr3
}
"
12000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr3
}
"
"
$main_ip
"
chain33_applyCoins
"
${
CollateralizeAddr
}
"
12000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
CollateralizeAddr
}
"
"
$main_ip
"
chain33_applyCoins
"
${
TokenAddr
}
"
12000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
TokenAddr
}
"
"
$main_ip
"
else
# tx fee
chain33_applyCoins
${
IssuanceAddr1
}
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
${
IssuanceAddr1
}
"
$main_ip
"
chain33_applyCoins
"
${
IssuanceAddr2
}
"
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr2
}
"
"
$main_ip
"
chain33_applyCoins
"
${
IssuanceAddr3
}
"
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr3
}
"
"
$main_ip
"
chain33_applyCoins
"
${
CollateralizeAddr
}
"
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
CollateralizeAddr
}
"
"
$main_ip
"
chain33_applyCoins
"
${
TokenAddr
}
"
1000000000
"
${
main_ip
}
"
chain33_QueryBalance
"
${
TokenAddr
}
"
"
$main_ip
"
local
para_ip
=
"
${
MAIN_HTTP
}
"
#para chain import pri key
#1C9t6uNcmbUgebt9HZfKweNb58hUcq5MZY
chain33_ImportPrivkey
${
IssuancePriv1
}
${
IssuanceAddr1
}
"issuance1"
"
${
para_ip
}
"
#16pjXn7vMVPqKjuVnYV44ANQGD1TRaw3ct
chain33_ImportPrivkey
${
IssuancePriv2
}
${
IssuanceAddr2
}
"issuance2"
"
${
para_ip
}
"
#1CQMn9B5Rh6s8wtnYEhuQwtVxPjcXSC4qC
chain33_ImportPrivkey
${
IssuancePriv3
}
${
IssuanceAddr3
}
"issuance3"
"
${
para_ip
}
"
#1BLfkPaAGqSiXyovx3Pm9xUTMHmusLXtLZ
chain33_ImportPrivkey
${
CollateralizePriv
}
${
CollateralizeAddr
}
"coll"
"
${
para_ip
}
"
chain33_applyCoins
"
${
IssuanceAddr3
}
"
12000000000
"
${
para_ip
}
"
chain33_QueryBalance
"
${
IssuanceAddr3
}
"
"
$para_ip
"
chain33_applyCoins
"
${
CollateralizeAddr
}
"
12000000000
"
${
para_ip
}
"
chain33_QueryBalance
"
${
CollateralizeAddr
}
"
"
$para_ip
"
fi
chain33_SendToAddress
"
${
IssuanceAddr3
}
"
"
$issuance_addr
"
10000000000
${
MAIN_HTTP
}
chain33_QueryExecBalance
"
${
IssuanceAddr3
}
"
"issuance"
"
$MAIN_HTTP
"
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
chain33_SendToAddress
"
${
CollateralizeAddr
}
"
"
$collateralize_addr
"
10000000000
${
MAIN_HTTP
}
chain33_QueryExecBalance
"
${
CollateralizeAddr
}
"
"collateralize"
"
$MAIN_HTTP
"
chain33_BlockWait 1
"
${
MAIN_HTTP
}
"
}
manage
()
{
echo
"========== # issuance add issuance-manage begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key": "issuance-manage", "value":"'
"
${
IssuanceAddr1
}
"
'", "op":"add"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
${
SystemManager
}
${
MAIN_HTTP
}
echo
"========== # issuance add issuance-manage end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add issuance-price-feed begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key": "issuance-price-feed", "value":"'
"
${
IssuanceAddr2
}
"
'", "op":"add"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
$tx
"
${
SystemManager
}
${
MAIN_HTTP
}
echo
"========== # issuance add issuance-price-feed end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
# echo "========== # issuance add issuance-guarantor begin =========="
# tx=$(curl -ksd '{"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key": "issuance-guarantor", "value":"'"${IssuanceAddr3}"'", "op":"add"}}]}' ${MAIN_HTTP} | jq -r ".result")
#
# data=$(curl -ksd '{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'"$tx"'"}]}' ${MAIN_HTTP} | jq -r ".result.txs[0]")
# ok=$(jq '(.execer != "")' <<<"$data")
#
# [ "$ok" == true ]
# echo_rst "$FUNCNAME" "$?"
#
# chain33_SignAndSendTx "$tx" ${SystemManager} ${MAIN_HTTP}
# echo "========== # issuance add issuance-guarantor end =========="
# chain33_BlockWait 1 ${MAIN_HTTP}
}
token
()
{
echo
"========== # issuance add token begin =========="
echo
"========== # issuance add token token-blacklist begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key": "token-blacklist", "value":"BTY", "op":"add"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token token-blacklist end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add token token-finisher begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer":"manage","actionName":"Modify","payload":{"key": "token-finisher", "value":"'
${
TokenAddr
}
'", "op":"add"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token token-finisher end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add token precreate begin =========="
tx
=
$(
curl
-ksd
'{"method":"token.CreateRawTokenPreCreateTx","params":[{"name": "ccny", "symbol": "CCNY", "total": 10000000000000000, "price": 0, "category": 1,"owner":"'
${
TokenAddr
}
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token precreate end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add token finish begin =========="
tx
=
$(
curl
-ksd
'{"method":"token.CreateRawTokenFinishTx","params":[{"symbol": "CCNY", "owner":"'
${
TokenAddr
}
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token finish end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add token transfer begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "10000000000000", "note": "", "to": "'
"
${
IssuanceAddr1
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "10000000000000", "note": "", "to": "'
"
${
IssuanceAddr3
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "100000000000", "note": "", "to": "'
"
${
CollateralizeAddr
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
TokenSuperManager
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token transfer end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
echo
"========== # issuance add token transfer to issuance begin =========="
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "10000000000000", "note": "", "to": "'
"
${
issuance_addr
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
IssuancePriv1
}
"
"
${
MAIN_HTTP
}
"
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "10000000000000", "note": "", "to": "'
"
${
collateralize_addr
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
IssuancePriv3
}
"
"
${
MAIN_HTTP
}
"
tx
=
$(
curl
-ksd
'{"method":"Chain33.CreateTransaction","params":[{"execer": "token","actionName":"Transfer","payload": {"cointoken":"CCNY", "amount": "100000000000", "note": "", "to": "'
"
${
collateralize_addr
}
"
'"}}]}'
${
MAIN_HTTP
}
| jq
-r
".result"
)
data
=
$(
curl
-ksd
'{"method":"Chain33.DecodeRawTransaction","params":[{"txHex":"'
"
$tx
"
'"}]}'
${
MAIN_HTTP
}
| jq
-r
".result.txs[0]"
)
ok
=
$(
jq
'(.execer != "")'
<<<
"
$data
"
)
[
"
$ok
"
==
true
]
echo_rst
"
$FUNCNAME
"
"
$?
"
chain33_SignAndSendTx
"
${
tx
}
"
"
${
CollateralizePriv
}
"
"
${
MAIN_HTTP
}
"
echo
"========== # issuance add token transfer to issuance end =========="
chain33_BlockWait 1
${
MAIN_HTTP
}
}
function
issuance_test
()
{
issuance_Create
issuance_Manage
issuance_Feed
issuance_Debt
issuance_Repay
issuance_Close
}
function
collateralize_test
()
{
collateralize_Manage
collateralize_Create
collateralize_Feed
collateralize_Borrow
collateralize_Append
collateralize_Repay
collateralize_Retrieve
}
function
main
()
{
chain33_RpcTestBegin
"issuance & collateralize"
MAIN_HTTP
=
"
$1
"
echo
"ip=
$MAIN_HTTP
"
init
manage
token
issuance_test
collateralize_test
chain33_RpcTestRst
"issuance & collateralize"
"
$CASE_ERR
"
}
chain33_debug_function main
"
$1
"
plugin/dapp/issuance/commands/cmd.go
0 → 100644
View file @
a717a020
package
commands
import
(
"fmt"
"strconv"
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"
)
// IssuanceCmd 斗牛游戏命令行
func
IssuanceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"issuance"
,
Short
:
"Issuance command"
,
Args
:
cobra
.
MinimumNArgs
(
1
),
}
cmd
.
AddCommand
(
IssuanceCreateRawTxCmd
(),
IssuanceDebtRawTxCmd
(),
IssuanceRepayRawTxCmd
(),
IssuancePriceFeedRawTxCmd
(),
IssuanceCloseRawTxCmd
(),
IssuanceManageRawTxCmd
(),
IssuanceQueryCmd
(),
)
return
cmd
}
// IssuanceCreateRawTxCmd 生成开始交易命令行
func
IssuanceCreateRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"create"
,
Short
:
"Create a issuance"
,
Run
:
IssuanceCreate
,
}
addIssuanceCreateFlags
(
cmd
)
return
cmd
}
func
addIssuanceCreateFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Float64P
(
"balance"
,
"b"
,
0
,
"balance"
)
cmd
.
MarkFlagRequired
(
"balance"
)
cmd
.
Flags
()
.
Float64P
(
"debtCeiling"
,
"d"
,
0
,
"debtCeiling"
)
cmd
.
Flags
()
.
Float64P
(
"liquidationRatio"
,
"l"
,
0
,
"liquidationRatio"
)
cmd
.
Flags
()
.
Uint64P
(
"period"
,
"p"
,
0
,
"period"
)
}
func
IssuanceCreate
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
balance
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"balance"
)
debtCeiling
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"debtCeiling"
)
liquidationRatio
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"liquidationRatio"
)
period
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"period"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceCreate"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
totalBalance
\"
:%f,
\"
debtCeiling
\"
:%f,
\"
liquidationRatio
\"
:%f,
\"
period
\"
:%d}"
,
balance
,
debtCeiling
,
liquidationRatio
,
period
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// IssuanceDebtRawTxCmd 生成开始交易命令行
func
IssuanceDebtRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"debt"
,
Short
:
"Debt a issuance"
,
Run
:
IssuanceDebt
,
}
addIssuanceDebtFlags
(
cmd
)
return
cmd
}
func
addIssuanceDebtFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"issuanceID"
,
"g"
,
""
,
"issuance ID"
)
cmd
.
MarkFlagRequired
(
"issuanceID"
)
cmd
.
Flags
()
.
Float64P
(
"value"
,
"v"
,
0
,
"value"
)
cmd
.
MarkFlagRequired
(
"value"
)
}
func
IssuanceDebt
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
value
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"value"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceDebt"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
\"
%s
\"
,
\"
value
\"
:%f}"
,
issuanceID
,
value
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// IssuanceRepayRawTxCmd 生成开始交易命令行
func
IssuanceRepayRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"repay"
,
Short
:
"Repay a issuance"
,
Run
:
IssuanceRepay
,
}
addIssuanceRepayFlags
(
cmd
)
return
cmd
}
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
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
debtID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"debtID"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceRepay"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceID
\"
:
\"
%s
\"
,
\"
debtID
\"
:
\"
%s
\"
}"
,
issuanceID
,
debtID
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// IssuancePriceFeedRawTxCmd 生成开始交易命令行
func
IssuancePriceFeedRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"feed"
,
Short
:
"price feed"
,
Run
:
IssuancePriceFeed
,
}
addIssuancePriceFeedFlags
(
cmd
)
return
cmd
}
func
addIssuancePriceFeedFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
Float64P
(
"price"
,
"p"
,
0
,
"price"
)
cmd
.
MarkFlagRequired
(
"price"
)
cmd
.
Flags
()
.
Uint64P
(
"volume"
,
"v"
,
0
,
"volume"
)
cmd
.
MarkFlagRequired
(
"volume"
)
}
func
IssuancePriceFeed
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
price
,
_
:=
cmd
.
Flags
()
.
GetFloat64
(
"price"
)
volume
,
_
:=
cmd
.
Flags
()
.
GetUint64
(
"volume"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuancePriceFeed"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
price
\"
:[ %f ],
\"
volume
\"
:[ %d ]}"
,
price
,
volume
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// IssuanceCloseRawTxCmd 生成开始交易命令行
func
IssuanceCloseRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"close"
,
Short
:
"close a issuance"
,
Run
:
IssuanceClose
,
}
addIssuanceCloseFlags
(
cmd
)
return
cmd
}
func
addIssuanceCloseFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"issuanceID"
,
"g"
,
""
,
"issuance ID"
)
cmd
.
MarkFlagRequired
(
"issuanceID"
)
}
func
IssuanceClose
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceClose"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
issuanceId
\"
:
\"
%s
\"
}"
,
issuanceID
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
// IssuanceManageRawTxCmd 生成开始交易命令行
func
IssuanceManageRawTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"manage"
,
Short
:
"manage a issuance"
,
Run
:
IssuanceManage
,
}
addIssuanceManageFlags
(
cmd
)
return
cmd
}
func
addIssuanceManageFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"addr"
,
"a"
,
""
,
"addr"
)
cmd
.
MarkFlagRequired
(
"addr"
)
}
func
IssuanceManage
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
title
,
_
:=
cmd
.
Flags
()
.
GetString
(
"title"
)
cfg
:=
types
.
GetCliSysParam
(
title
)
if
cfg
==
nil
{
panic
(
fmt
.
Sprintln
(
"can not find CliSysParam title"
,
title
))
}
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"addr"
)
params
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
cfg
.
ExecName
(
pkt
.
IssuanceX
),
ActionName
:
"IssuanceManage"
,
Payload
:
[]
byte
(
fmt
.
Sprintf
(
"{
\"
addr
\"
:[
\"
%s
\"
]}"
,
addr
)),
}
var
res
string
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.CreateTransaction"
,
params
,
&
res
)
ctx
.
RunWithoutMarshal
()
}
func
IssuacneQueryPriceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"price"
,
Short
:
"Query latest price"
,
Run
:
IssuanceQueryPrice
,
}
return
cmd
}
func
IssuanceQueryPrice
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
IssuanceX
params
.
FuncName
=
"IssuancePrice"
var
res
pkt
.
RepIssuancePrice
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
func
IssuanceQueryUserBalanceCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"balance"
,
Short
:
"Query user balance"
,
Run
:
IssuanceQueryUserBalance
,
}
addIssuanceQueryBalanceFlags
(
cmd
)
return
cmd
}
func
addIssuanceQueryBalanceFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"address"
,
"a"
,
""
,
"address"
)
cmd
.
MarkFlagRequired
(
"address"
)
}
func
IssuanceQueryUserBalance
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
addr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"address"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
IssuanceX
params
.
FuncName
=
"IssuanceUserBalance"
req
:=
&
pkt
.
ReqIssuanceRecords
{
Addr
:
addr
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceUserBalance
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
// IssuanceQueryCmd 查询命令行
func
IssuanceQueryCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"query"
,
Short
:
"Query result"
,
Run
:
IssuanceQuery
,
}
addIssuanceQueryFlags
(
cmd
)
cmd
.
AddCommand
(
IssuacneQueryPriceCmd
(),
IssuanceQueryUserBalanceCmd
(),
)
return
cmd
}
func
addIssuanceQueryFlags
(
cmd
*
cobra
.
Command
)
{
cmd
.
Flags
()
.
StringP
(
"issuanceID"
,
"g"
,
""
,
"issuance ID"
)
cmd
.
Flags
()
.
StringP
(
"address"
,
"a"
,
""
,
"address"
)
cmd
.
Flags
()
.
StringP
(
"index"
,
"i"
,
""
,
"index"
)
cmd
.
Flags
()
.
StringP
(
"status"
,
"s"
,
""
,
"status"
)
cmd
.
Flags
()
.
StringP
(
"issuanceIDs"
,
"e"
,
""
,
"issuance IDs"
)
cmd
.
Flags
()
.
StringP
(
"debtID"
,
"d"
,
""
,
"debt ID"
)
}
func
IssuanceQuery
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
rpcLaddr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"rpc_laddr"
)
issuanceID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceID"
)
address
,
_
:=
cmd
.
Flags
()
.
GetString
(
"address"
)
statusStr
,
_
:=
cmd
.
Flags
()
.
GetString
(
"status"
)
issuanceIDs
,
_
:=
cmd
.
Flags
()
.
GetString
(
"issuanceIDs"
)
debtID
,
_
:=
cmd
.
Flags
()
.
GetString
(
"debtID"
)
var
params
rpctypes
.
Query4Jrpc
params
.
Execer
=
pkt
.
IssuanceX
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
!=
""
{
if
address
!=
""
{
params
.
FuncName
=
"IssuanceRecordsByAddr"
req
:=
&
pkt
.
ReqIssuanceRecords
{
IssuanceId
:
issuanceID
,
Status
:
int32
(
status
),
Addr
:
address
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
statusStr
!=
""
{
params
.
FuncName
=
"IssuanceRecordsByStatus"
req
:=
&
pkt
.
ReqIssuanceRecords
{
IssuanceId
:
issuanceID
,
Status
:
int32
(
status
),
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceRecords
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
debtID
!=
""
{
params
.
FuncName
=
"IssuanceRecordByID"
req
:=
&
pkt
.
ReqIssuanceRecords
{
IssuanceId
:
issuanceID
,
DebtId
:
debtID
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceDebtInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
params
.
FuncName
=
"IssuanceInfoByID"
req
:=
&
pkt
.
ReqIssuanceInfo
{
IssuanceId
:
issuanceID
,
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceCurrentInfo
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
}
else
if
statusStr
!=
""
{
params
.
FuncName
=
"IssuanceByStatus"
req
:=
&
pkt
.
ReqIssuanceByStatus
{
Status
:
int32
(
status
)}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
var
res
pkt
.
RepIssuanceIDs
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
if
issuanceIDs
!=
""
{
params
.
FuncName
=
"IssuanceInfoByIDs"
var
issuanceIDsS
[]
string
issuanceIDsS
=
append
(
issuanceIDsS
,
issuanceIDs
)
issuanceIDsS
=
append
(
issuanceIDsS
,
issuanceIDs
)
req
:=
&
pkt
.
ReqIssuanceInfos
{
IssuanceIds
:
issuanceIDsS
}
params
.
Payload
=
types
.
MustPBToJSON
(
req
)
fmt
.
Println
(
params
.
Payload
)
var
res
pkt
.
RepIssuanceCurrentInfos
ctx
:=
jsonrpc
.
NewRPCCtx
(
rpcLaddr
,
"Chain33.Query"
,
params
,
&
res
)
ctx
.
Run
()
}
else
{
cmd
.
Help
()
}
}
plugin/dapp/issuance/executor/doc.go
0 → 100644
View file @
a717a020
// 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/issuance/executor/exec.go
0 → 100644
View file @
a717a020
// 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/issuance/types"
)
// Exec_Create Action
func
(
c
*
Issuance
)
Exec_Create
(
payload
*
pty
.
IssuanceCreate
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewIssuanceAction
(
c
,
tx
,
index
)
return
actiondb
.
IssuanceCreate
(
payload
)
}
// Exec_Borrow Action
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
)
}
// Exec_Repay Action
func
(
c
*
Issuance
)
Exec_Repay
(
payload
*
pty
.
IssuanceRepay
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewIssuanceAction
(
c
,
tx
,
index
)
return
actiondb
.
IssuanceRepay
(
payload
)
}
// Exec_Feed Action
func
(
c
*
Issuance
)
Exec_Feed
(
payload
*
pty
.
IssuanceFeed
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
actiondb
:=
NewIssuanceAction
(
c
,
tx
,
index
)
return
actiondb
.
IssuanceFeed
(
payload
)
}
// Exec_Close Action
func
(
c
*
Issuance
)
Exec_Close
(
payload
*
pty
.
IssuanceClose
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
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
0 → 100644
View file @
a717a020
// 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/issuance/types"
)
func
(
c
*
Issuance
)
execDelLocal
(
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
kvs
,
err
:=
c
.
DelRollbackKV
(
tx
,
tx
.
Execer
)
if
err
!=
nil
{
return
nil
,
err
}
dbSet
:=
&
types
.
LocalDBSet
{}
dbSet
.
KV
=
append
(
dbSet
.
KV
,
kvs
...
)
return
dbSet
,
nil
}
// ExecDelLocal_Create Action
func
(
c
*
Issuance
)
ExecDelLocal_Create
(
payload
*
pty
.
IssuanceCreate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Debt Action
func
(
c
*
Issuance
)
ExecDelLocal_Debt
(
payload
*
pty
.
IssuanceDebt
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Repay Action
func
(
c
*
Issuance
)
ExecDelLocal_Repay
(
payload
*
pty
.
IssuanceRepay
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Feed Action
func
(
c
*
Issuance
)
ExecDelLocal_Feed
(
payload
*
pty
.
IssuanceFeed
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Close Action
func
(
c
*
Issuance
)
ExecDelLocal_Close
(
payload
*
pty
.
IssuanceClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
// ExecDelLocal_Manage Action
func
(
c
*
Issuance
)
ExecDelLocal_Manage
(
payload
*
pty
.
IssuanceManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execDelLocal
(
tx
,
receiptData
)
}
plugin/dapp/issuance/executor/exec_local.go
0 → 100644
View file @
a717a020
// 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/issuance/types"
)
func
(
c
*
Issuance
)
execLocal
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
)
(
*
types
.
LocalDBSet
,
error
)
{
set
:=
&
types
.
LocalDBSet
{}
for
_
,
item
:=
range
receipt
.
Logs
{
if
item
.
Ty
>=
pty
.
TyLogIssuanceCreate
&&
item
.
Ty
<=
pty
.
TyLogIssuanceClose
{
var
issuanceLog
pty
.
ReceiptIssuance
err
:=
types
.
Decode
(
item
.
Log
,
&
issuanceLog
)
if
err
!=
nil
{
return
nil
,
err
}
if
item
.
Ty
==
pty
.
TyLogIssuanceCreate
||
item
.
Ty
==
pty
.
TyLogIssuanceClose
{
IDtable
:=
pty
.
NewIssuanceTable
(
c
.
GetLocalDB
())
err
=
IDtable
.
Replace
(
&
pty
.
ReceiptIssuanceID
{
IssuanceId
:
issuanceLog
.
IssuanceId
,
Status
:
issuanceLog
.
Status
})
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
IDtable
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kvs
...
)
}
else
{
recordTable
:=
pty
.
NewRecordTable
(
c
.
GetLocalDB
())
err
=
recordTable
.
Replace
(
&
pty
.
ReceiptIssuance
{
IssuanceId
:
issuanceLog
.
IssuanceId
,
Status
:
issuanceLog
.
Status
,
DebtId
:
issuanceLog
.
DebtId
,
AccountAddr
:
issuanceLog
.
AccountAddr
})
if
err
!=
nil
{
return
nil
,
err
}
kvs
,
err
:=
recordTable
.
Save
()
if
err
!=
nil
{
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
kvs
...
)
}
}
}
set
.
KV
=
c
.
AddRollbackKV
(
tx
,
[]
byte
(
pty
.
IssuanceX
),
set
.
KV
)
return
set
,
nil
}
// ExecLocal_Create Action
func
(
c
*
Issuance
)
ExecLocal_Create
(
payload
*
pty
.
IssuanceCreate
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Debt Action
func
(
c
*
Issuance
)
ExecLocal_Debt
(
payload
*
pty
.
IssuanceDebt
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Repay Action
func
(
c
*
Issuance
)
ExecLocal_Repay
(
payload
*
pty
.
IssuanceRepay
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Feed Action
func
(
c
*
Issuance
)
ExecLocal_Feed
(
payload
*
pty
.
IssuanceFeed
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Close Action
func
(
c
*
Issuance
)
ExecLocal_Close
(
payload
*
pty
.
IssuanceClose
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
// ExecLocal_Manage Action
func
(
c
*
Issuance
)
ExecLocal_Manage
(
payload
*
pty
.
IssuanceManage
,
tx
*
types
.
Transaction
,
receiptData
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
c
.
execLocal
(
tx
,
receiptData
)
}
plugin/dapp/issuance/executor/issuance.go
0 → 100644
View file @
a717a020
// 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/issuance/types"
)
var
clog
=
log
.
New
(
"module"
,
"execs.issuance"
)
var
driverName
=
pty
.
IssuanceX
func
InitExecType
()
{
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
Issuance
{}))
}
// Init issuance
func
Init
(
name
string
,
cfg
*
types
.
Chain33Config
,
sub
[]
byte
)
{
driverName
:=
GetName
()
if
name
!=
driverName
{
panic
(
"system dapp can't be rename"
)
}
if
sub
!=
nil
{
types
.
MustDecode
(
sub
,
&
cfg
)
}
drivers
.
Register
(
cfg
,
driverName
,
newIssuance
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
}
// GetName for Issuance
func
GetName
()
string
{
return
newIssuance
()
.
GetName
()
}
// Issuance driver
type
Issuance
struct
{
drivers
.
DriverBase
}
func
newIssuance
()
drivers
.
Driver
{
c
:=
&
Issuance
{}
c
.
SetChild
(
c
)
c
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
return
c
}
// GetDriverName for Issuance
func
(
c
*
Issuance
)
GetDriverName
()
string
{
return
pty
.
IssuanceX
}
// CheckReceiptExecOk return true to check if receipt ty is ok
func
(
c
*
Issuance
)
CheckReceiptExecOk
()
bool
{
return
true
}
// ExecutorOrder 设置localdb的EnableRead
func
(
c
*
Issuance
)
ExecutorOrder
()
int64
{
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
if
cfg
.
IsFork
(
c
.
GetHeight
(),
"ForkLocalDBAccess"
)
{
return
drivers
.
ExecLocalSameTime
}
return
c
.
DriverBase
.
ExecutorOrder
()
}
plugin/dapp/issuance/executor/issuance_test.go
0 → 100644
View file @
a717a020
package
executor
import
(
"testing"
"time"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/account"
apimock
"github.com/33cn/chain33/client/mocks"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
pty
"github.com/33cn/chain33/system/dapp/manage/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pkt
"github.com/33cn/plugin/plugin/dapp/issuance/types"
tokenE
"github.com/33cn/plugin/plugin/dapp/token/executor"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)
type
execEnv
struct
{
blockTime
int64
blockHeight
int64
difficulty
uint64
kvdb
dbm
.
KVDB
api
client
.
QueueProtocolAPI
db
dbm
.
KV
execAddr
string
cfg
*
types
.
Chain33Config
}
var
(
PrivKeyA
=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
// 1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4
PrivKeyB
=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
// 1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR
PrivKeyC
=
"0xc2b31057b8692a56c7dd18199df71c1d21b781c0b6858c52997c9dbf778e8550"
// 12evczYyX9ZKPYvwSEvRkRyTjpSrJuLudg
Nodes
=
[][]
byte
{
[]
byte
(
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
),
[]
byte
(
"1JRNjdEqp4LJ5fqycUBm9ayCKSeeskgMKR"
),
[]
byte
(
"12evczYyX9ZKPYvwSEvRkRyTjpSrJuLudg"
),
}
total
=
10000
*
types
.
Coin
totalToken
=
100000
*
types
.
Coin
)
func
manageKeySet
(
key
string
,
value
string
,
db
dbm
.
KV
)
{
var
item
types
.
ConfigItem
item
.
Key
=
key
item
.
Addr
=
value
item
.
Ty
=
pty
.
ConfigItemArrayConfig
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
item
.
GetArr
()
.
Value
=
append
(
item
.
GetArr
()
.
Value
,
value
)
manageKey
:=
types
.
ManageKey
(
key
)
valueSave
:=
types
.
Encode
(
&
item
)
db
.
Set
([]
byte
(
manageKey
),
valueSave
)
}
func
initEnv
()
*
execEnv
{
cfg
:=
types
.
NewChain33Config
(
types
.
GetDefaultCfgstring
())
cfg
.
SetTitleOnlyForTest
(
"chain33"
)
Init
(
pkt
.
IssuanceX
,
cfg
,
nil
)
_
,
_
,
kvdb
:=
util
.
CreateTestDB
()
accountA
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountAToken
:=
types
.
Account
{
Balance
:
totalToken
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
0
]),
}
accountB
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
1
]),
}
accountC
:=
types
.
Account
{
Balance
:
total
,
Frozen
:
0
,
Addr
:
string
(
Nodes
[
2
]),
}
api
:=
new
(
apimock
.
QueueProtocolAPI
)
api
.
On
(
"GetConfig"
,
mock
.
Anything
)
.
Return
(
cfg
,
nil
)
execAddr
:=
dapp
.
ExecAddress
(
pkt
.
IssuanceX
)
stateDB
,
_
:=
dbm
.
NewGoMemDB
(
"1"
,
"2"
,
100
)
accA
:=
account
.
NewCoinsAccount
(
cfg
)
accA
.
SetDB
(
stateDB
)
accA
.
SaveExecAccount
(
execAddr
,
&
accountA
)
manageKeySet
(
"issuance-manage"
,
accountA
.
Addr
,
stateDB
)
tokenAccA
,
_
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pkt
.
CCNYTokenName
,
stateDB
)
tokenAccA
.
SaveExecAccount
(
execAddr
,
&
accountAToken
)
accB
:=
account
.
NewCoinsAccount
(
cfg
)
accB
.
SetDB
(
stateDB
)
accB
.
SaveExecAccount
(
execAddr
,
&
accountB
)
manageKeySet
(
"issuance-price-feed"
,
accountB
.
Addr
,
stateDB
)
accC
:=
account
.
NewCoinsAccount
(
cfg
)
accC
.
SetDB
(
stateDB
)
accC
.
SaveExecAccount
(
execAddr
,
&
accountC
)
manageKeySet
(
"issuance-guarantor"
,
accountC
.
Addr
,
stateDB
)
return
&
execEnv
{
blockTime
:
time
.
Now
()
.
Unix
(),
blockHeight
:
cfg
.
GetDappFork
(
pkt
.
IssuanceX
,
"Enable"
),
difficulty
:
1539918074
,
kvdb
:
kvdb
,
api
:
api
,
db
:
stateDB
,
execAddr
:
execAddr
,
cfg
:
cfg
,
}
}
func
TestIssuance
(
t
*
testing
.
T
)
{
env
:=
initEnv
()
// issuance create
p1
:=
&
pkt
.
IssuanceCreateTx
{
TotalBalance
:
1000
,
DebtCeiling
:
100
,
LiquidationRatio
:
0.25
,
Period
:
5
,
}
createTx
,
err
:=
pkt
.
CreateRawIssuanceCreateTx
(
env
.
cfg
,
p1
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
:=
newIssuance
()
exec
.
SetAPI
(
env
.
api
)
exec
.
SetStateDB
(
env
.
db
)
assert
.
Equal
(
t
,
exec
.
GetCoinsAccount
()
.
LoadExecAccount
(
string
(
Nodes
[
0
]),
env
.
execAddr
)
.
GetBalance
(),
total
)
exec
.
SetLocalDB
(
env
.
kvdb
)
exec
.
SetEnv
(
env
.
blockHeight
,
env
.
blockTime
,
env
.
difficulty
)
receipt
,
err
:=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
:=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
:=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
issuanceID
:=
createTx
.
Hash
()
// query issuance by id
res
,
err
:=
exec
.
Query
(
"IssuanceInfoByID"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceInfo
{
IssuanceId
:
common
.
ToHex
(
issuanceID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceByStatus
{
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuances by ids
var
issuanceIDsS
[]
string
issuanceIDsS
=
append
(
issuanceIDsS
,
common
.
ToHex
(
issuanceID
))
res
,
err
=
exec
.
Query
(
"IssuanceInfoByIDs"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceInfos
{
IssuanceIds
:
issuanceIDsS
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// issuance price
p2
:=
&
pkt
.
IssuanceFeedTx
{}
p2
.
Price
=
append
(
p2
.
Price
,
1
)
p2
.
Volume
=
append
(
p2
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawIssuanceFeedTx
(
env
.
cfg
,
p2
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query issuance by id
res
,
err
=
exec
.
Query
(
"IssuancePrice"
,
nil
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// issuance manage
p3
:=
&
pkt
.
IssuanceManageTx
{}
p3
.
Addr
=
append
(
p3
.
Addr
,
string
(
Nodes
[
1
]))
createTx
,
err
=
pkt
.
CreateRawIssuanceManageTx
(
env
.
cfg
,
p3
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// issuance debt
p4
:=
&
pkt
.
IssuanceDebtTx
{
IssuanceID
:
common
.
ToHex
(
issuanceID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawIssuanceDebtTx
(
env
.
cfg
,
p4
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
debtID
:=
createTx
.
Hash
()
// query issuance by id
res
,
err
=
exec
.
Query
(
"IssuanceRecordByID"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
IssuanceId
:
common
.
ToHex
(
issuanceID
),
DebtId
:
common
.
ToHex
(
debtID
)}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance by addr
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByAddr"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
])}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByAddr"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance user balance
res
,
err
=
exec
.
Query
(
"IssuanceUserBalance"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
100
*
types
.
Coin
,
res
.
(
*
pkt
.
RepIssuanceUserBalance
)
.
Balance
)
// issuance repay
p5
:=
&
pkt
.
IssuanceRepayTx
{
IssuanceID
:
common
.
ToHex
(
issuanceID
),
DebtID
:
common
.
ToHex
(
debtID
),
}
createTx
,
err
=
pkt
.
CreateRawIssuanceRepayTx
(
env
.
cfg
,
p5
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Status
:
6
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance by addr
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByAddr"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
])}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByAddr"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
6
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// query issuance user balance
res
,
err
=
exec
.
Query
(
"IssuanceUserBalance"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Addr
:
string
(
Nodes
[
1
]),
Status
:
1
}))
assert
.
Nil
(
t
,
err
)
assert
.
Equal
(
t
,
int64
(
0
),
res
.
(
*
pkt
.
RepIssuanceUserBalance
)
.
Balance
)
// issuance liquidate
p6
:=
&
pkt
.
IssuanceDebtTx
{
IssuanceID
:
common
.
ToHex
(
issuanceID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawIssuanceDebtTx
(
env
.
cfg
,
p6
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
p7
:=
&
pkt
.
IssuanceFeedTx
{}
p7
.
Price
=
append
(
p7
.
Price
,
0.25
)
p7
.
Volume
=
append
(
p7
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawIssuanceFeedTx
(
env
.
cfg
,
p7
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Status
:
3
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// expire liquidate
p8
:=
&
pkt
.
IssuanceDebtTx
{
IssuanceID
:
common
.
ToHex
(
issuanceID
),
Value
:
100
,
}
createTx
,
err
=
pkt
.
CreateRawIssuanceDebtTx
(
env
.
cfg
,
p8
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
1
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
p9
:=
&
pkt
.
IssuanceFeedTx
{}
p9
.
Price
=
append
(
p9
.
Price
,
1
)
p9
.
Volume
=
append
(
p9
.
Volume
,
100
)
createTx
,
err
=
pkt
.
CreateRawIssuanceFeedTx
(
env
.
cfg
,
p9
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyB
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
1
,
env
.
blockTime
+
6
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
t
.
Log
(
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceRecordsByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceRecords
{
Status
:
5
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
// issuance close
p10
:=
&
pkt
.
IssuanceCloseTx
{
IssuanceID
:
common
.
ToHex
(
issuanceID
),
}
createTx
,
err
=
pkt
.
CreateRawIssuanceCloseTx
(
env
.
cfg
,
p10
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process"
,
"err"
,
err
)
}
createTx
.
Execer
=
[]
byte
(
pkt
.
IssuanceX
)
createTx
,
err
=
signTx
(
createTx
,
PrivKeyA
)
if
err
!=
nil
{
t
.
Error
(
"RPC_Default_Process sign"
,
"err"
,
err
)
}
exec
.
SetEnv
(
env
.
blockHeight
+
2
,
env
.
blockTime
+
2
,
env
.
difficulty
)
receipt
,
err
=
exec
.
Exec
(
createTx
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
receipt
)
for
_
,
kv
:=
range
receipt
.
KV
{
env
.
db
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
receiptData
=
&
types
.
ReceiptData
{
Ty
:
receipt
.
Ty
,
Logs
:
receipt
.
Logs
}
set
,
err
=
exec
.
ExecLocal
(
createTx
,
receiptData
,
int
(
1
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
set
)
for
_
,
kv
:=
range
set
.
KV
{
env
.
kvdb
.
Set
(
kv
.
Key
,
kv
.
Value
)
}
// query issuance by status
res
,
err
=
exec
.
Query
(
"IssuanceByStatus"
,
types
.
Encode
(
&
pkt
.
ReqIssuanceByStatus
{
Status
:
2
}))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
res
)
}
func
signTx
(
tx
*
types
.
Transaction
,
hexPrivKey
string
)
(
*
types
.
Transaction
,
error
)
{
signType
:=
types
.
SECP256K1
c
,
err
:=
crypto
.
New
(
types
.
GetSignName
(
pkt
.
IssuanceX
,
signType
))
if
err
!=
nil
{
return
tx
,
err
}
bytes
,
err
:=
common
.
FromHex
(
hexPrivKey
[
:
])
if
err
!=
nil
{
return
tx
,
err
}
privKey
,
err
:=
c
.
PrivKeyFromBytes
(
bytes
)
if
err
!=
nil
{
return
tx
,
err
}
tx
.
Sign
(
int32
(
signType
),
privKey
)
return
tx
,
nil
}
plugin/dapp/issuance/executor/issuancedb.go
0 → 100644
View file @
a717a020
// 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/account"
"github.com/33cn/chain33/common"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/issuance/types"
tokenE
"github.com/33cn/plugin/plugin/dapp/token/executor"
)
// List control
const
(
ListDESC
=
int32
(
0
)
// list降序
ListASC
=
int32
(
1
)
// list升序
DefaultCount
=
int32
(
20
)
// 默认一次取多少条记录
MaxCount
=
int32
(
100
)
// 最多取100条
)
const
(
Coin
=
types
.
Coin
// 1e8
DefaultDebtCeiling
=
100000
*
Coin
// 默认借贷限额
DefaultLiquidationRatio
=
0.25
*
1e4
// 默认质押比
DefaultPeriod
=
3600
*
24
*
365
// 默认合约限期
PriceWarningRate
=
1.3
*
1e4
// 价格提前预警率
ExpireWarningTime
=
3600
*
24
*
10
// 提前10天超时预警
)
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
manageKey
:=
types
.
ManageKey
(
key
)
value
,
err
:=
db
.
Get
([]
byte
(
manageKey
))
if
err
!=
nil
{
return
nil
,
err
}
return
value
,
nil
}
func
getGuarantorAddr
(
db
dbm
.
KV
)
(
string
,
error
)
{
value
,
err
:=
getManageKey
(
pty
.
GuarantorKey
,
db
)
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"getGuarantorAddr"
,
err
)
return
""
,
err
}
if
value
==
nil
{
clog
.
Error
(
"IssuancePriceFeed guarantorKey found nil value"
)
return
""
,
err
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"getGuarantorAddr"
,
err
)
return
""
,
err
}
return
item
.
GetArr
()
.
Value
[
0
],
nil
}
func
isRightAddr
(
key
string
,
addr
string
,
db
dbm
.
KV
)
bool
{
value
,
err
:=
getManageKey
(
key
,
db
)
if
err
!=
nil
{
clog
.
Error
(
"isRightAddr"
,
"Key"
,
key
)
return
false
}
if
value
==
nil
{
clog
.
Error
(
"isRightAddr"
,
"key"
,
key
,
"error"
,
"Found key nil value"
)
return
false
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"isRightAddr"
,
"Decode"
,
value
)
return
false
}
for
_
,
op
:=
range
item
.
GetArr
()
.
Value
{
if
op
==
addr
{
return
true
}
}
return
false
}
func
isSuperAddr
(
addr
string
,
db
dbm
.
KV
)
bool
{
data
,
err
:=
db
.
Get
(
AddrKey
())
if
err
!=
nil
{
clog
.
Error
(
"getSuperAddr"
,
"error"
,
err
)
return
false
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
data
,
&
item
)
if
err
!=
nil
{
clog
.
Error
(
"isSuperAddr"
,
"Decode"
,
data
)
return
false
}
for
_
,
op
:=
range
item
.
GetArr
()
.
Value
{
if
op
==
addr
{
return
true
}
}
return
false
}
// IssuanceDB def
type
IssuanceDB
struct
{
pty
.
Issuance
}
// GetKVSet for IssuanceDB
func
(
issu
*
IssuanceDB
)
GetKVSet
()
(
kvset
[]
*
types
.
KeyValue
)
{
value
:=
types
.
Encode
(
&
issu
.
Issuance
)
kvset
=
append
(
kvset
,
&
types
.
KeyValue
{
Key
:
Key
(
issu
.
IssuanceId
),
Value
:
value
})
return
kvset
}
// Save for IssuanceDB
func
(
issu
*
IssuanceDB
)
Save
(
db
dbm
.
KV
)
{
set
:=
issu
.
GetKVSet
()
for
i
:=
0
;
i
<
len
(
set
);
i
++
{
db
.
Set
(
set
[
i
]
.
GetKey
(),
set
[
i
]
.
Value
)
}
}
// Key for Issuance
func
Key
(
id
string
)
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
IssuanceX
+
"-"
)
...
)
key
=
append
(
key
,
[]
byte
(
id
)
...
)
return
key
}
// Key for IssuanceAddrConfig
func
AddrKey
()
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
IssuanceX
+
"-addr"
)
...
)
return
key
}
// Key for IssuancePriceFeed
func
PriceKey
()
(
key
[]
byte
)
{
key
=
append
(
key
,
[]
byte
(
"mavl-"
+
pty
.
IssuanceX
+
"-price"
)
...
)
return
key
}
// Action struct
type
Action
struct
{
coinsAccount
*
account
.
DB
// bty账户
tokenAccount
*
account
.
DB
// ccny账户
db
dbm
.
KV
localDB
dbm
.
KVDB
txhash
[]
byte
fromaddr
string
blocktime
int64
height
int64
execaddr
string
difficulty
uint64
index
int
Issuance
*
Issuance
}
// NewIssuanceAction generate New Action
func
NewIssuanceAction
(
c
*
Issuance
,
tx
*
types
.
Transaction
,
index
int
)
*
Action
{
hash
:=
tx
.
Hash
()
fromaddr
:=
tx
.
From
()
cfg
:=
c
.
GetAPI
()
.
GetConfig
()
tokenDb
,
err
:=
account
.
NewAccountDB
(
cfg
,
tokenE
.
GetName
(),
pty
.
CCNYTokenName
,
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"NewIssuanceAction"
,
"Get Account DB error"
,
"error"
,
err
)
return
nil
}
return
&
Action
{
coinsAccount
:
c
.
GetCoinsAccount
(),
tokenAccount
:
tokenDb
,
db
:
c
.
GetStateDB
(),
localDB
:
c
.
GetLocalDB
(),
txhash
:
hash
,
fromaddr
:
fromaddr
,
blocktime
:
c
.
GetBlockTime
(),
height
:
c
.
GetHeight
(),
execaddr
:
dapp
.
ExecAddress
(
string
(
tx
.
Execer
)),
difficulty
:
c
.
GetDifficulty
(),
index
:
index
,
Issuance
:
c
}
}
// GetCreateReceiptLog generate logs for Issuance create action
func
(
action
*
Action
)
GetCreateReceiptLog
(
issuance
*
pty
.
Issuance
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogIssuanceCreate
c
:=
&
pty
.
ReceiptIssuance
{}
c
.
IssuanceId
=
issuance
.
IssuanceId
c
.
Status
=
issuance
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetDebtReceiptLog generate logs for Issuance debt action
func
(
action
*
Action
)
GetDebtReceiptLog
(
issuance
*
pty
.
Issuance
,
debtRecord
*
pty
.
DebtRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogIssuanceDebt
c
:=
&
pty
.
ReceiptIssuance
{}
c
.
IssuanceId
=
issuance
.
IssuanceId
c
.
AccountAddr
=
action
.
fromaddr
c
.
DebtId
=
debtRecord
.
DebtId
c
.
Status
=
debtRecord
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetRepayReceiptLog generate logs for Issuance Repay action
func
(
action
*
Action
)
GetRepayReceiptLog
(
issuance
*
pty
.
Issuance
,
debtRecord
*
pty
.
DebtRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogIssuanceRepay
c
:=
&
pty
.
ReceiptIssuance
{}
c
.
IssuanceId
=
issuance
.
IssuanceId
c
.
AccountAddr
=
action
.
fromaddr
c
.
DebtId
=
debtRecord
.
DebtId
c
.
Status
=
debtRecord
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetFeedReceiptLog generate logs for Issuance price feed action
func
(
action
*
Action
)
GetFeedReceiptLog
(
issuance
*
pty
.
Issuance
,
debtRecord
*
pty
.
DebtRecord
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogIssuanceFeed
c
:=
&
pty
.
ReceiptIssuance
{}
c
.
IssuanceId
=
issuance
.
IssuanceId
c
.
AccountAddr
=
debtRecord
.
AccountAddr
c
.
DebtId
=
debtRecord
.
DebtId
c
.
Status
=
debtRecord
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetCloseReceiptLog generate logs for Issuance close action
func
(
action
*
Action
)
GetCloseReceiptLog
(
issuance
*
pty
.
Issuance
)
*
types
.
ReceiptLog
{
log
:=
&
types
.
ReceiptLog
{}
log
.
Ty
=
pty
.
TyLogIssuanceClose
c
:=
&
pty
.
ReceiptIssuance
{}
c
.
IssuanceId
=
issuance
.
IssuanceId
c
.
Status
=
issuance
.
Status
log
.
Log
=
types
.
Encode
(
c
)
return
log
}
// GetIndex returns index in block
func
(
action
*
Action
)
GetIndex
()
int64
{
return
action
.
height
*
types
.
MaxTxsPerBlock
+
int64
(
action
.
index
)
}
func
getLatestLiquidationPrice
(
issu
*
pty
.
Issuance
)
int64
{
var
latest
int64
for
_
,
collRecord
:=
range
issu
.
DebtRecords
{
if
collRecord
.
LiquidationPrice
>
latest
{
latest
=
collRecord
.
LiquidationPrice
}
}
return
latest
}
func
getLatestExpireTime
(
issu
*
pty
.
Issuance
)
int64
{
var
latest
int64
=
0x7fffffffffffffff
for
_
,
collRecord
:=
range
issu
.
DebtRecords
{
if
collRecord
.
ExpireTime
<
latest
{
latest
=
collRecord
.
ExpireTime
}
}
return
latest
}
// IssuanceConfig 设置全局借贷参数(管理员权限)
func
(
action
*
Action
)
IssuanceManage
(
manage
*
pty
.
IssuanceManage
)
(
*
types
.
Receipt
,
error
)
{
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
// 是否配置管理用户
if
!
isRightAddr
(
pty
.
ManageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceManage"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to config"
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 添加大户地址
var
item
types
.
ConfigItem
data
,
err
:=
action
.
db
.
Get
(
AddrKey
())
if
err
!=
nil
{
if
err
!=
types
.
ErrNotFound
{
clog
.
Error
(
"IssuanceManage"
,
"error"
,
err
)
return
nil
,
err
}
emptyValue
:=
&
types
.
ArrayConfig
{
Value
:
make
([]
string
,
0
)}
arr
:=
types
.
ConfigItem_Arr
{
Arr
:
emptyValue
}
item
.
Value
=
&
arr
item
.
GetArr
()
.
Value
=
append
(
item
.
GetArr
()
.
Value
,
manage
.
SuperAddrs
...
)
value
:=
types
.
Encode
(
&
item
)
action
.
db
.
Set
(
AddrKey
(),
value
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
AddrKey
(),
Value
:
value
})
}
else
{
err
=
types
.
Decode
(
data
,
&
item
)
if
err
!=
nil
{
clog
.
Debug
(
"IssuanceManage"
,
"decode"
,
err
)
return
nil
,
err
}
item
.
GetArr
()
.
Value
=
append
(
item
.
GetArr
()
.
Value
,
manage
.
SuperAddrs
...
)
value
:=
types
.
Encode
(
&
item
)
action
.
db
.
Set
(
AddrKey
(),
value
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
AddrKey
(),
Value
:
value
})
}
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
nil
}
return
receipt
,
nil
}
func
(
action
*
Action
)
getSuperAddr
()
[]
string
{
data
,
err
:=
action
.
db
.
Get
(
AddrKey
())
if
err
!=
nil
{
clog
.
Error
(
"getSuperAddr"
,
"error"
,
err
)
return
nil
}
var
addrStore
pty
.
IssuanceManage
err
=
types
.
Decode
(
data
,
&
addrStore
)
if
err
!=
nil
{
clog
.
Debug
(
"getSuperAddr"
,
"decode"
,
err
)
return
nil
}
return
addrStore
.
SuperAddrs
}
// IssuanceCreate 创建借贷,持有一定数量ccny的用户可创建借贷,提供给其他用户借贷
func
(
action
*
Action
)
IssuanceCreate
(
create
*
pty
.
IssuanceCreate
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
// 是否配置管理用户
if
!
isRightAddr
(
pty
.
ManageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to create"
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 参数检查
if
create
.
GetTotalBalance
()
<=
0
{
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"total balance"
,
create
.
GetTotalBalance
(),
"error"
,
types
.
ErrAmount
)
return
nil
,
types
.
ErrAmount
}
if
create
.
DebtCeiling
<
0
||
create
.
LiquidationRatio
<
0
||
create
.
Period
<
0
{
clog
.
Error
(
"IssuanceCreate"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
types
.
ErrInvalidParam
)
return
nil
,
types
.
ErrInvalidParam
}
// 检查ccny余额
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
create
.
TotalBalance
,
false
)
{
return
nil
,
types
.
ErrInsufficientBalance
}
// 查找ID是否重复
issuanceID
:=
common
.
ToHex
(
action
.
txhash
)
_
,
err
:=
queryIssuanceByID
(
action
.
db
,
issuanceID
)
if
err
!=
types
.
ErrNotFound
{
clog
.
Error
(
"IssuanceCreate"
,
"IssuanceCreate repeated"
,
issuanceID
)
return
nil
,
pty
.
ErrIssuanceRepeatHash
}
// 冻结ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
action
.
fromaddr
,
action
.
execaddr
,
create
.
TotalBalance
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
create
.
TotalBalance
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 构造coll结构
issu
:=
&
IssuanceDB
{}
issu
.
IssuanceId
=
issuanceID
issu
.
TotalBalance
=
create
.
TotalBalance
if
create
.
LiquidationRatio
!=
0
{
issu
.
LiquidationRatio
=
create
.
LiquidationRatio
}
else
{
issu
.
LiquidationRatio
=
DefaultLiquidationRatio
}
if
create
.
DebtCeiling
!=
0
{
issu
.
DebtCeiling
=
create
.
DebtCeiling
}
else
{
issu
.
DebtCeiling
=
DefaultDebtCeiling
}
if
create
.
Period
!=
0
{
issu
.
Period
=
create
.
Period
}
else
{
issu
.
Period
=
DefaultPeriod
}
issu
.
Balance
=
create
.
TotalBalance
issu
.
CreateTime
=
action
.
blocktime
issu
.
IssuerAddr
=
action
.
fromaddr
issu
.
Status
=
pty
.
IssuanceActionCreate
clog
.
Debug
(
"IssuanceCreate created"
,
"IssuanceID"
,
issuanceID
,
"TotalBalance"
,
issu
.
TotalBalance
)
// 保存
issu
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
issu
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetCreateReceiptLog
(
&
issu
.
Issuance
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 根据最近抵押物价格计算需要冻结的BTY数量
func
getBtyNumToFrozen
(
value
int64
,
price
int64
,
ratio
int64
)
(
int64
,
error
)
{
if
price
==
0
{
clog
.
Error
(
"Bty price should greate to 0"
)
return
0
,
pty
.
ErrPriceInvalid
}
btyValue
:=
(
value
*
1e4
)
/
(
price
*
ratio
)
return
btyValue
*
1e4
,
nil
}
// 获取最近抵押物价格
func
getLatestPrice
(
db
dbm
.
KV
)
(
int64
,
error
)
{
data
,
err
:=
db
.
Get
(
PriceKey
())
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"get"
,
err
)
return
-
1
,
err
}
var
price
pty
.
IssuanceAssetPriceRecord
//decode
err
=
types
.
Decode
(
data
,
&
price
)
if
err
!=
nil
{
clog
.
Error
(
"getLatestPrice"
,
"decode"
,
err
)
return
-
1
,
err
}
return
price
.
BtyPrice
,
nil
}
// CheckExecAccountBalance 检查账户抵押物余额
func
(
action
*
Action
)
CheckExecAccountBalance
(
fromAddr
string
,
ToFrozen
,
ToActive
int64
)
bool
{
acc
:=
action
.
coinsAccount
.
LoadExecAccount
(
fromAddr
,
action
.
execaddr
)
if
acc
.
GetBalance
()
>=
ToFrozen
&&
acc
.
GetFrozen
()
>=
ToActive
{
return
true
}
return
false
}
// CheckExecAccount 检查账户token余额
func
(
action
*
Action
)
CheckExecTokenAccount
(
addr
string
,
amount
int64
,
isFrozen
bool
)
bool
{
acc
:=
action
.
tokenAccount
.
LoadExecAccount
(
addr
,
action
.
execaddr
)
if
isFrozen
{
if
acc
.
GetFrozen
()
>=
amount
{
return
true
}
}
else
{
if
acc
.
GetBalance
()
>=
amount
{
return
true
}
}
return
false
}
// IssuanceDebt 大户质押bty借出ccny
func
(
action
*
Action
)
IssuanceDebt
(
debt
*
pty
.
IssuanceDebt
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
!
isSuperAddr
(
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceDebt"
,
"error"
,
"IssuanceDebt need super address"
)
return
nil
,
pty
.
ErrPermissionDeny
}
// 查找对应的借贷ID
issuance
,
err
:=
queryIssuanceByID
(
action
.
db
,
debt
.
IssuanceId
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt"
,
"IssuanceId"
,
debt
.
IssuanceId
,
"error"
,
err
)
return
nil
,
err
}
// 状态检查
if
issuance
.
Status
==
pty
.
IssuanceStatusClose
{
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issuance
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"status"
,
issuance
.
Status
,
"error"
,
pty
.
ErrIssuanceStatus
)
return
nil
,
pty
.
ErrIssuanceStatus
}
issu
:=
&
IssuanceDB
{
*
issuance
}
// 借贷金额检查
if
debt
.
GetValue
()
<=
0
{
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"debt value"
,
debt
.
GetValue
(),
"error"
,
types
.
ErrInvalidParam
)
return
nil
,
types
.
ErrInvalidParam
}
// 借贷金额不超过个人限额
if
debt
.
GetValue
()
>
issu
.
DebtCeiling
{
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"debt value"
,
debt
.
GetValue
(),
"error"
,
pty
.
ErrIssuanceExceedDebtCeiling
)
return
nil
,
pty
.
ErrIssuanceExceedDebtCeiling
}
// 借贷金额不超过当前可借贷金额
if
debt
.
GetValue
()
>
issu
.
Balance
{
clog
.
Error
(
"IssuanceDebt"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"debt value"
,
debt
.
GetValue
(),
"error"
,
pty
.
ErrIssuanceLowBalance
)
return
nil
,
pty
.
ErrIssuanceLowBalance
}
clog
.
Debug
(
"IssuanceDebt"
,
"value"
,
debt
.
GetValue
())
// 获取抵押物价格
lastPrice
,
err
:=
getLatestPrice
(
action
.
db
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.getLatestPrice"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
// 根据价格和需要借贷的金额,计算需要质押的抵押物数量
btyFrozen
,
err
:=
getBtyNumToFrozen
(
debt
.
Value
,
lastPrice
,
issu
.
LiquidationRatio
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.getBtyNumToFrozen"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
err
)
return
nil
,
err
}
// 检查抵押物账户余额
if
!
action
.
CheckExecAccountBalance
(
action
.
fromaddr
,
btyFrozen
,
0
)
{
clog
.
Error
(
"IssuanceDebt.CheckExecAccountBalance"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"btyFrozen"
,
btyFrozen
,
"error"
,
types
.
ErrNoBalance
)
return
nil
,
types
.
ErrNoBalance
}
// 抵押物转账
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.ExecTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物冻结
receipt
,
err
=
action
.
coinsAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
btyFrozen
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.Frozen"
,
"addr"
,
issu
.
IssuerAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
btyFrozen
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借出ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debt
.
Value
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceDebt.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debt
.
Value
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 构造借出记录
debtRecord
:=
&
pty
.
DebtRecord
{}
debtRecord
.
AccountAddr
=
action
.
fromaddr
debtRecord
.
DebtId
=
common
.
ToHex
(
action
.
txhash
)
debtRecord
.
IssuId
=
issu
.
IssuanceId
debtRecord
.
CollateralValue
=
btyFrozen
debtRecord
.
StartTime
=
action
.
blocktime
debtRecord
.
CollateralPrice
=
lastPrice
debtRecord
.
DebtValue
=
debt
.
Value
debtRecord
.
LiquidationPrice
=
(
issu
.
LiquidationRatio
*
lastPrice
*
pty
.
IssuancePreLiquidationRatio
)
/
1e8
debtRecord
.
Status
=
pty
.
IssuanceUserStatusCreate
debtRecord
.
ExpireTime
=
action
.
blocktime
+
issu
.
Period
// 记录当前借贷的最高自动清算价格
if
issu
.
LatestLiquidationPrice
<
debtRecord
.
LiquidationPrice
{
issu
.
LatestLiquidationPrice
=
debtRecord
.
LiquidationPrice
}
// 保存
issu
.
DebtRecords
=
append
(
issu
.
DebtRecords
,
debtRecord
)
issu
.
CollateralValue
+=
btyFrozen
issu
.
DebtValue
+=
debt
.
Value
issu
.
Balance
-=
debt
.
Value
issu
.
LatestExpireTime
=
getLatestExpireTime
(
&
issu
.
Issuance
)
issu
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
issu
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetDebtReceiptLog
(
&
issu
.
Issuance
,
debtRecord
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// IssuanceRepay 用户主动清算
func
(
action
*
Action
)
IssuanceRepay
(
repay
*
pty
.
IssuanceRepay
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
// 找到相应的借贷
issuance
,
err
:=
queryIssuanceByID
(
action
.
db
,
repay
.
IssuanceId
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceRepay"
,
"CollID"
,
repay
.
IssuanceId
,
"error"
,
err
)
return
nil
,
err
}
issu
:=
&
IssuanceDB
{
*
issuance
}
// 状态检查
if
issu
.
Status
!=
pty
.
IssuanceStatusCreated
{
clog
.
Error
(
"IssuanceRepay"
,
"CollID"
,
repay
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
"status error"
,
"Status"
,
issu
.
Status
)
return
nil
,
pty
.
ErrIssuanceStatus
}
// 查找借出记录
var
debtRecord
*
pty
.
DebtRecord
var
index
int
for
i
,
record
:=
range
issu
.
DebtRecords
{
if
record
.
DebtId
==
repay
.
DebtId
{
debtRecord
=
record
index
=
i
break
}
}
if
debtRecord
==
nil
{
clog
.
Error
(
"IssuanceRepay"
,
"CollID"
,
repay
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
"Can not find debt record"
)
return
nil
,
pty
.
ErrRecordNotExist
}
// 检查
if
!
action
.
CheckExecTokenAccount
(
action
.
fromaddr
,
debtRecord
.
DebtValue
,
false
)
{
clog
.
Error
(
"IssuanceRepay"
,
"CollID"
,
issu
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
types
.
ErrInsufficientBalance
)
return
nil
,
types
.
ErrNoBalance
}
// ccny转移
receipt
,
err
=
action
.
tokenAccount
.
ExecTransfer
(
action
.
fromaddr
,
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceRepay.ExecTokenTransfer"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
DebtValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 冻结ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecFrozen
(
issu
.
IssuerAddr
,
action
.
execaddr
,
debtRecord
.
DebtValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceCreate.Frozen"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
DebtValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 抵押物归还
receipt
,
err
=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
action
.
fromaddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceRepay.ExecTransferFrozen"
,
"addr"
,
issu
.
IssuerAddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录关闭
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusClose
// 保存
issu
.
Balance
+=
debtRecord
.
DebtValue
issu
.
CollateralValue
-=
debtRecord
.
CollateralValue
issu
.
DebtValue
-=
debtRecord
.
DebtValue
issu
.
DebtRecords
=
append
(
issu
.
DebtRecords
[
:
index
],
issu
.
DebtRecords
[
index
+
1
:
]
...
)
issu
.
InvalidRecords
=
append
(
issu
.
InvalidRecords
,
debtRecord
)
issu
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
&
issu
.
Issuance
)
issu
.
LatestExpireTime
=
getLatestExpireTime
(
&
issu
.
Issuance
)
issu
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
issu
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetRepayReceiptLog
(
&
issu
.
Issuance
,
debtRecord
)
logs
=
append
(
logs
,
receiptLog
)
receipt
=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 系统清算
func
(
action
*
Action
)
systemLiquidation
(
issu
*
pty
.
Issuance
,
price
int64
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
for
index
,
debtRecord
:=
range
issu
.
DebtRecords
{
if
(
debtRecord
.
LiquidationPrice
*
PriceWarningRate
)
/
1e4
<
price
{
if
debtRecord
.
Status
==
pty
.
IssuanceUserStatusWarning
{
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusCreate
}
continue
}
if
debtRecord
.
LiquidationPrice
>=
price
{
getGuarantorAddr
,
err
:=
getGuarantorAddr
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"getGuarantorAddr"
,
err
)
continue
}
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
,
"error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录清算
debtRecord
.
LiquidateTime
=
action
.
blocktime
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusSystemLiquidate
issu
.
InvalidRecords
=
append
(
issu
.
InvalidRecords
,
debtRecord
)
issu
.
DebtRecords
=
append
(
issu
.
DebtRecords
[
:
index
],
issu
.
DebtRecords
[
index
+
1
:
]
...
)
}
else
{
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusWarning
}
log
:=
action
.
GetFeedReceiptLog
(
issu
,
debtRecord
)
logs
=
append
(
logs
,
log
)
}
// 保存
issu
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
issu
)
issu
.
LatestExpireTime
=
getLatestExpireTime
(
issu
)
collDB
:=
&
IssuanceDB
{
*
issu
}
collDB
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
collDB
.
GetKVSet
()
...
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 超时清算
func
(
action
*
Action
)
expireLiquidation
(
issu
*
pty
.
Issuance
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
for
index
,
debtRecord
:=
range
issu
.
DebtRecords
{
if
debtRecord
.
ExpireTime
-
ExpireWarningTime
>
action
.
blocktime
{
continue
}
if
debtRecord
.
ExpireTime
<=
action
.
blocktime
{
getGuarantorAddr
,
err
:=
getGuarantorAddr
(
action
.
db
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"getGuarantorAddr"
,
err
)
continue
}
}
// 抵押物转移
receipt
,
err
:=
action
.
coinsAccount
.
ExecTransferFrozen
(
issu
.
IssuerAddr
,
getGuarantorAddr
,
action
.
execaddr
,
debtRecord
.
CollateralValue
)
if
err
!=
nil
{
clog
.
Error
(
"systemLiquidation"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
debtRecord
.
CollateralValue
,
"error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
// 借贷记录清算
debtRecord
.
LiquidateTime
=
action
.
blocktime
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusExpireLiquidate
issu
.
InvalidRecords
=
append
(
issu
.
InvalidRecords
,
debtRecord
)
issu
.
DebtRecords
=
append
(
issu
.
DebtRecords
[
:
index
],
issu
.
DebtRecords
[
index
+
1
:
]
...
)
}
else
{
debtRecord
.
PreStatus
=
debtRecord
.
Status
debtRecord
.
Status
=
pty
.
IssuanceUserStatusExpire
}
log
:=
action
.
GetFeedReceiptLog
(
issu
,
debtRecord
)
logs
=
append
(
logs
,
log
)
}
// 保存
issu
.
LatestLiquidationPrice
=
getLatestLiquidationPrice
(
issu
)
issu
.
LatestExpireTime
=
getLatestExpireTime
(
issu
)
collDB
:=
&
IssuanceDB
{
*
issu
}
collDB
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
collDB
.
GetKVSet
()
...
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// 价格计算策略
func
pricePolicy
(
feed
*
pty
.
IssuanceFeed
)
int64
{
var
totalPrice
int64
var
totalVolume
int64
for
_
,
volume
:=
range
feed
.
Volume
{
totalVolume
+=
volume
}
if
totalVolume
==
0
{
clog
.
Error
(
"issuance price feed volume empty"
)
return
0
}
for
i
,
price
:=
range
feed
.
Price
{
totalPrice
+=
(
price
*
feed
.
Volume
[
i
])
/
totalVolume
}
return
totalPrice
}
// IssuanceFeed 喂价
func
(
action
*
Action
)
IssuanceFeed
(
feed
*
pty
.
IssuanceFeed
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
if
feed
==
nil
||
len
(
feed
.
Price
)
==
0
||
len
(
feed
.
Price
)
!=
len
(
feed
.
Volume
)
{
clog
.
Error
(
"IssuancePriceFeed"
,
types
.
ErrInvalidParam
)
return
nil
,
types
.
ErrInvalidParam
}
// 是否后台管理用户
if
!
isRightAddr
(
pty
.
PriceFeedKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuancePriceFeed"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to feed price"
)
return
nil
,
pty
.
ErrPermissionDeny
}
price
:=
pricePolicy
(
feed
)
if
price
<=
0
{
clog
.
Error
(
"IssuancePriceFeed"
,
"price"
,
price
,
"error"
,
pty
.
ErrPriceInvalid
)
return
nil
,
pty
.
ErrPriceInvalid
}
ids
,
err
:=
queryIssuanceByStatus
(
action
.
localDB
,
pty
.
IssuanceStatusCreated
,
""
)
if
err
!=
nil
{
clog
.
Debug
(
"IssuancePriceFeed"
,
"get issuance record error"
,
err
)
}
for
_
,
collID
:=
range
ids
{
issu
,
err
:=
queryIssuanceByID
(
action
.
db
,
collID
)
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"Issuance ID"
,
issu
.
IssuanceId
,
"get issuance record by id error"
,
err
)
continue
}
// 超时清算判断
if
issu
.
LatestExpireTime
-
ExpireWarningTime
<=
action
.
blocktime
{
receipt
,
err
:=
action
.
expireLiquidation
(
issu
)
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"Issuance ID"
,
issu
.
IssuanceId
,
"expire liquidation error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
// 系统清算判断
receipt
,
err
:=
action
.
systemLiquidation
(
issu
,
price
)
if
err
!=
nil
{
clog
.
Error
(
"IssuancePriceFeed"
,
"Issuance ID"
,
issu
.
IssuanceId
,
"system liquidation error"
,
err
)
continue
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
}
var
priceRecord
pty
.
IssuanceAssetPriceRecord
priceRecord
.
BtyPrice
=
price
priceRecord
.
RecordTime
=
action
.
blocktime
// 最近喂价记录
pricekv
:=
&
types
.
KeyValue
{
Key
:
PriceKey
(),
Value
:
types
.
Encode
(
&
priceRecord
)}
action
.
db
.
Set
(
pricekv
.
Key
,
pricekv
.
Value
)
kv
=
append
(
kv
,
pricekv
)
receipt
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
}
return
receipt
,
nil
}
// IssuanceClose 终止借贷
func
(
action
*
Action
)
IssuanceClose
(
close
*
pty
.
IssuanceClose
)
(
*
types
.
Receipt
,
error
)
{
var
logs
[]
*
types
.
ReceiptLog
var
kv
[]
*
types
.
KeyValue
var
receipt
*
types
.
Receipt
issuance
,
err
:=
queryIssuanceByID
(
action
.
db
,
close
.
IssuanceId
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceClose"
,
"IssuanceId"
,
close
.
IssuanceId
,
"error"
,
err
)
return
nil
,
err
}
if
!
isRightAddr
(
pty
.
ManageKey
,
action
.
fromaddr
,
action
.
db
)
{
clog
.
Error
(
"IssuanceClose"
,
"addr"
,
action
.
fromaddr
,
"error"
,
"Address has no permission to close"
)
return
nil
,
pty
.
ErrPermissionDeny
}
for
_
,
debtRecord
:=
range
issuance
.
DebtRecords
{
if
debtRecord
.
Status
!=
pty
.
IssuanceUserStatusClose
{
clog
.
Error
(
"IssuanceClose"
,
"IssuanceId"
,
close
.
IssuanceId
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"error"
,
pty
.
ErrIssuanceRecordNotEmpty
)
return
nil
,
pty
.
ErrIssuanceRecordNotEmpty
}
}
// 解冻ccny
receipt
,
err
=
action
.
tokenAccount
.
ExecActive
(
action
.
fromaddr
,
action
.
execaddr
,
issuance
.
Balance
)
if
err
!=
nil
{
clog
.
Error
(
"IssuanceClose.ExecActive"
,
"addr"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
issuance
.
Balance
,
"error"
,
err
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kv
=
append
(
kv
,
receipt
.
KV
...
)
clog
.
Debug
(
"IssuanceClose"
,
"ID"
,
close
.
IssuanceId
)
issu
:=
&
IssuanceDB
{
*
issuance
}
issu
.
Status
=
pty
.
IssuanceStatusClose
issu
.
Save
(
action
.
db
)
kv
=
append
(
kv
,
issu
.
GetKVSet
()
...
)
receiptLog
:=
action
.
GetCloseReceiptLog
(
&
issu
.
Issuance
)
logs
=
append
(
logs
,
receiptLog
)
return
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kv
,
Logs
:
logs
},
nil
}
// 根据ID查找发行信息
func
queryIssuanceByID
(
db
dbm
.
KV
,
issuanceID
string
)
(
*
pty
.
Issuance
,
error
)
{
data
,
err
:=
db
.
Get
(
Key
(
issuanceID
))
if
err
!=
nil
{
return
nil
,
err
}
var
issu
pty
.
Issuance
err
=
types
.
Decode
(
data
,
&
issu
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceByID"
,
"decode"
,
err
)
return
nil
,
err
}
return
&
issu
,
nil
}
// 根据发行状态查找发行ID
func
queryIssuanceByStatus
(
localdb
dbm
.
KVDB
,
status
int32
,
issuanceID
string
)
([]
string
,
error
)
{
query
:=
pty
.
NewIssuanceTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
issuanceID
)
>
0
{
primary
=
[]
byte
(
issuanceID
)
}
var
data
=
&
pty
.
ReceiptIssuanceID
{
IssuanceId
:
issuanceID
,
Status
:
status
,
}
rows
,
err
:=
query
.
List
(
"status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceByStatus.List"
,
"error"
,
err
)
return
nil
,
err
}
var
ids
[]
string
for
_
,
row
:=
range
rows
{
ids
=
append
(
ids
,
string
(
row
.
Primary
))
}
return
ids
,
nil
}
// 精确查找发行记录
func
queryIssuanceRecordByID
(
db
dbm
.
KV
,
issuanceID
string
,
debtID
string
)
(
*
pty
.
DebtRecord
,
error
)
{
issu
,
err
:=
queryIssuanceByID
(
db
,
issuanceID
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordByID"
,
"error"
,
err
)
return
nil
,
err
}
for
_
,
record
:=
range
issu
.
DebtRecords
{
if
record
.
DebtId
==
debtID
{
return
record
,
nil
}
}
for
_
,
record
:=
range
issu
.
InvalidRecords
{
if
record
.
DebtId
==
debtID
{
return
record
,
nil
}
}
return
nil
,
types
.
ErrNotFound
}
// 根据发行状态查找
func
queryIssuanceRecordsByStatus
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
status
int32
,
debtID
string
)
([]
*
pty
.
DebtRecord
,
error
)
{
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
debtID
)
>
0
{
primary
=
[]
byte
(
debtID
)
}
var
data
=
&
pty
.
ReceiptIssuance
{
Status
:
status
,
}
rows
,
err
:=
query
.
List
(
"status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordsByStatus.List"
,
"index"
,
"status"
,
"error"
,
err
)
return
nil
,
err
}
var
records
[]
*
pty
.
DebtRecord
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryIssuanceRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
IssuanceId
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
DebtId
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordsByStatus"
,
"decode"
,
err
)
continue
}
records
=
append
(
records
,
record
)
}
return
records
,
nil
}
// 根据用户地址查找
func
queryIssuanceRecordByAddr
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
,
status
int32
,
debtID
string
)
([]
*
pty
.
DebtRecord
,
error
)
{
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
if
len
(
debtID
)
>
0
{
primary
=
[]
byte
(
debtID
)
}
var
data
=
&
pty
.
ReceiptIssuance
{
AccountAddr
:
addr
,
Status
:
status
,
}
var
rows
[]
*
table
.
Row
var
err
error
if
status
==
0
{
rows
,
err
=
query
.
List
(
"addr"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordByAddr.List"
,
"index"
,
"addr"
,
"error"
,
err
)
return
nil
,
err
}
}
else
{
rows
,
err
=
query
.
List
(
"addr_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordByAddr.List"
,
"index"
,
"addr_status"
,
"error"
,
err
)
return
nil
,
err
}
}
var
records
[]
*
pty
.
DebtRecord
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryIssuanceRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
IssuanceId
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
DebtId
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceRecordByAddr"
,
"decode"
,
err
)
continue
}
records
=
append
(
records
,
record
)
}
return
records
,
nil
}
func
queryIssuanceUserBalanceStatus
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
,
status
int32
)
(
int64
,
error
)
{
var
totalBalance
int64
query
:=
pty
.
NewRecordTable
(
localdb
)
.
GetQuery
(
localdb
)
var
primary
[]
byte
var
data
=
&
pty
.
ReceiptIssuance
{
AccountAddr
:
addr
,
Status
:
status
,
}
var
rows
[]
*
table
.
Row
var
err
error
for
{
rows
,
err
=
query
.
List
(
"addr_status"
,
data
,
primary
,
DefaultCount
,
ListDESC
)
if
err
!=
nil
{
clog
.
Debug
(
"queryIssuanceRecordByAddr.List"
,
"index"
,
"addr"
,
"error"
,
err
)
return
-
1
,
err
}
for
_
,
row
:=
range
rows
{
record
,
err
:=
queryIssuanceRecordByID
(
db
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
IssuanceId
,
row
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
DebtId
)
if
err
!=
nil
{
clog
.
Debug
(
"queryIssuanceRecordByStatus.queryIssuanceRecordByID"
,
"error"
,
err
)
continue
}
totalBalance
+=
record
.
DebtValue
}
if
len
(
rows
)
<
int
(
DefaultCount
)
{
break
}
primary
=
[]
byte
(
rows
[
DefaultCount
-
1
]
.
Data
.
(
*
pty
.
ReceiptIssuance
)
.
DebtId
)
}
return
totalBalance
,
nil
}
func
queryIssuanceUserBalance
(
db
dbm
.
KV
,
localdb
dbm
.
KVDB
,
addr
string
)
(
int64
,
error
)
{
var
totalBalance
int64
balance
,
err
:=
queryIssuanceUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
IssuanceUserStatusCreate
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
balance
,
err
=
queryIssuanceUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
IssuanceUserStatusWarning
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
balance
,
err
=
queryIssuanceUserBalanceStatus
(
db
,
localdb
,
addr
,
pty
.
IssuanceUserStatusExpire
)
if
err
!=
nil
{
clog
.
Error
(
"queryIssuanceUserBalance"
,
"err"
,
err
)
}
else
{
totalBalance
+=
balance
}
return
totalBalance
,
nil
}
plugin/dapp/issuance/executor/query.go
0 → 100644
View file @
a717a020
// 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/issuance/types"
)
func
(
c
*
Issuance
)
Query_IssuanceInfoByID
(
req
*
pty
.
ReqIssuanceInfo
)
(
types
.
Message
,
error
)
{
issu
,
err
:=
queryIssuanceByID
(
c
.
GetStateDB
(),
req
.
IssuanceId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceInfoByID"
,
"id"
,
req
.
IssuanceId
,
"error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepIssuanceCurrentInfo
{
Status
:
issu
.
Status
,
TotalBalance
:
issu
.
TotalBalance
,
DebtCeiling
:
issu
.
DebtCeiling
,
LiquidationRatio
:
issu
.
LiquidationRatio
,
Balance
:
issu
.
Balance
,
CollateralValue
:
issu
.
CollateralValue
,
DebtValue
:
issu
.
DebtValue
,
Period
:
issu
.
Period
,
IssuId
:
issu
.
IssuanceId
,
CreateTime
:
issu
.
CreateTime
,
},
nil
}
func
(
c
*
Issuance
)
Query_IssuanceInfoByIDs
(
req
*
pty
.
ReqIssuanceInfos
)
(
types
.
Message
,
error
)
{
infos
:=
&
pty
.
RepIssuanceCurrentInfos
{}
for
_
,
id
:=
range
req
.
IssuanceIds
{
issu
,
err
:=
queryIssuanceByID
(
c
.
GetStateDB
(),
id
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceInfoByID"
,
"id"
,
id
,
"error"
,
err
)
return
nil
,
err
}
infos
.
Infos
=
append
(
infos
.
Infos
,
&
pty
.
RepIssuanceCurrentInfo
{
Status
:
issu
.
Status
,
TotalBalance
:
issu
.
TotalBalance
,
DebtCeiling
:
issu
.
DebtCeiling
,
LiquidationRatio
:
issu
.
LiquidationRatio
,
Balance
:
issu
.
Balance
,
CollateralValue
:
issu
.
CollateralValue
,
DebtValue
:
issu
.
DebtValue
,
Period
:
issu
.
Period
,
IssuId
:
issu
.
IssuanceId
,
CreateTime
:
issu
.
CreateTime
,
})
}
return
infos
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceByStatus
(
req
*
pty
.
ReqIssuanceByStatus
)
(
types
.
Message
,
error
)
{
ids
:=
&
pty
.
RepIssuanceIDs
{}
issuIDs
,
err
:=
queryIssuanceByStatus
(
c
.
GetLocalDB
(),
req
.
Status
,
req
.
IssuanceId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceByStatus"
,
"get issuance error"
,
err
)
return
nil
,
err
}
ids
.
IDs
=
append
(
ids
.
IDs
,
issuIDs
...
)
return
ids
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordByID
(
req
*
pty
.
ReqIssuanceRecords
)
(
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
.
Record
=
issuRecord
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordsByAddr
(
req
*
pty
.
ReqIssuanceRecords
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepIssuanceRecords
{}
records
,
err
:=
queryIssuanceRecordByAddr
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Addr
,
req
.
Status
,
req
.
DebtId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceDebtInfoByAddr"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
if
req
.
Status
==
0
{
ret
.
Records
=
records
}
else
{
for
_
,
record
:=
range
records
{
if
record
.
Status
==
req
.
Status
{
ret
.
Records
=
append
(
ret
.
Records
,
record
)
}
}
}
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuanceRecordsByStatus
(
req
*
pty
.
ReqIssuanceRecords
)
(
types
.
Message
,
error
)
{
ret
:=
&
pty
.
RepIssuanceRecords
{}
records
,
err
:=
queryIssuanceRecordsByStatus
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Status
,
req
.
DebtId
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceDebtInfoByStatus"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
ret
.
Records
=
append
(
ret
.
Records
,
records
...
)
return
ret
,
nil
}
func
(
c
*
Issuance
)
Query_IssuancePrice
(
req
*
pty
.
ReqIssuanceRecords
)
(
types
.
Message
,
error
)
{
price
,
err
:=
getLatestPrice
(
c
.
GetStateDB
())
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuancePrice"
,
"error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepIssuancePrice
{
Price
:
price
},
nil
}
func
(
c
*
Issuance
)
Query_IssuanceUserBalance
(
req
*
pty
.
ReqIssuanceRecords
)
(
types
.
Message
,
error
)
{
balance
,
err
:=
queryIssuanceUserBalance
(
c
.
GetStateDB
(),
c
.
GetLocalDB
(),
req
.
Addr
)
if
err
!=
nil
{
clog
.
Error
(
"Query_IssuanceRecordByAddr"
,
"get issuance record error"
,
err
)
return
nil
,
err
}
return
&
pty
.
RepIssuanceUserBalance
{
Balance
:
balance
},
nil
}
plugin/dapp/issuance/plugin.go
0 → 100644
View file @
a717a020
// 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
issuance
import
(
"github.com/33cn/chain33/pluginmgr"
"github.com/33cn/plugin/plugin/dapp/issuance/commands"
"github.com/33cn/plugin/plugin/dapp/issuance/executor"
"github.com/33cn/plugin/plugin/dapp/issuance/types"
)
func
init
()
{
pluginmgr
.
Register
(
&
pluginmgr
.
PluginBase
{
Name
:
types
.
IssuanceX
,
ExecName
:
executor
.
GetName
(),
Exec
:
executor
.
Init
,
Cmd
:
commands
.
IssuanceCmd
,
})
}
plugin/dapp/issuance/proto/Makefile
0 → 100644
View file @
a717a020
all
:
sh ./create_protobuf.sh
plugin/dapp/issuance/proto/create_protobuf.sh
0 → 100644
View file @
a717a020
#!/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/issuance/proto/issuance.proto
0 → 100644
View file @
a717a020
syntax
=
"proto3"
;
package
types
;
// 发行信息
message
Issuance
{
string
issuanceId
=
1
;
//发行ID,一期发行对应一个ID
int64
totalBalance
=
2
;
//当期发行的总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
4
;
//清算比例
int64
collateralValue
=
5
;
//抵押物总数量(bty)
int64
debtValue
=
6
;
//产生的ccny数量
repeated
DebtRecord
debtRecords
=
7
;
//大户抵押记录
repeated
DebtRecord
invalidRecords
=
8
;
//大户抵押记录
int32
status
=
9
;
//当期发行的状态,是否关闭
int64
latestLiquidationPrice
=
10
;
//最高清算价格
int64
period
=
11
;
//发行最大期限
int64
latestExpireTime
=
12
;
//最近超期时间
int64
createTime
=
13
;
//创建时间
int64
balance
=
14
;
//剩余可发行ccny
string
issuerAddr
=
15
;
//发行地址
}
// 抵押记录
message
DebtRecord
{
string
accountAddr
=
1
;
//抵押人地址
int64
startTime
=
2
;
//抵押时间
int64
collateralValue
=
3
;
//抵押物价值(bty)
int64
collateralPrice
=
4
;
//抵押物价格
int64
debtValue
=
5
;
//债务价值(ccny)
int64
liquidationPrice
=
6
;
//抵押物清算价格
int32
status
=
7
;
//抵押状态,是否被清算
int64
liquidateTime
=
8
;
//清算时间
int64
expireTime
=
9
;
//超时清算时间
int32
preStatus
=
10
;
//上一次抵押状态,用于告警恢复
string
debtId
=
11
;
//借贷id
string
issuId
=
12
;
//发行id
}
// 资产价格记录
message
IssuanceAssetPriceRecord
{
int64
recordTime
=
1
;
//价格记录时间
int64
btyPrice
=
2
;
//bty价格
}
// action
message
IssuanceAction
{
oneof
value
{
IssuanceCreate
create
=
1
;
//创建一期发行
IssuanceDebt
debt
=
2
;
//抵押
IssuanceRepay
repay
=
3
;
//清算
IssuanceFeed
feed
=
4
;
//喂价
IssuanceClose
close
=
5
;
//关闭
IssuanceManage
manage
=
6
;
//全局配置
}
int32
ty
=
10
;
}
message
IssuanceManage
{
repeated
string
superAddrs
=
1
;
//大户地址
}
// 创建发行
message
IssuanceCreate
{
int64
totalBalance
=
1
;
//发行总金额
int64
debtCeiling
=
2
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
3
;
//清算比例
int64
period
=
4
;
//发行最大期限
}
// 抵押
message
IssuanceDebt
{
string
issuanceId
=
1
;
//发行ID
int64
value
=
2
;
//借贷金额(ccny)
}
// 质押清算
message
IssuanceRepay
{
string
issuanceId
=
1
;
//发行ID
string
debtId
=
2
;
//抵押ID
}
// 喂价
message
IssuanceFeed
{
int32
collType
=
1
;
//抵押物价格类型(1,bty,2,btc,3,eth...)
repeated
int64
price
=
2
;
//喂价
repeated
int64
volume
=
3
;
//成交量
}
// 借贷关闭
message
IssuanceClose
{
string
issuanceId
=
1
;
//发行ID
}
// exec_local 发行信息
message
ReceiptIssuance
{
string
issuanceId
=
1
;
string
accountAddr
=
2
;
string
debtId
=
3
;
int32
status
=
4
;
}
// exec_local issuid记录信息
message
ReceiptIssuanceID
{
string
issuanceId
=
1
;
int32
status
=
2
;
}
// exec_local 抵押记录信息列表
message
IssuanceRecords
{
repeated
ReceiptIssuance
records
=
1
;
}
// 根据ID查询发行信息
message
ReqIssuanceInfo
{
string
issuanceId
=
1
;
}
// 返回一期发行信息
message
RepIssuanceCurrentInfo
{
int32
status
=
1
;
//当期发行的状态,是否关闭
int64
totalBalance
=
2
;
//当期发行总金额(ccny)
int64
debtCeiling
=
3
;
//单用户可借出的限额(ccny)
int64
liquidationRatio
=
4
;
//清算比例
int64
balance
=
5
;
//剩余可借贷金额(ccny)
int64
collateralValue
=
6
;
//抵押物总数量(bty)
int64
debtValue
=
7
;
//产生的ccny数量
int64
period
=
8
;
//发行最大期限
string
issuId
=
9
;
//发行ID
int64
createTime
=
10
;
//创建时间
}
// 根据ID列表查询多期发行信息
message
ReqIssuanceInfos
{
repeated
string
issuanceIds
=
1
;
}
// 返回多期发行信息
message
RepIssuanceCurrentInfos
{
repeated
RepIssuanceCurrentInfo
infos
=
1
;
}
// 根据发行状态查询
message
ReqIssuanceByStatus
{
int32
status
=
1
;
string
issuanceId
=
2
;
}
// 返回发行ID列表
message
RepIssuanceIDs
{
repeated
string
IDs
=
1
;
}
// 根据用户地址查询抵押记录
message
ReqIssuanceRecords
{
string
issuanceId
=
1
;
string
addr
=
2
;
int32
status
=
3
;
string
debtId
=
4
;
}
// 返回记录列表
message
RepIssuanceRecords
{
repeated
DebtRecord
records
=
1
;
}
// 返回记录
message
RepIssuanceDebtInfo
{
DebtRecord
record
=
1
;
}
// 返回最新抵押物价格
message
RepIssuancePrice
{
int64
price
=
1
;
//当前抵押物最新价格
}
// 返回用户发行总额
message
RepIssuanceUserBalance
{
int64
balance
=
1
;
//返回用户发行总额
}
\ No newline at end of file
plugin/dapp/issuance/readme.md
0 → 100644
View file @
a717a020
## 发行合约表结构
### 总发行表issuer表结构
字段名称|类型|说明
---|---|---
issuanceId|string|总发行ID,主键
status|int32|发行状态(1:已发行 2:已下线)
### 总发行表issuer表索引
索引名|说明
---|---
status|根据发行状态查询总发行ID
### 大户发行表debt表结构
字段名称|类型|说明
---|---|---
debtId|string|大户发行ID,主键
issuanceId|string|总发行ID
accountAddr|string|用户地址
status|int32|发行状态(1:已发行 2:价格清算告警 3:价格清算 4:超时清算告警 5:超时清算 6:关闭)
### 大户发行表debt表索引
索引名|说明
---|---
status|根据大户发行状态查询大户发行ID
addr|根据大户地址查询大户发行ID
addr_status|根据发行状态和大户地址查询大户发行ID
plugin/dapp/issuance/types/errors.go
0 → 100644
View file @
a717a020
// 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"
)
ErrIssuanceRepeatHash
=
errors
.
New
(
"ErrIssuanceRepeatHash"
)
ErrIssuanceStatus
=
errors
.
New
(
"ErrIssuanceStatus"
)
ErrIssuanceExceedDebtCeiling
=
errors
.
New
(
"ErrIssuanceExceedDebtCeiling"
)
ErrPriceInvalid
=
errors
.
New
(
"ErrPriceInvalid"
)
ErrAssetType
=
errors
.
New
(
"ErrAssetType"
)
ErrRecordNotExist
=
errors
.
New
(
"ErrRecordNotExist"
)
ErrIssuanceErrCloser
=
errors
.
New
(
"ErrIssuanceErrCloser"
)
ErrRepayValueInsufficient
=
errors
.
New
(
"ErrRepayValueInsufficient"
)
ErrIssuanceAccountExist
=
errors
.
New
(
"ErrIssuanceAccountExist"
)
ErrIssuanceLowBalance
=
errors
.
New
(
"ErrIssuanceLowBalance"
)
ErrIssuanceBalanceInvalid
=
errors
.
New
(
"ErrIssuanceBalanceInvalid"
)
ErrPermissionDeny
=
errors
.
New
(
"ErrPermissionDeny"
)
ErrIssuanceRecordNotEmpty
=
errors
.
New
(
"ErrIssuanceRecordNotEmpty"
)
)
plugin/dapp/issuance/types/issuance.go
0 → 100644
View file @
a717a020
// 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"
"math"
"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."
+
IssuanceX
)
)
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
IssuanceX
))
types
.
RegFork
(
IssuanceX
,
InitFork
)
types
.
RegExec
(
IssuanceX
,
InitExecutor
)
}
func
InitFork
(
cfg
*
types
.
Chain33Config
)
{
cfg
.
RegisterDappFork
(
IssuanceX
,
"Enable"
,
0
)
}
func
InitExecutor
(
cfg
*
types
.
Chain33Config
)
{
types
.
RegistorExecutor
(
IssuanceX
,
NewType
(
cfg
))
}
// IssuanceType def
type
IssuanceType
struct
{
types
.
ExecTypeBase
}
// NewType method
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
IssuanceType
{
c
:=
&
IssuanceType
{}
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
return
c
}
// GetName 获取执行器名称
func
(
issuance
*
IssuanceType
)
GetName
()
string
{
return
IssuanceX
}
// GetLogMap method
func
(
issuance
*
IssuanceType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
map
[
int64
]
*
types
.
LogInfo
{
TyLogIssuanceCreate
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptIssuance
{}),
Name
:
"LogIssuanceCreate"
},
TyLogIssuanceDebt
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptIssuance
{}),
Name
:
"LogIssuanceDebt"
},
TyLogIssuanceRepay
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptIssuance
{}),
Name
:
"LogIssuanceRepay"
},
TyLogIssuanceFeed
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptIssuance
{}),
Name
:
"LogIssuanceFeed"
},
TyLogIssuanceClose
:
{
Ty
:
reflect
.
TypeOf
(
ReceiptIssuance
{}),
Name
:
"LogIssuanceClose"
},
}
}
// GetPayload method
func
(
issuance
*
IssuanceType
)
GetPayload
()
types
.
Message
{
return
&
IssuanceAction
{}
}
// CreateTx method
func
(
issuance
IssuanceType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
llog
.
Debug
(
"Issuance.CreateTx"
,
"action"
,
action
)
cfg
:=
issuance
.
GetConfig
()
if
action
==
"IssuanceCreate"
{
var
param
IssuanceCreateTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceCreateTx
(
cfg
,
&
param
)
}
else
if
action
==
"IssuanceDebt"
{
var
param
IssuanceDebtTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceDebtTx
(
cfg
,
&
param
)
}
else
if
action
==
"IssuanceRepay"
{
var
param
IssuanceRepayTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceRepayTx
(
cfg
,
&
param
)
}
else
if
action
==
"IssuancePriceFeed"
{
var
param
IssuanceFeedTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceFeedTx
(
cfg
,
&
param
)
}
else
if
action
==
"IssuanceClose"
{
var
param
IssuanceCloseTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceCloseTx
(
cfg
,
&
param
)
}
else
if
action
==
"IssuanceManage"
{
var
param
IssuanceManageTx
err
:=
json
.
Unmarshal
(
message
,
&
param
)
if
err
!=
nil
{
llog
.
Error
(
"CreateTx"
,
"Error"
,
err
)
return
nil
,
types
.
ErrInvalidParam
}
return
CreateRawIssuanceManageTx
(
cfg
,
&
param
)
}
else
{
return
nil
,
types
.
ErrNotSupport
}
}
// GetTypeMap method
func
(
issuance
IssuanceType
)
GetTypeMap
()
map
[
string
]
int32
{
return
map
[
string
]
int32
{
"Create"
:
IssuanceActionCreate
,
"Debt"
:
IssuanceActionDebt
,
"Repay"
:
IssuanceActionRepay
,
"Feed"
:
IssuanceActionFeed
,
"Close"
:
IssuanceActionClose
,
"Manage"
:
IssuanceActionManage
,
}
}
// CreateRawIssuanceCreateTx method
func
CreateRawIssuanceCreateTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceCreateTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuanceCreateTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceCreate
{
TotalBalance
:
int64
(
math
.
Trunc
((
parm
.
TotalBalance
+
0.0000001
)
*
1e4
))
*
1e4
,
DebtCeiling
:
int64
(
math
.
Trunc
((
parm
.
DebtCeiling
+
0.0000001
)
*
1e4
))
*
1e4
,
LiquidationRatio
:
int64
(
math
.
Trunc
((
parm
.
LiquidationRatio
+
0.0000001
)
*
1e4
)),
Period
:
parm
.
Period
,
}
create
:=
&
IssuanceAction
{
Ty
:
IssuanceActionCreate
,
Value
:
&
IssuanceAction_Create
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
create
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawIssuanceDebtTx method
func
CreateRawIssuanceDebtTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceDebtTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuanceBorrowTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceDebt
{
IssuanceId
:
parm
.
IssuanceID
,
Value
:
int64
(
math
.
Trunc
((
parm
.
Value
+
0.0000001
)
*
1e4
))
*
1e4
,
}
debt
:=
&
IssuanceAction
{
Ty
:
IssuanceActionDebt
,
Value
:
&
IssuanceAction_Debt
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
debt
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawIssuanceRepayTx method
func
CreateRawIssuanceRepayTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceRepayTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuanceRepayTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceRepay
{
IssuanceId
:
parm
.
IssuanceID
,
DebtId
:
parm
.
DebtID
,
}
repay
:=
&
IssuanceAction
{
Ty
:
IssuanceActionRepay
,
Value
:
&
IssuanceAction_Repay
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
repay
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawIssuanceFeedTx method
func
CreateRawIssuanceFeedTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceFeedTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuancePriceFeedTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceFeed
{
Volume
:
parm
.
Volume
,
}
for
_
,
r
:=
range
parm
.
Price
{
v
.
Price
=
append
(
v
.
Price
,
int64
(
math
.
Trunc
(
r
*
1e4
)))
}
feed
:=
&
IssuanceAction
{
Ty
:
IssuanceActionFeed
,
Value
:
&
IssuanceAction_Feed
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
feed
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawIssuanceCloseTx method
func
CreateRawIssuanceCloseTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceCloseTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuanceCloseTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceClose
{
IssuanceId
:
parm
.
IssuanceID
,
}
close
:=
&
IssuanceAction
{
Ty
:
IssuanceActionClose
,
Value
:
&
IssuanceAction_Close
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
close
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
// CreateRawIssuanceManageTx method
func
CreateRawIssuanceManageTx
(
cfg
*
types
.
Chain33Config
,
parm
*
IssuanceManageTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
llog
.
Error
(
"CreateRawIssuanceManageTx"
,
"parm"
,
parm
)
return
nil
,
types
.
ErrInvalidParam
}
v
:=
&
IssuanceManage
{
SuperAddrs
:
parm
.
Addr
}
manage
:=
&
IssuanceAction
{
Ty
:
IssuanceActionManage
,
Value
:
&
IssuanceAction_Manage
{
v
},
}
tx
:=
&
types
.
Transaction
{
Execer
:
[]
byte
(
cfg
.
ExecName
(
IssuanceX
)),
Payload
:
types
.
Encode
(
manage
),
Fee
:
parm
.
Fee
,
To
:
address
.
ExecAddress
(
cfg
.
ExecName
(
IssuanceX
)),
}
name
:=
cfg
.
ExecName
(
IssuanceX
)
tx
,
err
:=
types
.
FormatTx
(
cfg
,
name
,
tx
)
if
err
!=
nil
{
return
nil
,
err
}
return
tx
,
nil
}
plugin/dapp/issuance/types/issuance.pb.go
0 → 100644
View file @
a717a020
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: issuance.proto
package
types
import
(
fmt
"fmt"
proto
"github.com/golang/protobuf/proto"
math
"math"
)
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const
_
=
proto
.
ProtoPackageIsVersion2
// please upgrade the proto package
// 发行信息
type
Issuance
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
TotalBalance
int64
`protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling
int64
`protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
CollateralValue
int64
`protobuf:"varint,5,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
DebtValue
int64
`protobuf:"varint,6,opt,name=debtValue,proto3" json:"debtValue,omitempty"`
DebtRecords
[]
*
DebtRecord
`protobuf:"bytes,7,rep,name=debtRecords,proto3" json:"debtRecords,omitempty"`
InvalidRecords
[]
*
DebtRecord
`protobuf:"bytes,8,rep,name=invalidRecords,proto3" json:"invalidRecords,omitempty"`
Status
int32
`protobuf:"varint,9,opt,name=status,proto3" json:"status,omitempty"`
LatestLiquidationPrice
int64
`protobuf:"varint,10,opt,name=latestLiquidationPrice,proto3" json:"latestLiquidationPrice,omitempty"`
Period
int64
`protobuf:"varint,11,opt,name=period,proto3" json:"period,omitempty"`
LatestExpireTime
int64
`protobuf:"varint,12,opt,name=latestExpireTime,proto3" json:"latestExpireTime,omitempty"`
CreateTime
int64
`protobuf:"varint,13,opt,name=createTime,proto3" json:"createTime,omitempty"`
Balance
int64
`protobuf:"varint,14,opt,name=balance,proto3" json:"balance,omitempty"`
IssuerAddr
string
`protobuf:"bytes,15,opt,name=issuerAddr,proto3" json:"issuerAddr,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
Issuance
)
Reset
()
{
*
m
=
Issuance
{}
}
func
(
m
*
Issuance
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Issuance
)
ProtoMessage
()
{}
func
(
*
Issuance
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
0
}
}
func
(
m
*
Issuance
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_Issuance
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
Issuance
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_Issuance
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
Issuance
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_Issuance
.
Merge
(
dst
,
src
)
}
func
(
m
*
Issuance
)
XXX_Size
()
int
{
return
xxx_messageInfo_Issuance
.
Size
(
m
)
}
func
(
m
*
Issuance
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_Issuance
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_Issuance
proto
.
InternalMessageInfo
func
(
m
*
Issuance
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
Issuance
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
Issuance
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
Issuance
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
Issuance
)
GetCollateralValue
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralValue
}
return
0
}
func
(
m
*
Issuance
)
GetDebtValue
()
int64
{
if
m
!=
nil
{
return
m
.
DebtValue
}
return
0
}
func
(
m
*
Issuance
)
GetDebtRecords
()
[]
*
DebtRecord
{
if
m
!=
nil
{
return
m
.
DebtRecords
}
return
nil
}
func
(
m
*
Issuance
)
GetInvalidRecords
()
[]
*
DebtRecord
{
if
m
!=
nil
{
return
m
.
InvalidRecords
}
return
nil
}
func
(
m
*
Issuance
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
Issuance
)
GetLatestLiquidationPrice
()
int64
{
if
m
!=
nil
{
return
m
.
LatestLiquidationPrice
}
return
0
}
func
(
m
*
Issuance
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
Issuance
)
GetLatestExpireTime
()
int64
{
if
m
!=
nil
{
return
m
.
LatestExpireTime
}
return
0
}
func
(
m
*
Issuance
)
GetCreateTime
()
int64
{
if
m
!=
nil
{
return
m
.
CreateTime
}
return
0
}
func
(
m
*
Issuance
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
(
m
*
Issuance
)
GetIssuerAddr
()
string
{
if
m
!=
nil
{
return
m
.
IssuerAddr
}
return
""
}
// 抵押记录
type
DebtRecord
struct
{
AccountAddr
string
`protobuf:"bytes,1,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
StartTime
int64
`protobuf:"varint,2,opt,name=startTime,proto3" json:"startTime,omitempty"`
CollateralValue
int64
`protobuf:"varint,3,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
CollateralPrice
int64
`protobuf:"varint,4,opt,name=collateralPrice,proto3" json:"collateralPrice,omitempty"`
DebtValue
int64
`protobuf:"varint,5,opt,name=debtValue,proto3" json:"debtValue,omitempty"`
LiquidationPrice
int64
`protobuf:"varint,6,opt,name=liquidationPrice,proto3" json:"liquidationPrice,omitempty"`
Status
int32
`protobuf:"varint,7,opt,name=status,proto3" json:"status,omitempty"`
LiquidateTime
int64
`protobuf:"varint,8,opt,name=liquidateTime,proto3" json:"liquidateTime,omitempty"`
ExpireTime
int64
`protobuf:"varint,9,opt,name=expireTime,proto3" json:"expireTime,omitempty"`
PreStatus
int32
`protobuf:"varint,10,opt,name=preStatus,proto3" json:"preStatus,omitempty"`
DebtId
string
`protobuf:"bytes,11,opt,name=debtId,proto3" json:"debtId,omitempty"`
IssuId
string
`protobuf:"bytes,12,opt,name=issuId,proto3" json:"issuId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
DebtRecord
)
Reset
()
{
*
m
=
DebtRecord
{}
}
func
(
m
*
DebtRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
DebtRecord
)
ProtoMessage
()
{}
func
(
*
DebtRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
1
}
}
func
(
m
*
DebtRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_DebtRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
DebtRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_DebtRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
DebtRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_DebtRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
DebtRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_DebtRecord
.
Size
(
m
)
}
func
(
m
*
DebtRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_DebtRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_DebtRecord
proto
.
InternalMessageInfo
func
(
m
*
DebtRecord
)
GetAccountAddr
()
string
{
if
m
!=
nil
{
return
m
.
AccountAddr
}
return
""
}
func
(
m
*
DebtRecord
)
GetStartTime
()
int64
{
if
m
!=
nil
{
return
m
.
StartTime
}
return
0
}
func
(
m
*
DebtRecord
)
GetCollateralValue
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralValue
}
return
0
}
func
(
m
*
DebtRecord
)
GetCollateralPrice
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralPrice
}
return
0
}
func
(
m
*
DebtRecord
)
GetDebtValue
()
int64
{
if
m
!=
nil
{
return
m
.
DebtValue
}
return
0
}
func
(
m
*
DebtRecord
)
GetLiquidationPrice
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationPrice
}
return
0
}
func
(
m
*
DebtRecord
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
DebtRecord
)
GetLiquidateTime
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidateTime
}
return
0
}
func
(
m
*
DebtRecord
)
GetExpireTime
()
int64
{
if
m
!=
nil
{
return
m
.
ExpireTime
}
return
0
}
func
(
m
*
DebtRecord
)
GetPreStatus
()
int32
{
if
m
!=
nil
{
return
m
.
PreStatus
}
return
0
}
func
(
m
*
DebtRecord
)
GetDebtId
()
string
{
if
m
!=
nil
{
return
m
.
DebtId
}
return
""
}
func
(
m
*
DebtRecord
)
GetIssuId
()
string
{
if
m
!=
nil
{
return
m
.
IssuId
}
return
""
}
// 资产价格记录
type
IssuanceAssetPriceRecord
struct
{
RecordTime
int64
`protobuf:"varint,1,opt,name=recordTime,proto3" json:"recordTime,omitempty"`
BtyPrice
int64
`protobuf:"varint,2,opt,name=btyPrice,proto3" json:"btyPrice,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceAssetPriceRecord
)
Reset
()
{
*
m
=
IssuanceAssetPriceRecord
{}
}
func
(
m
*
IssuanceAssetPriceRecord
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceAssetPriceRecord
)
ProtoMessage
()
{}
func
(
*
IssuanceAssetPriceRecord
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
2
}
}
func
(
m
*
IssuanceAssetPriceRecord
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceAssetPriceRecord
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceAssetPriceRecord
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceAssetPriceRecord
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceAssetPriceRecord
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceAssetPriceRecord
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceAssetPriceRecord
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceAssetPriceRecord
.
Size
(
m
)
}
func
(
m
*
IssuanceAssetPriceRecord
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceAssetPriceRecord
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceAssetPriceRecord
proto
.
InternalMessageInfo
func
(
m
*
IssuanceAssetPriceRecord
)
GetRecordTime
()
int64
{
if
m
!=
nil
{
return
m
.
RecordTime
}
return
0
}
func
(
m
*
IssuanceAssetPriceRecord
)
GetBtyPrice
()
int64
{
if
m
!=
nil
{
return
m
.
BtyPrice
}
return
0
}
// action
type
IssuanceAction
struct
{
// Types that are valid to be assigned to Value:
// *IssuanceAction_Create
// *IssuanceAction_Debt
// *IssuanceAction_Repay
// *IssuanceAction_Feed
// *IssuanceAction_Close
// *IssuanceAction_Manage
Value
isIssuanceAction_Value
`protobuf_oneof:"value"`
Ty
int32
`protobuf:"varint,10,opt,name=ty,proto3" json:"ty,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceAction
)
Reset
()
{
*
m
=
IssuanceAction
{}
}
func
(
m
*
IssuanceAction
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceAction
)
ProtoMessage
()
{}
func
(
*
IssuanceAction
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
3
}
}
func
(
m
*
IssuanceAction
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceAction
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceAction
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceAction
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceAction
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceAction
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceAction
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceAction
.
Size
(
m
)
}
func
(
m
*
IssuanceAction
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceAction
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceAction
proto
.
InternalMessageInfo
type
isIssuanceAction_Value
interface
{
isIssuanceAction_Value
()
}
type
IssuanceAction_Create
struct
{
Create
*
IssuanceCreate
`protobuf:"bytes,1,opt,name=create,proto3,oneof"`
}
type
IssuanceAction_Debt
struct
{
Debt
*
IssuanceDebt
`protobuf:"bytes,2,opt,name=debt,proto3,oneof"`
}
type
IssuanceAction_Repay
struct
{
Repay
*
IssuanceRepay
`protobuf:"bytes,3,opt,name=repay,proto3,oneof"`
}
type
IssuanceAction_Feed
struct
{
Feed
*
IssuanceFeed
`protobuf:"bytes,4,opt,name=feed,proto3,oneof"`
}
type
IssuanceAction_Close
struct
{
Close
*
IssuanceClose
`protobuf:"bytes,5,opt,name=close,proto3,oneof"`
}
type
IssuanceAction_Manage
struct
{
Manage
*
IssuanceManage
`protobuf:"bytes,6,opt,name=manage,proto3,oneof"`
}
func
(
*
IssuanceAction_Create
)
isIssuanceAction_Value
()
{}
func
(
*
IssuanceAction_Debt
)
isIssuanceAction_Value
()
{}
func
(
*
IssuanceAction_Repay
)
isIssuanceAction_Value
()
{}
func
(
*
IssuanceAction_Feed
)
isIssuanceAction_Value
()
{}
func
(
*
IssuanceAction_Close
)
isIssuanceAction_Value
()
{}
func
(
*
IssuanceAction_Manage
)
isIssuanceAction_Value
()
{}
func
(
m
*
IssuanceAction
)
GetValue
()
isIssuanceAction_Value
{
if
m
!=
nil
{
return
m
.
Value
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetCreate
()
*
IssuanceCreate
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Create
);
ok
{
return
x
.
Create
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetDebt
()
*
IssuanceDebt
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Debt
);
ok
{
return
x
.
Debt
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetRepay
()
*
IssuanceRepay
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Repay
);
ok
{
return
x
.
Repay
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetFeed
()
*
IssuanceFeed
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Feed
);
ok
{
return
x
.
Feed
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetClose
()
*
IssuanceClose
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Close
);
ok
{
return
x
.
Close
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetManage
()
*
IssuanceManage
{
if
x
,
ok
:=
m
.
GetValue
()
.
(
*
IssuanceAction_Manage
);
ok
{
return
x
.
Manage
}
return
nil
}
func
(
m
*
IssuanceAction
)
GetTy
()
int32
{
if
m
!=
nil
{
return
m
.
Ty
}
return
0
}
// XXX_OneofFuncs is for the internal use of the proto package.
func
(
*
IssuanceAction
)
XXX_OneofFuncs
()
(
func
(
msg
proto
.
Message
,
b
*
proto
.
Buffer
)
error
,
func
(
msg
proto
.
Message
,
tag
,
wire
int
,
b
*
proto
.
Buffer
)
(
bool
,
error
),
func
(
msg
proto
.
Message
)
(
n
int
),
[]
interface
{})
{
return
_IssuanceAction_OneofMarshaler
,
_IssuanceAction_OneofUnmarshaler
,
_IssuanceAction_OneofSizer
,
[]
interface
{}{
(
*
IssuanceAction_Create
)(
nil
),
(
*
IssuanceAction_Debt
)(
nil
),
(
*
IssuanceAction_Repay
)(
nil
),
(
*
IssuanceAction_Feed
)(
nil
),
(
*
IssuanceAction_Close
)(
nil
),
(
*
IssuanceAction_Manage
)(
nil
),
}
}
func
_IssuanceAction_OneofMarshaler
(
msg
proto
.
Message
,
b
*
proto
.
Buffer
)
error
{
m
:=
msg
.
(
*
IssuanceAction
)
// value
switch
x
:=
m
.
Value
.
(
type
)
{
case
*
IssuanceAction_Create
:
b
.
EncodeVarint
(
1
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Create
);
err
!=
nil
{
return
err
}
case
*
IssuanceAction_Debt
:
b
.
EncodeVarint
(
2
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Debt
);
err
!=
nil
{
return
err
}
case
*
IssuanceAction_Repay
:
b
.
EncodeVarint
(
3
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Repay
);
err
!=
nil
{
return
err
}
case
*
IssuanceAction_Feed
:
b
.
EncodeVarint
(
4
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Feed
);
err
!=
nil
{
return
err
}
case
*
IssuanceAction_Close
:
b
.
EncodeVarint
(
5
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Close
);
err
!=
nil
{
return
err
}
case
*
IssuanceAction_Manage
:
b
.
EncodeVarint
(
6
<<
3
|
proto
.
WireBytes
)
if
err
:=
b
.
EncodeMessage
(
x
.
Manage
);
err
!=
nil
{
return
err
}
case
nil
:
default
:
return
fmt
.
Errorf
(
"IssuanceAction.Value has unexpected type %T"
,
x
)
}
return
nil
}
func
_IssuanceAction_OneofUnmarshaler
(
msg
proto
.
Message
,
tag
,
wire
int
,
b
*
proto
.
Buffer
)
(
bool
,
error
)
{
m
:=
msg
.
(
*
IssuanceAction
)
switch
tag
{
case
1
:
// value.create
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceCreate
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Create
{
msg
}
return
true
,
err
case
2
:
// value.debt
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceDebt
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Debt
{
msg
}
return
true
,
err
case
3
:
// value.repay
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceRepay
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Repay
{
msg
}
return
true
,
err
case
4
:
// value.feed
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceFeed
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Feed
{
msg
}
return
true
,
err
case
5
:
// value.close
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceClose
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Close
{
msg
}
return
true
,
err
case
6
:
// value.manage
if
wire
!=
proto
.
WireBytes
{
return
true
,
proto
.
ErrInternalBadWireType
}
msg
:=
new
(
IssuanceManage
)
err
:=
b
.
DecodeMessage
(
msg
)
m
.
Value
=
&
IssuanceAction_Manage
{
msg
}
return
true
,
err
default
:
return
false
,
nil
}
}
func
_IssuanceAction_OneofSizer
(
msg
proto
.
Message
)
(
n
int
)
{
m
:=
msg
.
(
*
IssuanceAction
)
// value
switch
x
:=
m
.
Value
.
(
type
)
{
case
*
IssuanceAction_Create
:
s
:=
proto
.
Size
(
x
.
Create
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
IssuanceAction_Debt
:
s
:=
proto
.
Size
(
x
.
Debt
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
IssuanceAction_Repay
:
s
:=
proto
.
Size
(
x
.
Repay
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
IssuanceAction_Feed
:
s
:=
proto
.
Size
(
x
.
Feed
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
IssuanceAction_Close
:
s
:=
proto
.
Size
(
x
.
Close
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
*
IssuanceAction_Manage
:
s
:=
proto
.
Size
(
x
.
Manage
)
n
+=
1
// tag and wire
n
+=
proto
.
SizeVarint
(
uint64
(
s
))
n
+=
s
case
nil
:
default
:
panic
(
fmt
.
Sprintf
(
"proto: unexpected type %T in oneof"
,
x
))
}
return
n
}
type
IssuanceManage
struct
{
SuperAddrs
[]
string
`protobuf:"bytes,1,rep,name=superAddrs,proto3" json:"superAddrs,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceManage
)
Reset
()
{
*
m
=
IssuanceManage
{}
}
func
(
m
*
IssuanceManage
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceManage
)
ProtoMessage
()
{}
func
(
*
IssuanceManage
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
4
}
}
func
(
m
*
IssuanceManage
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceManage
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceManage
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceManage
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceManage
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceManage
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceManage
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceManage
.
Size
(
m
)
}
func
(
m
*
IssuanceManage
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceManage
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceManage
proto
.
InternalMessageInfo
func
(
m
*
IssuanceManage
)
GetSuperAddrs
()
[]
string
{
if
m
!=
nil
{
return
m
.
SuperAddrs
}
return
nil
}
// 创建发行
type
IssuanceCreate
struct
{
TotalBalance
int64
`protobuf:"varint,1,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling
int64
`protobuf:"varint,2,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,3,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
Period
int64
`protobuf:"varint,4,opt,name=period,proto3" json:"period,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceCreate
)
Reset
()
{
*
m
=
IssuanceCreate
{}
}
func
(
m
*
IssuanceCreate
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceCreate
)
ProtoMessage
()
{}
func
(
*
IssuanceCreate
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
5
}
}
func
(
m
*
IssuanceCreate
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceCreate
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceCreate
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceCreate
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceCreate
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceCreate
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceCreate
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceCreate
.
Size
(
m
)
}
func
(
m
*
IssuanceCreate
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceCreate
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceCreate
proto
.
InternalMessageInfo
func
(
m
*
IssuanceCreate
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
IssuanceCreate
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
IssuanceCreate
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
IssuanceCreate
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
// 抵押
type
IssuanceDebt
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
Value
int64
`protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceDebt
)
Reset
()
{
*
m
=
IssuanceDebt
{}
}
func
(
m
*
IssuanceDebt
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceDebt
)
ProtoMessage
()
{}
func
(
*
IssuanceDebt
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
6
}
}
func
(
m
*
IssuanceDebt
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceDebt
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceDebt
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceDebt
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceDebt
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceDebt
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceDebt
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceDebt
.
Size
(
m
)
}
func
(
m
*
IssuanceDebt
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceDebt
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceDebt
proto
.
InternalMessageInfo
func
(
m
*
IssuanceDebt
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
IssuanceDebt
)
GetValue
()
int64
{
if
m
!=
nil
{
return
m
.
Value
}
return
0
}
// 质押清算
type
IssuanceRepay
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
DebtId
string
`protobuf:"bytes,2,opt,name=debtId,proto3" json:"debtId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceRepay
)
Reset
()
{
*
m
=
IssuanceRepay
{}
}
func
(
m
*
IssuanceRepay
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceRepay
)
ProtoMessage
()
{}
func
(
*
IssuanceRepay
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
7
}
}
func
(
m
*
IssuanceRepay
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceRepay
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceRepay
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceRepay
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceRepay
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceRepay
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceRepay
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceRepay
.
Size
(
m
)
}
func
(
m
*
IssuanceRepay
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceRepay
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceRepay
proto
.
InternalMessageInfo
func
(
m
*
IssuanceRepay
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
IssuanceRepay
)
GetDebtId
()
string
{
if
m
!=
nil
{
return
m
.
DebtId
}
return
""
}
// 喂价
type
IssuanceFeed
struct
{
CollType
int32
`protobuf:"varint,1,opt,name=collType,proto3" json:"collType,omitempty"`
Price
[]
int64
`protobuf:"varint,2,rep,packed,name=price,proto3" json:"price,omitempty"`
Volume
[]
int64
`protobuf:"varint,3,rep,packed,name=volume,proto3" json:"volume,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceFeed
)
Reset
()
{
*
m
=
IssuanceFeed
{}
}
func
(
m
*
IssuanceFeed
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceFeed
)
ProtoMessage
()
{}
func
(
*
IssuanceFeed
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
8
}
}
func
(
m
*
IssuanceFeed
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceFeed
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceFeed
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceFeed
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceFeed
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceFeed
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceFeed
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceFeed
.
Size
(
m
)
}
func
(
m
*
IssuanceFeed
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceFeed
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceFeed
proto
.
InternalMessageInfo
func
(
m
*
IssuanceFeed
)
GetCollType
()
int32
{
if
m
!=
nil
{
return
m
.
CollType
}
return
0
}
func
(
m
*
IssuanceFeed
)
GetPrice
()
[]
int64
{
if
m
!=
nil
{
return
m
.
Price
}
return
nil
}
func
(
m
*
IssuanceFeed
)
GetVolume
()
[]
int64
{
if
m
!=
nil
{
return
m
.
Volume
}
return
nil
}
// 借贷关闭
type
IssuanceClose
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceClose
)
Reset
()
{
*
m
=
IssuanceClose
{}
}
func
(
m
*
IssuanceClose
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceClose
)
ProtoMessage
()
{}
func
(
*
IssuanceClose
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
9
}
}
func
(
m
*
IssuanceClose
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceClose
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceClose
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceClose
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceClose
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceClose
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceClose
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceClose
.
Size
(
m
)
}
func
(
m
*
IssuanceClose
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceClose
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceClose
proto
.
InternalMessageInfo
func
(
m
*
IssuanceClose
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
// exec_local 发行信息
type
ReceiptIssuance
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
AccountAddr
string
`protobuf:"bytes,2,opt,name=accountAddr,proto3" json:"accountAddr,omitempty"`
DebtId
string
`protobuf:"bytes,3,opt,name=debtId,proto3" json:"debtId,omitempty"`
Status
int32
`protobuf:"varint,4,opt,name=status,proto3" json:"status,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReceiptIssuance
)
Reset
()
{
*
m
=
ReceiptIssuance
{}
}
func
(
m
*
ReceiptIssuance
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReceiptIssuance
)
ProtoMessage
()
{}
func
(
*
ReceiptIssuance
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
10
}
}
func
(
m
*
ReceiptIssuance
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReceiptIssuance
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReceiptIssuance
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReceiptIssuance
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReceiptIssuance
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReceiptIssuance
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReceiptIssuance
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReceiptIssuance
.
Size
(
m
)
}
func
(
m
*
ReceiptIssuance
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReceiptIssuance
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReceiptIssuance
proto
.
InternalMessageInfo
func
(
m
*
ReceiptIssuance
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
ReceiptIssuance
)
GetAccountAddr
()
string
{
if
m
!=
nil
{
return
m
.
AccountAddr
}
return
""
}
func
(
m
*
ReceiptIssuance
)
GetDebtId
()
string
{
if
m
!=
nil
{
return
m
.
DebtId
}
return
""
}
func
(
m
*
ReceiptIssuance
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
// exec_local issuid记录信息
type
ReceiptIssuanceID
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
Status
int32
`protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReceiptIssuanceID
)
Reset
()
{
*
m
=
ReceiptIssuanceID
{}
}
func
(
m
*
ReceiptIssuanceID
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReceiptIssuanceID
)
ProtoMessage
()
{}
func
(
*
ReceiptIssuanceID
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
11
}
}
func
(
m
*
ReceiptIssuanceID
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReceiptIssuanceID
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReceiptIssuanceID
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReceiptIssuanceID
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReceiptIssuanceID
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReceiptIssuanceID
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReceiptIssuanceID
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReceiptIssuanceID
.
Size
(
m
)
}
func
(
m
*
ReceiptIssuanceID
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReceiptIssuanceID
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReceiptIssuanceID
proto
.
InternalMessageInfo
func
(
m
*
ReceiptIssuanceID
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
ReceiptIssuanceID
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
// exec_local 抵押记录信息列表
type
IssuanceRecords
struct
{
Records
[]
*
ReceiptIssuance
`protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
IssuanceRecords
)
Reset
()
{
*
m
=
IssuanceRecords
{}
}
func
(
m
*
IssuanceRecords
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
IssuanceRecords
)
ProtoMessage
()
{}
func
(
*
IssuanceRecords
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
12
}
}
func
(
m
*
IssuanceRecords
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_IssuanceRecords
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
IssuanceRecords
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_IssuanceRecords
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
IssuanceRecords
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_IssuanceRecords
.
Merge
(
dst
,
src
)
}
func
(
m
*
IssuanceRecords
)
XXX_Size
()
int
{
return
xxx_messageInfo_IssuanceRecords
.
Size
(
m
)
}
func
(
m
*
IssuanceRecords
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_IssuanceRecords
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_IssuanceRecords
proto
.
InternalMessageInfo
func
(
m
*
IssuanceRecords
)
GetRecords
()
[]
*
ReceiptIssuance
{
if
m
!=
nil
{
return
m
.
Records
}
return
nil
}
// 根据ID查询发行信息
type
ReqIssuanceInfo
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqIssuanceInfo
)
Reset
()
{
*
m
=
ReqIssuanceInfo
{}
}
func
(
m
*
ReqIssuanceInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqIssuanceInfo
)
ProtoMessage
()
{}
func
(
*
ReqIssuanceInfo
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
13
}
}
func
(
m
*
ReqIssuanceInfo
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqIssuanceInfo
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqIssuanceInfo
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqIssuanceInfo
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqIssuanceInfo
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqIssuanceInfo
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqIssuanceInfo
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqIssuanceInfo
.
Size
(
m
)
}
func
(
m
*
ReqIssuanceInfo
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqIssuanceInfo
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqIssuanceInfo
proto
.
InternalMessageInfo
func
(
m
*
ReqIssuanceInfo
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
// 返回一期发行信息
type
RepIssuanceCurrentInfo
struct
{
Status
int32
`protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
TotalBalance
int64
`protobuf:"varint,2,opt,name=totalBalance,proto3" json:"totalBalance,omitempty"`
DebtCeiling
int64
`protobuf:"varint,3,opt,name=debtCeiling,proto3" json:"debtCeiling,omitempty"`
LiquidationRatio
int64
`protobuf:"varint,4,opt,name=liquidationRatio,proto3" json:"liquidationRatio,omitempty"`
Balance
int64
`protobuf:"varint,5,opt,name=balance,proto3" json:"balance,omitempty"`
CollateralValue
int64
`protobuf:"varint,6,opt,name=collateralValue,proto3" json:"collateralValue,omitempty"`
DebtValue
int64
`protobuf:"varint,7,opt,name=debtValue,proto3" json:"debtValue,omitempty"`
Period
int64
`protobuf:"varint,8,opt,name=period,proto3" json:"period,omitempty"`
IssuId
string
`protobuf:"bytes,9,opt,name=issuId,proto3" json:"issuId,omitempty"`
CreateTime
int64
`protobuf:"varint,10,opt,name=createTime,proto3" json:"createTime,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceCurrentInfo
)
Reset
()
{
*
m
=
RepIssuanceCurrentInfo
{}
}
func
(
m
*
RepIssuanceCurrentInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceCurrentInfo
)
ProtoMessage
()
{}
func
(
*
RepIssuanceCurrentInfo
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
14
}
}
func
(
m
*
RepIssuanceCurrentInfo
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceCurrentInfo
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceCurrentInfo
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceCurrentInfo
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceCurrentInfo
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceCurrentInfo
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceCurrentInfo
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceCurrentInfo
.
Size
(
m
)
}
func
(
m
*
RepIssuanceCurrentInfo
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceCurrentInfo
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceCurrentInfo
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceCurrentInfo
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetTotalBalance
()
int64
{
if
m
!=
nil
{
return
m
.
TotalBalance
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetDebtCeiling
()
int64
{
if
m
!=
nil
{
return
m
.
DebtCeiling
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetLiquidationRatio
()
int64
{
if
m
!=
nil
{
return
m
.
LiquidationRatio
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetCollateralValue
()
int64
{
if
m
!=
nil
{
return
m
.
CollateralValue
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetDebtValue
()
int64
{
if
m
!=
nil
{
return
m
.
DebtValue
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetPeriod
()
int64
{
if
m
!=
nil
{
return
m
.
Period
}
return
0
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetIssuId
()
string
{
if
m
!=
nil
{
return
m
.
IssuId
}
return
""
}
func
(
m
*
RepIssuanceCurrentInfo
)
GetCreateTime
()
int64
{
if
m
!=
nil
{
return
m
.
CreateTime
}
return
0
}
// 根据ID列表查询多期发行信息
type
ReqIssuanceInfos
struct
{
IssuanceIds
[]
string
`protobuf:"bytes,1,rep,name=issuanceIds,proto3" json:"issuanceIds,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqIssuanceInfos
)
Reset
()
{
*
m
=
ReqIssuanceInfos
{}
}
func
(
m
*
ReqIssuanceInfos
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqIssuanceInfos
)
ProtoMessage
()
{}
func
(
*
ReqIssuanceInfos
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
15
}
}
func
(
m
*
ReqIssuanceInfos
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqIssuanceInfos
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqIssuanceInfos
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqIssuanceInfos
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqIssuanceInfos
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqIssuanceInfos
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqIssuanceInfos
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqIssuanceInfos
.
Size
(
m
)
}
func
(
m
*
ReqIssuanceInfos
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqIssuanceInfos
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqIssuanceInfos
proto
.
InternalMessageInfo
func
(
m
*
ReqIssuanceInfos
)
GetIssuanceIds
()
[]
string
{
if
m
!=
nil
{
return
m
.
IssuanceIds
}
return
nil
}
// 返回多期发行信息
type
RepIssuanceCurrentInfos
struct
{
Infos
[]
*
RepIssuanceCurrentInfo
`protobuf:"bytes,1,rep,name=infos,proto3" json:"infos,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceCurrentInfos
)
Reset
()
{
*
m
=
RepIssuanceCurrentInfos
{}
}
func
(
m
*
RepIssuanceCurrentInfos
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceCurrentInfos
)
ProtoMessage
()
{}
func
(
*
RepIssuanceCurrentInfos
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
16
}
}
func
(
m
*
RepIssuanceCurrentInfos
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceCurrentInfos
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceCurrentInfos
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceCurrentInfos
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceCurrentInfos
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceCurrentInfos
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceCurrentInfos
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceCurrentInfos
.
Size
(
m
)
}
func
(
m
*
RepIssuanceCurrentInfos
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceCurrentInfos
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceCurrentInfos
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceCurrentInfos
)
GetInfos
()
[]
*
RepIssuanceCurrentInfo
{
if
m
!=
nil
{
return
m
.
Infos
}
return
nil
}
// 根据发行状态查询
type
ReqIssuanceByStatus
struct
{
Status
int32
`protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"`
IssuanceId
string
`protobuf:"bytes,2,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqIssuanceByStatus
)
Reset
()
{
*
m
=
ReqIssuanceByStatus
{}
}
func
(
m
*
ReqIssuanceByStatus
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqIssuanceByStatus
)
ProtoMessage
()
{}
func
(
*
ReqIssuanceByStatus
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
17
}
}
func
(
m
*
ReqIssuanceByStatus
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqIssuanceByStatus
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqIssuanceByStatus
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqIssuanceByStatus
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqIssuanceByStatus
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqIssuanceByStatus
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqIssuanceByStatus
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqIssuanceByStatus
.
Size
(
m
)
}
func
(
m
*
ReqIssuanceByStatus
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqIssuanceByStatus
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqIssuanceByStatus
proto
.
InternalMessageInfo
func
(
m
*
ReqIssuanceByStatus
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqIssuanceByStatus
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
// 返回发行ID列表
type
RepIssuanceIDs
struct
{
IDs
[]
string
`protobuf:"bytes,1,rep,name=IDs,proto3" json:"IDs,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceIDs
)
Reset
()
{
*
m
=
RepIssuanceIDs
{}
}
func
(
m
*
RepIssuanceIDs
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceIDs
)
ProtoMessage
()
{}
func
(
*
RepIssuanceIDs
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
18
}
}
func
(
m
*
RepIssuanceIDs
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceIDs
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceIDs
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceIDs
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceIDs
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceIDs
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceIDs
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceIDs
.
Size
(
m
)
}
func
(
m
*
RepIssuanceIDs
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceIDs
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceIDs
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceIDs
)
GetIDs
()
[]
string
{
if
m
!=
nil
{
return
m
.
IDs
}
return
nil
}
// 根据用户地址查询抵押记录
type
ReqIssuanceRecords
struct
{
IssuanceId
string
`protobuf:"bytes,1,opt,name=issuanceId,proto3" json:"issuanceId,omitempty"`
Addr
string
`protobuf:"bytes,2,opt,name=addr,proto3" json:"addr,omitempty"`
Status
int32
`protobuf:"varint,3,opt,name=status,proto3" json:"status,omitempty"`
DebtId
string
`protobuf:"bytes,4,opt,name=debtId,proto3" json:"debtId,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
ReqIssuanceRecords
)
Reset
()
{
*
m
=
ReqIssuanceRecords
{}
}
func
(
m
*
ReqIssuanceRecords
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ReqIssuanceRecords
)
ProtoMessage
()
{}
func
(
*
ReqIssuanceRecords
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
19
}
}
func
(
m
*
ReqIssuanceRecords
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_ReqIssuanceRecords
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
ReqIssuanceRecords
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_ReqIssuanceRecords
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
ReqIssuanceRecords
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_ReqIssuanceRecords
.
Merge
(
dst
,
src
)
}
func
(
m
*
ReqIssuanceRecords
)
XXX_Size
()
int
{
return
xxx_messageInfo_ReqIssuanceRecords
.
Size
(
m
)
}
func
(
m
*
ReqIssuanceRecords
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_ReqIssuanceRecords
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_ReqIssuanceRecords
proto
.
InternalMessageInfo
func
(
m
*
ReqIssuanceRecords
)
GetIssuanceId
()
string
{
if
m
!=
nil
{
return
m
.
IssuanceId
}
return
""
}
func
(
m
*
ReqIssuanceRecords
)
GetAddr
()
string
{
if
m
!=
nil
{
return
m
.
Addr
}
return
""
}
func
(
m
*
ReqIssuanceRecords
)
GetStatus
()
int32
{
if
m
!=
nil
{
return
m
.
Status
}
return
0
}
func
(
m
*
ReqIssuanceRecords
)
GetDebtId
()
string
{
if
m
!=
nil
{
return
m
.
DebtId
}
return
""
}
// 返回记录列表
type
RepIssuanceRecords
struct
{
Records
[]
*
DebtRecord
`protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceRecords
)
Reset
()
{
*
m
=
RepIssuanceRecords
{}
}
func
(
m
*
RepIssuanceRecords
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceRecords
)
ProtoMessage
()
{}
func
(
*
RepIssuanceRecords
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
20
}
}
func
(
m
*
RepIssuanceRecords
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceRecords
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceRecords
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceRecords
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceRecords
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceRecords
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceRecords
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceRecords
.
Size
(
m
)
}
func
(
m
*
RepIssuanceRecords
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceRecords
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceRecords
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceRecords
)
GetRecords
()
[]
*
DebtRecord
{
if
m
!=
nil
{
return
m
.
Records
}
return
nil
}
// 返回记录
type
RepIssuanceDebtInfo
struct
{
Record
*
DebtRecord
`protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceDebtInfo
)
Reset
()
{
*
m
=
RepIssuanceDebtInfo
{}
}
func
(
m
*
RepIssuanceDebtInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceDebtInfo
)
ProtoMessage
()
{}
func
(
*
RepIssuanceDebtInfo
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
21
}
}
func
(
m
*
RepIssuanceDebtInfo
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceDebtInfo
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceDebtInfo
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceDebtInfo
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceDebtInfo
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceDebtInfo
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceDebtInfo
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceDebtInfo
.
Size
(
m
)
}
func
(
m
*
RepIssuanceDebtInfo
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceDebtInfo
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceDebtInfo
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceDebtInfo
)
GetRecord
()
*
DebtRecord
{
if
m
!=
nil
{
return
m
.
Record
}
return
nil
}
// 返回最新抵押物价格
type
RepIssuancePrice
struct
{
Price
int64
`protobuf:"varint,1,opt,name=price,proto3" json:"price,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuancePrice
)
Reset
()
{
*
m
=
RepIssuancePrice
{}
}
func
(
m
*
RepIssuancePrice
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuancePrice
)
ProtoMessage
()
{}
func
(
*
RepIssuancePrice
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
22
}
}
func
(
m
*
RepIssuancePrice
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuancePrice
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuancePrice
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuancePrice
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuancePrice
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuancePrice
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuancePrice
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuancePrice
.
Size
(
m
)
}
func
(
m
*
RepIssuancePrice
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuancePrice
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuancePrice
proto
.
InternalMessageInfo
func
(
m
*
RepIssuancePrice
)
GetPrice
()
int64
{
if
m
!=
nil
{
return
m
.
Price
}
return
0
}
// 返回用户发行总额
type
RepIssuanceUserBalance
struct
{
Balance
int64
`protobuf:"varint,1,opt,name=balance,proto3" json:"balance,omitempty"`
XXX_NoUnkeyedLiteral
struct
{}
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
XXX_sizecache
int32
`json:"-"`
}
func
(
m
*
RepIssuanceUserBalance
)
Reset
()
{
*
m
=
RepIssuanceUserBalance
{}
}
func
(
m
*
RepIssuanceUserBalance
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
RepIssuanceUserBalance
)
ProtoMessage
()
{}
func
(
*
RepIssuanceUserBalance
)
Descriptor
()
([]
byte
,
[]
int
)
{
return
fileDescriptor_issuance_4d8bb77ed2bb92a1
,
[]
int
{
23
}
}
func
(
m
*
RepIssuanceUserBalance
)
XXX_Unmarshal
(
b
[]
byte
)
error
{
return
xxx_messageInfo_RepIssuanceUserBalance
.
Unmarshal
(
m
,
b
)
}
func
(
m
*
RepIssuanceUserBalance
)
XXX_Marshal
(
b
[]
byte
,
deterministic
bool
)
([]
byte
,
error
)
{
return
xxx_messageInfo_RepIssuanceUserBalance
.
Marshal
(
b
,
m
,
deterministic
)
}
func
(
dst
*
RepIssuanceUserBalance
)
XXX_Merge
(
src
proto
.
Message
)
{
xxx_messageInfo_RepIssuanceUserBalance
.
Merge
(
dst
,
src
)
}
func
(
m
*
RepIssuanceUserBalance
)
XXX_Size
()
int
{
return
xxx_messageInfo_RepIssuanceUserBalance
.
Size
(
m
)
}
func
(
m
*
RepIssuanceUserBalance
)
XXX_DiscardUnknown
()
{
xxx_messageInfo_RepIssuanceUserBalance
.
DiscardUnknown
(
m
)
}
var
xxx_messageInfo_RepIssuanceUserBalance
proto
.
InternalMessageInfo
func
(
m
*
RepIssuanceUserBalance
)
GetBalance
()
int64
{
if
m
!=
nil
{
return
m
.
Balance
}
return
0
}
func
init
()
{
proto
.
RegisterType
((
*
Issuance
)(
nil
),
"types.Issuance"
)
proto
.
RegisterType
((
*
DebtRecord
)(
nil
),
"types.DebtRecord"
)
proto
.
RegisterType
((
*
IssuanceAssetPriceRecord
)(
nil
),
"types.IssuanceAssetPriceRecord"
)
proto
.
RegisterType
((
*
IssuanceAction
)(
nil
),
"types.IssuanceAction"
)
proto
.
RegisterType
((
*
IssuanceManage
)(
nil
),
"types.IssuanceManage"
)
proto
.
RegisterType
((
*
IssuanceCreate
)(
nil
),
"types.IssuanceCreate"
)
proto
.
RegisterType
((
*
IssuanceDebt
)(
nil
),
"types.IssuanceDebt"
)
proto
.
RegisterType
((
*
IssuanceRepay
)(
nil
),
"types.IssuanceRepay"
)
proto
.
RegisterType
((
*
IssuanceFeed
)(
nil
),
"types.IssuanceFeed"
)
proto
.
RegisterType
((
*
IssuanceClose
)(
nil
),
"types.IssuanceClose"
)
proto
.
RegisterType
((
*
ReceiptIssuance
)(
nil
),
"types.ReceiptIssuance"
)
proto
.
RegisterType
((
*
ReceiptIssuanceID
)(
nil
),
"types.ReceiptIssuanceID"
)
proto
.
RegisterType
((
*
IssuanceRecords
)(
nil
),
"types.IssuanceRecords"
)
proto
.
RegisterType
((
*
ReqIssuanceInfo
)(
nil
),
"types.ReqIssuanceInfo"
)
proto
.
RegisterType
((
*
RepIssuanceCurrentInfo
)(
nil
),
"types.RepIssuanceCurrentInfo"
)
proto
.
RegisterType
((
*
ReqIssuanceInfos
)(
nil
),
"types.ReqIssuanceInfos"
)
proto
.
RegisterType
((
*
RepIssuanceCurrentInfos
)(
nil
),
"types.RepIssuanceCurrentInfos"
)
proto
.
RegisterType
((
*
ReqIssuanceByStatus
)(
nil
),
"types.ReqIssuanceByStatus"
)
proto
.
RegisterType
((
*
RepIssuanceIDs
)(
nil
),
"types.RepIssuanceIDs"
)
proto
.
RegisterType
((
*
ReqIssuanceRecords
)(
nil
),
"types.ReqIssuanceRecords"
)
proto
.
RegisterType
((
*
RepIssuanceRecords
)(
nil
),
"types.RepIssuanceRecords"
)
proto
.
RegisterType
((
*
RepIssuanceDebtInfo
)(
nil
),
"types.RepIssuanceDebtInfo"
)
proto
.
RegisterType
((
*
RepIssuancePrice
)(
nil
),
"types.RepIssuancePrice"
)
proto
.
RegisterType
((
*
RepIssuanceUserBalance
)(
nil
),
"types.RepIssuanceUserBalance"
)
}
func
init
()
{
proto
.
RegisterFile
(
"issuance.proto"
,
fileDescriptor_issuance_4d8bb77ed2bb92a1
)
}
var
fileDescriptor_issuance_4d8bb77ed2bb92a1
=
[]
byte
{
// 1041 bytes of a gzipped FileDescriptorProto
0x1f
,
0x8b
,
0x08
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x02
,
0xff
,
0xbc
,
0x57
,
0x5f
,
0x6f
,
0xe3
,
0x44
,
0x10
,
0xaf
,
0xed
,
0x38
,
0x7f
,
0x26
,
0x6d
,
0xda
,
0xdb
,
0x3b
,
0x8a
,
0x85
,
0xe0
,
0x14
,
0xad
,
0x78
,
0xc8
,
0x01
,
0xea
,
0x1d
,
0x29
,
0x42
,
0xe2
,
0x8d
,
0xb6
,
0x01
,
0x1a
,
0xc1
,
0x21
,
0x64
,
0x8e
,
0x13
,
0xaf
,
0xae
,
0xbd
,
0x77
,
0xb2
,
0xe4
,
0xc6
,
0x3e
,
0xef
,
0xa6
,
0xba
,
0x3c
,
0xf3
,
0x1d
,
0x78
,
0xe0
,
0xbb
,
0xf0
,
0xc2
,
0x67
,
0xe0
,
0x03
,
0xa1
,
0xd9
,
0x5d
,
0x7b
,
0xd7
,
0x9b
,
0x54
,
0xe9
,
0x13
,
0x2f
,
0x55
,
0x76
,
0xf6
,
0xb7
,
0xb3
,
0xb3
,
0xf3
,
0xfb
,
0xcd
,
0x8c
,
0x0b
,
0x93
,
0x9c
,
0xf3
,
0x75
,
0xb2
,
0x4a
,
0xd9
,
0x59
,
0x55
,
0x97
,
0xa2
,
0x24
,
0xa1
,
0xd8
,
0x54
,
0x8c
,
0xd3
,
0x7f
,
0x7a
,
0x30
,
0x5c
,
0xea
,
0x1d
,
0xf2
,
0x14
,
0xa0
,
0x41
,
0x2d
,
0xb3
,
0xc8
,
0x9b
,
0x7a
,
0xb3
,
0x51
,
0x6c
,
0x59
,
0x08
,
0x85
,
0x43
,
0x51
,
0x8a
,
0xa4
,
0xb8
,
0x4c
,
0x0a
,
0xb4
,
0x44
,
0xfe
,
0xd4
,
0x9b
,
0x05
,
0x71
,
0xc7
,
0x46
,
0xa6
,
0x30
,
0xce
,
0xd8
,
0x8d
,
0xb8
,
0x62
,
0x79
,
0x91
,
0xaf
,
0xde
,
0x46
,
0x81
,
0x84
,
0xd8
,
0x26
,
0xf2
,
0x19
,
0x9c
,
0x14
,
0xf9
,
0xbb
,
0x75
,
0x9e
,
0x25
,
0x22
,
0x2f
,
0x57
,
0x31
,
0xfe
,
0x8d
,
0x7a
,
0x12
,
0xb6
,
0x65
,
0x27
,
0x33
,
0x38
,
0x4e
,
0xcb
,
0xa2
,
0x48
,
0x04
,
0xab
,
0x93
,
0xe2
,
0x75
,
0x52
,
0xac
,
0x59
,
0x14
,
0x4a
,
0xa8
,
0x6b
,
0x26
,
0x1f
,
0xc3
,
0x08
,
0x2f
,
0x51
,
0x98
,
0xbe
,
0xc4
,
0x18
,
0x03
,
0x39
,
0x57
,
0x51
,
0xc5
,
0x2c
,
0x2d
,
0xeb
,
0x8c
,
0x47
,
0x83
,
0x69
,
0x30
,
0x1b
,
0xcf
,
0x1f
,
0x9d
,
0xc9
,
0x1c
,
0x9c
,
0x2d
,
0xda
,
0x9d
,
0xd8
,
0x46
,
0x91
,
0x6f
,
0x60
,
0x92
,
0xaf
,
0xee
,
0x92
,
0x22
,
0xcf
,
0x9a
,
0x73
,
0xc3
,
0xfb
,
0xce
,
0x39
,
0x40
,
0x72
,
0x0a
,
0x7d
,
0x2e
,
0x12
,
0xb1
,
0xe6
,
0xd1
,
0x68
,
0xea
,
0xcd
,
0xc2
,
0x58
,
0xaf
,
0xc8
,
0xd7
,
0x70
,
0x8a
,
0x51
,
0x73
,
0xf1
,
0x93
,
0x79
,
0xe9
,
0x2f
,
0x75
,
0x9e
,
0xb2
,
0x08
,
0x64
,
0xc8
,
0xf7
,
0xec
,
0xa2
,
0xbf
,
0x8a
,
0xd5
,
0x79
,
0x99
,
0x45
,
0x63
,
0x89
,
0xd3
,
0x2b
,
0x99
,
0x4b
,
0x79
,
0xe2
,
0xbb
,
0xf7
,
0x55
,
0x5e
,
0xb3
,
0x57
,
0xf9
,
0x2d
,
0x8b
,
0x0e
,
0x75
,
0x2e
,
0x1d
,
0x3b
,
0xb2
,
0x9b
,
0xd6
,
0x2c
,
0x11
,
0x0a
,
0x75
,
0x24
,
0x51
,
0x96
,
0x85
,
0x44
,
0x30
,
0xb8
,
0xd1
,
0xc4
,
0x4e
,
0xe4
,
0x66
,
0xb3
,
0x6c
,
0x74
,
0xc1
,
0xea
,
0x8b
,
0x2c
,
0xab
,
0xa3
,
0x63
,
0xa3
,
0x0b
,
0x65
,
0xa1
,
0x7f
,
0x06
,
0x00
,
0x26
,
0x19
,
0x28
,
0x81
,
0x24
,
0x4d
,
0xcb
,
0xf5
,
0x4a
,
0x48
,
0xbc
,
0xd2
,
0x91
,
0x6d
,
0x42
,
0xb2
,
0xb8
,
0x48
,
0x6a
,
0x21
,
0x23
,
0x51
,
0x2a
,
0x32
,
0x86
,
0x5d
,
0xa4
,
0x07
,
0xbb
,
0x49
,
0xef
,
0x20
,
0x55
,
0x1e
,
0x7b
,
0x2e
,
0x52
,
0x25
,
0xb0
,
0x23
,
0x8f
,
0xd0
,
0x95
,
0x47
,
0x57
,
0x92
,
0xca
,
0x51
,
0x7f
,
0x4b
,
0x92
,
0x2d
,
0x15
,
0x9a
,
0xda
,
0x41
,
0x87
,
0xda
,
0x4f
,
0xe1
,
0xa8
,
0xc1
,
0xaa
,
0x0c
,
0x0f
,
0xa5
,
0x83
,
0xae
,
0x11
,
0x53
,
0xc9
,
0x0c
,
0x55
,
0x23
,
0x45
,
0x82
,
0xb1
,
0x60
,
0x9c
,
0x55
,
0xcd
,
0x7e
,
0x55
,
0x17
,
0x80
,
0xbc
,
0xc0
,
0x18
,
0xf0
,
0x6e
,
0x0c
,
0x7a
,
0xa9
,
0x64
,
0x30
,
0x8a
,
0xf5
,
0x0a
,
0xed
,
0x48
,
0xc7
,
0x32
,
0x93
,
0xe4
,
0x8f
,
0x62
,
0xbd
,
0xa2
,
0xaf
,
0x21
,
0x6a
,
0x8a
,
0xfb
,
0x82
,
0x73
,
0x26
,
0xe4
,
0x0b
,
0x34
,
0x4b
,
0x4f
,
0x01
,
0x6a
,
0xf9
,
0x4b
,
0x46
,
0xe2
,
0xa9
,
0x48
,
0x8c
,
0x85
,
0x7c
,
0x04
,
0xc3
,
0x1b
,
0xb1
,
0x51
,
0xb9
,
0x50
,
0x14
,
0xb5
,
0x6b
,
0xfa
,
0xb7
,
0x0f
,
0x93
,
0xd6
,
0x71
,
0x8a
,
0xb9
,
0x21
,
0xcf
,
0xa1
,
0xaf
,
0xb4
,
0x24
,
0x5d
,
0x8d
,
0xe7
,
0x1f
,
0xe8
,
0x22
,
0x69
,
0x60
,
0x57
,
0x72
,
0xf3
,
0xfa
,
0x20
,
0xd6
,
0x30
,
0xf2
,
0x0c
,
0x7a
,
0x18
,
0xbd
,
0xf4
,
0x3d
,
0x9e
,
0x3f
,
0x76
,
0xe0
,
0x28
,
0xa7
,
0xeb
,
0x83
,
0x58
,
0x42
,
0xc8
,
0x17
,
0x10
,
0xd6
,
0xac
,
0x4a
,
0x36
,
0x52
,
0x06
,
0xe3
,
0xf9
,
0x13
,
0x07
,
0x1b
,
0xe3
,
0xde
,
0xf5
,
0x41
,
0xac
,
0x40
,
0xe8
,
0xf8
,
0x0d
,
0x63
,
0x99
,
0x54
,
0xc2
,
0xb6
,
0xe3
,
0xef
,
0x19
,
0xcb
,
0xd0
,
0x31
,
0x42
,
0xd0
,
0x71
,
0x5a
,
0x94
,
0x5c
,
0x29
,
0x62
,
0xdb
,
0xf1
,
0x15
,
0xee
,
0xa1
,
0x63
,
0x09
,
0xc2
,
0x27
,
0xde
,
0x26
,
0xab
,
0xe4
,
0xad
,
0xd2
,
0xc6
,
0xf6
,
0x13
,
0x5f
,
0xca
,
0x4d
,
0x7c
,
0xa2
,
0x82
,
0x91
,
0x09
,
0xf8
,
0x62
,
0xa3
,
0x59
,
0xf4
,
0xc5
,
0xe6
,
0x72
,
0x00
,
0xe1
,
0x1d
,
0xea
,
0x8d
,
0xbe
,
0x30
,
0xe9
,
0x53
,
0x87
,
0x90
,
0x0d
,
0xbe
,
0xae
,
0x54
,
0x3d
,
0xf1
,
0xc8
,
0x9b
,
0x06
,
0x58
,
0x62
,
0xc6
,
0x42
,
0xff
,
0xf2
,
0xcc
,
0x11
,
0x95
,
0xca
,
0xad
,
0x6e
,
0xec
,
0xed
,
0xef
,
0xc6
,
0xfe
,
0xc3
,
0xba
,
0x71
,
0x70
,
0x4f
,
0x37
,
0x36
,
0x5d
,
0xa8
,
0x67
,
0x77
,
0x21
,
0xba
,
0x80
,
0x43
,
0x9b
,
0xb7
,
0xbd
,
0x73
,
0xe4
,
0x89
,
0xce
,
0x83
,
0x8e
,
0x47
,
0x27
,
0xe5
,
0x07
,
0x38
,
0xea
,
0x30
,
0xba
,
0xd7
,
0x8d
,
0xa9
,
0x06
,
0xdf
,
0xae
,
0x06
,
0xfa
,
0xbb
,
0x09
,
0x07
,
0xd9
,
0x46
,
0x25
,
0x63
,
0x3b
,
0x78
,
0xb5
,
0xa9
,
0x54
,
0x92
,
0xc2
,
0xb8
,
0x5d
,
0x63
,
0x28
,
0x95
,
0x96
,
0x78
,
0x80
,
0xa1
,
0x54
,
0x4d
,
0x8d
,
0xdf
,
0x95
,
0xc5
,
0xfa
,
0x16
,
0x1b
,
0x0f
,
0x9a
,
0xf5
,
0x8a
,
0x3e
,
0x37
,
0x21
,
0x4a
,
0x6d
,
0xec
,
0x0b
,
0x91
,
0xfe
,
0xe1
,
0xc1
,
0x71
,
0xcc
,
0x52
,
0x96
,
0x57
,
0xe2
,
0xc1
,
0x53
,
0xd6
,
0x69
,
0x9f
,
0xfe
,
0x76
,
0xfb
,
0x34
,
0x0f
,
0x0f
,
0xdc
,
0x36
,
0xa0
,
0x5b
,
0x53
,
0xcf
,
0x6e
,
0x4d
,
0xf4
,
0x47
,
0x78
,
0xe4
,
0x04
,
0xb1
,
0x5c
,
0x3c
,
0x24
,
0xbb
,
0xda
,
0x99
,
0xdf
,
0x71
,
0x76
,
0x05
,
0xc7
,
0x86
,
0x26
,
0x35
,
0xed
,
0x5e
,
0xc0
,
0xa0
,
0xd6
,
0x13
,
0xd2
,
0x93
,
0x13
,
0xf2
,
0x54
,
0x57
,
0x86
,
0x73
,
0x6b
,
0xdc
,
0xc0
,
0xe8
,
0x97
,
0x98
,
0x96
,
0x77
,
0x6d
,
0x34
,
0xab
,
0x37
,
0xe5
,
0xde
,
0x54
,
0xfe
,
0xeb
,
0xc3
,
0x69
,
0xcc
,
0xaa
,
0x36
,
0xff
,
0xeb
,
0xba
,
0x66
,
0x2b
,
0x21
,
0x8f
,
0x9a
,
0x50
,
0xbd
,
0x4e
,
0x4b
,
0xfe
,
0xff
,
0xbf
,
0x57
,
0xac
,
0x19
,
0x1a
,
0x76
,
0x67
,
0xe8
,
0x8e
,
0xa1
,
0xd6
,
0x7f
,
0xc0
,
0x97
,
0xcc
,
0xc0
,
0x1d
,
0x55
,
0xa6
,
0x06
,
0x87
,
0x9d
,
0x2f
,
0x01
,
0x33
,
0x02
,
0x46
,
0xf6
,
0x08
,
0x70
,
0xa6
,
0x3e
,
0xb8
,
0x53
,
0x9f
,
0x7e
,
0x05
,
0x27
,
0x0e
,
0x13
,
0x1c
,
0x73
,
0x62
,
0x12
,
0xdf
,
0x74
,
0x23
,
0xdb
,
0x44
,
0x7f
,
0x86
,
0x0f
,
0x77
,
0x73
,
0xc1
,
0xc9
,
0x39
,
0x84
,
0x39
,
0xfe
,
0xd0
,
0x52
,
0xf8
,
0xa4
,
0x95
,
0xc2
,
0x2e
,
0x78
,
0xac
,
0xb0
,
0xf4
,
0x25
,
0x3c
,
0xb6
,
0xa2
,
0xb8
,
0xdc
,
0x98
,
0x79
,
0xb7
,
0x93
,
0xd8
,
0xae
,
0x56
,
0xfc
,
0x2d
,
0xad
,
0x50
,
0x98
,
0x58
,
0xf7
,
0x2d
,
0x17
,
0x9c
,
0x9c
,
0x40
,
0xb0
,
0x5c
,
0x34
,
0x4f
,
0xc1
,
0x9f
,
0xf4
,
0x3d
,
0x10
,
0xeb
,
0xca
,
0x46
,
0xca
,
0xfb
,
0xaa
,
0x82
,
0x40
,
0x2f
,
0x31
,
0x55
,
0x29
,
0x7f
,
0x5b
,
0x51
,
0x06
,
0x9d
,
0x28
,
0x4d
,
0x99
,
0xf6
,
0x3a
,
0xfd
,
0xe9
,
0x02
,
0x6f
,
0xae
,
0xdc
,
0x9b
,
0x3f
,
0x77
,
0x8b
,
0x68
,
0xc7
,
0x67
,
0x66
,
0x5b
,
0x3f
,
0xdf
,
0x62
,
0xbe
,
0x2a
,
0xbb
,
0xe9
,
0xca
,
0x42
,
0x78
,
0x06
,
0x7d
,
0x85
,
0xd0
,
0x43
,
0x78
,
0x87
,
0x0b
,
0x0d
,
0xa0
,
0x33
,
0xe4
,
0xbd
,
0xf5
,
0xa0
,
0x3e
,
0x6d
,
0xda
,
0x66
,
0xa8
,
0x46
,
0x89
,
0x5a
,
0xd0
,
0x79
,
0xa7
,
0xee
,
0x7e
,
0xe3
,
0xac
,
0x6e
,
0x6a
,
0xc7
,
0x52
,
0xbb
,
0xd7
,
0x51
,
0xfb
,
0x4d
,
0x5f
,
0xfe
,
0x93
,
0x71
,
0xfe
,
0x5f
,
0x00
,
0x00
,
0x00
,
0xff
,
0xff
,
0x57
,
0x52
,
0x66
,
0x8a
,
0x76
,
0x0c
,
0x00
,
0x00
,
}
plugin/dapp/issuance/types/table.go
0 → 100644
View file @
a717a020
package
types
import
(
"fmt"
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
)
var
opt
=
&
table
.
Option
{
Prefix
:
"LODB-issuance"
,
Name
:
"issuer"
,
Primary
:
"issuanceid"
,
Index
:
[]
string
{
"status"
},
}
//NewTable 新建表
func
NewIssuanceTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewIssuanceRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
opt
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//IssuanceRow table meta 结构
type
IssuanceRow
struct
{
*
ReceiptIssuanceID
}
//NewIssuanceRow 新建一个meta 结构
func
NewIssuanceRow
()
*
IssuanceRow
{
return
&
IssuanceRow
{
ReceiptIssuanceID
:
&
ReceiptIssuanceID
{}}
}
//CreateRow 新建数据行
func
(
tx
*
IssuanceRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
ReceiptIssuanceID
{}}
}
//SetPayload 设置数据
func
(
tx
*
IssuanceRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
txdata
,
ok
:=
data
.
(
*
ReceiptIssuanceID
);
ok
{
tx
.
ReceiptIssuanceID
=
txdata
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
tx
*
IssuanceRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"issuanceid"
{
return
[]
byte
(
tx
.
IssuanceId
),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
tx
.
Status
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
var
optRecord
=
&
table
.
Option
{
Prefix
:
"LODB-issuance"
,
Name
:
"debt"
,
Primary
:
"debtid"
,
Index
:
[]
string
{
"status"
,
"addr"
,
"addr_status"
},
}
// NewRecordTable 大户发行记录表
func
NewRecordTable
(
kvdb
db
.
KV
)
*
table
.
Table
{
rowmeta
:=
NewRecordRow
()
table
,
err
:=
table
.
NewTable
(
rowmeta
,
kvdb
,
optRecord
)
if
err
!=
nil
{
panic
(
err
)
}
return
table
}
//IssuanceRow table meta 结构
type
IssuanceRecordRow
struct
{
*
ReceiptIssuance
}
//NewIssuanceRow 新建一个meta 结构
func
NewRecordRow
()
*
IssuanceRecordRow
{
return
&
IssuanceRecordRow
{
ReceiptIssuance
:
&
ReceiptIssuance
{}}
}
//CreateRow 新建数据行
func
(
tx
*
IssuanceRecordRow
)
CreateRow
()
*
table
.
Row
{
return
&
table
.
Row
{
Data
:
&
ReceiptIssuance
{}}
}
//SetPayload 设置数据
func
(
tx
*
IssuanceRecordRow
)
SetPayload
(
data
types
.
Message
)
error
{
if
txdata
,
ok
:=
data
.
(
*
ReceiptIssuance
);
ok
{
tx
.
ReceiptIssuance
=
txdata
return
nil
}
return
types
.
ErrTypeAsset
}
//Get 按照indexName 查询 indexValue
func
(
tx
*
IssuanceRecordRow
)
Get
(
key
string
)
([]
byte
,
error
)
{
if
key
==
"debtid"
{
return
[]
byte
(
tx
.
DebtId
),
nil
}
else
if
key
==
"status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%2d"
,
tx
.
Status
)),
nil
}
else
if
key
==
"addr"
{
return
[]
byte
(
tx
.
AccountAddr
),
nil
}
else
if
key
==
"addr_status"
{
return
[]
byte
(
fmt
.
Sprintf
(
"%s:%2d"
,
tx
.
AccountAddr
,
tx
.
Status
)),
nil
}
return
nil
,
types
.
ErrNotFound
}
plugin/dapp/issuance/types/tx.go
0 → 100644
View file @
a717a020
// 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
// IssuanceCreateTx for construction
type
IssuanceCreateTx
struct
{
DebtCeiling
float64
`json:"debtCeiling"`
LiquidationRatio
float64
`json:"liquidationRatio"`
Period
int64
`json:"period"`
TotalBalance
float64
`json:"totalBalance"`
Fee
int64
`json:"fee"`
}
// IssuanceDebtTx for construction
type
IssuanceDebtTx
struct
{
IssuanceID
string
`json:"issuanceId"`
Value
float64
`json:"value"`
Fee
int64
`json:"fee"`
}
// IssuanceRepayTx for construction
type
IssuanceRepayTx
struct
{
IssuanceID
string
`json:"issuanceId"`
DebtID
string
`json:"debtId"`
Fee
int64
`json:"fee"`
}
// IssuanceFeedTx for construction
type
IssuanceFeedTx
struct
{
Price
[]
float64
`json:"price"`
Volume
[]
int64
`json:"volume"`
Fee
int64
`json:"fee"`
}
// IssuanceCloseTx for construction
type
IssuanceCloseTx
struct
{
IssuanceID
string
`json:"issuanceId"`
Fee
int64
`json:"fee"`
}
// IssuanceManageTx for construction
type
IssuanceManageTx
struct
{
Addr
[]
string
`json:"addr"`
Fee
int64
`json:"fee"`
}
plugin/dapp/issuance/types/types.go
0 → 100644
View file @
a717a020
// 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
//Issuance op
const
(
IssuanceActionCreate
=
1
+
iota
// 创建借贷
IssuanceActionDebt
// 大户抵押
IssuanceActionRepay
// 大户清算
IssuanceActionFeed
// 发行合约喂价
IssuanceActionClose
// 关闭借贷
IssuanceActionManage
// 借贷管理
//log for Issuance
TyLogIssuanceCreate
=
741
TyLogIssuanceDebt
=
742
TyLogIssuanceRepay
=
743
TyLogIssuanceFeed
=
745
TyLogIssuanceClose
=
746
)
// Issuance name
const
(
IssuanceX
=
"issuance"
CCNYTokenName
=
"CCNY"
IssuancePreLiquidationRatio
=
11000
//TODO 预清算比例,抵押物价值跌到借出ccny价值110%的时候开始清算
)
//Issuance status
const
(
IssuanceStatusCreated
=
1
+
iota
IssuanceStatusClose
)
const
(
IssuanceUserStatusCreate
=
1
+
iota
IssuanceUserStatusWarning
IssuanceUserStatusSystemLiquidate
IssuanceUserStatusExpire
IssuanceUserStatusExpireLiquidate
IssuanceUserStatusClose
)
const
(
PriceFeedKey
=
"issuance-price-feed"
GuarantorKey
=
"issuance-guarantor"
ManageKey
=
"issuance-manage"
)
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