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
365c5f6c
Commit
365c5f6c
authored
Jan 08, 2020
by
linj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove code : convert types from receipt
parent
8253c6eb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
254 deletions
+0
-254
query_v1.go
plugin/dapp/trade/executor/query_v1.go
+0
-254
No files found.
plugin/dapp/trade/executor/query_v1.go
View file @
365c5f6c
package
executor
import
(
"strconv"
"strings"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/db/table"
"github.com/33cn/chain33/types"
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
...
...
@@ -181,253 +177,3 @@ func (t *trade) GetOnesSellOrdersWithStatus(req *pty.ReqAddrAssets) (types.Messa
func
(
t
*
trade
)
GetOnesBuyOrdersWithStatus
(
req
*
pty
.
ReqAddrAssets
)
(
types
.
Message
,
error
)
{
return
t
.
GetOnesStatusOrder
(
false
,
req
)
}
// utils
// SellMarkMarket BuyMarket 没有tradeOrder 需要调用这个函数进行转化
// BuyRevoke, SellRevoke 也需要
// SellLimit/BuyLimit 有order 但order 里面没有 bolcktime, 直接访问 order 还需要再次访问 block, 还不如直接访问交易
func
buyBase2Order
(
base
*
pty
.
ReceiptBuyBase
,
txHash
string
,
blockTime
int64
)
*
pty
.
ReplyTradeOrder
{
amount
,
err
:=
strconv
.
ParseFloat
(
base
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
price
,
err
:=
strconv
.
ParseFloat
(
base
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
key
:=
txHash
if
len
(
base
.
BuyID
)
>
0
{
key
=
base
.
BuyID
}
//txhash := common.ToHex(txResult.GetTx().Hash())
reply
:=
&
pty
.
ReplyTradeOrder
{
TokenSymbol
:
base
.
TokenSymbol
,
Owner
:
base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
base
.
TotalBoardlot
,
TradedBoardlot
:
base
.
BoughtBoardlot
,
BuyID
:
base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
base
.
Status
],
SellID
:
base
.
SellID
,
TxHash
:
txHash
,
Height
:
base
.
Height
,
Key
:
key
,
BlockTime
:
blockTime
,
IsSellOrder
:
false
,
AssetExec
:
base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
}
func
sellBase2Order
(
base
*
pty
.
ReceiptSellBase
,
txHash
string
,
blockTime
int64
)
*
pty
.
ReplyTradeOrder
{
amount
,
err
:=
strconv
.
ParseFloat
(
base
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
price
,
err
:=
strconv
.
ParseFloat
(
base
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
//txhash := common.ToHex(txResult.GetTx().Hash())
key
:=
txHash
if
len
(
base
.
SellID
)
>
0
{
key
=
base
.
SellID
}
reply
:=
&
pty
.
ReplyTradeOrder
{
TokenSymbol
:
base
.
TokenSymbol
,
Owner
:
base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
base
.
TotalBoardlot
,
TradedBoardlot
:
base
.
SoldBoardlot
,
BuyID
:
base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
base
.
Status
],
SellID
:
base
.
SellID
,
TxHash
:
txHash
,
Height
:
base
.
Height
,
Key
:
key
,
BlockTime
:
blockTime
,
IsSellOrder
:
true
,
AssetExec
:
base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
}
func
(
t
*
trade
)
replyReplySellOrderfromID
(
key
[]
byte
)
*
pty
.
ReplySellOrder
{
tradelog
.
Debug
(
"trade Query"
,
"id"
,
string
(
key
),
"check-prefix"
,
sellIDPrefix
)
if
strings
.
HasPrefix
(
string
(
key
),
sellIDPrefix
)
{
if
sellorder
,
err
:=
getSellOrderFromID
(
key
,
t
.
GetStateDB
());
err
==
nil
{
tradelog
.
Debug
(
"trade Query"
,
"getSellOrderFromID"
,
string
(
key
))
return
sellOrder2reply
(
sellorder
)
}
}
else
{
// txhash as key
txResult
,
err
:=
getTx
(
key
,
t
.
GetLocalDB
(),
t
.
GetAPI
())
tradelog
.
Debug
(
"GetOnesSellOrder "
,
"load txhash"
,
string
(
key
))
if
err
!=
nil
{
return
nil
}
return
txResult2sellOrderReply
(
txResult
)
}
return
nil
}
func
(
t
*
trade
)
replyReplyBuyOrderfromID
(
key
[]
byte
)
*
pty
.
ReplyBuyOrder
{
tradelog
.
Debug
(
"trade Query"
,
"id"
,
string
(
key
),
"check-prefix"
,
buyIDPrefix
)
if
strings
.
HasPrefix
(
string
(
key
),
buyIDPrefix
)
{
if
buyOrder
,
err
:=
getBuyOrderFromID
(
key
,
t
.
GetStateDB
());
err
==
nil
{
tradelog
.
Debug
(
"trade Query"
,
"getSellOrderFromID"
,
string
(
key
))
return
buyOrder2reply
(
buyOrder
)
}
}
else
{
// txhash as key
txResult
,
err
:=
getTx
(
key
,
t
.
GetLocalDB
(),
t
.
GetAPI
())
tradelog
.
Debug
(
"replyReplyBuyOrderfromID "
,
"load txhash"
,
string
(
key
))
if
err
!=
nil
{
return
nil
}
return
txResult2buyOrderReply
(
txResult
)
}
return
nil
}
func
sellOrder2reply
(
sellOrder
*
pty
.
SellOrder
)
*
pty
.
ReplySellOrder
{
reply
:=
&
pty
.
ReplySellOrder
{
TokenSymbol
:
sellOrder
.
TokenSymbol
,
Owner
:
sellOrder
.
Address
,
AmountPerBoardlot
:
sellOrder
.
AmountPerBoardlot
,
MinBoardlot
:
sellOrder
.
MinBoardlot
,
PricePerBoardlot
:
sellOrder
.
PricePerBoardlot
,
TotalBoardlot
:
sellOrder
.
TotalBoardlot
,
SoldBoardlot
:
sellOrder
.
SoldBoardlot
,
BuyID
:
""
,
Status
:
sellOrder
.
Status
,
SellID
:
sellOrder
.
SellID
,
TxHash
:
strings
.
Replace
(
sellOrder
.
SellID
,
sellIDPrefix
,
"0x"
,
1
),
Height
:
sellOrder
.
Height
,
Key
:
sellOrder
.
SellID
,
AssetExec
:
sellOrder
.
AssetExec
,
}
return
reply
}
func
txResult2sellOrderReply
(
txResult
*
types
.
TxResult
)
*
pty
.
ReplySellOrder
{
logs
:=
txResult
.
Receiptdate
.
Logs
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show logs"
,
logs
)
for
_
,
log
:=
range
logs
{
if
log
.
Ty
==
pty
.
TyLogTradeSellMarket
{
var
receipt
pty
.
ReceiptSellMarket
err
:=
types
.
Decode
(
log
.
Log
,
&
receipt
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show logs 1 "
,
receipt
)
amount
,
err
:=
strconv
.
ParseFloat
(
receipt
.
Base
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
price
,
err
:=
strconv
.
ParseFloat
(
receipt
.
Base
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
txhash
:=
common
.
ToHex
(
txResult
.
GetTx
()
.
Hash
())
reply
:=
&
pty
.
ReplySellOrder
{
TokenSymbol
:
receipt
.
Base
.
TokenSymbol
,
Owner
:
receipt
.
Base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
receipt
.
Base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
receipt
.
Base
.
TotalBoardlot
,
SoldBoardlot
:
receipt
.
Base
.
SoldBoardlot
,
BuyID
:
receipt
.
Base
.
BuyID
,
Status
:
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
SellID
:
""
,
TxHash
:
txhash
,
Height
:
receipt
.
Base
.
Height
,
Key
:
txhash
,
AssetExec
:
receipt
.
Base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
}
}
return
nil
}
func
buyOrder2reply
(
buyOrder
*
pty
.
BuyLimitOrder
)
*
pty
.
ReplyBuyOrder
{
reply
:=
&
pty
.
ReplyBuyOrder
{
TokenSymbol
:
buyOrder
.
TokenSymbol
,
Owner
:
buyOrder
.
Address
,
AmountPerBoardlot
:
buyOrder
.
AmountPerBoardlot
,
MinBoardlot
:
buyOrder
.
MinBoardlot
,
PricePerBoardlot
:
buyOrder
.
PricePerBoardlot
,
TotalBoardlot
:
buyOrder
.
TotalBoardlot
,
BoughtBoardlot
:
buyOrder
.
BoughtBoardlot
,
BuyID
:
buyOrder
.
BuyID
,
Status
:
buyOrder
.
Status
,
SellID
:
""
,
TxHash
:
strings
.
Replace
(
buyOrder
.
BuyID
,
buyIDPrefix
,
"0x"
,
1
),
Height
:
buyOrder
.
Height
,
Key
:
buyOrder
.
BuyID
,
AssetExec
:
buyOrder
.
AssetExec
,
}
return
reply
}
func
txResult2buyOrderReply
(
txResult
*
types
.
TxResult
)
*
pty
.
ReplyBuyOrder
{
logs
:=
txResult
.
Receiptdate
.
Logs
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show logs"
,
logs
)
for
_
,
log
:=
range
logs
{
if
log
.
Ty
==
pty
.
TyLogTradeBuyMarket
{
var
receipt
pty
.
ReceiptTradeBuyMarket
err
:=
types
.
Decode
(
log
.
Log
,
&
receipt
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show logs 1 "
,
receipt
)
amount
,
err
:=
strconv
.
ParseFloat
(
receipt
.
Base
.
AmountPerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
price
,
err
:=
strconv
.
ParseFloat
(
receipt
.
Base
.
PricePerBoardlot
,
64
)
if
err
!=
nil
{
tradelog
.
Error
(
"txResult2sellOrderReply"
,
"decode receipt"
,
err
)
return
nil
}
txhash
:=
common
.
ToHex
(
txResult
.
GetTx
()
.
Hash
())
reply
:=
&
pty
.
ReplyBuyOrder
{
TokenSymbol
:
receipt
.
Base
.
TokenSymbol
,
Owner
:
receipt
.
Base
.
Owner
,
AmountPerBoardlot
:
int64
(
amount
*
float64
(
types
.
TokenPrecision
)),
MinBoardlot
:
receipt
.
Base
.
MinBoardlot
,
PricePerBoardlot
:
int64
(
price
*
float64
(
types
.
Coin
)),
TotalBoardlot
:
receipt
.
Base
.
TotalBoardlot
,
BoughtBoardlot
:
receipt
.
Base
.
BoughtBoardlot
,
BuyID
:
""
,
Status
:
pty
.
SellOrderStatus2Int
[
receipt
.
Base
.
Status
],
SellID
:
receipt
.
Base
.
SellID
,
TxHash
:
txhash
,
Height
:
receipt
.
Base
.
Height
,
Key
:
txhash
,
AssetExec
:
receipt
.
Base
.
AssetExec
,
}
tradelog
.
Debug
(
"txResult2sellOrderReply"
,
"show reply"
,
reply
)
return
reply
}
}
return
nil
}
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