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
e2b9a8ab
Commit
e2b9a8ab
authored
Nov 19, 2018
by
hezhengjun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix golint warnings for trade
parent
eacf28fd
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
138 additions
and
120 deletions
+138
-120
Makefile
plugin/dapp/relay/cmd/Makefile
+0
-0
trade.go
plugin/dapp/trade/commands/trade.go
+17
-17
types.go
plugin/dapp/trade/commands/types.go
+7
-7
kv.go
plugin/dapp/trade/executor/kv.go
+6
-6
trade.go
plugin/dapp/trade/executor/trade.go
+2
-2
util.go
plugin/dapp/trade/executor/util.go
+3
-3
jrpc.go
plugin/dapp/trade/rpc/jrpc.go
+18
-17
rpc.go
plugin/dapp/trade/rpc/rpc.go
+12
-12
types.go
plugin/dapp/trade/rpc/types.go
+6
-6
const.go
plugin/dapp/trade/types/const.go
+6
-5
errors.go
plugin/dapp/trade/types/errors.go
+15
-0
rpctrade.go
plugin/dapp/trade/types/rpctrade.go
+4
-4
trade.go
plugin/dapp/trade/types/trade.go
+33
-32
trade_test.go
plugin/dapp/trade/types/trade_test.go
+3
-3
tx.go
plugin/dapp/trade/types/tx.go
+6
-6
No files found.
plugin/dapp/relay/cmd/Makefile
View file @
e2b9a8ab
plugin/dapp/trade/commands/trade.go
View file @
e2b9a8ab
...
...
@@ -15,7 +15,7 @@ import (
pty
"github.com/33cn/plugin/plugin/dapp/trade/types"
"github.com/spf13/cobra"
)
// TradeCmd : cmd related to trade,安装trade合约相关命令
func
TradeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"trade"
,
...
...
@@ -42,7 +42,7 @@ func TradeCmd() *cobra.Command {
return
cmd
}
// show one's sell order
//
ShowOnesSellOrdersCmd :
show one's sell order
func
ShowOnesSellOrdersCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"sell_order"
,
...
...
@@ -81,7 +81,7 @@ func showOnesSellOrders(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
// show one's sell order with status
//
ShowOnesSellOrdersStatusCmd :
show one's sell order with status
func
ShowOnesSellOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_sell_order"
,
...
...
@@ -122,7 +122,7 @@ func showOnesSellOrdersStatus(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
// show token sell order with status
//
ShowTokenSellOrdersStatusCmd :
show token sell order with status
func
ShowTokenSellOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_token_sell_order"
,
...
...
@@ -177,9 +177,9 @@ func showTokenSellOrdersStatus(cmd *cobra.Command, args []string) {
func
parseSellOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplySellOrdersResult
var
result
r
eplySellOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
...
...
@@ -201,7 +201,7 @@ func parseSellOrders(arg interface{}) (interface{}, error) {
return
result
,
nil
}
// show one's buy order
//
ShowOnesBuyOrderCmd :
show one's buy order
func
ShowOnesBuyOrderCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"buy_order"
,
...
...
@@ -238,7 +238,7 @@ func showOnesBuyOrders(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
// show one's buy order with status
//
ShowOnesBuyOrdersStatusCmd :
show one's buy order with status
func
ShowOnesBuyOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_buy_order"
,
...
...
@@ -278,7 +278,7 @@ func showOnesBuyOrdersStatus(cmd *cobra.Command, args []string) {
ctx
.
Run
()
}
// show token buy order with status
//
ShowTokenBuyOrdersStatusCmd :
show token buy order with status
func
ShowTokenBuyOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_token_buy_order"
,
...
...
@@ -333,9 +333,9 @@ func showTokenBuyOrdersStatus(cmd *cobra.Command, args []string) {
func
parseBuyOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplyBuyOrdersResult
var
result
r
eplyBuyOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
...
...
@@ -357,7 +357,7 @@ func parseBuyOrders(arg interface{}) (interface{}, error) {
return
result
,
nil
}
//
//
ShowOnesOrdersStatusCmd : show one's order with status specified
func
ShowOnesOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_order"
,
...
...
@@ -407,9 +407,9 @@ func showOnesOrdersStatus(cmd *cobra.Command, args []string) {
func
parseTradeOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplyTradeOrdersResult
var
result
r
eplyTradeOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
...
...
@@ -433,7 +433,7 @@ func parseTradeOrders(arg interface{}) (interface{}, error) {
/************* create trade transactions *************/
// create raw sell token transaction
//
CreateRawTradeSellTxCmd :
create raw sell token transaction
func
CreateRawTradeSellTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"sell"
,
...
...
@@ -485,7 +485,7 @@ func tokenSell(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
}
// create raw buy token transaction
//
CreateRawTradeBuyTxCmd :
create raw buy token transaction
func
CreateRawTradeBuyTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"buy"
,
...
...
@@ -521,7 +521,7 @@ func tokenBuy(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
}
// create raw revoke token transaction
//
CreateRawTradeRevokeTxCmd :
create raw revoke token transaction
func
CreateRawTradeRevokeTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"revoke"
,
...
...
plugin/dapp/trade/commands/types.go
View file @
e2b9a8ab
...
...
@@ -4,7 +4,7 @@
package
commands
type
T
radeOrderResult
struct
{
type
t
radeOrderResult
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
Owner
string
`json:"owner"`
AmountPerBoardlot
string
`json:"amountPerBoardlot"`
...
...
@@ -22,14 +22,14 @@ type TradeOrderResult struct {
IsSellOrder
bool
`json:"isSellOrder"`
}
type
R
eplySellOrdersResult
struct
{
SellOrders
[]
*
T
radeOrderResult
`json:"sellOrders"`
type
r
eplySellOrdersResult
struct
{
SellOrders
[]
*
t
radeOrderResult
`json:"sellOrders"`
}
type
R
eplyBuyOrdersResult
struct
{
BuyOrders
[]
*
T
radeOrderResult
`json:"buyOrders"`
type
r
eplyBuyOrdersResult
struct
{
BuyOrders
[]
*
t
radeOrderResult
`json:"buyOrders"`
}
type
R
eplyTradeOrdersResult
struct
{
Orders
[]
*
T
radeOrderResult
`json:"orders"`
type
r
eplyTradeOrdersResult
struct
{
Orders
[]
*
t
radeOrderResult
`json:"orders"`
}
plugin/dapp/trade/executor/kv.go
View file @
e2b9a8ab
...
...
@@ -155,15 +155,15 @@ func calcOnesOrderPrefixStatus(addr string, status int32) []byte {
func
genBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
keyI
d
:=
receipt
.
TxHash
keyI
D
:=
receipt
.
TxHash
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
d
,
height
)
newkey
:=
calcTokenBuyOrderKey
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
D
,
height
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
d
)
newkey
=
calcOnesBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
D
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
d
)
newkey
=
calcOnesBuyOrderKeyToken
(
receipt
.
TokenSymbol
,
receipt
.
Owner
,
status
,
keyI
D
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
...
...
@@ -179,11 +179,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
price
:=
calcPriceOfToken
(
priceBoardlotInt64
,
AmountPerBoardlotInt64
)
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyI
d
)
price
,
receipt
.
Owner
,
keyI
D
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
st
,
ty
:=
fromStatus
(
status
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyI
d
)
newkey
=
calcOnesOrderKey
(
receipt
.
Owner
,
st
,
ty
,
height
,
keyI
D
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
return
kv
...
...
plugin/dapp/trade/executor/trade.go
View file @
e2b9a8ab
...
...
@@ -34,11 +34,11 @@ func init() {
ety
:=
types
.
LoadExecutorType
(
driverName
)
ety
.
InitFuncList
(
types
.
ListMethod
(
&
trade
{}))
}
// Init : 注册当前trade合约
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newTrade
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
// GetName : 获取trade合约名字
func
GetName
()
string
{
return
newTrade
()
.
GetName
()
}
...
...
plugin/dapp/trade/executor/util.go
View file @
e2b9a8ab
...
...
@@ -26,7 +26,7 @@ import (
*/
// return exec, symbol
//
GetExecSymbol :
return exec, symbol
func
GetExecSymbol
(
order
*
pt
.
SellOrder
)
(
string
,
string
)
{
if
order
.
AssetExec
==
""
{
return
defaultAssetExec
,
defaultAssetExec
+
"."
+
order
.
TokenSymbol
...
...
@@ -50,7 +50,7 @@ func checkAsset(height int64, exec, symbol string) bool {
func
createAccountDB
(
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
"ForkTradeAsset"
)
{
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
}
else
{
return
account
.
NewAccountDB
(
defaultAssetExec
,
symbol
,
db
)
}
return
account
.
NewAccountDB
(
defaultAssetExec
,
symbol
,
db
)
}
plugin/dapp/trade/rpc/jrpc.go
View file @
e2b9a8ab
...
...
@@ -13,7 +13,8 @@ import (
ptypes
"github.com/33cn/plugin/plugin/dapp/trade/types"
)
func
(
this
*
Jrpc
)
CreateRawTradeSellTx
(
in
*
ptypes
.
TradeSellTx
,
result
*
interface
{})
error
{
//CreateRawTradeSellTx : 创建出售token的未签名交易
func
(
jrpc
*
Jrpc
)
CreateRawTradeSellTx
(
in
*
ptypes
.
TradeSellTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -29,15 +30,15 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
AssetExec
:
in
.
AssetExec
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeSellTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeSellTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
func
(
this
*
Jrpc
)
CreateRawTradeBuyTx
(
in
*
ptypes
.
TradeBuyTx
,
result
*
interface
{})
error
{
//CreateRawTradeBuyTx : 创建购买token的未签名交易,向指定卖单发起购买
func
(
jrpc
*
Jrpc
)
CreateRawTradeBuyTx
(
in
*
ptypes
.
TradeBuyTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -46,15 +47,15 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
BoardlotCnt
:
in
.
BoardlotCnt
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeBuyTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeBuyTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
func
(
this
*
Jrpc
)
CreateRawTradeRevokeTx
(
in
*
ptypes
.
TradeRevokeTx
,
result
*
interface
{})
error
{
//CreateRawTradeRevokeTx : 取消指定卖单
func
(
jrpc
*
Jrpc
)
CreateRawTradeRevokeTx
(
in
*
ptypes
.
TradeRevokeTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -62,15 +63,15 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
SellID
:
in
.
SellID
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeRevokeTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeRevokeTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
func
(
this
*
Jrpc
)
CreateRawTradeBuyLimitTx
(
in
*
ptypes
.
TradeBuyLimitTx
,
result
*
interface
{})
error
{
//CreateRawTradeBuyLimitTx : 挂买单购买token
func
(
jrpc
*
Jrpc
)
CreateRawTradeBuyLimitTx
(
in
*
ptypes
.
TradeBuyLimitTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -83,15 +84,15 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
AssetExec
:
in
.
AssetExec
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeBuyLimitTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeBuyLimitTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
func
(
this
*
Jrpc
)
CreateRawTradeSellMarketTx
(
in
*
ptypes
.
TradeSellMarketTx
,
result
*
interface
{})
error
{
//CreateRawTradeSellMarketTx : 向指定买单出售token
func
(
jrpc
*
Jrpc
)
CreateRawTradeSellMarketTx
(
in
*
ptypes
.
TradeSellMarketTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -100,15 +101,15 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
BoardlotCnt
:
in
.
BoardlotCnt
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeSellMarketTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeSellMarketTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
*
result
=
hex
.
EncodeToString
(
reply
.
Data
)
return
nil
}
func
(
this
*
Jrpc
)
CreateRawTradeRevokeBuyTx
(
in
*
ptypes
.
TradeRevokeBuyTx
,
result
*
interface
{})
error
{
//CreateRawTradeRevokeBuyTx : 取消指定买单
func
(
jrpc
*
Jrpc
)
CreateRawTradeRevokeBuyTx
(
in
*
ptypes
.
TradeRevokeBuyTx
,
result
*
interface
{})
error
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
}
...
...
@@ -116,7 +117,7 @@ func (this *Jrpc) CreateRawTradeRevokeBuyTx(in *ptypes.TradeRevokeBuyTx, result
BuyID
:
in
.
BuyID
,
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeRevokeBuyTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeRevokeBuyTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/trade/rpc/rpc.go
View file @
e2b9a8ab
...
...
@@ -10,8 +10,8 @@ import (
"github.com/33cn/chain33/types"
ptypes
"github.com/33cn/plugin/plugin/dapp/trade/types"
)
func
(
this
*
channelClient
)
CreateRawTradeSellTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForSell
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeSellTx :
func
(
cc
*
channelClient
)
CreateRawTradeSellTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForSell
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -26,8 +26,8 @@ func (this *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
this
*
channelClient
)
CreateRawTradeBuyTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForBuy
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeBuyTx :
func
(
cc
*
channelClient
)
CreateRawTradeBuyTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForBuy
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -42,8 +42,8 @@ func (this *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.T
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
this
*
channelClient
)
CreateRawTradeRevokeTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForRevokeSell
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeRevokeTx :
func
(
cc
*
channelClient
)
CreateRawTradeRevokeTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForRevokeSell
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -58,8 +58,8 @@ func (this *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptype
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
this
*
channelClient
)
CreateRawTradeBuyLimitTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForBuyLimit
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeBuyLimitTx :
func
(
cc
*
channelClient
)
CreateRawTradeBuyLimitTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForBuyLimit
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -74,8 +74,8 @@ func (this *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *pty
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
this
*
channelClient
)
CreateRawTradeSellMarketTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForSellMarket
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeSellMarketTx :
func
(
cc
*
channelClient
)
CreateRawTradeSellMarketTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForSellMarket
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
@@ -90,8 +90,8 @@ func (this *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *p
data
:=
types
.
Encode
(
tx
)
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
}
func
(
this
*
channelClient
)
CreateRawTradeRevokeBuyTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForRevokeBuy
)
(
*
types
.
UnsignTx
,
error
)
{
//CreateRawTradeRevokeBuyTx :
func
(
cc
*
channelClient
)
CreateRawTradeRevokeBuyTx
(
ctx
context
.
Context
,
in
*
ptypes
.
TradeForRevokeBuy
)
(
*
types
.
UnsignTx
,
error
)
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
}
...
...
plugin/dapp/trade/rpc/types.go
View file @
e2b9a8ab
...
...
@@ -13,24 +13,24 @@ import (
type
channelClient
struct
{
rpctypes
.
ChannelClient
}
//Jrpc : Jrpc struct definition
type
Jrpc
struct
{
cli
*
channelClient
}
//Grpc : Grpc struct definition
type
Grpc
struct
{
*
channelClient
}
//Init : do the init operation
func
Init
(
name
string
,
s
rpctypes
.
RPCServer
)
{
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
cli
.
Init
(
name
,
s
,
&
Jrpc
{
cli
:
cli
},
grpc
)
ptypes
.
RegisterTradeServer
(
s
.
GRPC
(),
grpc
)
}
func
(
this
*
Jrpc
)
GetLastMemPool
(
in
types
.
ReqNil
,
result
*
interface
{})
error
{
reply
,
err
:=
this
.
cli
.
GetLastMempool
()
//GetLastMemPool : get the last memory pool
func
(
jrpc
*
Jrpc
)
GetLastMemPool
(
in
types
.
ReqNil
,
result
*
interface
{})
error
{
reply
,
err
:=
jrpc
.
cli
.
GetLastMempool
()
if
err
!=
nil
{
return
err
}
...
...
plugin/dapp/trade/types/const.go
View file @
e2b9a8ab
...
...
@@ -27,7 +27,7 @@ const (
// 0->not start, 1->on sale, 2->sold out, 3->revoke, 4->expired
const
(
TradeOrderStatusNotStart
=
iota
TradeOrderStatusNotStart
=
iota
//TradeOrderStatusNotStart :
TradeOrderStatusOnSale
TradeOrderStatusSoldOut
TradeOrderStatusRevoked
...
...
@@ -36,7 +36,7 @@ const (
TradeOrderStatusBoughtOut
TradeOrderStatusBuyRevoked
)
//SellOrderStatus : sell order status map
var
SellOrderStatus
=
map
[
int32
]
string
{
TradeOrderStatusNotStart
:
"NotStart"
,
TradeOrderStatusOnSale
:
"OnSale"
,
...
...
@@ -47,7 +47,7 @@ var SellOrderStatus = map[int32]string{
TradeOrderStatusBoughtOut
:
"BoughtOut"
,
TradeOrderStatusBuyRevoked
:
"BuyRevoked"
,
}
//SellOrderStatus2Int : SellOrderStatus info to value in int32
var
SellOrderStatus2Int
=
map
[
string
]
int32
{
"NotStart"
:
TradeOrderStatusNotStart
,
"OnSale"
:
TradeOrderStatusOnSale
,
...
...
@@ -58,13 +58,13 @@ var SellOrderStatus2Int = map[string]int32{
"BoughtOut"
:
TradeOrderStatusBoughtOut
,
"BuyRevoked"
:
TradeOrderStatusBuyRevoked
,
}
//MapSellOrderStatusStr2Int :
var
MapSellOrderStatusStr2Int
=
map
[
string
]
int32
{
"onsale"
:
TradeOrderStatusOnSale
,
"soldout"
:
TradeOrderStatusSoldOut
,
"revoked"
:
TradeOrderStatusRevoked
,
}
//MapBuyOrderStatusStr2Int :
var
MapBuyOrderStatusStr2Int
=
map
[
string
]
int32
{
"onbuy"
:
TradeOrderStatusOnBuy
,
"boughtout"
:
TradeOrderStatusBoughtOut
,
...
...
@@ -72,5 +72,6 @@ var MapBuyOrderStatusStr2Int = map[string]int32{
}
const
(
//InvalidStartTime :
InvalidStartTime
=
0
)
plugin/dapp/trade/types/errors.go
View file @
e2b9a8ab
...
...
@@ -7,19 +7,34 @@ package types
import
"errors"
var
(
//ErrTSellBalanceNotEnough :
ErrTSellBalanceNotEnough
=
errors
.
New
(
"ErrTradeSellBalanceNotEnough"
)
//ErrTSellOrderNotExist :
ErrTSellOrderNotExist
=
errors
.
New
(
"ErrTradeSellOrderNotExist"
)
//ErrTSellOrderNotStart :
ErrTSellOrderNotStart
=
errors
.
New
(
"ErrTradeSellOrderNotStart"
)
//ErrTSellOrderNotEnough :
ErrTSellOrderNotEnough
=
errors
.
New
(
"ErrTradeSellOrderNotEnough"
)
//ErrTSellOrderSoldout :
ErrTSellOrderSoldout
=
errors
.
New
(
"ErrTradeSellOrderSoldout"
)
//ErrTSellOrderRevoked :
ErrTSellOrderRevoked
=
errors
.
New
(
"ErrTradeSellOrderRevoked"
)
//ErrTSellOrderExpired :
ErrTSellOrderExpired
=
errors
.
New
(
"ErrTradeSellOrderExpired"
)
//ErrTSellOrderRevoke :
ErrTSellOrderRevoke
=
errors
.
New
(
"ErrTradeSellOrderRevokeNotAllowed"
)
//ErrTSellNoSuchOrder :
ErrTSellNoSuchOrder
=
errors
.
New
(
"ErrTradeSellNoSuchOrder"
)
//ErrTBuyOrderNotExist :
ErrTBuyOrderNotExist
=
errors
.
New
(
"ErrTradeBuyOrderNotExist"
)
//ErrTBuyOrderNotEnough :
ErrTBuyOrderNotEnough
=
errors
.
New
(
"ErrTradeBuyOrderNotEnough"
)
//ErrTBuyOrderSoldout :
ErrTBuyOrderSoldout
=
errors
.
New
(
"ErrTradeBuyOrderSoldout"
)
//ErrTBuyOrderRevoked :
ErrTBuyOrderRevoked
=
errors
.
New
(
"ErrTradeBuyOrderRevoked"
)
//ErrTBuyOrderRevoke :
ErrTBuyOrderRevoke
=
errors
.
New
(
"ErrTradeBuyOrderRevokeNotAllowed"
)
//ErrTCntLessThanMinBoardlot :
ErrTCntLessThanMinBoardlot
=
errors
.
New
(
"ErrTradeCountLessThanMinBoardlot"
)
)
plugin/dapp/trade/types/rpctrade.go
View file @
e2b9a8ab
...
...
@@ -8,8 +8,8 @@ import (
"encoding/json"
)
// trade order
type
R
pc
ReplyTradeOrder
struct
{
//
RPCReplyTradeOrder :
trade order
type
R
PC
ReplyTradeOrder
struct
{
TokenSymbol
string
`protobuf:"bytes,1,opt,name=tokenSymbol" json:"tokenSymbol"`
Owner
string
`protobuf:"bytes,2,opt,name=owner" json:"owner"`
AmountPerBoardlot
int64
`protobuf:"varint,3,opt,name=amountPerBoardlot" json:"amountPerBoardlot"`
...
...
@@ -27,8 +27,8 @@ type RpcReplyTradeOrder struct {
IsSellOrder
bool
`protobuf:"varint,15,opt,name=isSellOrder" json:"isSellOrder"`
AssetExec
string
`protobuf:"bytes,16,opt,name=assetExec" json:"assetExec"`
}
//MarshalJSON :
func
(
reply
*
ReplyTradeOrder
)
MarshalJSON
()
([]
byte
,
error
)
{
r
:=
(
*
R
pc
ReplyTradeOrder
)(
reply
)
r
:=
(
*
R
PC
ReplyTradeOrder
)(
reply
)
return
json
.
Marshal
(
r
)
}
plugin/dapp/trade/types/trade.go
View file @
e2b9a8ab
...
...
@@ -13,6 +13,7 @@ import (
)
var
(
//TradeX :
TradeX
=
"trade"
tlog
=
log
.
New
(
"module"
,
TradeX
)
...
...
@@ -43,13 +44,13 @@ func (t *tradeType) GetTypeMap() map[string]int32 {
return
actionName
}
func
(
a
t
*
tradeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
func
(
t
*
tradeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
logInfo
}
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TradeX
))
types
.
RegistorExecutor
(
TradeX
,
N
ewType
())
types
.
RegistorExecutor
(
TradeX
,
n
ewType
())
types
.
RegisterDappFork
(
TradeX
,
"Enable"
,
100899
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeBuyLimit"
,
301000
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeAsset"
,
1010000
)
...
...
@@ -59,17 +60,17 @@ type tradeType struct {
types
.
ExecTypeBase
}
func
N
ewType
()
*
tradeType
{
func
n
ewType
()
*
tradeType
{
c
:=
&
tradeType
{}
c
.
SetChild
(
c
)
return
c
}
func
(
a
t
*
tradeType
)
GetPayload
()
types
.
Message
{
func
(
t
*
tradeType
)
GetPayload
()
types
.
Message
{
return
&
Trade
{}
}
func
(
t
rade
tradeType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
//ActionName :
func
(
t
*
tradeType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
var
action
Trade
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
if
err
!=
nil
{
...
...
@@ -91,7 +92,7 @@ func (trade tradeType) ActionName(tx *types.Transaction) string {
return
"unknown"
}
func
(
t
tradeType
)
Amount
(
tx
*
types
.
Transaction
)
(
int64
,
error
)
{
func
(
t
*
tradeType
)
Amount
(
tx
*
types
.
Transaction
)
(
int64
,
error
)
{
//TODO: 补充和完善token和trade分支的amount的计算, added by hzj
var
trade
Trade
err
:=
types
.
Decode
(
tx
.
GetPayload
(),
&
trade
)
...
...
@@ -109,7 +110,7 @@ func (t tradeType) Amount(tx *types.Transaction) (int64, error) {
return
0
,
nil
}
func
(
t
rade
tradeType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
func
(
t
*
tradeType
)
CreateTx
(
action
string
,
message
json
.
RawMessage
)
(
*
types
.
Transaction
,
error
)
{
var
tx
*
types
.
Transaction
if
action
==
"TradeSellLimit"
{
var
param
TradeSellTx
...
...
@@ -165,7 +166,7 @@ func (trade tradeType) CreateTx(action string, message json.RawMessage) (*types.
return
tx
,
nil
}
//CreateRawTradeSellTx : 创建卖单交易
func
CreateRawTradeSellTx
(
parm
*
TradeSellTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -187,7 +188,7 @@ func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sell
))
}
//CreateRawTradeBuyTx :创建想指定卖单发起的买单交易
func
CreateRawTradeBuyTx
(
parm
*
TradeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -199,7 +200,7 @@ func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
//CreateRawTradeRevokeTx :创建取消卖单的交易
func
CreateRawTradeRevokeTx
(
parm
*
TradeRevokeTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -212,7 +213,7 @@ func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
//CreateRawTradeBuyLimitTx :创建买单交易
func
CreateRawTradeBuyLimitTx
(
parm
*
TradeBuyLimitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -231,7 +232,7 @@ func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error)
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buyLimit
))
}
//CreateRawTradeSellMarketTx : 创建向指定买单出售token的卖单交易
func
CreateRawTradeSellMarketTx
(
parm
*
TradeSellMarketTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -243,7 +244,7 @@ func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, er
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sellMarket
))
}
//CreateRawTradeRevokeBuyTx : 取消发起的买单交易
func
CreateRawTradeRevokeBuyTx
(
parm
*
TradeRevokeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
...
...
@@ -257,14 +258,14 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
//
log
//
TradeSellLimitLog :
type
TradeSellLimitLog
struct
{
}
//Name : get name string of TradeSellLimitLog
func
(
l
TradeSellLimitLog
)
Name
()
string
{
return
"LogTradeSell"
}
//Decode : decode the log
func
(
l
TradeSellLimitLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeSellLimit
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
@@ -273,14 +274,14 @@ func (l TradeSellLimitLog) Decode(msg []byte) (interface{}, error) {
}
return
logTmp
,
err
}
//TradeSellMarketLog :
type
TradeSellMarketLog
struct
{
}
//Name :
func
(
l
TradeSellMarketLog
)
Name
()
string
{
return
"LogTradeSellMarket"
}
//Decode :
func
(
l
TradeSellMarketLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptSellMarket
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
@@ -289,14 +290,14 @@ func (l TradeSellMarketLog) Decode(msg []byte) (interface{}, error) {
}
return
logTmp
,
err
}
//TradeBuyMarketLog :
type
TradeBuyMarketLog
struct
{
}
//Name :
func
(
l
TradeBuyMarketLog
)
Name
()
string
{
return
"LogTradeBuyMarket"
}
//Decode :
func
(
l
TradeBuyMarketLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyMarket
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
@@ -305,14 +306,14 @@ func (l TradeBuyMarketLog) Decode(msg []byte) (interface{}, error) {
}
return
logTmp
,
err
}
//TradeBuyLimitLog :
type
TradeBuyLimitLog
struct
{
}
//Name :
func
(
l
TradeBuyLimitLog
)
Name
()
string
{
return
"LogTradeBuyLimit"
}
//Decode :
func
(
l
TradeBuyLimitLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyLimit
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
@@ -321,14 +322,14 @@ func (l TradeBuyLimitLog) Decode(msg []byte) (interface{}, error) {
}
return
logTmp
,
err
}
//TradeBuyRevokeLog :
type
TradeBuyRevokeLog
struct
{
}
//Name :
func
(
l
TradeBuyRevokeLog
)
Name
()
string
{
return
"LogTradeBuyRevoke"
}
//Decode :
func
(
l
TradeBuyRevokeLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyRevoke
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
@@ -337,14 +338,14 @@ func (l TradeBuyRevokeLog) Decode(msg []byte) (interface{}, error) {
}
return
logTmp
,
err
}
//TradeSellRevokeLog :
type
TradeSellRevokeLog
struct
{
}
//Name :
func
(
l
TradeSellRevokeLog
)
Name
()
string
{
return
"LogTradeSellRevoke"
}
//Decode :
func
(
l
TradeSellRevokeLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeSellRevoke
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
...
...
plugin/dapp/trade/types/trade_test.go
View file @
e2b9a8ab
...
...
@@ -11,19 +11,19 @@ import (
)
func
TestTradeType_GetName
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
assert
.
Equal
(
t
,
TradeX
,
tp
.
GetName
())
}
func
TestTradeType_GetTypeMap
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
actoins
:=
tp
.
GetTypeMap
()
assert
.
NotNil
(
t
,
actoins
)
assert
.
NotEqual
(
t
,
0
,
len
(
actoins
))
}
func
TestTradeType_GetLogMap
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
l
:=
tp
.
GetLogMap
()
assert
.
NotNil
(
t
,
l
)
assert
.
NotEqual
(
t
,
0
,
len
(
l
))
...
...
plugin/dapp/trade/types/tx.go
View file @
e2b9a8ab
...
...
@@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
package
types
//TradeSellTx : info for sell order
type
TradeSellTx
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
...
...
@@ -13,18 +13,18 @@ type TradeSellTx struct {
Fee
int64
`json:"fee"`
AssetExec
string
`json:"assetExec"`
}
//TradeBuyTx :info for buy order to speficied order
type
TradeBuyTx
struct
{
SellID
string
`json:"sellID"`
BoardlotCnt
int64
`json:"boardlotCnt"`
Fee
int64
`json:"fee"`
}
//TradeRevokeTx :用于取消卖单的信息
type
TradeRevokeTx
struct
{
SellID
string
`json:"sellID,"`
Fee
int64
`json:"fee"`
}
//TradeBuyLimitTx :用于挂买单的信息
type
TradeBuyLimitTx
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
...
...
@@ -34,13 +34,13 @@ type TradeBuyLimitTx struct {
Fee
int64
`json:"fee"`
AssetExec
string
`json:"assetExec"`
}
//TradeSellMarketTx :用于向指定买单出售token的信息
type
TradeSellMarketTx
struct
{
BuyID
string
`json:"buyID"`
BoardlotCnt
int64
`json:"boardlotCnt"`
Fee
int64
`json:"fee"`
}
//TradeRevokeBuyTx :取消指定买单
type
TradeRevokeBuyTx
struct
{
BuyID
string
`json:"buyID,"`
Fee
int64
`json:"fee"`
...
...
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