Commit 9ee34269 authored by harrylee's avatar harrylee Committed by vipwzw

make linter

parent 52e94ec0
...@@ -55,9 +55,8 @@ func (a *Action) updateStateDBCache(order *et.Order) { ...@@ -55,9 +55,8 @@ func (a *Action) updateStateDBCache(order *et.Order) {
func (a *Action) OpSwap(op int32) int32 { func (a *Action) OpSwap(op int32) int32 {
if op == et.OpBuy { if op == et.OpBuy {
return et.OpSell return et.OpSell
} else {
return et.OpBuy
} }
return et.OpBuy
} }
//计算实际花费 //计算实际花费
...@@ -83,10 +82,7 @@ func CheckOp(op int32) bool { ...@@ -83,10 +82,7 @@ func CheckOp(op int32) bool {
} }
func CheckCount(count int32) bool { func CheckCount(count int32) bool {
if count > 20 { return count > 20
return false
}
return true
} }
func CheckDirection(direction int32) bool { func CheckDirection(direction int32) bool {
...@@ -247,7 +243,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc ...@@ -247,7 +243,7 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
or := &et.Order{ or := &et.Order{
OrderID: common.ToHex(a.txhash), OrderID: common.ToHex(a.txhash),
Value: &et.Order_LimitOrder{payload}, Value: &et.Order_LimitOrder{LimitOrder: payload},
Ty: et.TyLimitOrderAction, Ty: et.TyLimitOrderAction,
Executed: 0, Executed: 0,
Balance: payload.GetAmount(), Balance: payload.GetAmount(),
...@@ -324,9 +320,8 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc ...@@ -324,9 +320,8 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
matchorder.Status = func(a, b int64) int32 { matchorder.Status = func(a, b int64) int32 {
if a > b { if a > b {
return et.Ordered return et.Ordered
} else {
return et.Completed
} }
return et.Completed
}(matchorder.GetBalance(), or.GetBalance()) }(matchorder.GetBalance(), or.GetBalance())
matchorder.Balance = matchorder.GetBalance() - or.GetBalance() matchorder.Balance = matchorder.GetBalance() - or.GetBalance()
matchorder.Executed = matchorder.Executed + or.GetBalance() matchorder.Executed = matchorder.Executed + or.GetBalance()
...@@ -348,43 +343,42 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc ...@@ -348,43 +343,42 @@ func (a *Action) matchLimitOrder(payload *et.LimitOrder, leftAccountDB, rightAcc
logs = append(logs, receiptlog) logs = append(logs, receiptlog)
receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs} receipts := &types.Receipt{Ty: types.ExecOk, KV: kvs, Logs: logs}
return receipts, nil return receipts, nil
} else { }
if payload.Op == et.OpSell { if payload.Op == et.OpSell {
//转移冻结资产 //转移冻结资产
receipt, err := rightAccountDB.ExecTransferFrozen(matchorder.Addr, a.fromaddr, a.execaddr, a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice())) receipt, err := rightAccountDB.ExecTransferFrozen(matchorder.Addr, a.fromaddr, a.execaddr, a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()))
if err != nil { if err != nil {
elog.Error("matchLimitOrder.ExecTransferFrozen", "addr", matchorder.Addr, "execaddr", a.execaddr, "amount", a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error()) elog.Error("matchLimitOrder.ExecTransferFrozen", "addr", matchorder.Addr, "execaddr", a.execaddr, "amount", a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error())
return nil, err return nil, err
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
//将达成交易的相应资产结算
receipt, err = leftAccountDB.ExecTransfer(a.fromaddr, matchorder.Addr, a.execaddr, a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()))
if err != nil {
elog.Error("matchLimitOrder.ExecTransfer", "addr", a.fromaddr, "execaddr", a.execaddr, "amount", a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error())
return nil, err
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
} }
if payload.Op == et.OpBuy { logs = append(logs, receipt.Logs...)
//转移冻结资产 kvs = append(kvs, receipt.KV...)
receipt, err := leftAccountDB.ExecTransferFrozen(matchorder.Addr, a.fromaddr, a.execaddr, a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice())) //将达成交易的相应资产结算
if err != nil { receipt, err = leftAccountDB.ExecTransfer(a.fromaddr, matchorder.Addr, a.execaddr, a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()))
elog.Error("matchLimitOrder.ExecTransferFrozen", "addr", matchorder.Addr, "execaddr", a.execaddr, "amount", a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error()) if err != nil {
return nil, err elog.Error("matchLimitOrder.ExecTransfer", "addr", a.fromaddr, "execaddr", a.execaddr, "amount", a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error())
} return nil, err
logs = append(logs, receipt.Logs...) }
kvs = append(kvs, receipt.KV...) logs = append(logs, receipt.Logs...)
//将达成交易的相应资产结算 kvs = append(kvs, receipt.KV...)
receipt, err = rightAccountDB.ExecTransfer(a.fromaddr, matchorder.Addr, a.execaddr, a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice())) }
if err != nil { if payload.Op == et.OpBuy {
elog.Error("matchLimitOrder.ExecTransfer", "addr", a.fromaddr, "execaddr", a.execaddr, "amount", a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error()) //转移冻结资产
return nil, err receipt, err := leftAccountDB.ExecTransferFrozen(matchorder.Addr, a.fromaddr, a.execaddr, a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()))
} if err != nil {
logs = append(logs, receipt.Logs...) elog.Error("matchLimitOrder.ExecTransferFrozen", "addr", matchorder.Addr, "execaddr", a.execaddr, "amount", a.calcActualCost(matchorder.GetLimitOrder().Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error())
kvs = append(kvs, receipt.KV...) return nil, err
}
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
//将达成交易的相应资产结算
receipt, err = rightAccountDB.ExecTransfer(a.fromaddr, matchorder.Addr, a.execaddr, a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()))
if err != nil {
elog.Error("matchLimitOrder.ExecTransfer", "addr", a.fromaddr, "execaddr", a.execaddr, "amount", a.calcActualCost(payload.Op, matchorder.GetBalance(), payload.GetPrice()), "err", err.Error())
return nil, err
} }
logs = append(logs, receipt.Logs...)
kvs = append(kvs, receipt.KV...)
//涉及赋值先后顺序,不可颠倒 //涉及赋值先后顺序,不可颠倒
or.Balance = or.Balance - matchorder.Balance or.Balance = or.Balance - matchorder.Balance
......
...@@ -229,7 +229,6 @@ func (e *exchange) updateIndex(receipt *exchangetypes.ReceiptExchange) (kvs []*t ...@@ -229,7 +229,6 @@ func (e *exchange) updateIndex(receipt *exchangetypes.ReceiptExchange) (kvs []*t
func OpSwap(op int32) int32 { func OpSwap(op int32) int32 {
if op == exchangetypes.OpBuy { if op == exchangetypes.OpBuy {
return exchangetypes.OpSell return exchangetypes.OpSell
} else {
return exchangetypes.OpBuy
} }
return exchangetypes.OpBuy
} }
...@@ -96,28 +96,28 @@ func InitExecutor(cfg *types.Chain33Config) { ...@@ -96,28 +96,28 @@ func InitExecutor(cfg *types.Chain33Config) {
types.RegistorExecutor(ExchangeX, NewType(cfg)) types.RegistorExecutor(ExchangeX, NewType(cfg))
} }
type exchangeType struct { type ExchangeType struct {
types.ExecTypeBase types.ExecTypeBase
} }
func NewType(cfg *types.Chain33Config) *exchangeType { func NewType(cfg *types.Chain33Config) *ExchangeType {
c := &exchangeType{} c := &ExchangeType{}
c.SetChild(c) c.SetChild(c)
c.SetConfig(cfg) c.SetConfig(cfg)
return c return c
} }
// GetPayload 获取合约action结构 // GetPayload 获取合约action结构
func (e *exchangeType) GetPayload() types.Message { func (e *ExchangeType) GetPayload() types.Message {
return &ExchangeAction{} return &ExchangeAction{}
} }
// GeTypeMap 获取合约action的id和name信息 // GeTypeMap 获取合约action的id和name信息
func (e *exchangeType) GetTypeMap() map[string]int32 { func (e *ExchangeType) GetTypeMap() map[string]int32 {
return actionMap return actionMap
} }
// GetLogMap 获取合约log相关信息 // GetLogMap 获取合约log相关信息
func (e *exchangeType) GetLogMap() map[int64]*types.LogInfo { func (e *ExchangeType) GetLogMap() map[int64]*types.LogInfo {
return logMap return logMap
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment