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
937318cf
Commit
937318cf
authored
Jan 09, 2020
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除手动生成KV的代码
parent
e221a622
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
226 deletions
+22
-226
kv.go
plugin/dapp/trade/executor/kv.go
+22
-140
localdb_v1.go
plugin/dapp/trade/executor/localdb_v1.go
+0
-86
No files found.
plugin/dapp/trade/executor/kv.go
View file @
937318cf
...
@@ -6,12 +6,14 @@ package executor
...
@@ -6,12 +6,14 @@ package executor
import
(
import
(
"fmt"
"fmt"
"strconv"
)
"github.com/33cn/chain33/types"
const
(
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
sellIDPrefix
=
"mavl-trade-sell-"
buyIDPrefix
=
"mavl-trade-buy-"
)
)
// 下个版本可以删除
const
(
const
(
sellOrderSHTAS
=
"LODB-trade-sellorder-shtas:"
sellOrderSHTAS
=
"LODB-trade-sellorder-shtas:"
sellOrderASTS
=
"LODB-trade-sellorder-asts:"
sellOrderASTS
=
"LODB-trade-sellorder-asts:"
...
@@ -21,57 +23,10 @@ const (
...
@@ -21,57 +23,10 @@ const (
buyOrderASTS
=
"LODB-trade-buyorder-asts:"
buyOrderASTS
=
"LODB-trade-buyorder-asts:"
buyOrderATSS
=
"LODB-trade-buyorder-atss:"
buyOrderATSS
=
"LODB-trade-buyorder-atss:"
buyOrderTSPAS
=
"LODB-trade-buyorder-tspas:"
buyOrderTSPAS
=
"LODB-trade-buyorder-tspas:"
sellIDPrefix
=
"mavl-trade-sell-"
buyIDPrefix
=
"mavl-trade-buy-"
// Addr-Status-Type-Height-Key
// Addr-Status-Type-Height-Key
orderASTHK
=
"LODB-trade-order-asthk:"
orderASTHK
=
"LODB-trade-order-asthk:"
)
)
// sell order 4 key, 4prefix
// 特定状态下的卖单
func
calcTokenSellOrderKey
(
token
string
,
addr
string
,
status
int32
,
sellOrderID
string
,
height
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
sellOrderSHTAS
+
"%d:%d:%s:%s:%s"
,
status
,
height
,
token
,
addr
,
sellOrderID
)
return
[]
byte
(
key
)
}
// 特定账户下特定状态的卖单
func
calcOnesSellOrderKeyStatus
(
token
string
,
addr
string
,
status
int32
,
sellOrderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
sellOrderASTS
+
"%s:%d:%s:%s"
,
addr
,
status
,
token
,
sellOrderID
)
return
[]
byte
(
key
)
}
// 特定账户下特定token的卖单
func
calcOnesSellOrderKeyToken
(
token
string
,
addr
string
,
status
int32
,
sellOrderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
sellOrderATSS
+
"%s:%s:%d:%s"
,
addr
,
token
,
status
,
sellOrderID
)
return
[]
byte
(
key
)
}
// 指定token的卖单, 带上价格方便排序
func
calcTokensSellOrderKeyStatus
(
token
string
,
status
int32
,
price
int64
,
addr
string
,
sellOrderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
sellOrderTSPAS
+
"%s:%d:%016d:%s:%s"
,
token
,
status
,
price
,
addr
,
sellOrderID
)
return
[]
byte
(
key
)
}
func
calcTokensSellOrderPrefixStatus
(
token
string
,
status
int32
)
[]
byte
{
prefix
:=
fmt
.
Sprintf
(
sellOrderTSPAS
+
"%s:%d:"
,
token
,
status
)
return
[]
byte
(
prefix
)
}
// 特定账户下指定token的卖单
func
calcOnesSellOrderPrefixToken
(
token
string
,
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
sellOrderATSS
+
"%s:%s"
,
addr
,
token
)
return
[]
byte
(
key
)
}
// 特定账户下的卖单
func
calcOnesSellOrderPrefixAddr
(
addr
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
sellOrderASTS
+
"%s"
,
addr
))
}
func
calcOnesSellOrderPrefixStatus
(
addr
string
,
status
int32
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
sellOrderASTS
+
"%s:%d"
,
addr
,
status
))
}
// ids
// ids
func
calcTokenSellID
(
hash
string
)
string
{
func
calcTokenSellID
(
hash
string
)
string
{
return
sellIDPrefix
+
hash
return
sellIDPrefix
+
hash
...
@@ -81,51 +36,6 @@ func calcTokenBuyID(hash string) string {
...
@@ -81,51 +36,6 @@ func calcTokenBuyID(hash string) string {
return
buyIDPrefix
+
hash
return
buyIDPrefix
+
hash
}
}
// buy limit order 4 key, 4prefix
// 特定状态下的买单
func
calcTokenBuyOrderKey
(
token
string
,
addr
string
,
status
int32
,
orderID
string
,
height
int64
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
buyOrderSHTAS
+
"%d:%d:%s:%s:%s"
,
status
,
height
,
token
,
addr
,
orderID
)
return
[]
byte
(
key
)
}
// 特定账户下特定状态的买单
func
calcOnesBuyOrderKeyStatus
(
token
string
,
addr
string
,
status
int32
,
orderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
buyOrderASTS
+
"%s:%d:%s:%s"
,
addr
,
status
,
token
,
orderID
)
return
[]
byte
(
key
)
}
// 特定账户下特定token的买单
func
calcOnesBuyOrderKeyToken
(
token
string
,
addr
string
,
status
int32
,
orderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
buyOrderATSS
+
"%s:%s:%d:%s"
,
addr
,
token
,
status
,
orderID
)
return
[]
byte
(
key
)
}
// 指定token的卖单, 带上价格方便排序
func
calcTokensBuyOrderKeyStatus
(
token
string
,
status
int32
,
price
int64
,
addr
string
,
orderID
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
buyOrderTSPAS
+
"%s:%d:%016d:%s:%s"
,
token
,
status
,
price
,
addr
,
orderID
)
return
[]
byte
(
key
)
}
func
calcTokensBuyOrderPrefixStatus
(
token
string
,
status
int32
)
[]
byte
{
prefix
:=
fmt
.
Sprintf
(
buyOrderTSPAS
+
"%s:%d:"
,
token
,
status
)
return
[]
byte
(
prefix
)
}
// 特定账户下指定token的买单
func
calcOnesBuyOrderPrefixToken
(
token
string
,
addr
string
)
[]
byte
{
key
:=
fmt
.
Sprintf
(
buyOrderATSS
+
"%s:%s"
,
addr
,
token
)
return
[]
byte
(
key
)
}
// 特定账户下的买单
func
calcOnesBuyOrderPrefixAddr
(
addr
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
buyOrderASTS
+
"%s"
,
addr
))
}
func
calcOnesBuyOrderPrefixStatus
(
addr
string
,
status
int32
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
buyOrderASTS
+
"%s:%d"
,
addr
,
status
))
}
// 特定帐号下的订单
// 特定帐号下的订单
// 这里状态进行转化, 分成 状态和类型, 状态三种, 类型 两种
// 这里状态进行转化, 分成 状态和类型, 状态三种, 类型 两种
// on: OnSale OnBuy
// on: OnSale OnBuy
...
@@ -133,51 +43,6 @@ func calcOnesBuyOrderPrefixStatus(addr string, status int32) []byte {
...
@@ -133,51 +43,6 @@ func calcOnesBuyOrderPrefixStatus(addr string, status int32) []byte {
// revoke: RevokeSell RevokeBuy
// revoke: RevokeSell RevokeBuy
// buy/sell 两种类型
// buy/sell 两种类型
// 目前页面是按addr, 状态来
// 目前页面是按addr, 状态来
func
calcOnesOrderKey
(
addr
string
,
status
int32
,
ty
int32
,
height
int64
,
key
string
)
[]
byte
{
return
[]
byte
(
fmt
.
Sprintf
(
orderASTHK
+
"%s:%d:%010d:%d:%s"
,
addr
,
status
,
height
,
ty
,
key
))
}
// 特定状态下的买单
//func calcTokenBuyOrderPrefixStatus(status int32) []byte {
// return []byte(fmt.Sprintf(buyOrderSHTAS+"%d", status))
//}
func
genSellMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptSellBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
keyID
:=
receipt
.
TxHash
newkey
:=
calcTokenSellOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyID
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
Key
:
newkey
,
Value
:
value
})
newkey
=
calcOnesSellOrderKeyToken
(
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
=
calcTokensSellOrderKeyStatus
(
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
}
// make a number as token's price whether cheap or dear
// make a number as token's price whether cheap or dear
// support 1e8 bty pre token or 1/1e8 bty pre token, [1Coins, 1e16Coins]
// support 1e8 bty pre token or 1/1e8 bty pre token, [1Coins, 1e16Coins]
...
@@ -185,3 +50,20 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
...
@@ -185,3 +50,20 @@ func genSellMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptSellBa
func
calcPriceOfToken
(
priceBoardlot
,
AmountPerBoardlot
int64
)
int64
{
func
calcPriceOfToken
(
priceBoardlot
,
AmountPerBoardlot
int64
)
int64
{
return
1e8
*
priceBoardlot
/
AmountPerBoardlot
return
1e8
*
priceBoardlot
/
AmountPerBoardlot
}
}
// UpdateLocalDBPart1 手动生成KV,需要在原有数据库中删除
// TODO
func
UpdateLocalDBPart1
()
{
prefix
:=
[]
string
{
sellOrderSHTAS
,
sellOrderASTS
,
sellOrderATSS
,
sellOrderTSPAS
,
buyOrderSHTAS
,
buyOrderASTS
,
buyOrderATSS
,
buyOrderTSPAS
,
orderASTHK
,
}
fmt
.
Printf
(
"%+v"
,
prefix
)
}
plugin/dapp/trade/executor/localdb_v1.go
View file @
937318cf
package
executor
package
executor
import
(
"strconv"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
)
// 生成 key -> id 格式的本地数据库数据, 在下个版本这个文件可以全部删除
// 生成 key -> id 格式的本地数据库数据, 在下个版本这个文件可以全部删除
// 由于数据库精简需要保存具体数据
// 由于数据库精简需要保存具体数据
// 将手动生成的local db 的代码和用table 生成的local db的代码分离出来
// 将手动生成的local db 的代码和用table 生成的local db的代码分离出来
// 手动生成的local db, 将不生成任意资产标价的数据, 保留用coins 生成交易的数据, 来兼容为升级的app 应用
// 手动生成的local db, 将不生成任意资产标价的数据, 保留用coins 生成交易的数据, 来兼容为升级的app 应用
// 希望有全量数据的, 需要调用新的rpc
// 希望有全量数据的, 需要调用新的rpc
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
}
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
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
}
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