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
57954618
Unverified
Commit
57954618
authored
Nov 20, 2018
by
33cn
Committed by
GitHub
Nov 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #30 from zhengjunhe/fix_golint_warnings_for_trade
解决trade合约的golint告警问题
parents
870bb008
4e8c0667
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
120 additions
and
163 deletions
+120
-163
Makefile
plugin/dapp/relay/cmd/Makefile
+0
-0
trade.go
plugin/dapp/trade/commands/trade.go
+17
-16
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
-0
util.go
plugin/dapp/trade/executor/util.go
+3
-3
jrpc.go
plugin/dapp/trade/rpc/jrpc.go
+18
-12
rpc.go
plugin/dapp/trade/rpc/rpc.go
+12
-6
types.go
plugin/dapp/trade/rpc/types.go
+6
-2
const.go
plugin/dapp/trade/types/const.go
+6
-1
errors.go
plugin/dapp/trade/types/errors.go
+15
-0
rpctrade.go
plugin/dapp/trade/types/rpctrade.go
+4
-3
trade.go
plugin/dapp/trade/types/trade.go
+15
-104
trade_test.go
plugin/dapp/trade/types/trade_test.go
+3
-3
tx.go
plugin/dapp/trade/types/tx.go
+6
-0
No files found.
plugin/dapp/relay/cmd/Makefile
View file @
57954618
plugin/dapp/trade/commands/trade.go
View file @
57954618
...
...
@@ -16,6 +16,7 @@ import (
"github.com/spf13/cobra"
)
// TradeCmd : cmd related to trade,安装trade合约相关命令
func
TradeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"trade"
,
...
...
@@ -42,7 +43,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 +82,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 +123,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 +178,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 +202,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 +239,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 +279,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 +334,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 +358,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 +408,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 +434,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 +486,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 +522,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 @
57954618
...
...
@@ -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 @
57954618
...
...
@@ -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 @
57954618
...
...
@@ -35,10 +35,12 @@ func init() {
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 @
57954618
...
...
@@ -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 @
57954618
...
...
@@ -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,7 +30,7 @@ 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
}
...
...
@@ -37,7 +38,8 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
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,7 +48,7 @@ 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
}
...
...
@@ -54,7 +56,8 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
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,7 +65,7 @@ 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
}
...
...
@@ -70,7 +73,8 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
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,7 +87,7 @@ 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
}
...
...
@@ -91,7 +95,8 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
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,7 +105,7 @@ 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
}
...
...
@@ -108,7 +113,8 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
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 +122,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 @
57954618
...
...
@@ -11,7 +11,8 @@ import (
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
}
...
...
@@ -27,7 +28,8 @@ func (this *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.
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
}
...
...
@@ -43,7 +45,8 @@ func (this *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.T
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
}
...
...
@@ -59,7 +62,8 @@ func (this *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptype
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
}
...
...
@@ -75,7 +79,8 @@ func (this *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *pty
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
}
...
...
@@ -91,7 +96,8 @@ func (this *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *p
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 @
57954618
...
...
@@ -14,14 +14,17 @@ 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
}
...
...
@@ -29,8 +32,9 @@ func Init(name string, s rpctypes.RPCServer) {
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 @
57954618
...
...
@@ -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
...
...
@@ -37,6 +37,7 @@ const (
TradeOrderStatusBuyRevoked
)
//SellOrderStatus : sell order status map
var
SellOrderStatus
=
map
[
int32
]
string
{
TradeOrderStatusNotStart
:
"NotStart"
,
TradeOrderStatusOnSale
:
"OnSale"
,
...
...
@@ -48,6 +49,7 @@ var SellOrderStatus = map[int32]string{
TradeOrderStatusBuyRevoked
:
"BuyRevoked"
,
}
//SellOrderStatus2Int : SellOrderStatus info to value in int32
var
SellOrderStatus2Int
=
map
[
string
]
int32
{
"NotStart"
:
TradeOrderStatusNotStart
,
"OnSale"
:
TradeOrderStatusOnSale
,
...
...
@@ -59,12 +61,14 @@ var SellOrderStatus2Int = map[string]int32{
"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 +76,6 @@ var MapBuyOrderStatusStr2Int = map[string]int32{
}
const
(
//InvalidStartTime :
InvalidStartTime
=
0
)
plugin/dapp/trade/types/errors.go
View file @
57954618
...
...
@@ -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 @
57954618
...
...
@@ -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"`
...
...
@@ -28,7 +28,8 @@ type RpcReplyTradeOrder struct {
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 @
57954618
...
...
@@ -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,18 @@ 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
(
trade
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 +93,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 +111,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
...
...
@@ -166,6 +168,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
...
...
@@ -188,6 +191,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
...
...
@@ -200,6 +204,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
...
...
@@ -213,6 +218,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
...
...
@@ -232,6 +238,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
...
...
@@ -244,6 +251,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
...
...
@@ -256,100 +264,3 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
// log
type
TradeSellLimitLog
struct
{
}
func
(
l
TradeSellLimitLog
)
Name
()
string
{
return
"LogTradeSell"
}
func
(
l
TradeSellLimitLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeSellLimit
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
TradeSellMarketLog
struct
{
}
func
(
l
TradeSellMarketLog
)
Name
()
string
{
return
"LogTradeSellMarket"
}
func
(
l
TradeSellMarketLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptSellMarket
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
TradeBuyMarketLog
struct
{
}
func
(
l
TradeBuyMarketLog
)
Name
()
string
{
return
"LogTradeBuyMarket"
}
func
(
l
TradeBuyMarketLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyMarket
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
TradeBuyLimitLog
struct
{
}
func
(
l
TradeBuyLimitLog
)
Name
()
string
{
return
"LogTradeBuyLimit"
}
func
(
l
TradeBuyLimitLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyLimit
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
TradeBuyRevokeLog
struct
{
}
func
(
l
TradeBuyRevokeLog
)
Name
()
string
{
return
"LogTradeBuyRevoke"
}
func
(
l
TradeBuyRevokeLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeBuyRevoke
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
type
TradeSellRevokeLog
struct
{
}
func
(
l
TradeSellRevokeLog
)
Name
()
string
{
return
"LogTradeSellRevoke"
}
func
(
l
TradeSellRevokeLog
)
Decode
(
msg
[]
byte
)
(
interface
{},
error
)
{
var
logTmp
ReceiptTradeSellRevoke
err
:=
types
.
Decode
(
msg
,
&
logTmp
)
if
err
!=
nil
{
return
nil
,
err
}
return
logTmp
,
err
}
plugin/dapp/trade/types/trade_test.go
View file @
57954618
...
...
@@ -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 @
57954618
...
...
@@ -4,6 +4,7 @@
package
types
//TradeSellTx : info for sell order
type
TradeSellTx
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
...
...
@@ -14,17 +15,20 @@ type TradeSellTx struct {
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"`
...
...
@@ -35,12 +39,14 @@ type TradeBuyLimitTx struct {
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