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
f792dd54
Commit
f792dd54
authored
Jan 17, 2019
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trade local rollback : sellLimit/sellRevoke
parent
12f9b6a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
11 deletions
+48
-11
exec_del_local.go
plugin/dapp/trade/executor/exec_del_local.go
+18
-9
local_order.go
plugin/dapp/trade/executor/local_order.go
+23
-0
trade.go
plugin/dapp/trade/executor/trade.go
+7
-2
No files found.
plugin/dapp/trade/executor/exec_del_local.go
View file @
f792dd54
...
@@ -7,34 +7,37 @@ package executor
...
@@ -7,34 +7,37 @@ package executor
import
(
import
(
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/33cn/chain33/system/dapp"
)
)
func
(
t
*
trade
)
ExecDelLocal_SellLimit
(
sell
*
pty
.
TradeForSell
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_SellLimit
(
sell
*
pty
.
TradeForSell
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
0
)
}
}
func
(
t
*
trade
)
ExecDelLocal_BuyMarket
(
buy
*
pty
.
TradeForBuy
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_BuyMarket
(
buy
*
pty
.
TradeForBuy
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
buy
.
BoardlotCnt
)
}
}
func
(
t
*
trade
)
ExecDelLocal_RevokeSell
(
revoke
*
pty
.
TradeForRevokeSell
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_RevokeSell
(
revoke
*
pty
.
TradeForRevokeSell
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
0
)
}
}
func
(
t
*
trade
)
ExecDelLocal_BuyLimit
(
buy
*
pty
.
TradeForBuyLimit
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_BuyLimit
(
buy
*
pty
.
TradeForBuyLimit
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
0
)
}
}
func
(
t
*
trade
)
ExecDelLocal_SellMarket
(
sell
*
pty
.
TradeForSellMarket
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_SellMarket
(
sell
*
pty
.
TradeForSellMarket
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
sell
.
BoardlotCnt
)
}
}
func
(
t
*
trade
)
ExecDelLocal_RevokeBuy
(
revoke
*
pty
.
TradeForRevokeBuy
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
ExecDelLocal_RevokeBuy
(
revoke
*
pty
.
TradeForRevokeBuy
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
return
t
.
localDelLog
(
tx
,
receipt
,
index
)
return
t
.
localDelLog
(
tx
,
receipt
,
index
,
0
)
}
}
func
(
t
*
trade
)
localDelLog
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
func
(
t
*
trade
)
localDelLog
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
,
tradedBoardlot
int64
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
var
set
types
.
LocalDBSet
table
:=
NewOrderTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
for
i
:=
0
;
i
<
len
(
receipt
.
Logs
);
i
++
{
for
i
:=
0
;
i
<
len
(
receipt
.
Logs
);
i
++
{
item
:=
receipt
.
Logs
[
i
]
item
:=
receipt
.
Logs
[
i
]
...
@@ -44,7 +47,7 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
...
@@ -44,7 +47,7 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
panic
(
err
)
//数据错误了,已经被修改了
}
}
kv
:=
t
.
deleteSell
(
[]
byte
(
receipt
.
Base
.
SellID
),
item
.
Ty
)
kv
:=
t
.
deleteSell
(
receipt
.
Base
,
item
.
Ty
,
tx
,
txIndex
,
table
,
tradedBoardlot
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeSellRevoke
{
}
else
if
item
.
Ty
==
pty
.
TyLogTradeSellRevoke
{
var
receipt
pty
.
ReceiptTradeSellRevoke
var
receipt
pty
.
ReceiptTradeSellRevoke
...
@@ -52,7 +55,7 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
...
@@ -52,7 +55,7 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
panic
(
err
)
//数据错误了,已经被修改了
}
}
kv
:=
t
.
deleteSell
(
[]
byte
(
receipt
.
Base
.
SellID
),
item
.
Ty
)
kv
:=
t
.
deleteSell
(
receipt
.
Base
,
item
.
Ty
,
tx
,
txIndex
,
table
,
tradedBoardlot
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeBuyMarket
{
}
else
if
item
.
Ty
==
pty
.
TyLogTradeBuyMarket
{
var
receipt
pty
.
ReceiptTradeBuyMarket
var
receipt
pty
.
ReceiptTradeBuyMarket
...
@@ -88,6 +91,12 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
...
@@ -88,6 +91,12 @@ func (t *trade) localDelLog(tx *types.Transaction, receipt *types.ReceiptData, i
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
}
}
}
newKvs
,
err
:=
table
.
Save
()
if
err
!=
nil
{
tradelog
.
Error
(
"trade table.Save failed"
,
"error"
,
err
)
return
nil
,
err
}
set
.
KV
=
append
(
set
.
KV
,
newKvs
...
)
return
&
set
,
nil
return
&
set
,
nil
}
}
plugin/dapp/trade/executor/local_order.go
View file @
f792dd54
...
@@ -197,6 +197,29 @@ func (t *trade) updateSellLimit(tx *types.Transaction, sell *pty.ReceiptSellBase
...
@@ -197,6 +197,29 @@ func (t *trade) updateSellLimit(tx *types.Transaction, sell *pty.ReceiptSellBase
return
order
return
order
}
}
func
(
t
*
trade
)
rollBackSellLimit
(
tx
*
types
.
Transaction
,
sell
*
pty
.
ReceiptSellBase
,
sellorder
*
pty
.
SellOrder
,
txIndex
string
,
ldb
*
table
.
Table
,
tradedBoardlot
int64
)
*
pty
.
LocalOrder
{
xs
,
err
:=
ldb
.
ListIndex
(
"key"
,
[]
byte
(
sell
.
SellID
),
nil
,
1
,
0
)
if
err
!=
nil
||
len
(
xs
)
!=
1
{
return
nil
}
order
,
ok
:=
xs
[
0
]
.
Data
.
(
*
pty
.
LocalOrder
)
if
!
ok
{
return
nil
}
// 撤销订单回滚, 只需要修改状态
// 其他的操作需要还修改数量
order
.
Status
=
pty
.
TradeOrderStatusOnBuy
order
.
TxHash
=
order
.
TxHash
[
:
len
(
order
.
TxHash
)
-
1
]
order
.
TradedBoardlot
=
order
.
TradedBoardlot
-
tradedBoardlot
ldb
.
Replace
(
order
)
return
order
}
func
parseOrderAmountFloat
(
s
string
)
int64
{
func
parseOrderAmountFloat
(
s
string
)
int64
{
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
x
,
err
:=
strconv
.
ParseFloat
(
s
,
64
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
plugin/dapp/trade/executor/trade.go
View file @
f792dd54
...
@@ -114,8 +114,13 @@ func genDeleteSellKv(sellorder *pty.SellOrder) []*types.KeyValue {
...
@@ -114,8 +114,13 @@ func genDeleteSellKv(sellorder *pty.SellOrder) []*types.KeyValue {
return
kv
return
kv
}
}
func
(
t
*
trade
)
deleteSell
(
sellID
[]
byte
,
ty
int32
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
deleteSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
,
tradedBoardlot
int64
)
[]
*
types
.
KeyValue
{
sellorder
:=
t
.
getSellOrderFromDb
(
sellID
)
sellorder
:=
t
.
getSellOrderFromDb
([]
byte
(
base
.
SellID
))
if
ty
==
pty
.
TyLogTradeSellLimit
&&
sellorder
.
SoldBoardlot
==
0
{
ldb
.
Del
([]
byte
(
txIndex
))
}
else
{
t
.
rollBackSellLimit
(
tx
,
base
,
sellorder
,
txIndex
,
ldb
,
tradedBoardlot
)
}
return
genDeleteSellKv
(
sellorder
)
return
genDeleteSellKv
(
sellorder
)
}
}
...
...
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