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
a5e4f7d7
Commit
a5e4f7d7
authored
Jan 16, 2019
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use table for trade local exec
parent
12dc88b0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
19 deletions
+38
-19
exec_local.go
plugin/dapp/trade/executor/exec_local.go
+15
-8
local_order.go
plugin/dapp/trade/executor/local_order.go
+0
-0
trade.go
plugin/dapp/trade/executor/trade.go
+23
-11
No files found.
plugin/dapp/trade/executor/exec_local.go
View file @
a5e4f7d7
...
...
@@ -7,6 +7,7 @@ package executor
import
(
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/33cn/chain33/system/dapp"
)
func
(
t
*
trade
)
ExecLocal_SellLimit
(
sell
*
pty
.
TradeForSell
,
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
...
...
@@ -35,7 +36,8 @@ func (t *trade) ExecLocal_RevokeBuy(revoke *pty.TradeForRevokeBuy, tx *types.Tra
func
(
t
*
trade
)
localAddLog
(
tx
*
types
.
Transaction
,
receipt
*
types
.
ReceiptData
,
index
int
)
(
*
types
.
LocalDBSet
,
error
)
{
var
set
types
.
LocalDBSet
//table := NewOrderTable(t.GetLocalDB())
table
:=
NewOrderTable
(
t
.
GetLocalDB
())
txIndex
:=
dapp
.
HeightIndexStr
(
t
.
GetHeight
(),
int64
(
index
))
for
i
:=
0
;
i
<
len
(
receipt
.
Logs
);
i
++
{
item
:=
receipt
.
Logs
[
i
]
...
...
@@ -45,7 +47,7 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveSell
(
receipt
.
Base
,
item
.
Ty
)
kv
:=
t
.
saveSell
(
receipt
.
Base
,
item
.
Ty
,
txIndex
,
tx
,
table
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeSellRevoke
{
var
receipt
pty
.
ReceiptTradeSellRevoke
...
...
@@ -53,7 +55,7 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveSell
(
receipt
.
Base
,
item
.
Ty
)
kv
:=
t
.
saveSell
(
receipt
.
Base
,
item
.
Ty
,
txIndex
,
tx
,
table
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeBuyMarket
{
var
receipt
pty
.
ReceiptTradeBuyMarket
...
...
@@ -61,7 +63,7 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveBuy
(
receipt
.
Base
)
kv
:=
t
.
saveBuy
(
receipt
.
Base
,
tx
,
txIndex
,
table
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeBuyRevoke
{
var
receipt
pty
.
ReceiptTradeBuyRevoke
...
...
@@ -70,7 +72,7 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveBuyLimit
(
[]
byte
(
receipt
.
Base
.
BuyID
),
item
.
Ty
)
kv
:=
t
.
saveBuyLimit
(
receipt
.
Base
,
item
.
Ty
,
tx
,
txIndex
,
table
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeBuyLimit
{
var
receipt
pty
.
ReceiptTradeBuyLimit
...
...
@@ -79,7 +81,7 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveBuyLimit
(
[]
byte
(
receipt
.
Base
.
BuyID
),
item
.
Ty
)
kv
:=
t
.
saveBuyLimit
(
receipt
.
Base
,
item
.
Ty
,
tx
,
txIndex
,
table
)
set
.
KV
=
append
(
set
.
KV
,
kv
...
)
}
else
if
item
.
Ty
==
pty
.
TyLogTradeSellMarket
{
var
receipt
pty
.
ReceiptSellMarket
...
...
@@ -87,11 +89,16 @@ func (t *trade) localAddLog(tx *types.Transaction, receipt *types.ReceiptData, i
if
err
!=
nil
{
panic
(
err
)
//数据错误了,已经被修改了
}
kv
:=
t
.
saveSellMarket
(
receipt
.
Base
)
kv
:=
t
.
saveSellMarket
(
receipt
.
Base
,
tx
,
txIndex
,
table
)
//tradelog.Info("saveSellMarket", "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
}
plugin/dapp/trade/executor/local_order.go
0 → 100644
View file @
a5e4f7d7
This diff is collapsed.
Click to expand it.
plugin/dapp/trade/executor/trade.go
View file @
a5e4f7d7
...
...
@@ -82,14 +82,15 @@ func genSaveSellKv(sellorder *pty.SellOrder) []*types.KeyValue {
return
kv
}
func
(
t
*
trade
)
saveSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
saveSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
,
txIndex
string
,
tx
*
types
.
Transaction
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
sellorder
:=
t
.
getSellOrderFromDb
([]
byte
(
base
.
SellID
))
//t.genSell(tx, nil, sellorder)
//if ty == pty.TyLogTradeSellLimit && sellorder.SoldBoardlot == 0 {
// ldb.Add()
//} else {
// ldb.Update()
//}
if
ty
==
pty
.
TyLogTradeSellLimit
&&
sellorder
.
SoldBoardlot
==
0
{
newOrder
:=
t
.
genSellLimit
(
tx
,
base
,
sellorder
,
txIndex
)
ldb
.
Add
(
newOrder
)
}
else
{
t
.
updateSellLimit
(
tx
,
base
,
sellorder
,
txIndex
,
ldb
)
}
return
genSaveSellKv
(
sellorder
)
}
...
...
@@ -118,10 +119,12 @@ func (t *trade) deleteSell(sellID []byte, ty int32) []*types.KeyValue {
return
genDeleteSellKv
(
sellorder
)
}
func
(
t
*
trade
)
saveBuy
(
receiptTradeBuy
*
pty
.
ReceiptBuyBase
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
saveBuy
(
receiptTradeBuy
*
pty
.
ReceiptBuyBase
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
//tradelog.Info("save", "buy", receiptTradeBuy)
var
kv
[]
*
types
.
KeyValue
order
:=
t
.
genBuyMarket
(
tx
,
receiptTradeBuy
,
txIndex
)
ldb
.
Add
(
order
)
return
saveBuyMarketOrderKeyValue
(
kv
,
receiptTradeBuy
,
pty
.
TradeOrderStatusBoughtOut
,
t
.
GetHeight
())
}
...
...
@@ -152,8 +155,15 @@ func genSaveBuyLimitKv(buyOrder *pty.BuyLimitOrder) []*types.KeyValue {
return
kv
}
func
(
t
*
trade
)
saveBuyLimit
(
buyID
[]
byte
,
ty
int32
)
[]
*
types
.
KeyValue
{
buyOrder
:=
t
.
getBuyOrderFromDb
(
buyID
)
func
(
t
*
trade
)
saveBuyLimit
(
buy
*
pty
.
ReceiptBuyBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
buyOrder
:=
t
.
getBuyOrderFromDb
([]
byte
(
buy
.
BuyID
))
if
ty
==
pty
.
TradeOrderStatusOnBuy
&&
buy
.
BoughtBoardlot
==
0
{
order
:=
t
.
genBuyLimit
(
tx
,
buy
,
txIndex
)
ldb
.
Add
(
order
)
}
else
{
t
.
updateBuyLimit
(
tx
,
buy
,
buyOrder
,
txIndex
,
ldb
)
}
return
genSaveBuyLimitKv
(
buyOrder
)
}
...
...
@@ -182,8 +192,10 @@ func (t *trade) deleteBuyLimit(buyID []byte, ty int32) []*types.KeyValue {
return
genDeleteBuyLimitKv
(
buyOrder
)
}
func
(
t
*
trade
)
saveSellMarket
(
receiptTradeBuy
*
pty
.
ReceiptSellBase
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
saveSellMarket
(
receiptTradeBuy
*
pty
.
ReceiptSellBase
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
var
kv
[]
*
types
.
KeyValue
order
:=
t
.
genSellMarket
(
tx
,
receiptTradeBuy
,
txIndex
)
ldb
.
Add
(
order
)
return
saveSellMarketOrderKeyValue
(
kv
,
receiptTradeBuy
,
pty
.
TradeOrderStatusSoldOut
,
t
.
GetHeight
())
}
...
...
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