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
9ee34269
Commit
9ee34269
authored
Dec 10, 2019
by
harrylee
Committed by
vipwzw
Dec 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make linter
parent
52e94ec0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
52 deletions
+45
-52
exchangedb.go
plugin/dapp/exchange/executor/exchangedb.go
+38
-44
exec_local.go
plugin/dapp/exchange/executor/exec_local.go
+1
-2
exchange.go
plugin/dapp/exchange/types/exchange.go
+6
-6
No files found.
plugin/dapp/exchange/executor/exchangedb.go
View file @
9ee34269
...
@@ -55,9 +55,8 @@ func (a *Action) updateStateDBCache(order *et.Order) {
...
@@ -55,9 +55,8 @@ func (a *Action) updateStateDBCache(order *et.Order) {
func
(
a
*
Action
)
OpSwap
(
op
int32
)
int32
{
func
(
a
*
Action
)
OpSwap
(
op
int32
)
int32
{
if
op
==
et
.
OpBuy
{
if
op
==
et
.
OpBuy
{
return
et
.
OpSell
return
et
.
OpSell
}
else
{
return
et
.
OpBuy
}
}
return
et
.
OpBuy
}
}
//计算实际花费
//计算实际花费
...
@@ -83,10 +82,7 @@ func CheckOp(op int32) bool {
...
@@ -83,10 +82,7 @@ func CheckOp(op int32) bool {
}
}
func
CheckCount
(
count
int32
)
bool
{
func
CheckCount
(
count
int32
)
bool
{
if
count
>
20
{
return
count
>
20
return
false
}
return
true
}
}
func
CheckDirection
(
direction
int32
)
bool
{
func
CheckDirection
(
direction
int32
)
bool
{
...
@@ -247,7 +243,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -247,7 +243,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
or
:=
&
et
.
Order
{
or
:=
&
et
.
Order
{
OrderID
:
common
.
ToHex
(
a
.
txhash
),
OrderID
:
common
.
ToHex
(
a
.
txhash
),
Value
:
&
et
.
Order_LimitOrder
{
payload
},
Value
:
&
et
.
Order_LimitOrder
{
LimitOrder
:
payload
},
Ty
:
et
.
TyLimitOrderAction
,
Ty
:
et
.
TyLimitOrderAction
,
Executed
:
0
,
Executed
:
0
,
Balance
:
payload
.
GetAmount
(),
Balance
:
payload
.
GetAmount
(),
...
@@ -324,9 +320,8 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -324,9 +320,8 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
matchorder
.
Status
=
func
(
a
,
b
int64
)
int32
{
matchorder
.
Status
=
func
(
a
,
b
int64
)
int32
{
if
a
>
b
{
if
a
>
b
{
return
et
.
Ordered
return
et
.
Ordered
}
else
{
return
et
.
Completed
}
}
return
et
.
Completed
}(
matchorder
.
GetBalance
(),
or
.
GetBalance
())
}(
matchorder
.
GetBalance
(),
or
.
GetBalance
())
matchorder
.
Balance
=
matchorder
.
GetBalance
()
-
or
.
GetBalance
()
matchorder
.
Balance
=
matchorder
.
GetBalance
()
-
or
.
GetBalance
()
matchorder
.
Executed
=
matchorder
.
Executed
+
or
.
GetBalance
()
matchorder
.
Executed
=
matchorder
.
Executed
+
or
.
GetBalance
()
...
@@ -348,43 +343,42 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
...
@@ -348,43 +343,42 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
logs
=
append
(
logs
,
receiptlog
)
logs
=
append
(
logs
,
receiptlog
)
receipts
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
receipts
:=
&
types
.
Receipt
{
Ty
:
types
.
ExecOk
,
KV
:
kvs
,
Logs
:
logs
}
return
receipts
,
nil
return
receipts
,
nil
}
else
{
}
if
payload
.
Op
==
et
.
OpSell
{
if
payload
.
Op
==
et
.
OpSell
{
//转移冻结资产
//转移冻结资产
receipt
,
err
:=
rightAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
receipt
,
err
:=
rightAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
if
err
!=
nil
{
if
err
!=
nil
{
elog
.
Error
(
"matchLimitOrder.ExecTransferFrozen"
,
"addr"
,
matchorder
.
Addr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
elog
.
Error
(
"matchLimitOrder.ExecTransferFrozen"
,
"addr"
,
matchorder
.
Addr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
return
nil
,
err
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
//将达成交易的相应资产结算
receipt
,
err
=
leftAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
if
err
!=
nil
{
elog
.
Error
(
"matchLimitOrder.ExecTransfer"
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
}
}
if
payload
.
Op
==
et
.
OpBuy
{
logs
=
append
(
logs
,
receipt
.
Logs
...
)
//转移冻结资产
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
receipt
,
err
:=
leftAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
//将达成交易的相应资产结算
if
err
!=
nil
{
receipt
,
err
=
leftAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
elog
.
Error
(
"matchLimitOrder.ExecTransferFrozen"
,
"addr"
,
matchorder
.
Addr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
if
err
!=
nil
{
return
nil
,
err
elog
.
Error
(
"matchLimitOrder.ExecTransfer"
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
}
return
nil
,
err
logs
=
append
(
logs
,
receipt
.
Logs
...
)
}
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
//将达成交易的相应资产结算
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
receipt
,
err
=
rightAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
}
if
err
!=
nil
{
if
payload
.
Op
==
et
.
OpBuy
{
elog
.
Error
(
"matchLimitOrder.ExecTransfer"
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
//转移冻结资产
return
nil
,
err
receipt
,
err
:=
leftAccountDB
.
ExecTransferFrozen
(
matchorder
.
Addr
,
a
.
fromaddr
,
a
.
execaddr
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
}
if
err
!=
nil
{
logs
=
append
(
logs
,
receipt
.
Logs
...
)
elog
.
Error
(
"matchLimitOrder.ExecTransferFrozen"
,
"addr"
,
matchorder
.
Addr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
matchorder
.
GetLimitOrder
()
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
return
nil
,
err
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
//将达成交易的相应资产结算
receipt
,
err
=
rightAccountDB
.
ExecTransfer
(
a
.
fromaddr
,
matchorder
.
Addr
,
a
.
execaddr
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()))
if
err
!=
nil
{
elog
.
Error
(
"matchLimitOrder.ExecTransfer"
,
"addr"
,
a
.
fromaddr
,
"execaddr"
,
a
.
execaddr
,
"amount"
,
a
.
calcActualCost
(
payload
.
Op
,
matchorder
.
GetBalance
(),
payload
.
GetPrice
()),
"err"
,
err
.
Error
())
return
nil
,
err
}
}
logs
=
append
(
logs
,
receipt
.
Logs
...
)
kvs
=
append
(
kvs
,
receipt
.
KV
...
)
//涉及赋值先后顺序,不可颠倒
//涉及赋值先后顺序,不可颠倒
or
.
Balance
=
or
.
Balance
-
matchorder
.
Balance
or
.
Balance
=
or
.
Balance
-
matchorder
.
Balance
...
...
plugin/dapp/exchange/executor/exec_local.go
View file @
9ee34269
...
@@ -229,7 +229,6 @@ func (e *exchange) updateIndex(receipt *exchangetypes.ReceiptExchange) (kvs []*t
...
@@ -229,7 +229,6 @@ func (e *exchange) updateIndex(receipt *exchangetypes.ReceiptExchange) (kvs []*t
func
OpSwap
(
op
int32
)
int32
{
func
OpSwap
(
op
int32
)
int32
{
if
op
==
exchangetypes
.
OpBuy
{
if
op
==
exchangetypes
.
OpBuy
{
return
exchangetypes
.
OpSell
return
exchangetypes
.
OpSell
}
else
{
return
exchangetypes
.
OpBuy
}
}
return
exchangetypes
.
OpBuy
}
}
plugin/dapp/exchange/types/exchange.go
View file @
9ee34269
...
@@ -96,28 +96,28 @@ func InitExecutor(cfg *types.Chain33Config) {
...
@@ -96,28 +96,28 @@ func InitExecutor(cfg *types.Chain33Config) {
types
.
RegistorExecutor
(
ExchangeX
,
NewType
(
cfg
))
types
.
RegistorExecutor
(
ExchangeX
,
NewType
(
cfg
))
}
}
type
e
xchangeType
struct
{
type
E
xchangeType
struct
{
types
.
ExecTypeBase
types
.
ExecTypeBase
}
}
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
e
xchangeType
{
func
NewType
(
cfg
*
types
.
Chain33Config
)
*
E
xchangeType
{
c
:=
&
e
xchangeType
{}
c
:=
&
E
xchangeType
{}
c
.
SetChild
(
c
)
c
.
SetChild
(
c
)
c
.
SetConfig
(
cfg
)
c
.
SetConfig
(
cfg
)
return
c
return
c
}
}
// GetPayload 获取合约action结构
// GetPayload 获取合约action结构
func
(
e
*
e
xchangeType
)
GetPayload
()
types
.
Message
{
func
(
e
*
E
xchangeType
)
GetPayload
()
types
.
Message
{
return
&
ExchangeAction
{}
return
&
ExchangeAction
{}
}
}
// GeTypeMap 获取合约action的id和name信息
// GeTypeMap 获取合约action的id和name信息
func
(
e
*
e
xchangeType
)
GetTypeMap
()
map
[
string
]
int32
{
func
(
e
*
E
xchangeType
)
GetTypeMap
()
map
[
string
]
int32
{
return
actionMap
return
actionMap
}
}
// GetLogMap 获取合约log相关信息
// GetLogMap 获取合约log相关信息
func
(
e
*
e
xchangeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
func
(
e
*
E
xchangeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
logMap
return
logMap
}
}
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