use table for trade local exec
@@ -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())
}
