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
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
135 additions
and
179 deletions
+135
-179
Makefile
plugin/dapp/relay/cmd/Makefile
+1
-2
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
+29
-14
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
all
:
all
:
chmod
+x ./build.sh
chmod
+x ./build.sh
./build.sh
$(OUT)
$(FLAG)
./build.sh
$(OUT)
$(FLAG)
\ No newline at end of file
plugin/dapp/trade/commands/trade.go
View file @
57954618
...
@@ -16,6 +16,7 @@ import (
...
@@ -16,6 +16,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra"
)
)
// TradeCmd : cmd related to trade,安装trade合约相关命令
func
TradeCmd
()
*
cobra
.
Command
{
func
TradeCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"trade"
,
Use
:
"trade"
,
...
@@ -42,7 +43,7 @@ func TradeCmd() *cobra.Command {
...
@@ -42,7 +43,7 @@ func TradeCmd() *cobra.Command {
return
cmd
return
cmd
}
}
// show one's sell order
//
ShowOnesSellOrdersCmd :
show one's sell order
func
ShowOnesSellOrdersCmd
()
*
cobra
.
Command
{
func
ShowOnesSellOrdersCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"sell_order"
,
Use
:
"sell_order"
,
...
@@ -81,7 +82,7 @@ func showOnesSellOrders(cmd *cobra.Command, args []string) {
...
@@ -81,7 +82,7 @@ func showOnesSellOrders(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// show one's sell order with status
//
ShowOnesSellOrdersStatusCmd :
show one's sell order with status
func
ShowOnesSellOrdersStatusCmd
()
*
cobra
.
Command
{
func
ShowOnesSellOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_sell_order"
,
Use
:
"status_sell_order"
,
...
@@ -122,7 +123,7 @@ func showOnesSellOrdersStatus(cmd *cobra.Command, args []string) {
...
@@ -122,7 +123,7 @@ func showOnesSellOrdersStatus(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// show token sell order with status
//
ShowTokenSellOrdersStatusCmd :
show token sell order with status
func
ShowTokenSellOrdersStatusCmd
()
*
cobra
.
Command
{
func
ShowTokenSellOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_token_sell_order"
,
Use
:
"status_token_sell_order"
,
...
@@ -177,9 +178,9 @@ func showTokenSellOrdersStatus(cmd *cobra.Command, args []string) {
...
@@ -177,9 +178,9 @@ func showTokenSellOrdersStatus(cmd *cobra.Command, args []string) {
func
parseSellOrders
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseSellOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplySellOrdersResult
var
result
r
eplySellOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
BuyID
:
o
.
BuyID
,
...
@@ -201,7 +202,7 @@ func parseSellOrders(arg interface{}) (interface{}, error) {
...
@@ -201,7 +202,7 @@ func parseSellOrders(arg interface{}) (interface{}, error) {
return
result
,
nil
return
result
,
nil
}
}
// show one's buy order
//
ShowOnesBuyOrderCmd :
show one's buy order
func
ShowOnesBuyOrderCmd
()
*
cobra
.
Command
{
func
ShowOnesBuyOrderCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"buy_order"
,
Use
:
"buy_order"
,
...
@@ -238,7 +239,7 @@ func showOnesBuyOrders(cmd *cobra.Command, args []string) {
...
@@ -238,7 +239,7 @@ func showOnesBuyOrders(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// show one's buy order with status
//
ShowOnesBuyOrdersStatusCmd :
show one's buy order with status
func
ShowOnesBuyOrdersStatusCmd
()
*
cobra
.
Command
{
func
ShowOnesBuyOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_buy_order"
,
Use
:
"status_buy_order"
,
...
@@ -278,7 +279,7 @@ func showOnesBuyOrdersStatus(cmd *cobra.Command, args []string) {
...
@@ -278,7 +279,7 @@ func showOnesBuyOrdersStatus(cmd *cobra.Command, args []string) {
ctx
.
Run
()
ctx
.
Run
()
}
}
// show token buy order with status
//
ShowTokenBuyOrdersStatusCmd :
show token buy order with status
func
ShowTokenBuyOrdersStatusCmd
()
*
cobra
.
Command
{
func
ShowTokenBuyOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_token_buy_order"
,
Use
:
"status_token_buy_order"
,
...
@@ -333,9 +334,9 @@ func showTokenBuyOrdersStatus(cmd *cobra.Command, args []string) {
...
@@ -333,9 +334,9 @@ func showTokenBuyOrdersStatus(cmd *cobra.Command, args []string) {
func
parseBuyOrders
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseBuyOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplyBuyOrdersResult
var
result
r
eplyBuyOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
BuyID
:
o
.
BuyID
,
...
@@ -357,7 +358,7 @@ func parseBuyOrders(arg interface{}) (interface{}, error) {
...
@@ -357,7 +358,7 @@ func parseBuyOrders(arg interface{}) (interface{}, error) {
return
result
,
nil
return
result
,
nil
}
}
//
//
ShowOnesOrdersStatusCmd : show one's order with status specified
func
ShowOnesOrdersStatusCmd
()
*
cobra
.
Command
{
func
ShowOnesOrdersStatusCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"status_order"
,
Use
:
"status_order"
,
...
@@ -407,9 +408,9 @@ func showOnesOrdersStatus(cmd *cobra.Command, args []string) {
...
@@ -407,9 +408,9 @@ func showOnesOrdersStatus(cmd *cobra.Command, args []string) {
func
parseTradeOrders
(
arg
interface
{})
(
interface
{},
error
)
{
func
parseTradeOrders
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
res
:=
arg
.
(
*
pty
.
ReplyTradeOrders
)
var
result
R
eplyTradeOrdersResult
var
result
r
eplyTradeOrdersResult
for
_
,
o
:=
range
res
.
Orders
{
for
_
,
o
:=
range
res
.
Orders
{
order
:=
&
T
radeOrderResult
{
order
:=
&
t
radeOrderResult
{
TokenSymbol
:
o
.
TokenSymbol
,
TokenSymbol
:
o
.
TokenSymbol
,
Owner
:
o
.
Owner
,
Owner
:
o
.
Owner
,
BuyID
:
o
.
BuyID
,
BuyID
:
o
.
BuyID
,
...
@@ -433,7 +434,7 @@ func parseTradeOrders(arg interface{}) (interface{}, error) {
...
@@ -433,7 +434,7 @@ func parseTradeOrders(arg interface{}) (interface{}, error) {
/************* create trade transactions *************/
/************* create trade transactions *************/
// create raw sell token transaction
//
CreateRawTradeSellTxCmd :
create raw sell token transaction
func
CreateRawTradeSellTxCmd
()
*
cobra
.
Command
{
func
CreateRawTradeSellTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"sell"
,
Use
:
"sell"
,
...
@@ -485,7 +486,7 @@ func tokenSell(cmd *cobra.Command, args []string) {
...
@@ -485,7 +486,7 @@ func tokenSell(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
ctx
.
RunWithoutMarshal
()
}
}
// create raw buy token transaction
//
CreateRawTradeBuyTxCmd :
create raw buy token transaction
func
CreateRawTradeBuyTxCmd
()
*
cobra
.
Command
{
func
CreateRawTradeBuyTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"buy"
,
Use
:
"buy"
,
...
@@ -521,7 +522,7 @@ func tokenBuy(cmd *cobra.Command, args []string) {
...
@@ -521,7 +522,7 @@ func tokenBuy(cmd *cobra.Command, args []string) {
ctx
.
RunWithoutMarshal
()
ctx
.
RunWithoutMarshal
()
}
}
// create raw revoke token transaction
//
CreateRawTradeRevokeTxCmd :
create raw revoke token transaction
func
CreateRawTradeRevokeTxCmd
()
*
cobra
.
Command
{
func
CreateRawTradeRevokeTxCmd
()
*
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
cmd
:=
&
cobra
.
Command
{
Use
:
"revoke"
,
Use
:
"revoke"
,
...
...
plugin/dapp/trade/commands/types.go
View file @
57954618
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
package
commands
package
commands
type
T
radeOrderResult
struct
{
type
t
radeOrderResult
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
TokenSymbol
string
`json:"tokenSymbol"`
Owner
string
`json:"owner"`
Owner
string
`json:"owner"`
AmountPerBoardlot
string
`json:"amountPerBoardlot"`
AmountPerBoardlot
string
`json:"amountPerBoardlot"`
...
@@ -22,14 +22,14 @@ type TradeOrderResult struct {
...
@@ -22,14 +22,14 @@ type TradeOrderResult struct {
IsSellOrder
bool
`json:"isSellOrder"`
IsSellOrder
bool
`json:"isSellOrder"`
}
}
type
R
eplySellOrdersResult
struct
{
type
r
eplySellOrdersResult
struct
{
SellOrders
[]
*
T
radeOrderResult
`json:"sellOrders"`
SellOrders
[]
*
t
radeOrderResult
`json:"sellOrders"`
}
}
type
R
eplyBuyOrdersResult
struct
{
type
r
eplyBuyOrdersResult
struct
{
BuyOrders
[]
*
T
radeOrderResult
`json:"buyOrders"`
BuyOrders
[]
*
t
radeOrderResult
`json:"buyOrders"`
}
}
type
R
eplyTradeOrdersResult
struct
{
type
r
eplyTradeOrdersResult
struct
{
Orders
[]
*
T
radeOrderResult
`json:"orders"`
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 {
...
@@ -155,15 +155,15 @@ func calcOnesOrderPrefixStatus(addr string, status int32) []byte {
func
genBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
func
genBuyMarketOrderKeyValue
(
kv
[]
*
types
.
KeyValue
,
receipt
*
pty
.
ReceiptBuyBase
,
status
int32
,
height
int64
,
value
[]
byte
)
[]
*
types
.
KeyValue
{
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
})
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
})
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
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
priceBoardlot
,
err
:=
strconv
.
ParseFloat
(
receipt
.
PricePerBoardlot
,
64
)
...
@@ -179,11 +179,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
...
@@ -179,11 +179,11 @@ func genBuyMarketOrderKeyValue(kv []*types.KeyValue, receipt *pty.ReceiptBuyBase
price
:=
calcPriceOfToken
(
priceBoardlotInt64
,
AmountPerBoardlotInt64
)
price
:=
calcPriceOfToken
(
priceBoardlotInt64
,
AmountPerBoardlotInt64
)
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
newkey
=
calcTokensBuyOrderKeyStatus
(
receipt
.
TokenSymbol
,
status
,
price
,
receipt
.
Owner
,
keyI
d
)
price
,
receipt
.
Owner
,
keyI
D
)
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
st
,
ty
:=
fromStatus
(
status
)
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
})
kv
=
append
(
kv
,
&
types
.
KeyValue
{
newkey
,
value
})
return
kv
return
kv
...
...
plugin/dapp/trade/executor/trade.go
View file @
57954618
...
@@ -35,10 +35,12 @@ func init() {
...
@@ -35,10 +35,12 @@ func init() {
ety
.
InitFuncList
(
types
.
ListMethod
(
&
trade
{}))
ety
.
InitFuncList
(
types
.
ListMethod
(
&
trade
{}))
}
}
// Init : 注册当前trade合约
func
Init
(
name
string
,
sub
[]
byte
)
{
func
Init
(
name
string
,
sub
[]
byte
)
{
drivers
.
Register
(
GetName
(),
newTrade
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
GetName
(),
newTrade
,
types
.
GetDappFork
(
driverName
,
"Enable"
))
}
}
// GetName : 获取trade合约名字
func
GetName
()
string
{
func
GetName
()
string
{
return
newTrade
()
.
GetName
()
return
newTrade
()
.
GetName
()
}
}
...
...
plugin/dapp/trade/executor/util.go
View file @
57954618
...
@@ -26,7 +26,7 @@ import (
...
@@ -26,7 +26,7 @@ import (
*/
*/
// return exec, symbol
//
GetExecSymbol :
return exec, symbol
func
GetExecSymbol
(
order
*
pt
.
SellOrder
)
(
string
,
string
)
{
func
GetExecSymbol
(
order
*
pt
.
SellOrder
)
(
string
,
string
)
{
if
order
.
AssetExec
==
""
{
if
order
.
AssetExec
==
""
{
return
defaultAssetExec
,
defaultAssetExec
+
"."
+
order
.
TokenSymbol
return
defaultAssetExec
,
defaultAssetExec
+
"."
+
order
.
TokenSymbol
...
@@ -50,7 +50,7 @@ func checkAsset(height int64, exec, symbol string) bool {
...
@@ -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
)
{
func
createAccountDB
(
height
int64
,
db
db
.
KV
,
exec
,
symbol
string
)
(
*
account
.
DB
,
error
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
"ForkTradeAsset"
)
{
if
types
.
IsDappFork
(
height
,
pt
.
TradeX
,
"ForkTradeAsset"
)
{
return
account
.
NewAccountDB
(
exec
,
symbol
,
db
)
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 (
...
@@ -13,7 +13,8 @@ import (
ptypes
"github.com/33cn/plugin/plugin/dapp/trade/types"
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -29,7 +30,7 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
...
@@ -29,7 +30,7 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
AssetExec
:
in
.
AssetExec
,
AssetExec
:
in
.
AssetExec
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeSellTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeSellTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -37,7 +38,8 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
...
@@ -37,7 +38,8 @@ func (this *Jrpc) CreateRawTradeSellTx(in *ptypes.TradeSellTx, result *interface
return
nil
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -46,7 +48,7 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
...
@@ -46,7 +48,7 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
BoardlotCnt
:
in
.
BoardlotCnt
,
BoardlotCnt
:
in
.
BoardlotCnt
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeBuyTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeBuyTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -54,7 +56,8 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
...
@@ -54,7 +56,8 @@ func (this *Jrpc) CreateRawTradeBuyTx(in *ptypes.TradeBuyTx, result *interface{}
return
nil
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -62,7 +65,7 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
...
@@ -62,7 +65,7 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
SellID
:
in
.
SellID
,
SellID
:
in
.
SellID
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeRevokeTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeRevokeTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -70,7 +73,8 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
...
@@ -70,7 +73,8 @@ func (this *Jrpc) CreateRawTradeRevokeTx(in *ptypes.TradeRevokeTx, result *inter
return
nil
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -83,7 +87,7 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
...
@@ -83,7 +87,7 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
AssetExec
:
in
.
AssetExec
,
AssetExec
:
in
.
AssetExec
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeBuyLimitTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeBuyLimitTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -91,7 +95,8 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
...
@@ -91,7 +95,8 @@ func (this *Jrpc) CreateRawTradeBuyLimitTx(in *ptypes.TradeBuyLimitTx, result *i
return
nil
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -100,7 +105,7 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
...
@@ -100,7 +105,7 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
BoardlotCnt
:
in
.
BoardlotCnt
,
BoardlotCnt
:
in
.
BoardlotCnt
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeSellMarketTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeSellMarketTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -108,7 +113,8 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
...
@@ -108,7 +113,8 @@ func (this *Jrpc) CreateRawTradeSellMarketTx(in *ptypes.TradeSellMarketTx, resul
return
nil
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
{
if
in
==
nil
{
return
types
.
ErrInvalidParam
return
types
.
ErrInvalidParam
}
}
...
@@ -116,7 +122,7 @@ func (this *Jrpc) CreateRawTradeRevokeBuyTx(in *ptypes.TradeRevokeBuyTx, result
...
@@ -116,7 +122,7 @@ func (this *Jrpc) CreateRawTradeRevokeBuyTx(in *ptypes.TradeRevokeBuyTx, result
BuyID
:
in
.
BuyID
,
BuyID
:
in
.
BuyID
,
}
}
reply
,
err
:=
this
.
cli
.
CreateRawTradeRevokeBuyTx
(
context
.
Background
(),
param
)
reply
,
err
:=
jrpc
.
cli
.
CreateRawTradeRevokeBuyTx
(
context
.
Background
(),
param
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/dapp/trade/rpc/rpc.go
View file @
57954618
...
@@ -11,7 +11,8 @@ import (
...
@@ -11,7 +11,8 @@ import (
ptypes
"github.com/33cn/plugin/plugin/dapp/trade/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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -27,7 +28,8 @@ func (this *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.
...
@@ -27,7 +28,8 @@ func (this *channelClient) CreateRawTradeSellTx(ctx context.Context, in *ptypes.
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -43,7 +45,8 @@ func (this *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.T
...
@@ -43,7 +45,8 @@ func (this *channelClient) CreateRawTradeBuyTx(ctx context.Context, in *ptypes.T
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -59,7 +62,8 @@ func (this *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptype
...
@@ -59,7 +62,8 @@ func (this *channelClient) CreateRawTradeRevokeTx(ctx context.Context, in *ptype
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -75,7 +79,8 @@ func (this *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *pty
...
@@ -75,7 +79,8 @@ func (this *channelClient) CreateRawTradeBuyLimitTx(ctx context.Context, in *pty
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
@@ -91,7 +96,8 @@ func (this *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *p
...
@@ -91,7 +96,8 @@ func (this *channelClient) CreateRawTradeSellMarketTx(ctx context.Context, in *p
return
&
types
.
UnsignTx
{
Data
:
data
},
nil
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
{
if
in
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
}
}
...
...
plugin/dapp/trade/rpc/types.go
View file @
57954618
...
@@ -14,14 +14,17 @@ type channelClient struct {
...
@@ -14,14 +14,17 @@ type channelClient struct {
rpctypes
.
ChannelClient
rpctypes
.
ChannelClient
}
}
//Jrpc : Jrpc struct definition
type
Jrpc
struct
{
type
Jrpc
struct
{
cli
*
channelClient
cli
*
channelClient
}
}
//Grpc : Grpc struct definition
type
Grpc
struct
{
type
Grpc
struct
{
*
channelClient
*
channelClient
}
}
//Init : do the init operation
func
Init
(
name
string
,
s
rpctypes
.
RPCServer
)
{
func
Init
(
name
string
,
s
rpctypes
.
RPCServer
)
{
cli
:=
&
channelClient
{}
cli
:=
&
channelClient
{}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
grpc
:=
&
Grpc
{
channelClient
:
cli
}
...
@@ -29,8 +32,9 @@ func Init(name string, s rpctypes.RPCServer) {
...
@@ -29,8 +32,9 @@ func Init(name string, s rpctypes.RPCServer) {
ptypes
.
RegisterTradeServer
(
s
.
GRPC
(),
grpc
)
ptypes
.
RegisterTradeServer
(
s
.
GRPC
(),
grpc
)
}
}
func
(
this
*
Jrpc
)
GetLastMemPool
(
in
types
.
ReqNil
,
result
*
interface
{})
error
{
//GetLastMemPool : get the last memory pool
reply
,
err
:=
this
.
cli
.
GetLastMempool
()
func
(
jrpc
*
Jrpc
)
GetLastMemPool
(
in
types
.
ReqNil
,
result
*
interface
{})
error
{
reply
,
err
:=
jrpc
.
cli
.
GetLastMempool
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
plugin/dapp/trade/types/const.go
View file @
57954618
...
@@ -27,7 +27,7 @@ const (
...
@@ -27,7 +27,7 @@ const (
// 0->not start, 1->on sale, 2->sold out, 3->revoke, 4->expired
// 0->not start, 1->on sale, 2->sold out, 3->revoke, 4->expired
const
(
const
(
TradeOrderStatusNotStart
=
iota
TradeOrderStatusNotStart
=
iota
//TradeOrderStatusNotStart :
TradeOrderStatusOnSale
TradeOrderStatusOnSale
TradeOrderStatusSoldOut
TradeOrderStatusSoldOut
TradeOrderStatusRevoked
TradeOrderStatusRevoked
...
@@ -37,6 +37,7 @@ const (
...
@@ -37,6 +37,7 @@ const (
TradeOrderStatusBuyRevoked
TradeOrderStatusBuyRevoked
)
)
//SellOrderStatus : sell order status map
var
SellOrderStatus
=
map
[
int32
]
string
{
var
SellOrderStatus
=
map
[
int32
]
string
{
TradeOrderStatusNotStart
:
"NotStart"
,
TradeOrderStatusNotStart
:
"NotStart"
,
TradeOrderStatusOnSale
:
"OnSale"
,
TradeOrderStatusOnSale
:
"OnSale"
,
...
@@ -48,6 +49,7 @@ var SellOrderStatus = map[int32]string{
...
@@ -48,6 +49,7 @@ var SellOrderStatus = map[int32]string{
TradeOrderStatusBuyRevoked
:
"BuyRevoked"
,
TradeOrderStatusBuyRevoked
:
"BuyRevoked"
,
}
}
//SellOrderStatus2Int : SellOrderStatus info to value in int32
var
SellOrderStatus2Int
=
map
[
string
]
int32
{
var
SellOrderStatus2Int
=
map
[
string
]
int32
{
"NotStart"
:
TradeOrderStatusNotStart
,
"NotStart"
:
TradeOrderStatusNotStart
,
"OnSale"
:
TradeOrderStatusOnSale
,
"OnSale"
:
TradeOrderStatusOnSale
,
...
@@ -59,12 +61,14 @@ var SellOrderStatus2Int = map[string]int32{
...
@@ -59,12 +61,14 @@ var SellOrderStatus2Int = map[string]int32{
"BuyRevoked"
:
TradeOrderStatusBuyRevoked
,
"BuyRevoked"
:
TradeOrderStatusBuyRevoked
,
}
}
//MapSellOrderStatusStr2Int :
var
MapSellOrderStatusStr2Int
=
map
[
string
]
int32
{
var
MapSellOrderStatusStr2Int
=
map
[
string
]
int32
{
"onsale"
:
TradeOrderStatusOnSale
,
"onsale"
:
TradeOrderStatusOnSale
,
"soldout"
:
TradeOrderStatusSoldOut
,
"soldout"
:
TradeOrderStatusSoldOut
,
"revoked"
:
TradeOrderStatusRevoked
,
"revoked"
:
TradeOrderStatusRevoked
,
}
}
//MapBuyOrderStatusStr2Int :
var
MapBuyOrderStatusStr2Int
=
map
[
string
]
int32
{
var
MapBuyOrderStatusStr2Int
=
map
[
string
]
int32
{
"onbuy"
:
TradeOrderStatusOnBuy
,
"onbuy"
:
TradeOrderStatusOnBuy
,
"boughtout"
:
TradeOrderStatusBoughtOut
,
"boughtout"
:
TradeOrderStatusBoughtOut
,
...
@@ -72,5 +76,6 @@ var MapBuyOrderStatusStr2Int = map[string]int32{
...
@@ -72,5 +76,6 @@ var MapBuyOrderStatusStr2Int = map[string]int32{
}
}
const
(
const
(
//InvalidStartTime :
InvalidStartTime
=
0
InvalidStartTime
=
0
)
)
plugin/dapp/trade/types/errors.go
View file @
57954618
...
@@ -7,19 +7,34 @@ package types
...
@@ -7,19 +7,34 @@ package types
import
"errors"
import
"errors"
var
(
var
(
ErrTSellBalanceNotEnough
=
errors
.
New
(
"ErrTradeSellBalanceNotEnough"
)
//ErrTSellBalanceNotEnough :
ErrTSellOrderNotExist
=
errors
.
New
(
"ErrTradeSellOrderNotExist"
)
ErrTSellBalanceNotEnough
=
errors
.
New
(
"ErrTradeSellBalanceNotEnough"
)
ErrTSellOrderNotStart
=
errors
.
New
(
"ErrTradeSellOrderNotStart"
)
//ErrTSellOrderNotExist :
ErrTSellOrderNotEnough
=
errors
.
New
(
"ErrTradeSellOrderNotEnough"
)
ErrTSellOrderNotExist
=
errors
.
New
(
"ErrTradeSellOrderNotExist"
)
ErrTSellOrderSoldout
=
errors
.
New
(
"ErrTradeSellOrderSoldout"
)
//ErrTSellOrderNotStart :
ErrTSellOrderRevoked
=
errors
.
New
(
"ErrTradeSellOrderRevoked"
)
ErrTSellOrderNotStart
=
errors
.
New
(
"ErrTradeSellOrderNotStart"
)
ErrTSellOrderExpired
=
errors
.
New
(
"ErrTradeSellOrderExpired"
)
//ErrTSellOrderNotEnough :
ErrTSellOrderRevoke
=
errors
.
New
(
"ErrTradeSellOrderRevokeNotAllowed"
)
ErrTSellOrderNotEnough
=
errors
.
New
(
"ErrTradeSellOrderNotEnough"
)
ErrTSellNoSuchOrder
=
errors
.
New
(
"ErrTradeSellNoSuchOrder"
)
//ErrTSellOrderSoldout :
ErrTBuyOrderNotExist
=
errors
.
New
(
"ErrTradeBuyOrderNotExist"
)
ErrTSellOrderSoldout
=
errors
.
New
(
"ErrTradeSellOrderSoldout"
)
ErrTBuyOrderNotEnough
=
errors
.
New
(
"ErrTradeBuyOrderNotEnough"
)
//ErrTSellOrderRevoked :
ErrTBuyOrderSoldout
=
errors
.
New
(
"ErrTradeBuyOrderSoldout"
)
ErrTSellOrderRevoked
=
errors
.
New
(
"ErrTradeSellOrderRevoked"
)
ErrTBuyOrderRevoked
=
errors
.
New
(
"ErrTradeBuyOrderRevoked"
)
//ErrTSellOrderExpired :
ErrTBuyOrderRevoke
=
errors
.
New
(
"ErrTradeBuyOrderRevokeNotAllowed"
)
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"
)
ErrTCntLessThanMinBoardlot
=
errors
.
New
(
"ErrTradeCountLessThanMinBoardlot"
)
)
)
plugin/dapp/trade/types/rpctrade.go
View file @
57954618
...
@@ -8,8 +8,8 @@ import (
...
@@ -8,8 +8,8 @@ import (
"encoding/json"
"encoding/json"
)
)
// trade order
//
RPCReplyTradeOrder :
trade order
type
R
pc
ReplyTradeOrder
struct
{
type
R
PC
ReplyTradeOrder
struct
{
TokenSymbol
string
`protobuf:"bytes,1,opt,name=tokenSymbol" json:"tokenSymbol"`
TokenSymbol
string
`protobuf:"bytes,1,opt,name=tokenSymbol" json:"tokenSymbol"`
Owner
string
`protobuf:"bytes,2,opt,name=owner" json:"owner"`
Owner
string
`protobuf:"bytes,2,opt,name=owner" json:"owner"`
AmountPerBoardlot
int64
`protobuf:"varint,3,opt,name=amountPerBoardlot" json:"amountPerBoardlot"`
AmountPerBoardlot
int64
`protobuf:"varint,3,opt,name=amountPerBoardlot" json:"amountPerBoardlot"`
...
@@ -28,7 +28,8 @@ type RpcReplyTradeOrder struct {
...
@@ -28,7 +28,8 @@ type RpcReplyTradeOrder struct {
AssetExec
string
`protobuf:"bytes,16,opt,name=assetExec" json:"assetExec"`
AssetExec
string
`protobuf:"bytes,16,opt,name=assetExec" json:"assetExec"`
}
}
//MarshalJSON :
func
(
reply
*
ReplyTradeOrder
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
reply
*
ReplyTradeOrder
)
MarshalJSON
()
([]
byte
,
error
)
{
r
:=
(
*
R
pc
ReplyTradeOrder
)(
reply
)
r
:=
(
*
R
PC
ReplyTradeOrder
)(
reply
)
return
json
.
Marshal
(
r
)
return
json
.
Marshal
(
r
)
}
}
plugin/dapp/trade/types/trade.go
View file @
57954618
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
)
)
var
(
var
(
//TradeX :
TradeX
=
"trade"
TradeX
=
"trade"
tlog
=
log
.
New
(
"module"
,
TradeX
)
tlog
=
log
.
New
(
"module"
,
TradeX
)
...
@@ -43,13 +44,13 @@ func (t *tradeType) GetTypeMap() map[string]int32 {
...
@@ -43,13 +44,13 @@ func (t *tradeType) GetTypeMap() map[string]int32 {
return
actionName
return
actionName
}
}
func
(
a
t
*
tradeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
func
(
t
*
tradeType
)
GetLogMap
()
map
[
int64
]
*
types
.
LogInfo
{
return
logInfo
return
logInfo
}
}
func
init
()
{
func
init
()
{
types
.
AllowUserExec
=
append
(
types
.
AllowUserExec
,
[]
byte
(
TradeX
))
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
,
"Enable"
,
100899
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeBuyLimit"
,
301000
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeBuyLimit"
,
301000
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeAsset"
,
1010000
)
types
.
RegisterDappFork
(
TradeX
,
"ForkTradeAsset"
,
1010000
)
...
@@ -59,17 +60,18 @@ type tradeType struct {
...
@@ -59,17 +60,18 @@ type tradeType struct {
types
.
ExecTypeBase
types
.
ExecTypeBase
}
}
func
N
ewType
()
*
tradeType
{
func
n
ewType
()
*
tradeType
{
c
:=
&
tradeType
{}
c
:=
&
tradeType
{}
c
.
SetChild
(
c
)
c
.
SetChild
(
c
)
return
c
return
c
}
}
func
(
a
t
*
tradeType
)
GetPayload
()
types
.
Message
{
func
(
t
*
tradeType
)
GetPayload
()
types
.
Message
{
return
&
Trade
{}
return
&
Trade
{}
}
}
func
(
trade
tradeType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
//ActionName :
func
(
t
*
tradeType
)
ActionName
(
tx
*
types
.
Transaction
)
string
{
var
action
Trade
var
action
Trade
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
err
:=
types
.
Decode
(
tx
.
Payload
,
&
action
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -91,7 +93,7 @@ func (trade tradeType) ActionName(tx *types.Transaction) string {
...
@@ -91,7 +93,7 @@ func (trade tradeType) ActionName(tx *types.Transaction) string {
return
"unknown"
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
//TODO: 补充和完善token和trade分支的amount的计算, added by hzj
var
trade
Trade
var
trade
Trade
err
:=
types
.
Decode
(
tx
.
GetPayload
(),
&
trade
)
err
:=
types
.
Decode
(
tx
.
GetPayload
(),
&
trade
)
...
@@ -109,7 +111,7 @@ func (t tradeType) Amount(tx *types.Transaction) (int64, error) {
...
@@ -109,7 +111,7 @@ func (t tradeType) Amount(tx *types.Transaction) (int64, error) {
return
0
,
nil
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
var
tx
*
types
.
Transaction
if
action
==
"TradeSellLimit"
{
if
action
==
"TradeSellLimit"
{
var
param
TradeSellTx
var
param
TradeSellTx
...
@@ -166,6 +168,7 @@ func (trade tradeType) CreateTx(action string, message json.RawMessage) (*types.
...
@@ -166,6 +168,7 @@ func (trade tradeType) CreateTx(action string, message json.RawMessage) (*types.
return
tx
,
nil
return
tx
,
nil
}
}
//CreateRawTradeSellTx : 创建卖单交易
func
CreateRawTradeSellTx
(
parm
*
TradeSellTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeSellTx
(
parm
*
TradeSellTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -188,6 +191,7 @@ func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
...
@@ -188,6 +191,7 @@ func CreateRawTradeSellTx(parm *TradeSellTx) (*types.Transaction, error) {
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sell
))
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sell
))
}
}
//CreateRawTradeBuyTx :创建想指定卖单发起的买单交易
func
CreateRawTradeBuyTx
(
parm
*
TradeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeBuyTx
(
parm
*
TradeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -200,6 +204,7 @@ func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
...
@@ -200,6 +204,7 @@ func CreateRawTradeBuyTx(parm *TradeBuyTx) (*types.Transaction, error) {
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
}
//CreateRawTradeRevokeTx :创建取消卖单的交易
func
CreateRawTradeRevokeTx
(
parm
*
TradeRevokeTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeRevokeTx
(
parm
*
TradeRevokeTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -213,6 +218,7 @@ func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
...
@@ -213,6 +218,7 @@ func CreateRawTradeRevokeTx(parm *TradeRevokeTx) (*types.Transaction, error) {
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
}
}
//CreateRawTradeBuyLimitTx :创建买单交易
func
CreateRawTradeBuyLimitTx
(
parm
*
TradeBuyLimitTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeBuyLimitTx
(
parm
*
TradeBuyLimitTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -232,6 +238,7 @@ func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error)
...
@@ -232,6 +238,7 @@ func CreateRawTradeBuyLimitTx(parm *TradeBuyLimitTx) (*types.Transaction, error)
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buyLimit
))
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buyLimit
))
}
}
//CreateRawTradeSellMarketTx : 创建向指定买单出售token的卖单交易
func
CreateRawTradeSellMarketTx
(
parm
*
TradeSellMarketTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeSellMarketTx
(
parm
*
TradeSellMarketTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -244,6 +251,7 @@ func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, er
...
@@ -244,6 +251,7 @@ func CreateRawTradeSellMarketTx(parm *TradeSellMarketTx) (*types.Transaction, er
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sellMarket
))
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
sellMarket
))
}
}
//CreateRawTradeRevokeBuyTx : 取消发起的买单交易
func
CreateRawTradeRevokeBuyTx
(
parm
*
TradeRevokeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
func
CreateRawTradeRevokeBuyTx
(
parm
*
TradeRevokeBuyTx
)
(
*
types
.
Transaction
,
error
)
{
if
parm
==
nil
{
if
parm
==
nil
{
return
nil
,
types
.
ErrInvalidParam
return
nil
,
types
.
ErrInvalidParam
...
@@ -256,100 +264,3 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
...
@@ -256,100 +264,3 @@ func CreateRawTradeRevokeBuyTx(parm *TradeRevokeBuyTx) (*types.Transaction, erro
}
}
return
types
.
CreateFormatTx
(
types
.
ExecName
(
TradeX
),
types
.
Encode
(
buy
))
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 (
...
@@ -11,19 +11,19 @@ import (
)
)
func
TestTradeType_GetName
(
t
*
testing
.
T
)
{
func
TestTradeType_GetName
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
assert
.
Equal
(
t
,
TradeX
,
tp
.
GetName
())
assert
.
Equal
(
t
,
TradeX
,
tp
.
GetName
())
}
}
func
TestTradeType_GetTypeMap
(
t
*
testing
.
T
)
{
func
TestTradeType_GetTypeMap
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
actoins
:=
tp
.
GetTypeMap
()
actoins
:=
tp
.
GetTypeMap
()
assert
.
NotNil
(
t
,
actoins
)
assert
.
NotNil
(
t
,
actoins
)
assert
.
NotEqual
(
t
,
0
,
len
(
actoins
))
assert
.
NotEqual
(
t
,
0
,
len
(
actoins
))
}
}
func
TestTradeType_GetLogMap
(
t
*
testing
.
T
)
{
func
TestTradeType_GetLogMap
(
t
*
testing
.
T
)
{
tp
:=
N
ewType
()
tp
:=
n
ewType
()
l
:=
tp
.
GetLogMap
()
l
:=
tp
.
GetLogMap
()
assert
.
NotNil
(
t
,
l
)
assert
.
NotNil
(
t
,
l
)
assert
.
NotEqual
(
t
,
0
,
len
(
l
))
assert
.
NotEqual
(
t
,
0
,
len
(
l
))
...
...
plugin/dapp/trade/types/tx.go
View file @
57954618
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
package
types
package
types
//TradeSellTx : info for sell order
type
TradeSellTx
struct
{
type
TradeSellTx
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
TokenSymbol
string
`json:"tokenSymbol"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
...
@@ -14,17 +15,20 @@ type TradeSellTx struct {
...
@@ -14,17 +15,20 @@ type TradeSellTx struct {
AssetExec
string
`json:"assetExec"`
AssetExec
string
`json:"assetExec"`
}
}
//TradeBuyTx :info for buy order to speficied order
type
TradeBuyTx
struct
{
type
TradeBuyTx
struct
{
SellID
string
`json:"sellID"`
SellID
string
`json:"sellID"`
BoardlotCnt
int64
`json:"boardlotCnt"`
BoardlotCnt
int64
`json:"boardlotCnt"`
Fee
int64
`json:"fee"`
Fee
int64
`json:"fee"`
}
}
//TradeRevokeTx :用于取消卖单的信息
type
TradeRevokeTx
struct
{
type
TradeRevokeTx
struct
{
SellID
string
`json:"sellID,"`
SellID
string
`json:"sellID,"`
Fee
int64
`json:"fee"`
Fee
int64
`json:"fee"`
}
}
//TradeBuyLimitTx :用于挂买单的信息
type
TradeBuyLimitTx
struct
{
type
TradeBuyLimitTx
struct
{
TokenSymbol
string
`json:"tokenSymbol"`
TokenSymbol
string
`json:"tokenSymbol"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
AmountPerBoardlot
int64
`json:"amountPerBoardlot"`
...
@@ -35,12 +39,14 @@ type TradeBuyLimitTx struct {
...
@@ -35,12 +39,14 @@ type TradeBuyLimitTx struct {
AssetExec
string
`json:"assetExec"`
AssetExec
string
`json:"assetExec"`
}
}
//TradeSellMarketTx :用于向指定买单出售token的信息
type
TradeSellMarketTx
struct
{
type
TradeSellMarketTx
struct
{
BuyID
string
`json:"buyID"`
BuyID
string
`json:"buyID"`
BoardlotCnt
int64
`json:"boardlotCnt"`
BoardlotCnt
int64
`json:"boardlotCnt"`
Fee
int64
`json:"fee"`
Fee
int64
`json:"fee"`
}
}
//TradeRevokeBuyTx :取消指定买单
type
TradeRevokeBuyTx
struct
{
type
TradeRevokeBuyTx
struct
{
BuyID
string
`json:"buyID,"`
BuyID
string
`json:"buyID,"`
Fee
int64
`json:"fee"`
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