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
446024a6
Commit
446024a6
authored
Sep 02, 2019
by
linj
Committed by
vipwzw
Sep 05, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
price: update buy market exec
parent
98640b04
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
2 deletions
+20
-2
trade.go
plugin/dapp/trade/executor/trade.go
+1
-0
tradedb.go
plugin/dapp/trade/executor/tradedb.go
+8
-2
util.go
plugin/dapp/trade/executor/util.go
+11
-0
No files found.
plugin/dapp/trade/executor/trade.go
View file @
446024a6
...
...
@@ -29,6 +29,7 @@ var (
tradelog
=
log
.
New
(
"module"
,
"execs.trade"
)
defaultAssetExec
=
"token"
driverName
=
"trade"
defaultPriceExec
=
"coins"
)
func
init
()
{
...
...
plugin/dapp/trade/executor/tradedb.go
View file @
446024a6
...
...
@@ -93,6 +93,8 @@ func (selldb *sellDB) getBuyLogs(buyerAddr string, boardlotcnt int64, txhash str
TxHash
:
txhash
,
Height
:
selldb
.
Height
,
AssetExec
:
selldb
.
AssetExec
,
PriceExec
:
selldb
.
PriceExec
,
PriceSymbol
:
selldb
.
PriceSymbol
,
}
receipt
:=
&
pty
.
ReceiptTradeBuyMarket
{
Base
:
base
}
...
...
@@ -343,8 +345,12 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
return
nil
,
pty
.
ErrTCntLessThanMinBoardlot
}
priceAcc
,
err
:=
createPriceDB
(
action
.
height
,
action
.
db
,
sellOrder
.
PriceExec
,
sellOrder
.
PriceSymbol
)
if
err
!=
nil
{
return
nil
,
err
}
//首先购买费用的划转
receiptFromAcc
,
err
:=
action
.
coinsAccount
.
ExecTransfer
(
action
.
fromaddr
,
sellOrder
.
Address
,
action
.
execaddr
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
PricePerBoardlot
)
receiptFromAcc
,
err
:=
priceAcc
.
ExecTransfer
(
action
.
fromaddr
,
sellOrder
.
Address
,
action
.
execaddr
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
PricePerBoardlot
)
if
err
!=
nil
{
tradelog
.
Error
(
"account.Transfer "
,
"addrFrom"
,
action
.
fromaddr
,
"addrTo"
,
sellOrder
.
Address
,
"amount"
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
PricePerBoardlot
)
...
...
@@ -362,7 +368,7 @@ func (action *tradeAction) tradeBuy(buyOrder *pty.TradeForBuy) (*types.Receipt,
"addrTo"
,
action
.
fromaddr
,
"execaddr"
,
action
.
execaddr
,
"amount"
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
AmountPerBoardlot
)
//因为未能成功将对应的token进行转账,所以需要将购买方的账户资金进行回退
action
.
coinsAccount
.
ExecTransfer
(
sellOrder
.
Address
,
action
.
fromaddr
,
action
.
execaddr
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
PricePerBoardlot
)
priceAcc
.
ExecTransfer
(
sellOrder
.
Address
,
action
.
fromaddr
,
action
.
execaddr
,
buyOrder
.
BoardlotCnt
*
sellOrder
.
PricePerBoardlot
)
return
nil
,
err
}
...
...
plugin/dapp/trade/executor/util.go
View file @
446024a6
...
...
@@ -81,3 +81,14 @@ func createAccountDB(height int64, db db.KV, exec, symbol string) (*account.DB,
return
account
.
NewAccountDB
(
defaultAssetExec
,
symbol
,
db
)
}
func
createPriceDB
(
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
pt
.
ForkTradePriceX
)
{
// 在fork 之前提的交易
if
exec
==
""
{
return
account
.
NewCoinsAccount
(),
nil
}
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
}
return
account
.
NewCoinsAccount
(),
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