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
63a80e7d
Commit
63a80e7d
authored
Sep 02, 2019
by
linj
Committed by
vipwzw
Sep 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码移动
parent
5a3e7542
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
176 additions
and
158 deletions
+176
-158
kv.go
plugin/dapp/trade/executor/kv.go
+0
-76
localdb_v1.go
plugin/dapp/trade/executor/localdb_v1.go
+176
-2
trade.go
plugin/dapp/trade/executor/trade.go
+0
-80
No files found.
plugin/dapp/trade/executor/kv.go
View file @
63a80e7d
...
@@ -151,42 +151,6 @@ func calcOnesOrderPrefixStatus(addr string, status int32) []byte {
...
@@ -151,42 +151,6 @@ func calcOnesOrderPrefixStatus(addr string, status int32) []byte {
// return []byte(fmt.Sprintf(buyOrderSHTAS+"%d", status))
// return []byte(fmt.Sprintf(buyOrderSHTAS+"%d", status))
//}
//}
func
genBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
panic
(
err
)
}
priceBoardlotInt64
:=
int64
(
priceBoardlot
*
float64
(
types
.
TokenPrecision
))
AmountPerBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
panic
(
err
)
}
AmountPerBoardlotInt64
:=
int64
(
AmountPerBoardlot
*
float64
(
types
.
Coin
))
price
:=
calcPriceOfToken
(
priceBoardlotInt64
,
AmountPerBoardlotInt64
)
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
func
genSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
func
genSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
...
@@ -232,44 +196,4 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
...
@@ -232,44 +196,4 @@ func calcPriceOfToken(priceBoardlot, AmountPerBoardlot int64) int64 {
return
1e8
*
priceBoardlot
/
AmountPerBoardlot
return
1e8
*
priceBoardlot
/
AmountPerBoardlot
}
}
func
genBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenBuyOrderKey
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
,
buyOrder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
buyOrder
.
PricePerBoardlot
,
buyOrder
.
AmountPerBoardlot
),
buyOrder
.
Address
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
buyOrder
.
Address
,
st
,
ty
,
buyOrder
.
Height
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
func
genSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenSellOrderKey
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
,
sellorder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
sellorder
.
PricePerBoardlot
,
sellorder
.
AmountPerBoardlot
),
sellorder
.
Address
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
sellorder
.
Address
,
st
,
ty
,
sellorder
.
Height
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
plugin/dapp/trade/executor/localdb_v1.go
View file @
63a80e7d
package
executor
package
executor
import
(
"strconv"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
)
// 将手动生成的local db 的代码和用table 生成的local db的代码分离出来
// 将手动生成的local db 的代码和用table 生成的local db的代码分离出来
// 手动生成的local db, 将不生成任意资产标价的数据, 保留用coins 生成交易的数据, 来兼容为升级的app 应用
// 手动生成的local db, 将不生成任意资产标价的数据, 保留用coins 生成交易的数据, 来兼容为升级的app 应用
// 希望有全量数据的, 需要调用新的rpc
// 希望有全量数据的, 需要调用新的rpc
\ No newline at end of file
// sell limit
func
genSaveSellKv
(
sellorder
*
pty
.
SellOrder
)
[]
*
types
.
KeyValue
{
status
:=
sellorder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
saveSellOrderKeyValue
(
kv
,
sellorder
,
status
)
if
pty
.
TradeOrderStatusSoldOut
==
status
||
pty
.
TradeOrderStatusRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellid"
,
sellorder
.
SellID
)
kv
=
deleteSellOrderKeyValue
(
kv
,
sellorder
,
pty
.
TradeOrderStatusOnSale
)
}
return
kv
}
func
saveSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
sellID
:=
[]
byte
(
sellorder
.
SellID
)
return
genSellOrderKeyValue
(
kv
,
sellorder
,
status
,
sellID
)
}
func
deleteSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
return
genSellOrderKeyValue
(
kv
,
sellorder
,
status
,
nil
)
}
func
genSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenSellOrderKey
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
,
sellorder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
sellorder
.
TokenSymbol
,
sellorder
.
Address
,
status
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensSellOrderKeyStatus
(
sellorder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
sellorder
.
PricePerBoardlot
,
sellorder
.
AmountPerBoardlot
),
sellorder
.
Address
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
sellorder
.
Address
,
st
,
ty
,
sellorder
.
Height
,
sellorder
.
SellID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
// buy market
func
saveBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
txhash
:=
[]
byte
(
receipt
.
TxHash
)
return
genBuyMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
txhash
)
}
func
genBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
panic
(
err
)
}
priceBoardlotInt64
:=
int64
(
priceBoardlot
*
float64
(
types
.
TokenPrecision
))
AmountPerBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
panic
(
err
)
}
AmountPerBoardlotInt64
:=
int64
(
AmountPerBoardlot
*
float64
(
types
.
Coin
))
price
:=
calcPriceOfToken
(
priceBoardlotInt64
,
AmountPerBoardlotInt64
)
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
// buy limit
func
genSaveBuyLimitKv
(
buyOrder
*
pty
.
BuyLimitOrder
)
[]
*
types
.
KeyValue
{
status
:=
buyOrder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
saveBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
)
if
pty
.
TradeOrderStatusBoughtOut
==
status
||
pty
.
TradeOrderStatusBuyRevoked
==
status
{
tradelog
.
Debug
(
"trade saveBuyLimit "
,
"remove old status with Buyid"
,
buyOrder
.
BuyID
)
kv
=
deleteBuyLimitKeyValue
(
kv
,
buyOrder
,
pty
.
TradeOrderStatusOnBuy
)
}
return
kv
}
func
saveBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
buyID
:=
[]
byte
(
buyOrder
.
BuyID
)
return
genBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
,
buyID
)
}
func
deleteBuyLimitKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
return
genBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
,
nil
)
}
func
genBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
newkey
:=
calcTokenBuyOrderKey
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
,
buyOrder
.
Height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
buyOrder
.
TokenSymbol
,
buyOrder
.
Address
,
status
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcTokensBuyOrderKeyStatus
(
buyOrder
.
TokenSymbol
,
status
,
calcPriceOfToken
(
buyOrder
.
PricePerBoardlot
,
buyOrder
.
AmountPerBoardlot
),
buyOrder
.
Address
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
buyOrder
.
Address
,
st
,
ty
,
buyOrder
.
Height
,
buyOrder
.
BuyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
return
kv
}
// sell market
func
saveSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
txhash
:=
[]
byte
(
receipt
.
TxHash
)
return
genSellMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
txhash
)
}
// delete part
// sell limit
func
genDeleteSellKv
(
sellorder
*
pty
.
SellOrder
)
[]
*
types
.
KeyValue
{
status
:=
sellorder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
deleteSellOrderKeyValue
(
kv
,
sellorder
,
status
)
if
pty
.
TradeOrderStatusSoldOut
==
status
||
pty
.
TradeOrderStatusRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellID"
,
sellorder
.
SellID
)
kv
=
saveSellOrderKeyValue
(
kv
,
sellorder
,
pty
.
TradeOrderStatusOnSale
)
}
return
kv
}
// buy market
func
deleteBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
return
genBuyMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
nil
)
}
// buy limit
func
genDeleteBuyLimitKv
(
buyOrder
*
pty
.
BuyLimitOrder
)
[]
*
types
.
KeyValue
{
status
:=
buyOrder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
deleteBuyLimitKeyValue
(
kv
,
buyOrder
,
status
)
if
pty
.
TradeOrderStatusBoughtOut
==
status
||
pty
.
TradeOrderStatusBuyRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellid"
,
buyOrder
.
BuyID
)
kv
=
saveBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
pty
.
TradeOrderStatusOnBuy
)
}
return
kv
}
// sell market
func
deleteSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
return
genSellMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
nil
)
}
plugin/dapp/trade/executor/trade.go
View file @
63a80e7d
...
@@ -72,17 +72,6 @@ func (t *trade) getSellOrderFromDb(sellID []byte) *pty.SellOrder {
...
@@ -72,17 +72,6 @@ func (t *trade) getSellOrderFromDb(sellID []byte) *pty.SellOrder {
return
&
sellorder
return
&
sellorder
}
}
func
genSaveSellKv
(
sellorder
*
pty
.
SellOrder
)
[]
*
types
.
KeyValue
{
status
:=
sellorder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
saveSellOrderKeyValue
(
kv
,
sellorder
,
status
)
if
pty
.
TradeOrderStatusSoldOut
==
status
||
pty
.
TradeOrderStatusRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellid"
,
sellorder
.
SellID
)
kv
=
deleteSellOrderKeyValue
(
kv
,
sellorder
,
pty
.
TradeOrderStatusOnSale
)
}
return
kv
}
func
(
t
*
trade
)
saveSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
saveSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
sellorder
:=
t
.
getSellOrderFromDb
([]
byte
(
base
.
SellID
))
sellorder
:=
t
.
getSellOrderFromDb
([]
byte
(
base
.
SellID
))
...
@@ -96,26 +85,6 @@ func (t *trade) saveSell(base *pty.ReceiptSellBase, ty int32, tx *types.Transact
...
@@ -96,26 +85,6 @@ func (t *trade) saveSell(base *pty.ReceiptSellBase, ty int32, tx *types.Transact
return
genSaveSellKv
(
sellorder
)
return
genSaveSellKv
(
sellorder
)
}
}
func
deleteSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
return
genSellOrderKeyValue
(
kv
,
sellorder
,
status
,
nil
)
}
func
saveSellOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
sellorder
*
pty
.
SellOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
sellID
:=
[]
byte
(
sellorder
.
SellID
)
return
genSellOrderKeyValue
(
kv
,
sellorder
,
status
,
sellID
)
}
func
genDeleteSellKv
(
sellorder
*
pty
.
SellOrder
)
[]
*
types
.
KeyValue
{
status
:=
sellorder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
deleteSellOrderKeyValue
(
kv
,
sellorder
,
status
)
if
pty
.
TradeOrderStatusSoldOut
==
status
||
pty
.
TradeOrderStatusRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellID"
,
sellorder
.
SellID
)
kv
=
saveSellOrderKeyValue
(
kv
,
sellorder
,
pty
.
TradeOrderStatusOnSale
)
}
return
kv
}
func
(
t
*
trade
)
deleteSell
(
base
*
pty
.
ReceiptSellBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
,
tradedBoardlot
int64
)
[]
*
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
([]
byte
(
base
.
SellID
))
sellorder
:=
t
.
getSellOrderFromDb
([]
byte
(
base
.
SellID
))
if
ty
==
pty
.
TyLogTradeSellLimit
&&
sellorder
.
SoldBoardlot
==
0
{
if
ty
==
pty
.
TyLogTradeSellLimit
&&
sellorder
.
SoldBoardlot
==
0
{
...
@@ -153,17 +122,6 @@ func (t *trade) getBuyOrderFromDb(buyID []byte) *pty.BuyLimitOrder {
...
@@ -153,17 +122,6 @@ func (t *trade) getBuyOrderFromDb(buyID []byte) *pty.BuyLimitOrder {
return
&
buyOrder
return
&
buyOrder
}
}
func
genSaveBuyLimitKv
(
buyOrder
*
pty
.
BuyLimitOrder
)
[]
*
types
.
KeyValue
{
status
:=
buyOrder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
saveBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
)
if
pty
.
TradeOrderStatusBoughtOut
==
status
||
pty
.
TradeOrderStatusBuyRevoked
==
status
{
tradelog
.
Debug
(
"trade saveBuyLimit "
,
"remove old status with Buyid"
,
buyOrder
.
BuyID
)
kv
=
deleteBuyLimitKeyValue
(
kv
,
buyOrder
,
pty
.
TradeOrderStatusOnBuy
)
}
return
kv
}
func
(
t
*
trade
)
saveBuyLimit
(
buy
*
pty
.
ReceiptBuyBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
)
[]
*
types
.
KeyValue
{
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
))
buyOrder
:=
t
.
getBuyOrderFromDb
([]
byte
(
buy
.
BuyID
))
tradelog
.
Debug
(
"Table"
,
"buy-add"
,
buyOrder
)
tradelog
.
Debug
(
"Table"
,
"buy-add"
,
buyOrder
)
...
@@ -178,26 +136,6 @@ func (t *trade) saveBuyLimit(buy *pty.ReceiptBuyBase, ty int32, tx *types.Transa
...
@@ -178,26 +136,6 @@ func (t *trade) saveBuyLimit(buy *pty.ReceiptBuyBase, ty int32, tx *types.Transa
return
genSaveBuyLimitKv
(
buyOrder
)
return
genSaveBuyLimitKv
(
buyOrder
)
}
}
func
saveBuyLimitOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
buyID
:=
[]
byte
(
buyOrder
.
BuyID
)
return
genBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
,
buyID
)
}
func
deleteBuyLimitKeyValue
(
kv
[]
*
types
.
KeyValue
,
buyOrder
*
pty
.
BuyLimitOrder
,
status
int32
)
[]
*
types
.
KeyValue
{
return
genBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
status
,
nil
)
}
func
genDeleteBuyLimitKv
(
buyOrder
*
pty
.
BuyLimitOrder
)
[]
*
types
.
KeyValue
{
status
:=
buyOrder
.
Status
var
kv
[]
*
types
.
KeyValue
kv
=
deleteBuyLimitKeyValue
(
kv
,
buyOrder
,
status
)
if
pty
.
TradeOrderStatusBoughtOut
==
status
||
pty
.
TradeOrderStatusBuyRevoked
==
status
{
tradelog
.
Debug
(
"trade saveSell "
,
"remove old status onsale to soldout or revoked with sellid"
,
buyOrder
.
BuyID
)
kv
=
saveBuyLimitOrderKeyValue
(
kv
,
buyOrder
,
pty
.
TradeOrderStatusOnBuy
)
}
return
kv
}
func
(
t
*
trade
)
deleteBuyLimit
(
buy
*
pty
.
ReceiptBuyBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
,
traded
int64
)
[]
*
types
.
KeyValue
{
func
(
t
*
trade
)
deleteBuyLimit
(
buy
*
pty
.
ReceiptBuyBase
,
ty
int32
,
tx
*
types
.
Transaction
,
txIndex
string
,
ldb
*
table
.
Table
,
traded
int64
)
[]
*
types
.
KeyValue
{
buyOrder
:=
t
.
getBuyOrderFromDb
([]
byte
(
buy
.
BuyID
))
buyOrder
:=
t
.
getBuyOrderFromDb
([]
byte
(
buy
.
BuyID
))
if
ty
==
pty
.
TyLogTradeBuyLimit
&&
buy
.
BoughtBoardlot
==
0
{
if
ty
==
pty
.
TyLogTradeBuyLimit
&&
buy
.
BoughtBoardlot
==
0
{
...
@@ -221,24 +159,6 @@ func (t *trade) deleteSellMarket(receiptTradeBuy *pty.ReceiptSellBase, txIndex s
...
@@ -221,24 +159,6 @@ func (t *trade) deleteSellMarket(receiptTradeBuy *pty.ReceiptSellBase, txIndex s
return
deleteSellMarketOrderKeyValue
(
kv
,
receiptTradeBuy
,
pty
.
TradeOrderStatusSoldOut
,
t
.
GetHeight
())
return
deleteSellMarketOrderKeyValue
(
kv
,
receiptTradeBuy
,
pty
.
TradeOrderStatusSoldOut
,
t
.
GetHeight
())
}
}
func
saveSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
txhash
:=
[]
byte
(
receipt
.
TxHash
)
return
genSellMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
txhash
)
}
func
deleteSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
return
genSellMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
nil
)
}
func
saveBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
txhash
:=
[]
byte
(
receipt
.
TxHash
)
return
genBuyMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
txhash
)
}
func
deleteBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
)
[]
*
types
.
KeyValue
{
return
genBuyMarketOrderKeyValue
(
kv
,
receipt
,
status
,
height
,
nil
)
}
// CheckReceiptExecOk return true to check if receipt ty is ok
// CheckReceiptExecOk return true to check if receipt ty is ok
func
(
t
*
trade
)
CheckReceiptExecOk
()
bool
{
func
(
t
*
trade
)
CheckReceiptExecOk
()
bool
{
return
true
return
true
...
...
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